diff --git a/crates/cli/tests/algorithms/fibonacci-platform/host.zig b/crates/cli/tests/algorithms/fibonacci-platform/host.zig index e75b1dd7a0..1747815c59 100644 --- a/crates/cli/tests/algorithms/fibonacci-platform/host.zig +++ b/crates/cli/tests/algorithms/fibonacci-platform/host.zig @@ -110,18 +110,10 @@ comptime { pub export fn main() u8 { const stdout = std.io.getStdOut().writer(); - var timer = std.time.Timer.start() catch unreachable; - const result = roc__mainForHost_1_exposed(10); - const nanos = timer.read(); - const seconds = (@as(f64, @floatFromInt(nanos)) / 1_000_000_000.0); - stdout.print("{d}\n", .{result}) catch unreachable; - const stderr = std.io.getStdErr().writer(); - stderr.print("runtime: {d:.3}ms\n", .{seconds * 1000}) catch unreachable; - return 0; } diff --git a/crates/cli/tests/cli_run.rs b/crates/cli/tests/cli_run.rs index cbd1e3edc3..65434588c7 100644 --- a/crates/cli/tests/cli_run.rs +++ b/crates/cli/tests/cli_run.rs @@ -10,7 +10,6 @@ extern crate roc_module; mod cli_run { use cli_utils::helpers::{dir_from_root, file_from_root, Run}; use const_format::concatcp; - use indoc::indoc; use roc_cli::{CMD_BUILD, CMD_CHECK, CMD_FORMAT, CMD_RUN, CMD_TEST}; #[cfg(all(unix, not(target_os = "macos")))] @@ -51,7 +50,6 @@ mod cli_run { #[test] #[cfg_attr(windows, ignore)] fn platform_switching_rust() { - let expected_ending = "Roc <3 Rust!\n🔨 Building host ...\n"; let runner = Run::new_roc() .arg(CMD_RUN) .arg(BUILD_HOST_FLAG) @@ -62,13 +60,12 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] #[cfg_attr(windows, ignore)] fn platform_switching_zig() { - let expected_ending = "Roc <3 Zig!\n🔨 Building host ...\n"; let runner = Run::new_roc() .arg(CMD_RUN) .arg(BUILD_HOST_FLAG) @@ -79,7 +76,7 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -97,11 +94,6 @@ mod cli_run { #[test] #[cfg_attr(windows, ignore)] fn test_module_imports_pkg_w_flag() { - let expected_ending = indoc!( - r#" - 0 failed and 1 passed in ms. - "# - ); let runner = Run::new_roc() .arg(CMD_TEST) .with_valgrind(ALLOW_VALGRIND) @@ -109,61 +101,24 @@ mod cli_run { .arg(file_from_root("crates/cli/tests/module_imports_pkg", "Module.roc").as_path()); let out = runner.run(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] #[cfg_attr(windows, ignore)] fn test_module_imports_pkg_no_flag() { - let expected_ending = indoc!( - r#" - ── UNRECOGNIZED PACKAGE in tests/module_imports_pkg/Module.roc ───────────────── - - This module is trying to import from `pkg`: - - 3│ import pkg.Foo - ^^^^^^^ - - A lowercase name indicates a package shorthand, but I don't know which - packages are available. - - When checking a module directly, I look for a `main.roc` app or - package to resolve shorthands from. - - You can create it, or specify an existing one with the --main flag."# - ); let runner = Run::new_roc() .arg(CMD_TEST) .with_valgrind(ALLOW_VALGRIND) .arg(file_from_root("crates/cli/tests/module_imports_pkg", "Module.roc").as_path()); let out = runner.run(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] #[cfg_attr(windows, ignore)] fn test_module_imports_unknown_pkg() { - let expected_ending = indoc!( - r#" - ── UNRECOGNIZED PACKAGE in tests/module_imports_pkg/ImportsUnknownPkg.roc ────── - - This module is trying to import from `cli`: - - 3│ import cli.Foo - ^^^^^^^ - - A lowercase name indicates a package shorthand, but I don't recognize - this one. Did you mean one of these? - - pkg - - Note: I'm using the following module to resolve package shorthands: - - tests/module_imports_pkg/app.roc - - You can specify a different one with the --main flag."# - ); let runner = Run::new_roc() .arg(CMD_TEST) .with_valgrind(ALLOW_VALGRIND) @@ -177,14 +132,13 @@ mod cli_run { ); let out = runner.run(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] #[cfg_attr(windows, ignore)] /// this tests that a platform can correctly import a package fn platform_requires_pkg() { - let expected_ending = "from app from package🔨 Building host ...\n"; let runner = Run::new_roc() .arg(CMD_RUN) .arg(BUILD_HOST_FLAG) @@ -194,40 +148,24 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] #[cfg_attr(windows, ignore)] fn transitive_expects() { - let expected_ending = indoc!( - r#" - 0 failed and 3 passed in ms. - "# - ); let runner = Run::new_roc() .arg(CMD_TEST) .with_valgrind(ALLOW_VALGRIND) .arg(file_from_root("crates/cli/tests/expects_transitive", "main.roc").as_path()); let out = runner.run(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] #[cfg_attr(windows, ignore)] fn transitive_expects_verbose() { - let expected_ending = indoc!( - r#" - Compiled in ms. - - Direct.roc: - 0 failed and 2 passed in ms. - - Transitive.roc: - 0 failed and 1 passed in ms. - "# - ); let runner = Run::new_roc() .arg(CMD_TEST) .with_valgrind(ALLOW_VALGRIND) @@ -235,7 +173,7 @@ mod cli_run { .arg(file_from_root("crates/cli/tests/expects_transitive", "main.roc").as_path()); let out = runner.run(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -244,7 +182,6 @@ mod cli_run { ignore = "Flaky failure: Roc command failed with status ExitStatus(ExitStatus(3221225477))" )] fn fibonacci() { - let expected_ending = ""; let runner = Run::new_roc() .arg(CMD_RUN) .arg(BUILD_HOST_FLAG) @@ -255,14 +192,12 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] #[cfg_attr(windows, ignore)] fn quicksort() { - let expected_ending = - "[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n🔨 Building host ...\n"; let runner = Run::new_roc() .arg(CMD_RUN) .arg(BUILD_HOST_FLAG) @@ -273,7 +208,7 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } // TODO: write a new test once mono bugs are resolved in investigation @@ -310,7 +245,6 @@ mod cli_run { #[cfg_attr(windows, ignore)] // tea = The Elm Architecture fn terminal_ui_tea() { - let expected_ending = "Hello Worldfoo!\n🔨 Building host ...\n"; let runner = Run::new_roc() .arg(CMD_RUN) .arg(BUILD_HOST_FLAG) @@ -322,7 +256,7 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -356,11 +290,9 @@ mod cli_run { .unwrap(), ]); - let expected_ending = "1414"; - let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } mod test_platform_effects_zig { @@ -393,7 +325,6 @@ mod cli_run { fn interactive_effects() { build_platform_host(); - let expected_ending = "hi there!\nIt is known\n"; let runner = Run::new_roc() .arg(CMD_RUN) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) @@ -403,7 +334,7 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -411,8 +342,6 @@ mod cli_run { fn combine_tasks_with_record_builder() { build_platform_host(); - let expected_ending = "For multiple tasks: {a: 123, b: \"abc\", c: [123]}\n"; - let runner = Run::new_roc() .arg(CMD_RUN) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) @@ -420,7 +349,7 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -428,7 +357,6 @@ mod cli_run { fn inspect_logging() { build_platform_host(); - let expected_ending = "(@Community {friends: [{2}, {2}, {0, 1}], people: [(@Person {age: 27, favoriteColor: Blue, firstName: \"John\", hasBeard: Bool.true, lastName: \"Smith\"}), (@Person {age: 47, favoriteColor: Green, firstName: \"Debby\", hasBeard: Bool.false, lastName: \"Johnson\"}), (@Person {age: 33, favoriteColor: (RGB (255, 255, 0)), firstName: \"Jane\", hasBeard: Bool.false, lastName: \"Doe\"})]})\n"; let runner = Run::new_roc() .arg(CMD_RUN) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) @@ -437,7 +365,7 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -453,14 +381,14 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with("Hi, Agus!\n"); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } } mod test_platform_simple_zig { use super::*; use cli_utils::helpers::{file_from_root, Run}; - use indoc::indoc; use roc_cli::{CMD_BUILD, CMD_DEV, CMD_RUN, CMD_TEST}; static BUILD_PLATFORM_HOST: std::sync::Once = std::sync::Once::new(); @@ -488,7 +416,6 @@ mod cli_run { fn run_multi_dep_str_unoptimized() { build_platform_host(); - let expected_ending = "I am Dep2.str2\n"; let runner = cli_utils::helpers::Run::new_roc() .arg(roc_cli::CMD_RUN) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) @@ -499,7 +426,8 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -507,7 +435,6 @@ mod cli_run { fn run_multi_dep_str_optimized() { build_platform_host(); - let expected_ending = "I am Dep2.str2\n"; let runner = cli_utils::helpers::Run::new_roc() .arg(CMD_RUN) .arg(OPTIMIZE_FLAG) @@ -519,7 +446,8 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -527,7 +455,6 @@ mod cli_run { fn run_multi_dep_thunk_unoptimized() { build_platform_host(); - let expected_ending = "I am Dep2.value2\n"; let runner = cli_utils::helpers::Run::new_roc() .arg(CMD_RUN) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) @@ -539,7 +466,8 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -550,7 +478,6 @@ mod cli_run { fn run_multi_dep_thunk_optimized() { build_platform_host(); - let expected_ending = "I am Dep2.value2\n"; let runner = cli_utils::helpers::Run::new_roc() .arg(CMD_RUN) .arg(OPTIMIZE_FLAG) @@ -563,7 +490,8 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -571,8 +499,6 @@ mod cli_run { fn run_packages_unoptimized() { build_platform_host(); - let expected_ending = - "Hello, World! This text came from a package! This text came from a CSV package!\n"; let runner = cli_utils::helpers::Run::new_roc() .arg(CMD_RUN) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) @@ -581,7 +507,8 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -589,8 +516,6 @@ mod cli_run { fn run_packages_optimized() { build_platform_host(); - let expected_ending = - "Hello, World! This text came from a package! This text came from a CSV package!\n"; let runner = cli_utils::helpers::Run::new_roc() .arg(CMD_RUN) .arg(OPTIMIZE_FLAG) @@ -600,7 +525,8 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -613,7 +539,6 @@ mod cli_run { "direct-one.roc", ); - let expected_ending = "[One imports Two: From two]\n"; let runner = cli_utils::helpers::Run::new_roc() .arg(CMD_RUN) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) @@ -622,7 +547,8 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -635,7 +561,6 @@ mod cli_run { "direct-one-and-two.roc", ); - let expected_ending = "[One imports Two: From two] | From two\n"; let runner = cli_utils::helpers::Run::new_roc() .arg(CMD_RUN) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) @@ -644,7 +569,8 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -657,7 +583,6 @@ mod cli_run { "direct-zero.roc", ); - let expected_ending = "[Zero imports One: [One imports Two: From two]]\n"; let runner = cli_utils::helpers::Run::new_roc() .arg(CMD_RUN) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) @@ -666,37 +591,14 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] fn expects_dev() { build_platform_host(); - let expected_ending = indoc!( - r#" - ── EXPECT FAILED in tests/expects/expects.roc ────────────────────────────────── - - This expectation failed: - - 25│ expect words == [] - ^^^^^^^^^^^ - - 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! - - [:28] x = 42 - [:30] "Fjoer en ferdjer frieten oan dyn geve lea" = "Fjoer en ferdjer frieten oan dyn geve lea" - [:32] "this is line 24" = "this is line 24" - [:18] x = "abc" - [:18] x = 10 - [:18] x = (A (B C)) - "# - ); let runner = cli_utils::helpers::Run::new_roc() .arg(CMD_DEV) .add_arg_if(LINKER_FLAG, TEST_LEGACY_LINKER) @@ -704,68 +606,22 @@ mod cli_run { .arg(file_from_root("crates/cli/tests/expects", "expects.roc").as_path()); let out = runner.run(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] fn expects_test() { build_platform_host(); - let expected_ending = indoc!( - r#" - ── EXPECT FAILED in tests/expects/expects.roc ────────────────────────────────── - - This expectation failed: - - 6│ expect a == 2 - ^^^^^^ - - When it failed, these variables had these values: - - a : Num * - a = 1 - - ── EXPECT FAILED in tests/expects/expects.roc ────────────────────────────────── - - This expectation failed: - - 7│ expect a == 3 - ^^^^^^ - - When it failed, these variables had these values: - - a : Num * - a = 1 - - ── EXPECT FAILED in tests/expects/expects.roc ────────────────────────────────── - - This expectation failed: - - 11│> expect - 12│> a = makeA - 13│> b = 2i64 - 14│> - 15│> a == b - - When it failed, these variables had these values: - - a : Int Signed64 - a = 1 - - b : I64 - b = 2 - - - 1 failed and 0 passed in ms. - "# - ); let runner = cli_utils::helpers::Run::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(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -773,45 +629,13 @@ mod cli_run { fn module_params() { build_platform_host(); - let expected_ending = indoc!( - r#" - App1.baseUrl: https://api.example.com/one - App2.baseUrl: http://api.example.com/two - App3.baseUrl: https://api.example.com/three - App1.getUser 1: https://api.example.com/one/users/1 - App2.getUser 2: http://api.example.com/two/users/2 - App3.getUser 3: https://api.example.com/three/users/3 - App1.getPost 1: https://api.example.com/one/posts/1 - App2.getPost 2: http://api.example.com/two/posts/2 - App3.getPost 3: https://api.example.com/three/posts/3 - App1.getPosts [1, 2]: ["https://api.example.com/one/posts/1", "https://api.example.com/one/posts/2"] - App2.getPosts [3, 4]: ["http://api.example.com/two/posts/3", "http://api.example.com/two/posts/4"] - App2.getPosts [5, 6]: ["http://api.example.com/two/posts/5", "http://api.example.com/two/posts/6"] - App1.getPostComments 1: https://api.example.com/one/posts/1/comments - App2.getPostComments 2: http://api.example.com/two/posts/2/comments - App2.getPostComments 3: http://api.example.com/two/posts/3/comments - App1.getCompanies [1, 2]: ["https://api.example.com/one/companies/1", "https://api.example.com/one/companies/2"] - App2.getCompanies [3, 4]: ["http://api.example.com/two/companies/3", "http://api.example.com/two/companies/4"] - App2.getCompanies [5, 6]: ["http://api.example.com/two/companies/5", "http://api.example.com/two/companies/6"] - App1.getPostAliased 1: https://api.example.com/one/posts/1 - App2.getPostAliased 2: http://api.example.com/two/posts/2 - App3.getPostAliased 3: https://api.example.com/three/posts/3 - App1.baseUrlAliased: https://api.example.com/one - App2.baseUrlAliased: http://api.example.com/two - App3.baseUrlAliased: https://api.example.com/three - App1.getUserSafe 1: https://api.example.com/one/users/1 - Prod.getUserSafe 2: http://api.example.com/prod_1/users/2?safe=true - usersApp1: ["https://api.example.com/one/users/1", "https://api.example.com/one/users/2", "https://api.example.com/one/users/3"] - getUserApp3Nested 3: https://api.example.com/three/users/3 - usersApp3Passed: ["https://api.example.com/three/users/1", "https://api.example.com/three/users/2", "https://api.example.com/three/users/3"] - "# - ); let runner = cli_utils::helpers::Run::new_roc() .arg(CMD_RUN) .arg(file_from_root("crates/cli/tests/module_params", "app.roc").as_path()); let out = runner.run(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] @@ -864,9 +688,8 @@ mod cli_run { fn test_benchmark( roc_filename: &str, stdin: Vec<&'static str>, - expected_ending: &str, use_valgrind: UseValgrind, - ) { + ) -> String { let dir_name = "crates/cli/tests/benchmarks"; let file_path = file_from_root(dir_name, roc_filename); @@ -883,31 +706,27 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + + out.normalize_stdout_and_stderr() } #[cfg(feature = "wasm32-cli-run")] - check_output_wasm(file_path.as_path(), stdin, expected_ending); + check_output_wasm(file_path.as_path(), stdin); #[cfg(feature = "i386-cli-run")] - check_output_i386(file_path.as_path(), stdin, expected_ending); + check_output_i386(file_path.as_path(), stdin); } #[cfg(feature = "wasm32-cli-run")] - fn check_output_wasm(file_name: &std::path::Path, stdin: Vec<&str>, expected_ending: &str) { + fn check_output_wasm(file_name: &std::path::Path, stdin: Vec<&str>) { // Check with and without optimizations - check_wasm_output_with_stdin(file_name, stdin.clone(), &[], expected_ending); + check_wasm_output_with_stdin(file_name, stdin.clone(), &[]); - check_wasm_output_with_stdin(file_name, stdin, &[OPTIMIZE_FLAG], expected_ending); + check_wasm_output_with_stdin(file_name, stdin, &[OPTIMIZE_FLAG]); } #[cfg(feature = "wasm32-cli-run")] - fn check_wasm_output_with_stdin( - file: &std::path::Path, - stdin: Vec<&str>, - flags: &[&str], - expected_ending: &str, - ) { + fn check_wasm_output_with_stdin(file: &std::path::Path, stdin: Vec<&str>, flags: &[&str]) { use super::{concatcp, TARGET_FLAG}; let mut flags = flags.to_vec(); @@ -924,20 +743,11 @@ mod cli_run { let stdout = crate::run_wasm(&file.with_extension("wasm"), stdin); - if !stdout.ends_with(expected_ending) { - panic!( - "expected output to end with {:?} but instead got {:#?}", - expected_ending, stdout - ); - } + insta::assert_snapshot!(stdout); } #[cfg(feature = "i386-cli-run")] - fn check_output_i386( - file_path: &std::path::Path, - stdin: Vec<&'static str>, - expected_ending: &str, - ) { + fn check_output_i386(file_path: &std::path::Path, stdin: Vec<&'static str>) { use super::{concatcp, TARGET_FLAG}; let i386_target_arg = concatcp!(TARGET_FLAG, "=x86_32"); @@ -951,7 +761,7 @@ mod cli_run { let out = runner.run(); out.assert_clean_success(); - out.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); let run_optimized = Run::new_roc() .arg(CMD_RUN) @@ -963,47 +773,41 @@ mod cli_run { let out_optimized = run_optimized.run(); out_optimized.assert_clean_success(); - out_optimized.assert_stdout_and_stderr_ends_with(expected_ending); + insta::assert_snapshot!(out_optimized.normalize_stdout_and_stderr()); } #[test] #[cfg_attr(windows, ignore)] fn nqueens() { - test_benchmark("nQueens.roc", vec!["6"], "4\n", UseValgrind::Yes) + insta::assert_snapshot!(test_benchmark("nQueens.roc", vec!["6"], UseValgrind::Yes)); } #[test] #[cfg_attr(windows, ignore)] fn cfold() { - test_benchmark("cFold.roc", vec!["3"], "11 & 11\n", UseValgrind::Yes) + insta::assert_snapshot!(test_benchmark("cFold.roc", vec!["3"], UseValgrind::Yes)) } #[test] #[cfg_attr(windows, ignore)] fn deriv() { - test_benchmark( - "deriv.roc", - vec!["2"], - "1 count: 6\n2 count: 22\n", - UseValgrind::Yes, - ) + insta::assert_snapshot!(test_benchmark("deriv.roc", vec!["2"], UseValgrind::Yes)) } #[test] #[cfg_attr(windows, ignore)] fn rbtree_ck() { - test_benchmark("rBTreeCk.roc", vec!["100"], "10\n", UseValgrind::Yes) + insta::assert_snapshot!(test_benchmark( + "rBTreeCk.roc", + vec!["100"], + UseValgrind::Yes + )) } #[test] #[cfg_attr(windows, ignore)] fn rbtree_insert() { - test_benchmark( - "rBTreeInsert.roc", - vec![], - "Node Black 0 {} Empty Empty\n", - UseValgrind::Yes, - ) + insta::assert_snapshot!(test_benchmark("rBTreeInsert.roc", vec![], UseValgrind::Yes)) } /* @@ -1025,31 +829,26 @@ mod 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."); } else { - test_benchmark("testAStar.roc", vec![], "True\n", UseValgrind::No) + insta::assert_snapshot!(test_benchmark("testAStar.roc", vec![], UseValgrind::No)) } } #[test] #[cfg_attr(windows, ignore)] fn base64() { - test_benchmark( - "testBase64.roc", - vec![], - "encoded: SGVsbG8gV29ybGQ=\ndecoded: Hello World\n", - UseValgrind::Yes, - ) + insta::assert_snapshot!(test_benchmark("testBase64.roc", vec![], UseValgrind::Yes)) } #[test] #[cfg_attr(windows, ignore)] fn closure() { - test_benchmark("closure.roc", vec![], "", UseValgrind::No) + insta::assert_snapshot!(test_benchmark("closure.roc", vec![], UseValgrind::No)) } #[test] #[cfg_attr(windows, ignore)] fn issue2279() { - test_benchmark("issue2279.roc", vec![], "Hello, world!\n", UseValgrind::Yes) + insta::assert_snapshot!(test_benchmark("issue2279.roc", vec![], UseValgrind::Yes)) } #[test] @@ -1066,131 +865,51 @@ mod cli_run { #[test] fn known_type_error() { - let expected_ending = indoc!( - r#" - - ── TYPE MISMATCH in tests/known_bad/TypeError.roc ────────────────────────────── - - Something is off with the body of the main definition: - - 3│ main : Str -> Task {} [] - 4│ main = \_ -> - 5│ "this is a string, not a Task {} [] function like the platform expects." - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - - The body is a string of type: - - Str - - But the type annotation on main says it should be: - - Task {} [] - - Tip: Add type annotations to functions or values to help you figure - this out. - - ──────────────────────────────────────────────────────────────────────────────── - - 1 error and 0 warning found in ms - "# - ); - - Run::new_roc() + let out = Run::new_roc() .arg(CMD_CHECK) .arg(file_from_root( "crates/cli/tests/known_bad", "TypeError.roc", )) - .run() - .assert_stdout_and_stderr_ends_with(expected_ending); + .run(); + + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] fn known_type_error_with_long_path() { - let expected_ending = indoc!( - r#" - - ── UNUSED IMPORT in ...nown_bad/UnusedImportButWithALongFileNameForTesting.roc ─ - - Symbol is imported but not used. - - 3│ import Symbol exposing [Ident] - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - - Since Symbol isn't used, you don't need to import it. - - ──────────────────────────────────────────────────────────────────────────────── - - 0 error and 1 warning found in ms - "# - ); - - Run::new_roc() + let out = Run::new_roc() .arg(CMD_CHECK) .arg(file_from_root( "crates/cli/tests/known_bad", "UnusedImportButWithALongFileNameForTesting.roc", )) - .run() - .assert_stdout_and_stderr_ends_with(expected_ending); + .run(); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] fn exposed_not_defined() { - let expected_ending = indoc!( - r#" - - ── MISSING DEFINITION in tests/known_bad/ExposedNotDefined.roc ───────────────── - - bar is listed as exposed, but it isn't defined in this module. - - You can fix this by adding a definition for bar, or by removing it - from exposes. - - ──────────────────────────────────────────────────────────────────────────────── - - 1 error and 0 warning found in ms - "# - ); - - Run::new_roc() + let out = Run::new_roc() .arg(CMD_CHECK) .arg(file_from_root( "crates/cli/tests/known_bad", "ExposedNotDefined.roc", )) - .run() - .assert_stdout_and_stderr_ends_with(expected_ending); + .run(); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] fn unused_import() { - let expected_ending = indoc!( - r#" - - ── UNUSED IMPORT in tests/known_bad/UnusedImport.roc ─────────────────────────── - - Symbol is imported but not used. - - 3│ import Symbol exposing [Ident] - ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - - Since Symbol isn't used, you don't need to import it. - - ──────────────────────────────────────────────────────────────────────────────── - - 0 error and 1 warning found in ms - "# - ); - - Run::new_roc() + let out = Run::new_roc() .arg(CMD_CHECK) .arg(file_from_root( "crates/cli/tests/known_bad", "UnusedImport.roc", )) - .run() - .assert_stdout_and_stderr_ends_with(expected_ending); + .run(); + insta::assert_snapshot!(out.normalize_stdout_and_stderr()); } #[test] diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__exposed_not_defined.snap b/crates/cli/tests/snapshots/cli_run__cli_run__exposed_not_defined.snap new file mode 100644 index 0000000000..dfb1984902 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__exposed_not_defined.snap @@ -0,0 +1,14 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +── MISSING DEFINITION in tests/known_bad/ExposedNotDefined.roc ───────────────── + +bar is listed as exposed, but it isn't defined in this module. + +You can fix this by adding a definition for bar, or by removing it +from exposes. + +──────────────────────────────────────────────────────────────────────────────── + +1 error and 0 warning found in ms diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__fibonacci.snap b/crates/cli/tests/snapshots/cli_run__cli_run__fibonacci.snap new file mode 100644 index 0000000000..3a4a1c3df1 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__fibonacci.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +55🔨 Building host ... diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__known_type_error.snap b/crates/cli/tests/snapshots/cli_run__cli_run__known_type_error.snap new file mode 100644 index 0000000000..d9a4ef62a2 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__known_type_error.snap @@ -0,0 +1,27 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +── TYPE MISMATCH in tests/known_bad/TypeError.roc ────────────────────────────── + +Something is off with the body of the main definition: + +3│ main : Str -> Task {} [] +4│ main = \_ -> +5│ "this is a string, not a Task {} [] function like the platform expects." + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The body is a string of type: + + Str + +But the type annotation on main says it should be: + + Task {} [] + +Tip: Add type annotations to functions or values to help you figure +this out. + +──────────────────────────────────────────────────────────────────────────────── + +1 error and 0 warning found in ms diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__known_type_error_with_long_path.snap b/crates/cli/tests/snapshots/cli_run__cli_run__known_type_error_with_long_path.snap new file mode 100644 index 0000000000..7ced745951 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__known_type_error_with_long_path.snap @@ -0,0 +1,16 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +── UNUSED IMPORT in ...nown_bad/UnusedImportButWithALongFileNameForTesting.roc ─ + +Symbol is imported but not used. + +3│ import Symbol exposing [Ident] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Since Symbol isn't used, you don't need to import it. + +──────────────────────────────────────────────────────────────────────────────── + +0 error and 1 warning found in ms diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__module_imports_pkg_no_flag.snap b/crates/cli/tests/snapshots/cli_run__cli_run__module_imports_pkg_no_flag.snap new file mode 100644 index 0000000000..4baf0d63d9 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__module_imports_pkg_no_flag.snap @@ -0,0 +1,18 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +── UNRECOGNIZED PACKAGE in tests/module_imports_pkg/Module.roc ───────────────── + +This module is trying to import from `pkg`: + +3│ import pkg.Foo + ^^^^^^^ + +A lowercase name indicates a package shorthand, but I don't know which +packages are available. + +When checking a module directly, I look for a `main.roc` app or +package to resolve shorthands from. + +You can create it, or specify an existing one with the --main flag. diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__module_imports_pkg_w_flag.snap b/crates/cli/tests/snapshots/cli_run__cli_run__module_imports_pkg_w_flag.snap new file mode 100644 index 0000000000..a63403fb7b --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__module_imports_pkg_w_flag.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +0 failed and 1 passed in ms. diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__module_imports_unknown_pkg.snap b/crates/cli/tests/snapshots/cli_run__cli_run__module_imports_unknown_pkg.snap new file mode 100644 index 0000000000..5d606fb5f3 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__module_imports_unknown_pkg.snap @@ -0,0 +1,21 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +── UNRECOGNIZED PACKAGE in tests/module_imports_pkg/ImportsUnknownPkg.roc ────── + +This module is trying to import from `cli`: + +3│ import cli.Foo + ^^^^^^^ + +A lowercase name indicates a package shorthand, but I don't recognize +this one. Did you mean one of these? + + pkg + +Note: I'm using the following module to resolve package shorthands: + + tests/module_imports_pkg/app.roc + +You can specify a different one with the --main flag. diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__platform_requires_pkg.snap b/crates/cli/tests/snapshots/cli_run__cli_run__platform_requires_pkg.snap new file mode 100644 index 0000000000..e16b8949ab --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__platform_requires_pkg.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +from app from package🔨 Building host ... diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__platform_switching_rust.snap b/crates/cli/tests/snapshots/cli_run__cli_run__platform_switching_rust.snap new file mode 100644 index 0000000000..b2376a65cb --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__platform_switching_rust.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +Roc <3 Rust!🔨 Building host ... diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__platform_switching_zig.snap b/crates/cli/tests/snapshots/cli_run__cli_run__platform_switching_zig.snap new file mode 100644 index 0000000000..1d33417366 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__platform_switching_zig.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +Roc <3 Zig!🔨 Building host ... diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__quicksort.snap b/crates/cli/tests/snapshots/cli_run__cli_run__quicksort.snap new file mode 100644 index 0000000000..3b6a986a44 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__quicksort.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]🔨 Building host ... diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__terminal_ui_tea.snap b/crates/cli/tests/snapshots/cli_run__cli_run__terminal_ui_tea.snap new file mode 100644 index 0000000000..15329614dd --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__terminal_ui_tea.snap @@ -0,0 +1,6 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +Hello World! +Hello Worldfoo!🔨 Building host ... diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__astar.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__astar.snap new file mode 100644 index 0000000000..f88526e6b9 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__astar.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: "test_benchmark(\"testAStar.roc\", vec![], UseValgrind::No)" +--- +True diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__base64.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__base64.snap new file mode 100644 index 0000000000..ac77eaac35 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__base64.snap @@ -0,0 +1,6 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: "test_benchmark(\"testBase64.roc\", vec![], UseValgrind::Yes)" +--- +encoded: SGVsbG8gV29ybGQ= +decoded: Hello World diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__cfold.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__cfold.snap new file mode 100644 index 0000000000..fc6cd0d43c --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__cfold.snap @@ -0,0 +1,6 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: "test_benchmark(\"cFold.roc\", vec![\"3\"], UseValgrind::Yes)" +--- +Please enter an integer +11 & 11 diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__closure.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__closure.snap new file mode 100644 index 0000000000..e7cd5f5a65 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__closure.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: "test_benchmark(\"closure.roc\", vec![], UseValgrind::No)" +--- + diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__deriv.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__deriv.snap new file mode 100644 index 0000000000..451a0b08e4 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__deriv.snap @@ -0,0 +1,7 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: "test_benchmark(\"deriv.roc\", vec![\"2\"], UseValgrind::Yes)" +--- +Please enter an integer +1 count: 6 +2 count: 22 diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__issue2279.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__issue2279.snap new file mode 100644 index 0000000000..44dd71eb36 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__issue2279.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: "test_benchmark(\"issue2279.roc\", vec![], UseValgrind::Yes)" +--- +Hello, world! diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__nqueens.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__nqueens.snap new file mode 100644 index 0000000000..35efc2a92c --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__nqueens.snap @@ -0,0 +1,6 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: "test_benchmark(\"nQueens.roc\", vec![\"6\"], UseValgrind::Yes)" +--- +Please enter an integer +4 diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__rbtree_ck.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__rbtree_ck.snap new file mode 100644 index 0000000000..e6ce69171e --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__rbtree_ck.snap @@ -0,0 +1,6 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: "test_benchmark(\"rBTreeCk.roc\", vec![\"100\"], UseValgrind::Yes)" +--- +Please enter an integer +10 diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__rbtree_insert.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__rbtree_insert.snap new file mode 100644 index 0000000000..e59508c79b --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_benchmarks__rbtree_insert.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: "test_benchmark(\"rBTreeInsert.roc\", vec![], UseValgrind::Yes)" +--- +Node Black 0 {} Empty Empty diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_effects_zig__combine_tasks_with_record_builder.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_effects_zig__combine_tasks_with_record_builder.snap new file mode 100644 index 0000000000..4ce76539dd --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_effects_zig__combine_tasks_with_record_builder.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +For multiple tasks: {a: 123, b: "abc", c: [123]} diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_effects_zig__inspect_logging.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_effects_zig__inspect_logging.snap new file mode 100644 index 0000000000..5560edcfbd --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_effects_zig__inspect_logging.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +(@Community {friends: [{2}, {2}, {0, 1}], people: [(@Person {age: 27, favoriteColor: Blue, firstName: "John", hasBeard: Bool.true, lastName: "Smith"}), (@Person {age: 47, favoriteColor: Green, firstName: "Debby", hasBeard: Bool.false, lastName: "Johnson"}), (@Person {age: 33, favoriteColor: (RGB (255, 255, 0)), firstName: "Jane", hasBeard: Bool.false, lastName: "Doe"})]}) diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_effects_zig__interactive_effects.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_effects_zig__interactive_effects.snap new file mode 100644 index 0000000000..7dfda94b42 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_effects_zig__interactive_effects.snap @@ -0,0 +1,6 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +You entered: hi there! +It is known diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_effects_zig__module_params_pass_task.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_effects_zig__module_params_pass_task.snap new file mode 100644 index 0000000000..addaa846da --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_effects_zig__module_params_pass_task.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +Hi, Agus! diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__expects_dev.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__expects_dev.snap new file mode 100644 index 0000000000..977d62e388 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__expects_dev.snap @@ -0,0 +1,22 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +── EXPECT FAILED in tests/expects/expects.roc ────────────────────────────────── + +This expectation failed: + +25│ expect words == [] + ^^^^^^^^^^^ + +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![:28] x = 42 +[:30] "Fjoer en ferdjer frieten oan dyn geve lea" = "Fjoer en ferdjer frieten oan dyn geve lea" +[:32] "this is line 24" = "this is line 24" +[:18] x = "abc" +[:18] x = 10 +[:18] x = (A (B C)) diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__expects_test.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__expects_test.snap new file mode 100644 index 0000000000..5cebd0e81f --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__expects_test.snap @@ -0,0 +1,48 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +── EXPECT FAILED in tests/expects/expects.roc ────────────────────────────────── + +This expectation failed: + +6│ expect a == 2 + ^^^^^^ + +When it failed, these variables had these values: + +a : Num * +a = 1 + +── EXPECT FAILED in tests/expects/expects.roc ────────────────────────────────── + +This expectation failed: + +7│ expect a == 3 + ^^^^^^ + +When it failed, these variables had these values: + +a : Num * +a = 1 + +── EXPECT FAILED in tests/expects/expects.roc ────────────────────────────────── + +This expectation failed: + +11│> expect +12│> a = makeA +13│> b = 2i64 +14│> +15│> a == b + +When it failed, these variables had these values: + +a : Int Signed64 +a = 1 + +b : I64 +b = 2 + + +1 failed and 0 passed in ms. diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__module_params.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__module_params.snap new file mode 100644 index 0000000000..15ce03d166 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__module_params.snap @@ -0,0 +1,33 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +App1.baseUrl: https://api.example.com/one +App2.baseUrl: http://api.example.com/two +App3.baseUrl: https://api.example.com/three +App1.getUser 1: https://api.example.com/one/users/1 +App2.getUser 2: http://api.example.com/two/users/2 +App3.getUser 3: https://api.example.com/three/users/3 +App1.getPost 1: https://api.example.com/one/posts/1 +App2.getPost 2: http://api.example.com/two/posts/2 +App3.getPost 3: https://api.example.com/three/posts/3 +App1.getPosts [1, 2]: ["https://api.example.com/one/posts/1", "https://api.example.com/one/posts/2"] +App2.getPosts [3, 4]: ["http://api.example.com/two/posts/3", "http://api.example.com/two/posts/4"] +App2.getPosts [5, 6]: ["http://api.example.com/two/posts/5", "http://api.example.com/two/posts/6"] +App1.getPostComments 1: https://api.example.com/one/posts/1/comments +App2.getPostComments 2: http://api.example.com/two/posts/2/comments +App2.getPostComments 3: http://api.example.com/two/posts/3/comments +App1.getCompanies [1, 2]: ["https://api.example.com/one/companies/1", "https://api.example.com/one/companies/2"] +App2.getCompanies [3, 4]: ["http://api.example.com/two/companies/3", "http://api.example.com/two/companies/4"] +App2.getCompanies [5, 6]: ["http://api.example.com/two/companies/5", "http://api.example.com/two/companies/6"] +App1.getPostAliased 1: https://api.example.com/one/posts/1 +App2.getPostAliased 2: http://api.example.com/two/posts/2 +App3.getPostAliased 3: https://api.example.com/three/posts/3 +App1.baseUrlAliased: https://api.example.com/one +App2.baseUrlAliased: http://api.example.com/two +App3.baseUrlAliased: https://api.example.com/three +App1.getUserSafe 1: https://api.example.com/one/users/1 +Prod.getUserSafe 2: http://api.example.com/prod_1/users/2?safe=true +usersApp1: ["https://api.example.com/one/users/1", "https://api.example.com/one/users/2", "https://api.example.com/one/users/3"] +getUserApp3Nested 3: https://api.example.com/three/users/3 +usersApp3Passed: ["https://api.example.com/three/users/1", "https://api.example.com/three/users/2", "https://api.example.com/three/users/3"] diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_double_transitive_dep_app.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_double_transitive_dep_app.snap new file mode 100644 index 0000000000..5b9ea6c8b7 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_double_transitive_dep_app.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +[Zero imports One: [One imports Two: From two]] diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_multi_dep_str_optimized.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_multi_dep_str_optimized.snap new file mode 100644 index 0000000000..fb77c80c42 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_multi_dep_str_optimized.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +I am Dep2.str2 diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_multi_dep_str_unoptimized.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_multi_dep_str_unoptimized.snap new file mode 100644 index 0000000000..fb77c80c42 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_multi_dep_str_unoptimized.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +I am Dep2.str2 diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_multi_dep_thunk_optimized.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_multi_dep_thunk_optimized.snap new file mode 100644 index 0000000000..0a40188d18 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_multi_dep_thunk_optimized.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +I am Dep2.value2 diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_multi_dep_thunk_unoptimized.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_multi_dep_thunk_unoptimized.snap new file mode 100644 index 0000000000..0a40188d18 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_multi_dep_thunk_unoptimized.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +I am Dep2.value2 diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_packages_optimized.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_packages_optimized.snap new file mode 100644 index 0000000000..75e523e59b --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_packages_optimized.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +Hello, World! This text came from a package! This text came from a CSV package! diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_packages_unoptimized.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_packages_unoptimized.snap new file mode 100644 index 0000000000..75e523e59b --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_packages_unoptimized.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +Hello, World! This text came from a package! This text came from a CSV package! diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_transitive_and_direct_dep_app.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_transitive_and_direct_dep_app.snap new file mode 100644 index 0000000000..47430a7967 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_transitive_and_direct_dep_app.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +[One imports Two: From two] | From two diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_transitive_deps_app.snap b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_transitive_deps_app.snap new file mode 100644 index 0000000000..a2e53c73f9 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__test_platform_simple_zig__run_transitive_deps_app.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +[One imports Two: From two] diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__transitive_expects.snap b/crates/cli/tests/snapshots/cli_run__cli_run__transitive_expects.snap new file mode 100644 index 0000000000..9860db104a --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__transitive_expects.snap @@ -0,0 +1,5 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +0 failed and 3 passed in ms. diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__transitive_expects_verbose.snap b/crates/cli/tests/snapshots/cli_run__cli_run__transitive_expects_verbose.snap new file mode 100644 index 0000000000..00ac212ed0 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__transitive_expects_verbose.snap @@ -0,0 +1,11 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +Compiled in ms. + +Direct.roc: + 0 failed and 2 passed in ms. + +Transitive.roc: + 0 failed and 1 passed in ms. diff --git a/crates/cli/tests/snapshots/cli_run__cli_run__unused_import.snap b/crates/cli/tests/snapshots/cli_run__cli_run__unused_import.snap new file mode 100644 index 0000000000..6050c0fcd0 --- /dev/null +++ b/crates/cli/tests/snapshots/cli_run__cli_run__unused_import.snap @@ -0,0 +1,16 @@ +--- +source: crates/cli/tests/cli_run.rs +expression: out.normalize_stdout_and_stderr() +--- +── UNUSED IMPORT in tests/known_bad/UnusedImport.roc ─────────────────────────── + +Symbol is imported but not used. + +3│ import Symbol exposing [Ident] + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Since Symbol isn't used, you don't need to import it. + +──────────────────────────────────────────────────────────────────────────────── + +0 error and 1 warning found in ms diff --git a/crates/cli_utils/src/helpers.rs b/crates/cli_utils/src/helpers.rs index 487f7f8638..2ebb34e485 100644 --- a/crates/cli_utils/src/helpers.rs +++ b/crates/cli_utils/src/helpers.rs @@ -6,7 +6,6 @@ extern crate tempfile; use regex::Regex; use roc_command_utils::{cargo, pretty_command_string, root_dir}; -use roc_reporting::report::ANSI_STYLE_CODES; use serde::Deserialize; use serde_xml_rs::from_str; use std::env; @@ -115,30 +114,6 @@ impl Out { normalized_output.trim().to_string() } - /// Assert that the stdout ends with the expected string - /// This normalises the output for comparison in tests such as replacing timings - /// with a placeholder, or stripping ANSI colors - pub fn assert_stdout_and_stderr_ends_with(&self, expected: &str) { - let normalised_output = format!( - "{}{}", - Out::normalize_for_tests(&self.stdout), - Out::normalize_for_tests(&self.stderr) - ); - - assert!( - normalised_output.ends_with(expected), - "\n{}EXPECTED stdout and stderr after normalizing:\n----------------\n{}{}\n{}ACTUAL stdout and stderr after normalizing:\n----------------\n{}{}{}\n----------------\n{}", - ANSI_STYLE_CODES.cyan, - ANSI_STYLE_CODES.reset, - expected, - ANSI_STYLE_CODES.cyan, - ANSI_STYLE_CODES.reset, - normalised_output, - ANSI_STYLE_CODES.cyan, - ANSI_STYLE_CODES.reset, - ); - } - pub fn normalize_stdout_and_stderr(&self) -> String { format!( "{}{}",