-
Notifications
You must be signed in to change notification settings - Fork 42
test untested env functions #364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #!/usr/bin/expect | ||
|
|
||
| # uncomment line below for debugging | ||
| # exp_internal 1 | ||
|
|
||
| set timeout 7 | ||
|
|
||
| source ./ci/expect_scripts/shared-code.exp | ||
|
|
||
| spawn $env(TESTS_DIR)env | ||
|
|
||
| expect "Testing Env module functions..." { | ||
| expect -re "Testing Env.cwd!:" { | ||
| # Match cwd path that has ArbitraryBytes with non-empty list of integers | ||
| # Use curly braces for the regex pattern to avoid Tcl interpretation of [ and ] | ||
| expect -re {cwd: \(@InternalPath \(ArbitraryBytes \[\d+(, \d+)*\]\)\)} { | ||
|
|
||
| expect -re "Testing Env.exe_path!:" { | ||
| # Match exe_path with any valid format | ||
| expect -re {exe_path: \(@InternalPath \(.*\[\d+(, \d+)*\].*\)\)} { | ||
|
|
||
| expect -re "Testing Env.platform!:" { | ||
| # Match platform info with any arch and OS | ||
| # Literal braces in regex need to be escaped: \{ and \} | ||
| expect -re {Current platform:\{arch: \w+, os: \w+\}} { | ||
|
|
||
| expect -re "Testing Env.dict!:" { | ||
| # Match environment variables count as non-zero number | ||
| expect -re {Environment variables count: (\d+)} { | ||
| set env_count $expect_out(1,string) | ||
| if {$env_count == 0} { | ||
| puts stderr "\nExpect script failed: environment variable count is zero." | ||
| exit 1 | ||
| } | ||
|
|
||
| # Match sample environment variables with non-empty strings | ||
| # Literal brackets [], parentheses (), and quotes "" need escaping or careful handling | ||
| expect -re {Sample environment variables:\[\("\w+", ".*"\)(, \("\w+", ".*"\))*\]} { | ||
|
|
||
| expect -re "Testing Env.set_cwd!:" { | ||
| # Match changed directory path with non-empty list of integers | ||
| expect -re {Changed current directory to: \(@InternalPath \(ArbitraryBytes \[\d+(, \d+)*\]\)\)} { | ||
|
|
||
| expect "All tests executed!" { | ||
| expect eof { | ||
| check_exit_and_segfault | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| puts stderr "\nExpect script failed: output was different from expected value." | ||
| exit 1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| sqlite | ||
| utc | ||
| url | ||
| url | ||
| env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| app [main!] { pf: platform "../platform/main.roc" } | ||
|
|
||
| import pf.Stdout | ||
| import pf.Env | ||
| import pf.Path | ||
| import pf.Arg exposing [Arg] | ||
|
|
||
| main! : List Arg => Result {} _ | ||
| main! = |_args| | ||
| Stdout.line!("Testing Env module functions...")? | ||
|
|
||
| Stdout.line!("\nTesting Env.cwd!:")? | ||
| cwd = Env.cwd!({})? | ||
| Stdout.line!("cwd: ${Inspect.to_str(cwd)}")? | ||
|
|
||
| Stdout.line!("\nTesting Env.exe_path!:")? | ||
| exe_path = Env.exe_path!({})? | ||
| Stdout.line!("exe_path: ${Inspect.to_str(exe_path)}")? | ||
|
|
||
| # Test Env.platform! | ||
| Stdout.line!("\nTesting Env.platform!:")? | ||
| platform = Env.platform!({}) | ||
| Stdout.line!("Current platform:${Inspect.to_str(platform)}")? | ||
|
|
||
| # Test Env.dict! | ||
| Stdout.line!("\nTesting Env.dict!:")? | ||
| env_vars = Env.dict!({}) | ||
| var_count = Dict.len(env_vars) | ||
| Stdout.line!("Environment variables count: ${Num.to_str(var_count)}")? | ||
|
|
||
| some_env_vars = Dict.to_list(env_vars) |> List.take_first(3) | ||
| Stdout.line!("Sample environment variables:${Inspect.to_str(some_env_vars)}")? | ||
|
|
||
| # Test Env.set_cwd! | ||
| Stdout.line!("\nTesting Env.set_cwd!:")? | ||
|
|
||
| # First get the current directory to restore it later | ||
| original_dir = Env.cwd!({})? | ||
| ls_list = Path.list_dir!(original_dir)? | ||
|
|
||
| dir_list = | ||
| ls_list | ||
| |> List.keep_if_try!(|path| Path.is_dir!(path))? | ||
|
|
||
| first_dir = | ||
| List.first(dir_list)? | ||
|
|
||
| Env.set_cwd!(first_dir)? | ||
| new_cwd = Env.cwd!({})? | ||
| Stdout.line!("Changed current directory to: ${Inspect.to_str(new_cwd)}")? | ||
|
|
||
| Stdout.line!("\nAll tests executed!")? | ||
|
|
||
| Ok({}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.