finished refactoring simple zig platform tests

This commit is contained in:
Anton-4 2024-10-18 17:45:28 +02:00
parent a18e4100c6
commit 54ae11be25
No known key found for this signature in database
GPG key ID: 0971D718C0A9B937
8 changed files with 120 additions and 65 deletions

View file

@ -428,80 +428,84 @@ mod cli_tests {
insta::assert_snapshot!(cli_dev_out.normalize_stdout_and_stderr());
}
/*
#[test]
#[cfg_attr(windows, ignore)]
fn module_params_bad_ann() {
build_platform_host();
let runner = cli_test_utils::helpers::ExecCli::new_roc()
.arg(CMD_DEV)
.arg(file_from_root("crates/cli/tests/module_params", "bad_ann.roc").as_path());
let cli_dev = ExecCli::new(
CMD_DEV,
file_from_root("crates/cli/tests/test-projects/module_params", "bad_ann.roc")
);
let out = runner.run();
insta::assert_snapshot!(out.normalize_stdout_and_stderr());
let cli_dev_out = cli_dev.run();
cli_dev_out.assert_nonzero_exit();
insta::assert_snapshot!(cli_dev_out.normalize_stdout_and_stderr());
}
#[test]
#[cfg_attr(windows, ignore)]
fn module_params_multiline_pattern() {
build_platform_host();
let runner = cli_test_utils::helpers::ExecCli::new_roc().arg(CMD_DEV).arg(
file_from_root("crates/cli/tests/module_params", "multiline_params.roc").as_path(),
);
let out = runner.run();
insta::assert_snapshot!(out.normalize_stdout_and_stderr());
let cli_dev = ExecCli::new(
CMD_DEV,
file_from_root("crates/cli/tests/test-projects/module_params", "multiline_params.roc")
);
let cli_dev_out = cli_dev.run();
cli_dev_out.assert_clean_success();
cli_dev_out.assert_stdout_and_stderr_ends_with("hi\n");
}
#[test]
#[cfg_attr(windows, ignore)]
fn module_params_unexpected_fn() {
build_platform_host();
let runner = cli_test_utils::helpers::ExecCli::new_roc().arg(CMD_DEV).arg(
file_from_root("crates/cli/tests/module_params", "unexpected_fn.roc").as_path(),
);
let cli_dev = ExecCli::new(
CMD_DEV,
file_from_root("crates/cli/tests/test-projects/module_params", "unexpected_fn.roc")
);
let cli_dev_out = cli_dev.run();
cli_dev_out.assert_nonzero_exit();
let out = runner.run();
insta::assert_snapshot!(out.normalize_stdout_and_stderr());
insta::assert_snapshot!(cli_dev_out.normalize_stdout_and_stderr());
}
*/
/*
#[test]
fn expects_dev() {
fn expects_dev_failure() {
build_platform_host();
let runner = cli_test_utils::helpers::ExecCli::new_roc()
.arg(CMD_DEV)
.add_arg_if(LEGACY_LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valgrind(ALLOW_VALGRIND)
.arg(file_from_root("crates/cli/tests/expects", "expects.roc").as_path());
let cli_dev = ExecCli::new(
CMD_DEV,
file_from_root("crates/cli/tests/test-projects/expects", "expects.roc")
);
let cli_dev_out = cli_dev.run();
// TODO enable or delete this based on https://roc.zulipchat.com/#narrow/channel/304641-ideas/topic/roc.20dev.20expect.20failure/near/477682063
//cli_dev_out.assert_nonzero_exit();
let out = runner.run();
insta::assert_snapshot!(out.normalize_stdout_and_stderr());
insta::assert_snapshot!(cli_dev_out.normalize_stdout_and_stderr());
}
#[test]
fn expects_test() {
fn expects_test_failure() {
build_platform_host();
let runner = cli_test_utils::helpers::ExecCli::new_roc()
.arg(CMD_TEST)
.with_valgrind(ALLOW_VALGRIND)
.arg(file_from_root("crates/cli/tests/expects", "expects.roc").as_path());
let out = runner.run();
insta::assert_snapshot!(out.normalize_stdout_and_stderr());
let cli_test = ExecCli::new(
CMD_TEST,
file_from_root("crates/cli/tests/test-projects/expects", "expects.roc")
);
let cli_test_out = cli_test.run();
cli_test_out.assert_nonzero_exit();
insta::assert_snapshot!(cli_test_out.normalize_stdout_and_stderr());
}
*/
}
/*
#[test]

View file

@ -1,5 +0,0 @@
---
source: crates/cli/tests/cli_tests.rs
expression: out.normalize_stdout_and_stderr()
---
hi

View file

@ -1,8 +1,8 @@
---
source: crates/cli/tests/cli_tests.rs
expression: out.normalize_stdout_and_stderr()
expression: cli_dev_out.normalize_stdout_and_stderr()
---
── EXPECT FAILED in tests/expects/expects.roc ──────────────────────────────────
── EXPECT FAILED in tests/test-projects/expects/expects.roc ────────────────────
This expectation failed:
@ -14,7 +14,9 @@ When it failed, these variables had these values:
words : List Str
words = ["this", "will", "for", "sure", "be", "a", "large", "string", "so", "when", "we", "split", "it", "it", "will", "use", "seamless", "slices", "which", "affect", "printing"]
Program finished![<ignored for tests>:28] x = 42
Program finished!
[<ignored for tests>:28] x = 42
[<ignored for tests>:30] "Fjoer en ferdjer frieten oan dyn geve lea" = "Fjoer en ferdjer frieten oan dyn geve lea"
[<ignored for tests>:32] "this is line 24" = "this is line 24"
[<ignored for tests>:18] x = "abc"

View file

@ -1,8 +1,8 @@
---
source: crates/cli/tests/cli_tests.rs
expression: out.normalize_stdout_and_stderr()
expression: cli_test_out.normalize_stdout_and_stderr()
---
── EXPECT FAILED in tests/expects/expects.roc ──────────────────────────────────
── EXPECT FAILED in tests/test-projects/expects/expects.roc ────────────────────
This expectation failed:
@ -14,7 +14,7 @@ When it failed, these variables had these values:
a : Num *
a = 1
── EXPECT FAILED in tests/expects/expects.roc ──────────────────────────────────
── EXPECT FAILED in tests/test-projects/expects/expects.roc ────────────────────
This expectation failed:
@ -26,7 +26,7 @@ When it failed, these variables had these values:
a : Num *
a = 1
── EXPECT FAILED in tests/expects/expects.roc ──────────────────────────────────
── EXPECT FAILED in tests/test-projects/expects/expects.roc ────────────────────
This expectation failed:

View file

@ -0,0 +1,43 @@
---
source: crates/cli/tests/cli_tests.rs
assertion_line: 429
expression: cli_dev_out.normalize_stdout_and_stderr()
---
── TOO MANY ARGS in tests/test-projects/module_params/arity_mismatch.roc ───────
The getUser function expects 1 argument, but it got 2 instead:
12│ $(Api.getUser 1 2)
^^^^^^^^^^^
Are there any missing commas? Or missing parentheses?
── TOO MANY ARGS in tests/test-projects/module_params/arity_mismatch.roc ───────
This value is not a function, but it was given 1 argument:
13│ $(Api.baseUrl 1)
^^^^^^^^^^^
Are there any missing commas? Or missing parentheses?
── TOO FEW ARGS in tests/test-projects/module_params/arity_mismatch.roc ────────
The getPostComment function expects 2 arguments, but it got only 1:
16│ $(Api.getPostComment 1)
^^^^^^^^^^^^^^^^^^
Roc does not allow functions to be partially applied. Use a closure to
make partial application explicit.
────────────────────────────────────────────────────────────────────────────────
3 error and 0 warning found in <ignored for test> ms
.
You can run <ignored for tests>

View file

@ -1,8 +1,10 @@
---
source: crates/cli/tests/cli_tests.rs
expression: out.normalize_stdout_and_stderr()
assertion_line: 445
expression: cli_dev_out.normalize_stdout_and_stderr()
---
── TYPE MISMATCH in tests/module_params/BadAnn.roc ─────────────────────────────
── TYPE MISMATCH in tests/test-projects/module_params/BadAnn.roc ───────────────
Something is off with the body of the fnAnnotatedAsValue definition:
@ -19,7 +21,7 @@ But the type annotation on fnAnnotatedAsValue says it should be:
Str
── TYPE MISMATCH in tests/module_params/BadAnn.roc ─────────────────────────────
── TYPE MISMATCH in tests/test-projects/module_params/BadAnn.roc ───────────────
Something is off with the body of the missingArg definition:
@ -42,4 +44,5 @@ Tip: It looks like it takes too many arguments. I'm seeing 1 extra.
2 error and 1 warning found in <ignored for test> ms
.
You can run the program anyway <ignored for tests>
You can run <ignored for tests>

View file

@ -1,8 +1,10 @@
---
source: crates/cli/tests/cli_tests.rs
expression: out.normalize_stdout_and_stderr()
assertion_line: 476
expression: cli_dev_out.normalize_stdout_and_stderr()
---
── TYPE MISMATCH in tests/module_params/unexpected_fn.roc ──────────────────────
── TYPE MISMATCH in tests/test-projects/module_params/unexpected_fn.roc ────────
This argument to this string interpolation has an unexpected type:
@ -22,4 +24,5 @@ But this string interpolation needs its argument to be:
1 error and 0 warning found in <ignored for test> ms
.
You can run the program anyway <ignored for tests>
You can run <ignored for tests>

View file

@ -153,6 +153,10 @@ fn normalize_for_tests(original_output: &str) -> String {
// replace file paths with a placeholder
let filepath_replacement = "[<ignored for tests>:$2]";
part_normalized = FILEPATH_REGEX.replace_all(&part_normalized, filepath_replacement).into_owned();
// replace tip "You can run the program anyway ..." with a placeholder
let run_anyway_replacement = "<ignored for tests>";
part_normalized = RUN_ANYWAY_REGEX.replace_all(&part_normalized, run_anyway_replacement).into_owned();
// replace error summary timings
let error_summary_replacement = "$1 error and $2 warning found in <ignored for test> ms";
@ -165,6 +169,7 @@ fn normalize_for_tests(original_output: &str) -> String {
lazy_static! {
static ref TIMING_REGEX: Regex = Regex::new(r" in (\d+) ms\.").expect("Invalid regex pattern");
static ref FILEPATH_REGEX: Regex = Regex::new(r"\[([^:]+):(\d+)\]").expect("Invalid filepath regex pattern");
static ref RUN_ANYWAY_REGEX: Regex = Regex::new(r"the program anyway with\s+.*").expect("Invalid run anyway regex pattern");
static ref ERROR_SUMMARY_REGEX: Regex = Regex::new(r"(\d+) error(?:s)? and (\d+) warning(?:s)? found in \d+ ms")
.expect("Invalid error summary regex pattern");
}