Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions ci/expect_scripts/env.exp
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
7 changes: 4 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

inputs = {

roc.url = "github:roc-lang/roc";
# TODO change this back once that commit is merged
Comment thread
Anton-4 marked this conversation as resolved.
Outdated
roc.url = "github:roc-lang/roc/2e3a32d218f5404f4451cfe9997eaa95e75486cb";

nixpkgs.follows = "roc/nixpkgs";

Expand Down
3 changes: 2 additions & 1 deletion tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sqlite
utc
url
url
env
54 changes: 54 additions & 0 deletions tests/env.roc
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({})
Loading