Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sc-460] Update tests to show HVM.log output #228

Merged
merged 3 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"chumsky",
"combinators",
"ctrs",
"Dall",
"datatypes",
"desugared",
"desugars",
Expand Down Expand Up @@ -49,9 +50,8 @@
"oprune",
"oref",
"postcondition",
"redex",
"redexes",
"readback",
"redex",
"redexes",
"resugar",
"resugared",
Expand Down
41 changes: 26 additions & 15 deletions tests/golden_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ use std::{
use stdext::function_name;
use walkdir::WalkDir;

fn format_output(output: std::process::Output) -> String {
format!("{}\n{}", String::from_utf8_lossy(&output.stderr), String::from_utf8_lossy(&output.stdout))
}

fn do_parse_term(code: &str) -> Result<Term, String> {
parse_term(code).map_err(|errs| errs.into_iter().map(|e| e.to_string()).join("\n"))
}
Expand All @@ -44,7 +48,12 @@ fn run_single_golden_test(
let file_path = format!("{}{}", &TESTS_PATH[1 ..], file_name);
let file_path = Path::new(&file_path);

let results = run.iter().map(|x| x(&code, file_path).unwrap_or_else(|err| err.to_string()));
let mut results: HashMap<&Path, Vec<String>> = HashMap::new();
for fun in run {
let result = fun(&code, file_path).unwrap_or_else(|err| err.to_string());
results.entry(file_path).or_default().push(result);
}
let results = results.into_values().map(|v| v.join("\n")).collect_vec();

let mut settings = insta::Settings::clone_current();
settings.set_prepend_module_to_snapshot(false);
Expand Down Expand Up @@ -141,19 +150,21 @@ fn linear_readback() {
#[test]
fn run_file() {
run_golden_test_dir_multiple(function_name!(), &[
(&|code, path| {
let book = do_parse_book(code, path)?;
// 1 million nodes for the test runtime. Smaller doesn't seem to make it any faster
let (res, info) =
run_book(book, 1 << 24, RunOpts::lazy(), WarningOpts::deny_all(), CompileOpts::heavy(), None)?;
Ok(format!("{}{}", display_readback_errors(&info.readback_errors), res))
(&|_code, path| {
let output = std::process::Command::new(env!("CARGO_BIN_EXE_hvml"))
.args(["run", path.to_str().unwrap(), "-Dall", "-Oall", "-L"])
imaqtkatt marked this conversation as resolved.
Show resolved Hide resolved
.output()
.expect("Run process");

Ok(format!("Lazy mode:\n{}", format_output(output)))
}),
(&|code, path| {
let book = do_parse_book(code, path)?;
// 1 million nodes for the test runtime. Smaller doesn't seem to make it any faster
let (res, info) =
run_book(book, 1 << 24, RunOpts::default(), WarningOpts::deny_all(), CompileOpts::heavy(), None)?;
Ok(format!("{}{}", display_readback_errors(&info.readback_errors), res))
(&|_code, path| {
let output = std::process::Command::new(env!("CARGO_BIN_EXE_hvml"))
.args(["run", path.to_str().unwrap(), "-Dall", "-Oall"])
.output()
.expect("Run process");

Ok(format!("Strict mode:\n{}", format_output(output)))
}),
])
}
Expand Down Expand Up @@ -319,8 +330,8 @@ fn cli() {
let args = args_buf.lines();

let output =
std::process::Command::new("cargo").arg("run").arg("-q").args(args).output().expect("Run process");
std::process::Command::new(env!("CARGO_BIN_EXE_hvml")).args(args).output().expect("Run command");

Ok(format!("{}\n{}", String::from_utf8_lossy(&output.stderr), String::from_utf8_lossy(&output.stdout)))
Ok(format_output(output))
})
}
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__addition.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/addition.hvm
---
Lazy mode:

10

Strict mode:

10
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__adt_match.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/adt_match.hvm
---
Lazy mode:

(Some 2)

Strict mode:

(Some 2)
9 changes: 9 additions & 0 deletions tests/snapshots/run_file__adt_match_wrong_tag.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/adt_match_wrong_tag.hvm
---
Lazy mode:

Readback Warning:
Unexpected tag found during Adt readback, expected '#Option', but found '#wrong_tag'
Invalid Adt Match
λa match a { (Some Some.val): #Option (#wrong_tag λb b Some.val); (None): * }

Strict mode:

Readback Warning:
Unexpected tag found during Adt readback, expected '#Option', but found '#wrong_tag'
Invalid Adt Match
Expand Down
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__adt_option_and.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/adt_option_and.hvm
---
Lazy mode:

λa λb match a { (Some c): match b { (Some d): (Some (c, d)); (None): None }; (None): None }

Strict mode:

λa match a { (Some b): λc (match c { (Some d): λe (Some (e, d)); (None): λ* None } b); (None): λ* None }
9 changes: 9 additions & 0 deletions tests/snapshots/run_file__adt_wrong_tag.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/adt_wrong_tag.hvm
---
Lazy mode:

Readback Warning:
Unexpected tag found during Adt readback, expected '#Option', but found '#wrong_tag'
Invalid Adt Match
λa match a { (Some Some.val): #Option (#wrong_tag λb b Some.val); (None): * }

Strict mode:

Readback Warning:
Unexpected tag found during Adt readback, expected '#Option', but found '#wrong_tag'
Invalid Adt Match
Expand Down
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__and.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/and.hvm
---
Lazy mode:

false

Strict mode:

false
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__bitonic_sort.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/bitonic_sort.hvm
---
Lazy mode:

120

Strict mode:

120
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__bitonic_sort_lam.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/bitonic_sort_lam.hvm
---
Lazy mode:

32640

Strict mode:

32640
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__box.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/box.hvm
---
Lazy mode:

(Box 10)

Strict mode:

(Box 10)
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__box2.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/box2.hvm
---
Lazy mode:

(Box 4)

Strict mode:

(Box 4)
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__callcc.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/callcc.hvm
---
Lazy mode:

52

Strict mode:

52
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__chars.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/chars.hvm
---
Lazy mode:

"ሴ!7"

Strict mode:

"ሴ!7"
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__chars_forall.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/chars_forall.hvm
---
Lazy mode:

8704

Strict mode:

8704
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__chars_lambda.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/chars_lambda.hvm
---
Lazy mode:

955

Strict mode:

955
9 changes: 9 additions & 0 deletions tests/snapshots/run_file__def_bool_num.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/def_bool_num.hvm
---
Lazy mode:

In definition 'go':
Non-exhaustive pattern matching. Hint:
Case '+' not covered.



Strict mode:

In definition 'go':
Non-exhaustive pattern matching. Hint:
Case '+' not covered.
9 changes: 9 additions & 0 deletions tests/snapshots/run_file__def_num_bool.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/def_num_bool.hvm
---
Lazy mode:

In definition 'go':
Non-exhaustive pattern matching. Hint:
Case '+' not covered.



Strict mode:

In definition 'go':
Non-exhaustive pattern matching. Hint:
Case '+' not covered.
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__def_tups.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/def_tups.hvm
---
Lazy mode:

15

Strict mode:

15
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__dup_global_lam.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/dup_global_lam.hvm
---
Lazy mode:

λa a

Strict mode:

λa a
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__empty.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/empty.hvm
---
Lazy mode:
File has no 'main' definition.



Strict mode:
File has no 'main' definition.
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__escape_sequences.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/escape_sequences.hvm
---
Lazy mode:

("\n\r\t\0\"'\u{afe}`", "\n\r\t\0\"'\u{afe}`")

Strict mode:

("\n\r\t\0\"'\u{afe}`", "\n\r\t\0\"'\u{afe}`")
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__eta.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/eta.hvm
---
Lazy mode:

λa a

Strict mode:

λa a
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__example.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/example.hvm
---
Lazy mode:

8

Strict mode:

8
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__exp.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/exp.hvm
---
Lazy mode:

λa λb (a (a (a (a b))))

Strict mode:

λa λb (a (a (a (a b))))
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__extracted_match_pred.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/extracted_match_pred.hvm
---
Lazy mode:

0

Strict mode:

0
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__field_vectorization.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/field_vectorization.hvm
---
Lazy mode:

(Cons T (Cons T (Cons F (Cons T Nil))))

Strict mode:

(Cons T (Cons T (Cons F (Cons T Nil))))
6 changes: 6 additions & 0 deletions tests/snapshots/run_file__id_underscore.hvm.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
source: tests/golden_tests.rs
input_file: tests/golden_tests/run_file/id_underscore.hvm
---
Lazy mode:

(2, 3)

Strict mode:

(2, 3)
Loading
Loading