diff --git a/ci/expect_scripts/env.exp b/ci/expect_scripts/env.exp new file mode 100644 index 00000000..bf4abdca --- /dev/null +++ b/ci/expect_scripts/env.exp @@ -0,0 +1,61 @@ +#!/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 + expect -re {cwd: /[^\r\n]*\r\n} { + + expect -re "Testing Env.exe_path!:" { + # Match exe_path with any valid format + expect -re {exe_path: /[^\r\n]*\r\n} { + + 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 < 1} { + puts stderr "\nExpect script failed: environment variable count is $env_count." + 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: /[^\r\n]*\r\n} { + + expect "All tests executed!" { + expect eof { + check_exit_and_segfault + } + } + } + } + } + } + } + } + } + } + } + } + } +} + +puts stderr "\nExpect script failed: output was different from expected value." +exit 1 \ No newline at end of file diff --git a/flake.lock b/flake.lock index 8d6f2240..6519aa87 100644 --- a/flake.lock +++ b/flake.lock @@ -76,11 +76,11 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1748006407, - "narHash": "sha256-WnN16rdapTl+ml7c/mtqfogosU768JaCG9Nc23be0Mg=", + "lastModified": 1748287595, + "narHash": "sha256-HhHNC+x3kkvByS78ZkZEVLnwT6bC3ROHVYMQaqXNfvA=", "owner": "roc-lang", "repo": "roc", - "rev": "d02adf08a6d81ed0a7191047dcd1ee32070384da", + "rev": "6870af73467ecc7373e045d51d24721826da1968", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index d9a4a997..cd8e9189 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,6 @@ description = "Basic cli devShell flake"; inputs = { - roc.url = "github:roc-lang/roc"; nixpkgs.follows = "roc/nixpkgs"; diff --git a/tests/.gitignore b/tests/.gitignore index ed765fa8..495363d0 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,3 +1,4 @@ sqlite utc -url \ No newline at end of file +url +env \ No newline at end of file diff --git a/tests/env.roc b/tests/env.roc new file mode 100644 index 00000000..964e6f6b --- /dev/null +++ b/tests/env.roc @@ -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: ${Path.display(cwd)}")? + + Stdout.line!("\nTesting Env.exe_path!:")? + exe_path = Env.exe_path!({})? + Stdout.line!("exe_path: ${Path.display(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: ${Path.display(new_cwd)}")? + + Stdout.line!("\nAll tests executed!")? + + Ok({}) \ No newline at end of file