move valgrind configuration into Run builder

This commit is contained in:
Luke Boswell 2024-08-18 16:41:20 +10:00
parent 0e917be911
commit 4e6178ce55
No known key found for this signature in database
GPG key ID: F6DB3C9DB47377B0
2 changed files with 115 additions and 239 deletions

View file

@ -57,18 +57,13 @@ mod cli_run {
.arg(BUILD_HOST_FLAG) .arg(BUILD_HOST_FLAG)
.arg(SUPPRESS_BUILD_HOST_WARNING_FLAG) .arg(SUPPRESS_BUILD_HOST_WARNING_FLAG)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("examples", "helloWorld.roc").as_path()); .arg(file_from_root("examples", "helloWorld.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -80,18 +75,13 @@ mod cli_run {
.arg(BUILD_HOST_FLAG) .arg(BUILD_HOST_FLAG)
.arg(SUPPRESS_BUILD_HOST_WARNING_FLAG) .arg(SUPPRESS_BUILD_HOST_WARNING_FLAG)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("examples/platform-switching", "main.roc").as_path()); .arg(file_from_root("examples/platform-switching", "main.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
// We exclude the C platforming switching example // We exclude the C platforming switching example
// because the main platform switching example runs the c platform. // because the main platform switching example runs the c platform.
@ -107,18 +97,13 @@ mod cli_run {
.arg(BUILD_HOST_FLAG) .arg(BUILD_HOST_FLAG)
.arg(SUPPRESS_BUILD_HOST_WARNING_FLAG) .arg(SUPPRESS_BUILD_HOST_WARNING_FLAG)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("examples/platform-switching", "rocLovesRust.roc").as_path()); .arg(file_from_root("examples/platform-switching", "rocLovesRust.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -129,18 +114,13 @@ mod cli_run {
.arg(BUILD_HOST_FLAG) .arg(BUILD_HOST_FLAG)
.arg(SUPPRESS_BUILD_HOST_WARNING_FLAG) .arg(SUPPRESS_BUILD_HOST_WARNING_FLAG)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("examples/platform-switching", "rocLovesZig.roc").as_path()); .arg(file_from_root("examples/platform-switching", "rocLovesZig.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
fn platform_switching_wasm() { fn platform_switching_wasm() {
@ -164,17 +144,13 @@ mod cli_run {
); );
let runner = Run::new_roc() let runner = Run::new_roc()
.arg(CMD_TEST) .arg(CMD_TEST)
.add_args(&["--main", "tests/module_imports_pkg/app.roc"]) .with_valigrind(ALLOW_VALGRIND)
.add_args(["--main", "tests/module_imports_pkg/app.roc"])
.arg(file_from_root("crates/cli/tests/module_imports_pkg", "Module.roc").as_path()); .arg(file_from_root("crates/cli/tests/module_imports_pkg", "Module.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -198,16 +174,12 @@ mod cli_run {
); );
let runner = Run::new_roc() let runner = Run::new_roc()
.arg(CMD_TEST) .arg(CMD_TEST)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("crates/cli/tests/module_imports_pkg", "Module.roc").as_path()); .arg(file_from_root("crates/cli/tests/module_imports_pkg", "Module.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -234,7 +206,8 @@ mod cli_run {
); );
let runner = Run::new_roc() let runner = Run::new_roc()
.arg(CMD_TEST) .arg(CMD_TEST)
.add_args(&["--main", "tests/module_imports_pkg/app.roc"]) .with_valigrind(ALLOW_VALGRIND)
.add_args(["--main", "tests/module_imports_pkg/app.roc"])
.arg( .arg(
file_from_root( file_from_root(
"crates/cli/tests/module_imports_pkg", "crates/cli/tests/module_imports_pkg",
@ -243,14 +216,9 @@ mod cli_run {
.as_path(), .as_path(),
); );
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -279,16 +247,12 @@ mod cli_run {
); );
let runner = Run::new_roc() let runner = Run::new_roc()
.arg(CMD_TEST) .arg(CMD_TEST)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("crates/cli/tests/expects_transitive", "main.roc").as_path()); .arg(file_from_root("crates/cli/tests/expects_transitive", "main.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -306,17 +270,13 @@ mod cli_run {
); );
let runner = Run::new_roc() let runner = Run::new_roc()
.arg(CMD_TEST) .arg(CMD_TEST)
.with_valigrind(ALLOW_VALGRIND)
.arg("--verbose") .arg("--verbose")
.arg(file_from_root("crates/cli/tests/expects_transitive", "main.roc").as_path()); .arg(file_from_root("crates/cli/tests/expects_transitive", "main.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr( #[cfg_attr(
@ -330,18 +290,13 @@ mod cli_run {
.arg(BUILD_HOST_FLAG) .arg(BUILD_HOST_FLAG)
.arg(SUPPRESS_BUILD_HOST_WARNING_FLAG) .arg(SUPPRESS_BUILD_HOST_WARNING_FLAG)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("crates/cli/tests/algorithms", "fibonacci.roc").as_path()); .arg(file_from_root("crates/cli/tests/algorithms", "fibonacci.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -353,18 +308,13 @@ mod cli_run {
.arg(BUILD_HOST_FLAG) .arg(BUILD_HOST_FLAG)
.arg(SUPPRESS_BUILD_HOST_WARNING_FLAG) .arg(SUPPRESS_BUILD_HOST_WARNING_FLAG)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("crates/cli/tests/algorithms", "quicksort.roc").as_path()); .arg(file_from_root("crates/cli/tests/algorithms", "quicksort.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
// TODO: write a new test once mono bugs are resolved in investigation // TODO: write a new test once mono bugs are resolved in investigation
#[test] #[test]
@ -478,19 +428,14 @@ mod cli_run {
.arg(BUILD_HOST_FLAG) .arg(BUILD_HOST_FLAG)
.arg(SUPPRESS_BUILD_HOST_WARNING_FLAG) .arg(SUPPRESS_BUILD_HOST_WARNING_FLAG)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("crates/cli/tests/effects", "main.roc").as_path()) .arg(file_from_root("crates/cli/tests/effects", "main.roc").as_path())
.with_stdin_vals(vec!["hi there!"]); .with_stdin_vals(vec!["hi there!"]);
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -502,19 +447,14 @@ mod cli_run {
.arg(BUILD_HOST_FLAG) .arg(BUILD_HOST_FLAG)
.arg(SUPPRESS_BUILD_HOST_WARNING_FLAG) .arg(SUPPRESS_BUILD_HOST_WARNING_FLAG)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("crates/cli/tests/tui", "main.roc").as_path()) .arg(file_from_root("crates/cli/tests/tui", "main.roc").as_path())
.with_stdin_vals(vec!["foo\n"]); .with_stdin_vals(vec!["foo\n"]);
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(any(target_os = "windows", target_os = "linux"), ignore = "Segfault")] #[cfg_attr(any(target_os = "windows", target_os = "linux"), ignore = "Segfault")]
@ -534,8 +474,9 @@ mod cli_run {
let runner = Run::new_roc() let runner = Run::new_roc()
.arg(CMD_RUN) .arg(CMD_RUN)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("crates/cli/tests/false-interpreter", "False.roc").as_path()) .arg(file_from_root("crates/cli/tests/false-interpreter", "False.roc").as_path())
.add_args(&[ .add_args([
"--", "--",
file_from_root("crates/cli/tests/false-interpreter/examples", "sqrt.false") file_from_root("crates/cli/tests/false-interpreter/examples", "sqrt.false")
.as_path() .as_path()
@ -545,16 +486,10 @@ mod cli_run {
let expected_ending = "1414"; let expected_ending = "1414";
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -701,19 +636,14 @@ mod cli_run {
let runner = Run::new_roc() let runner = Run::new_roc()
.arg(CMD_RUN) .arg(CMD_RUN)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
// uses basic-cli release // uses basic-cli release
.arg(file_from_root("examples", "inspect-logging.roc").as_path()); .arg(file_from_root("examples", "inspect-logging.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
mod test_platform_simple_zig { mod test_platform_simple_zig {
use super::{ use super::{
@ -753,20 +683,15 @@ mod cli_run {
let runner = cli_utils::helpers::Run::new_roc() let runner = cli_utils::helpers::Run::new_roc()
.arg(roc_cli::CMD_RUN) .arg(roc_cli::CMD_RUN)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg( .arg(
file_from_root("crates/cli/tests/fixtures/multi-dep-str", "Main.roc").as_path(), file_from_root("crates/cli/tests/fixtures/multi-dep-str", "Main.roc").as_path(),
); );
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -778,20 +703,15 @@ mod cli_run {
.arg(CMD_RUN) .arg(CMD_RUN)
.arg(OPTIMIZE_FLAG) .arg(OPTIMIZE_FLAG)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg( .arg(
file_from_root("crates/cli/tests/fixtures/multi-dep-str", "Main.roc").as_path(), file_from_root("crates/cli/tests/fixtures/multi-dep-str", "Main.roc").as_path(),
); );
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -802,21 +722,16 @@ mod cli_run {
let runner = cli_utils::helpers::Run::new_roc() let runner = cli_utils::helpers::Run::new_roc()
.arg(CMD_RUN) .arg(CMD_RUN)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg( .arg(
file_from_root("crates/cli/tests/fixtures/multi-dep-thunk", "Main.roc") file_from_root("crates/cli/tests/fixtures/multi-dep-thunk", "Main.roc")
.as_path(), .as_path(),
); );
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr( #[cfg_attr(
@ -831,21 +746,16 @@ mod cli_run {
.arg(CMD_RUN) .arg(CMD_RUN)
.arg(OPTIMIZE_FLAG) .arg(OPTIMIZE_FLAG)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg( .arg(
file_from_root("crates/cli/tests/fixtures/multi-dep-thunk", "Main.roc") file_from_root("crates/cli/tests/fixtures/multi-dep-thunk", "Main.roc")
.as_path(), .as_path(),
); );
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -857,18 +767,13 @@ mod cli_run {
let runner = cli_utils::helpers::Run::new_roc() let runner = cli_utils::helpers::Run::new_roc()
.arg(CMD_RUN) .arg(CMD_RUN)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("crates/cli/tests/fixtures/packages", "app.roc").as_path()); .arg(file_from_root("crates/cli/tests/fixtures/packages", "app.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -881,18 +786,13 @@ mod cli_run {
.arg(CMD_RUN) .arg(CMD_RUN)
.arg(OPTIMIZE_FLAG) .arg(OPTIMIZE_FLAG)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("crates/cli/tests/fixtures/packages", "app.roc").as_path()); .arg(file_from_root("crates/cli/tests/fixtures/packages", "app.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -908,18 +808,13 @@ mod cli_run {
let runner = cli_utils::helpers::Run::new_roc() let runner = cli_utils::helpers::Run::new_roc()
.arg(CMD_RUN) .arg(CMD_RUN)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_path.as_path()); .arg(file_path.as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -935,18 +830,13 @@ mod cli_run {
let runner = cli_utils::helpers::Run::new_roc() let runner = cli_utils::helpers::Run::new_roc()
.arg(CMD_RUN) .arg(CMD_RUN)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_path.as_path()); .arg(file_path.as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
#[cfg_attr(windows, ignore)] #[cfg_attr(windows, ignore)]
@ -962,18 +852,13 @@ mod cli_run {
let runner = cli_utils::helpers::Run::new_roc() let runner = cli_utils::helpers::Run::new_roc()
.arg(CMD_RUN) .arg(CMD_RUN)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_path.as_path()); .arg(file_path.as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
fn expects_dev() { fn expects_dev() {
@ -1006,20 +891,12 @@ mod cli_run {
let runner = cli_utils::helpers::Run::new_roc() let runner = cli_utils::helpers::Run::new_roc()
.arg(CMD_DEV) .arg(CMD_DEV)
.add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("crates/cli/tests/expects", "expects.roc").as_path()); .arg(file_from_root("crates/cli/tests/expects", "expects.roc").as_path());
dbg!(&runner);
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
// out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
// out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[test] #[test]
fn expects_test() { fn expects_test() {
@ -1075,19 +952,13 @@ mod cli_run {
); );
let runner = cli_utils::helpers::Run::new_roc() let runner = cli_utils::helpers::Run::new_roc()
.arg(CMD_TEST) .arg(CMD_TEST)
.with_valigrind(ALLOW_VALGRIND)
.arg(file_from_root("crates/cli/tests/expects", "expects.roc").as_path()); .arg(file_from_root("crates/cli/tests/expects", "expects.roc").as_path());
if ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
// out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
// out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
} }
}
// TODO not sure if this cfg should still be here: #[cfg(not(debug_assertions))] // TODO not sure if this cfg should still be here: #[cfg(not(debug_assertions))]
// this is for testing the benchmarks, to perform proper benchmarks see crates/cli/benches/README.md // this is for testing the benchmarks, to perform proper benchmarks see crates/cli/benches/README.md
@ -1138,18 +1009,13 @@ mod cli_run {
.arg(roc_cli::CMD_RUN) .arg(roc_cli::CMD_RUN)
.add_arg_if(super::LINKER_FLAG, super::TEST_LEGACY_LINKER) .add_arg_if(super::LINKER_FLAG, super::TEST_LEGACY_LINKER)
.arg(file_path.as_path()) .arg(file_path.as_path())
.with_valigrind(matches!(use_valgrind, UseValgrind::Yes) && ALLOW_VALGRIND)
.with_stdin_vals(stdin); .with_stdin_vals(stdin);
if matches!(use_valgrind, UseValgrind::Yes) && ALLOW_VALGRIND {
let out = runner.run_with_valgrind();
out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending);
} else {
let out = runner.run(); let out = runner.run();
out.assert_clean_success(); out.assert_clean_success();
out.assert_stdout_and_stderr_ends_with(expected_ending); out.assert_stdout_and_stderr_ends_with(expected_ending);
} }
}
#[cfg(feature = "wasm32-cli-run")] #[cfg(feature = "wasm32-cli-run")]
check_output_wasm(file_path.as_path(), stdin, expected_ending); check_output_wasm(file_path.as_path(), stdin, expected_ending);
@ -1289,7 +1155,6 @@ mod cli_run {
fn astar() { fn astar() {
if cfg!(feature = "wasm32-cli-run") { if cfg!(feature = "wasm32-cli-run") {
eprintln!("WARNING: skipping testing benchmark testAStar.roc because it currently does not work on wasm32 due to dictionaries."); eprintln!("WARNING: skipping testing benchmark testAStar.roc because it currently does not work on wasm32 due to dictionaries.");
return;
} else { } else {
test_benchmark("testAStar.roc", vec![], "True\n", UseValgrind::No) test_benchmark("testAStar.roc", vec![], "True\n", UseValgrind::No)
} }

View file

@ -141,6 +141,7 @@ pub struct Run {
env: Vec<(String, String)>, env: Vec<(String, String)>,
stdin_vals: Vec<&'static str>, stdin_vals: Vec<&'static str>,
cwd: Option<OsString>, cwd: Option<OsString>,
run_with_valgrind: bool,
} }
impl Run { impl Run {
@ -154,6 +155,7 @@ impl Run {
stdin_vals: vec![], stdin_vals: vec![],
env: vec![], env: vec![],
cwd: None, cwd: None,
run_with_valgrind: false,
} }
} }
@ -251,6 +253,11 @@ impl Run {
self self
} }
pub fn with_valigrind(mut self, use_valgrind: bool) -> Self {
self.run_with_valgrind = use_valgrind;
self
}
pub fn cwd<S>(mut self, arg: S) -> Self pub fn cwd<S>(mut self, arg: S) -> Self
where where
S: Into<OsString>, S: Into<OsString>,
@ -309,6 +316,10 @@ impl Run {
} }
pub fn run(self) -> Out { pub fn run(self) -> Out {
if self.run_with_valgrind {
return self.run_with_valgrind();
}
let command = self.command(); let command = self.command();
self.run_with_command(command) self.run_with_command(command)
} }