Skip to content

Commit acdd26f

Browse files
committed
enable+convert more cmd-test.roc
1 parent 3c5aa03 commit acdd26f

3 files changed

Lines changed: 59 additions & 75 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ repository = "https://github.com/roc-lang/basic-cli"
3939

4040
[workspace.dependencies]
4141
# Core Roc types
42-
# roc-nightly: 2026-02-20
43-
roc_std_new = { git = "https://github.com/roc-lang/roc", rev = "c5d87ef595fdc1c8b28dfdb6ebbe5b44ddea966f" }
42+
# roc-nightly: 2026-03-03
43+
roc_std_new = { git = "https://github.com/roc-lang/roc", rev = "3fa8df31997e3e233d5bda63eec8737ccd3ce941" }
4444

4545
# Internal crates
4646
roc_io_error = { path = "crates/roc_io_error" }

tests/cmd-test.roc

Lines changed: 56 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -13,89 +13,73 @@ main! = |_args| {
1313
"Try.Err(FailedToGetExitCode({ command: \"{ cmd: blablaXYZ, args: }\", err: NotFound }))"
1414
)?
1515

16-
# expect_err(
17-
# Cmd.exec!("cat", ["non_existent.txt"]),
18-
# "(Err (ExecFailed {command: \"cat non_existent.txt\", exit_code: 1}))"
19-
# )?
16+
expect_err(
17+
Cmd.exec!("cat", ["non_existent.txt"]),
18+
"Try.Err(ExecFailed({ command: \"cat non_existent.txt\", exit_code: 1 }))"
19+
)?
2020

21-
# # exec_cmd!
22-
# expect_err(
23-
# Cmd.new("blablaXYZ")
24-
# |> Cmd.exec_cmd!,
25-
# "(Err (FailedToGetExitCode {command: \"{ cmd: blablaXYZ, args: }\", err: NotFound}))"
26-
# )?
21+
# exec_cmd!
22+
expect_err(
23+
Cmd.new("blablaXYZ").exec_cmd!(),
24+
"Try.Err(FailedToGetExitCode({ command: \"{ cmd: blablaXYZ, args: }\", err: NotFound }))"
25+
)?
2726

28-
# expect_err(
29-
# Cmd.new("cat")
30-
# |> Cmd.arg("non_existent.txt")
31-
# |> Cmd.exec_cmd!,
32-
# "(Err (ExecCmdFailed {command: \"{ cmd: cat, args: non_existent.txt }\", exit_code: 1}))"
33-
# )?
27+
expect_err(
28+
Cmd.new("cat").arg("non_existent.txt").exec_cmd!(),
29+
"Try.Err(ExecCmdFailed({ command: \"{ cmd: cat, args: non_existent.txt }\", exit_code: 1 }))"
30+
)?
3431

35-
# # exec_output!
36-
# expect_err(
37-
# Cmd.new("blablaXYZ")
38-
# |> Cmd.exec_output!,
39-
# "(Err (FailedToGetExitCode {command: \"{ cmd: blablaXYZ, args: }\", err: NotFound}))"
40-
# )?
32+
# exec_output!
33+
expect_err(
34+
Cmd.new("blablaXYZ").exec_output!(),
35+
"Try.Err(FailedToGetExitCode({ command: \"{ cmd: blablaXYZ, args: }\", err: NotFound }))"
36+
)?
4137

42-
# expect_err(
43-
# Cmd.new("cat")
44-
# |> Cmd.arg("non_existent.txt")
45-
# |> Cmd.exec_output!,
46-
# "(Err (NonZeroExitCode {command: \"{ cmd: cat, args: non_existent.txt }\", exit_code: 1, stderr_utf8_lossy: \"cat: non_existent.txt: No such file or directory\n\", stdout_utf8_lossy: \"\"}))"
47-
# )?
38+
expect_err(
39+
Cmd.new("cat").arg("non_existent.txt").exec_output!(),
40+
"Try.Err(NonZeroExitCode({ command: \"{ cmd: cat, args: non_existent.txt }\", exit_code: 1, stderr_utf8_lossy: \"cat: non_existent.txt: No such file or directory\n\", stdout_utf8_lossy: \"\" }))"
41+
)?
4842

