-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathenv.roc
More file actions
54 lines (40 loc) · 1.51 KB
/
env.roc
File metadata and controls
54 lines (40 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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({})