49-
# # Test StdoutContainsInvalidUtf8 - using printf to output invalid UTF-8 bytes
43+
# Test StdoutContainsInvalidUtf8 - blocked by compiler bug
5044
# expect_err(
51-
# Cmd.new("printf")
52-
# |> Cmd.args(["\\377\\376"]) # Invalid UTF-8 sequence
53-
# |> Cmd.exec_output!,
54-
# "(Err (StdoutContainsInvalidUtf8 {cmd_str: \"{ cmd: printf, args: \\377\\376 }\", err: (BadUtf8 {index: 0, problem: InvalidStartByte})}))"
45+
# Cmd.new("printf").args(["\\377\\376"]).exec_output!(),
46+
# "Try.Err(StdoutContainsInvalidUtf8({ cmd_str: \"{ cmd: printf, args: \\377\\376 }\", err: BadUtf8({ index: 0, problem: InvalidStartByte }) }))"
5547
# )?
5648

57-
# # exec_output_bytes!
58-
# expect_err(
59-
# Cmd.new("blablaXYZ")
60-
# |> Cmd.exec_output_bytes!,
61-
# "(Err (FailedToGetExitCodeB NotFound))"
62-
# )?
49+
# exec_output_bytes!
50+
expect_err(
51+
Cmd.new("blablaXYZ").exec_output_bytes!(),
52+
"Try.Err(FailedToGetExitCodeB(NotFound))"
53+
)?
6354

64-
# expect_err(
65-
# Cmd.new("cat")
66-
# |> Cmd.arg("non_existent.txt")
67-
# |> Cmd.exec_output_bytes!,
68-
# "(Err (NonZeroExitCodeB {exit_code: 1, stderr_bytes: [99, 97, 116, 58, 32, 110, 111, 110, 95, 101, 120, 105, 115, 116, 101, 110, 116, 46, 116, 120, 116, 58, 32, 78, 111, 32, 115, 117, 99, 104, 32, 102, 105, 108, 101, 32, 111, 114, 32, 100, 105, 114, 101, 99, 116, 111, 114, 121, 10], stdout_bytes: []}))"
69-
# )?
55+
expect_err(
56+
Cmd.new("cat").arg("non_existent.txt").exec_output_bytes!(),
57+
"Try.Err(NonZeroExitCodeB({ exit_code: 1, stderr_bytes: [99, 97, 116, 58, 32, 110, 111, 110, 95, 101, 120, 105, 115, 116, 101, 110, 116, 46, 116, 120, 116, 58, 32, 78, 111, 32, 115, 117, 99, 104, 32, 102, 105, 108, 101, 32, 111, 114, 32, 100, 105, 114, 101, 99, 116, 111, 114, 121, 10], stdout_bytes: [] }))"
58+
)?
7059

71-
# # exec_exit_code!
72-
# expect_err(
73-
# Cmd.new("blablaXYZ")
74-
# |> Cmd.exec_exit_code!,
75-
# "(Err (FailedToGetExitCode {command: \"{ cmd: blablaXYZ, args: }\", err: NotFound}))"
76-
# )?
60+
# exec_exit_code!
61+
expect_err(
62+
Cmd.new("blablaXYZ").exec_exit_code!(),
63+
"Try.Err(FailedToGetExitCode({ command: \"{ cmd: blablaXYZ, args: }\", err: NotFound }))"
64+
)?
65+
66+
# exec_exit_code! with non-zero exit code is not an error - it returns the exit code
67+
exit_code =
68+
Cmd.new("cat")
69+
.arg("non_existent.txt")
70+
.exec_exit_code!()?
7771

78-
# # exec_exit_code! with non-zero exit code is not an error - it returns the exit code
79-
# exit_code =
80-
# Cmd.new("cat")
81-
# |> Cmd.arg("non_existent.txt")
82-
# |> Cmd.exec_exit_code!()?
83-
#
84-
# if exit_code == 1 {
85-
# Ok({})?
86-
# } else {
87-
# Err(FailedExpectation(
88-
# """
89-
#
90-
# - Expected:
91-
# 1
92-
#
93-
# - Got:
94-
# ${Inspect.to_str(exit_code)}
95-
#
96-
# """
97-
# ))?
98-
# }
72+
if exit_code == 1 {
73+
Ok({})?
74+
} else {
75+
Err(FailedExpectation(
76+
\\- Expected:
77+
\\1
78+
\\
79+
\\- Got:
80+
\\${Str.inspect(exit_code)}
81+
))?
82+
}
9983

10084
Stdout.line!("All tests passed.")?
10185

0 commit comments

Comments
 (0)