From 45e24fd5e9028a951811de5ace75ae0b8b36d57c Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Tue, 2 Apr 2024 22:39:15 +0200 Subject: [PATCH 1/9] Rename enum for future enhancement --- crates/cli/src/lib.rs | 2 +- crates/compiler/load_internal/src/file.rs | 12 ++++++------ crates/compiler/test_mono/src/tests.rs | 2 +- crates/repl_expect/src/lib.rs | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 978f42d4602..b82a0ca871b 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -504,7 +504,7 @@ pub fn test(matches: &ArgMatches, target: Target) -> io::Result { render: roc_reporting::report::RenderTarget::ColorTerminal, palette: roc_reporting::report::DEFAULT_PALETTE, threading, - exec_mode: ExecutionMode::Test, + exec_mode: ExecutionMode::TestIfCheck, }; let load_result = roc_load::load_and_monomorphize( arena, diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs index e38d70c2689..d02d73ff65a 100644 --- a/crates/compiler/load_internal/src/file.rs +++ b/crates/compiler/load_internal/src/file.rs @@ -120,7 +120,7 @@ pub enum ExecutionMode { ExecutableIfCheck, /// Test is like [`ExecutionMode::ExecutableIfCheck`], but rather than producing a proper /// executable, run tests. - Test, + TestIfCheck, } impl ExecutionMode { @@ -129,12 +129,12 @@ impl ExecutionMode { match self { Executable => Phase::MakeSpecializations, - Check | ExecutableIfCheck | Test => Phase::SolveTypes, + Check | ExecutableIfCheck | TestIfCheck => Phase::SolveTypes, } } fn build_if_checks(&self) -> bool { - matches!(self, Self::ExecutableIfCheck | Self::Test) + matches!(self, Self::ExecutableIfCheck | Self::TestIfCheck) } } @@ -398,7 +398,7 @@ fn start_phase<'a>( let derived_module = SharedDerivedModule::clone(&state.derived_module); let build_expects = - matches!(state.exec_mode, ExecutionMode::Test) && expectations.is_some(); + matches!(state.exec_mode, ExecutionMode::TestIfCheck) && expectations.is_some(); BuildTask::BuildPendingSpecializations { layout_cache, @@ -2624,7 +2624,7 @@ fn update<'a>( let add_to_host_exposed = is_host_exposed && // During testing, we don't need to expose anything to the host. - !matches!(state.exec_mode, ExecutionMode::Test); + !matches!(state.exec_mode, ExecutionMode::TestIfCheck); if add_to_host_exposed { state.exposed_to_host.top_level_values.extend( @@ -3201,7 +3201,7 @@ fn finish_specialization<'a>( let entry_point = { let interns: &mut Interns = &mut interns; match state.exec_mode { - ExecutionMode::Test => Ok(EntryPoint::Test), + ExecutionMode::TestIfCheck => Ok(EntryPoint::Test), ExecutionMode::Executable | ExecutionMode::ExecutableIfCheck => { use PlatformPath::*; diff --git a/crates/compiler/test_mono/src/tests.rs b/crates/compiler/test_mono/src/tests.rs index 736a2710ebc..babc759788b 100644 --- a/crates/compiler/test_mono/src/tests.rs +++ b/crates/compiler/test_mono/src/tests.rs @@ -83,7 +83,7 @@ fn compiles_to_ir(test_name: &str, src: &str, mode: &str, allow_type_errors: boo let exec_mode = match mode { "exec" => ExecutionMode::Executable, - "test" => ExecutionMode::Test, + "test" => ExecutionMode::TestIfCheck, _ => panic!("Invalid test_mono exec mode {mode}"), }; diff --git a/crates/repl_expect/src/lib.rs b/crates/repl_expect/src/lib.rs index 95fa5879858..31e681a7030 100644 --- a/crates/repl_expect/src/lib.rs +++ b/crates/repl_expect/src/lib.rs @@ -123,7 +123,7 @@ mod test { render: RenderTarget::ColorTerminal, palette: DEFAULT_PALETTE, threading: Threading::Single, - exec_mode: ExecutionMode::Test, + exec_mode: ExecutionMode::TestIfCheck, }; let loaded = match roc_load::load_and_monomorphize_from_str( arena, From b4bd75fce85d330257281bdaf0ddda24d3bec478 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Tue, 2 Apr 2024 23:29:10 +0200 Subject: [PATCH 2/9] Add --ignore-error flag --- crates/cli/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index b82a0ca871b..4e753fd7f7b 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -72,6 +72,7 @@ pub const FLAG_STDOUT: &str = "stdout"; pub const FLAG_WASM_STACK_SIZE_KB: &str = "wasm-stack-size-kb"; pub const FLAG_OUTPUT: &str = "output"; pub const FLAG_FUZZ: &str = "fuzz"; +pub const FLAG_IGNORE_ERROR: &str = "ignore-error"; pub const ROC_FILE: &str = "ROC_FILE"; pub const ROC_DIR: &str = "ROC_DIR"; pub const GLUE_DIR: &str = "GLUE_DIR"; @@ -149,6 +150,12 @@ pub fn build_app() -> Command { .action(ArgAction::SetTrue) .required(false); + let flag_ignore_error = Arg::new(FLAG_IGNORE_ERROR) + .long(FLAG_IGNORE_ERROR) + .help("Run tests even if it has build errors") + .action(ArgAction::SetTrue) + .required(false); + let roc_file_to_run = Arg::new(ROC_FILE) .help("The .roc file of an app to run") .value_parser(value_parser!(PathBuf)) @@ -237,6 +244,7 @@ pub fn build_app() -> Command { .arg(flag_linker.clone()) .arg(flag_prebuilt.clone()) .arg(flag_fuzz.clone()) + .arg(flag_ignore_error.clone()) .arg( Arg::new(FLAG_VERBOSE) .long(FLAG_VERBOSE) From 49f241fd446d5f259f8283793bff73a4aefa39e8 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Tue, 2 Apr 2024 23:32:09 +0200 Subject: [PATCH 3/9] Implement ignore-error for tests --- crates/cli/src/lib.rs | 8 +++++++- crates/compiler/load_internal/src/file.rs | 17 ++++++++++------- crates/compiler/test_mono/src/tests.rs | 1 + 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 4e753fd7f7b..c799fd5d583 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -504,6 +504,12 @@ pub fn test(matches: &ArgMatches, target: Target) -> io::Result { // TODO may need to determine this dynamically based on dev builds. let function_kind = FunctionKind::LambdaSet; + let exec_mode = if matches.get_flag(FLAG_IGNORE_ERROR) { + ExecutionMode::Test + } else { + ExecutionMode::TestIfCheck + }; + // Step 1: compile the app and generate the .o file let load_config = LoadConfig { target, @@ -512,7 +518,7 @@ pub fn test(matches: &ArgMatches, target: Target) -> io::Result { render: roc_reporting::report::RenderTarget::ColorTerminal, palette: roc_reporting::report::DEFAULT_PALETTE, threading, - exec_mode: ExecutionMode::TestIfCheck, + exec_mode, }; let load_result = roc_load::load_and_monomorphize( arena, diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs index d02d73ff65a..c2230182e1b 100644 --- a/crates/compiler/load_internal/src/file.rs +++ b/crates/compiler/load_internal/src/file.rs @@ -118,8 +118,8 @@ pub enum ExecutionMode { Executable, /// Like [`ExecutionMode::Executable`], but stops in the presence of type errors. ExecutableIfCheck, - /// Test is like [`ExecutionMode::ExecutableIfCheck`], but rather than producing a proper - /// executable, run tests. + Test, + /// Like [`ExecutionMode::Test`], but stops in the presence of type errors. TestIfCheck, } @@ -128,7 +128,7 @@ impl ExecutionMode { use ExecutionMode::*; match self { - Executable => Phase::MakeSpecializations, + Executable | Test => Phase::MakeSpecializations, Check | ExecutableIfCheck | TestIfCheck => Phase::SolveTypes, } } @@ -136,6 +136,10 @@ impl ExecutionMode { fn build_if_checks(&self) -> bool { matches!(self, Self::ExecutableIfCheck | Self::TestIfCheck) } + + fn build_tests(&self) -> bool { + matches!(self, Self::TestIfCheck | Self::Test) + } } type SharedIdentIdsByModule = Arc>; @@ -397,8 +401,7 @@ fn start_phase<'a>( let derived_module = SharedDerivedModule::clone(&state.derived_module); - let build_expects = - matches!(state.exec_mode, ExecutionMode::TestIfCheck) && expectations.is_some(); + let build_expects = state.exec_mode.build_tests() && expectations.is_some(); BuildTask::BuildPendingSpecializations { layout_cache, @@ -2624,7 +2627,7 @@ fn update<'a>( let add_to_host_exposed = is_host_exposed && // During testing, we don't need to expose anything to the host. - !matches!(state.exec_mode, ExecutionMode::TestIfCheck); + !state.exec_mode.build_tests(); if add_to_host_exposed { state.exposed_to_host.top_level_values.extend( @@ -3201,7 +3204,7 @@ fn finish_specialization<'a>( let entry_point = { let interns: &mut Interns = &mut interns; match state.exec_mode { - ExecutionMode::TestIfCheck => Ok(EntryPoint::Test), + ExecutionMode::TestIfCheck | ExecutionMode::Test => Ok(EntryPoint::Test), ExecutionMode::Executable | ExecutionMode::ExecutableIfCheck => { use PlatformPath::*; diff --git a/crates/compiler/test_mono/src/tests.rs b/crates/compiler/test_mono/src/tests.rs index babc759788b..691f73878a5 100644 --- a/crates/compiler/test_mono/src/tests.rs +++ b/crates/compiler/test_mono/src/tests.rs @@ -84,6 +84,7 @@ fn compiles_to_ir(test_name: &str, src: &str, mode: &str, allow_type_errors: boo let exec_mode = match mode { "exec" => ExecutionMode::Executable, "test" => ExecutionMode::TestIfCheck, + // TODO: I'm not sure if I should add anything here _ => panic!("Invalid test_mono exec mode {mode}"), }; From 075a4fa6a2242b4e1e75a63227717554d2eb5097 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Fri, 5 Apr 2024 11:54:21 +0200 Subject: [PATCH 4/9] name changes --- crates/cli/src/lib.rs | 16 ++++++++-------- crates/compiler/build/src/program.rs | 4 ++-- crates/compiler/load_internal/src/file.rs | 20 ++++++++++---------- crates/compiler/test_gen/src/helpers/llvm.rs | 2 +- crates/compiler/test_mono/src/tests.rs | 4 ++-- crates/compiler/uitest/src/mono.rs | 2 +- crates/linker/src/lib.rs | 2 +- crates/repl_eval/src/gen.rs | 2 +- crates/repl_expect/src/lib.rs | 2 +- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index c799fd5d583..94056dac2e3 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -72,7 +72,7 @@ pub const FLAG_STDOUT: &str = "stdout"; pub const FLAG_WASM_STACK_SIZE_KB: &str = "wasm-stack-size-kb"; pub const FLAG_OUTPUT: &str = "output"; pub const FLAG_FUZZ: &str = "fuzz"; -pub const FLAG_IGNORE_ERROR: &str = "ignore-error"; +pub const FLAG_IGNORE_ERRORS: &str = "ignore-errors"; pub const ROC_FILE: &str = "ROC_FILE"; pub const ROC_DIR: &str = "ROC_DIR"; pub const GLUE_DIR: &str = "GLUE_DIR"; @@ -150,9 +150,9 @@ pub fn build_app() -> Command { .action(ArgAction::SetTrue) .required(false); - let flag_ignore_error = Arg::new(FLAG_IGNORE_ERROR) - .long(FLAG_IGNORE_ERROR) - .help("Run tests even if it has build errors") + let flag_ignore_errors = Arg::new(FLAG_IGNORE_ERRORS) + .long(FLAG_IGNORE_ERRORS) + .help("Run tests even if there were build errors") .action(ArgAction::SetTrue) .required(false); @@ -244,7 +244,7 @@ pub fn build_app() -> Command { .arg(flag_linker.clone()) .arg(flag_prebuilt.clone()) .arg(flag_fuzz.clone()) - .arg(flag_ignore_error.clone()) + .arg(flag_ignore_errors.clone()) .arg( Arg::new(FLAG_VERBOSE) .long(FLAG_VERBOSE) @@ -504,10 +504,10 @@ pub fn test(matches: &ArgMatches, target: Target) -> io::Result { // TODO may need to determine this dynamically based on dev builds. let function_kind = FunctionKind::LambdaSet; - let exec_mode = if matches.get_flag(FLAG_IGNORE_ERROR) { - ExecutionMode::Test + let exec_mode = if matches.get_flag(FLAG_IGNORE_ERRORS) { + ExecutionMode::TestIgnoreErrors } else { - ExecutionMode::TestIfCheck + ExecutionMode::Test }; // Step 1: compile the app and generate the .o file diff --git a/crates/compiler/build/src/program.rs b/crates/compiler/build/src/program.rs index 767ac6c4fc4..79b5bd02211 100644 --- a/crates/compiler/build/src/program.rs +++ b/crates/compiler/build/src/program.rs @@ -692,8 +692,8 @@ pub fn standard_load_config( threading: Threading, ) -> LoadConfig { let exec_mode = match order { - BuildOrdering::BuildIfChecks => ExecutionMode::ExecutableIfCheck, - BuildOrdering::AlwaysBuild => ExecutionMode::Executable, + BuildOrdering::BuildIfChecks => ExecutionMode::Executable, + BuildOrdering::AlwaysBuild => ExecutionMode::ExecutableIgnoreErrors, }; // UNSTABLE(lambda-erasure) diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs index c2230182e1b..ce7da6d18e3 100644 --- a/crates/compiler/load_internal/src/file.rs +++ b/crates/compiler/load_internal/src/file.rs @@ -115,12 +115,12 @@ pub struct LoadConfig { #[derive(Debug, Clone, Copy)] pub enum ExecutionMode { Check, + ExecutableIgnoreErrors, + /// Like [`ExecutionMode::ExecutableIgnoreErrors`], but stops in the presence of type errors. Executable, - /// Like [`ExecutionMode::Executable`], but stops in the presence of type errors. - ExecutableIfCheck, + TestIgnoreErrors, + /// Like [`ExecutionMode::TestIgnoreErrors`], but stops in the presence of type errors. Test, - /// Like [`ExecutionMode::Test`], but stops in the presence of type errors. - TestIfCheck, } impl ExecutionMode { @@ -128,17 +128,17 @@ impl ExecutionMode { use ExecutionMode::*; match self { - Executable | Test => Phase::MakeSpecializations, - Check | ExecutableIfCheck | TestIfCheck => Phase::SolveTypes, + ExecutableIgnoreErrors | TestIgnoreErrors => Phase::MakeSpecializations, + Check | Executable | Test => Phase::SolveTypes, } } fn build_if_checks(&self) -> bool { - matches!(self, Self::ExecutableIfCheck | Self::TestIfCheck) + matches!(self, Self::Executable | Self::Test) } fn build_tests(&self) -> bool { - matches!(self, Self::TestIfCheck | Self::Test) + matches!(self, Self::Test | Self::TestIgnoreErrors) } } @@ -3204,8 +3204,8 @@ fn finish_specialization<'a>( let entry_point = { let interns: &mut Interns = &mut interns; match state.exec_mode { - ExecutionMode::TestIfCheck | ExecutionMode::Test => Ok(EntryPoint::Test), - ExecutionMode::Executable | ExecutionMode::ExecutableIfCheck => { + ExecutionMode::Test | ExecutionMode::TestIgnoreErrors => Ok(EntryPoint::Test), + ExecutionMode::ExecutableIgnoreErrors | ExecutionMode::Executable => { use PlatformPath::*; let platform_path = match &state.platform_path { diff --git a/crates/compiler/test_gen/src/helpers/llvm.rs b/crates/compiler/test_gen/src/helpers/llvm.rs index feb543f6ec4..002b5bae848 100644 --- a/crates/compiler/test_gen/src/helpers/llvm.rs +++ b/crates/compiler/test_gen/src/helpers/llvm.rs @@ -75,7 +75,7 @@ fn create_llvm_module<'a>( render: RenderTarget::ColorTerminal, palette: DEFAULT_PALETTE, threading: Threading::Single, - exec_mode: ExecutionMode::Executable, + exec_mode: ExecutionMode::ExecutableIgnoreErrors, }; let loaded = roc_load::load_and_monomorphize_from_str( arena, diff --git a/crates/compiler/test_mono/src/tests.rs b/crates/compiler/test_mono/src/tests.rs index 691f73878a5..5d6e28bbc27 100644 --- a/crates/compiler/test_mono/src/tests.rs +++ b/crates/compiler/test_mono/src/tests.rs @@ -82,8 +82,8 @@ fn compiles_to_ir(test_name: &str, src: &str, mode: &str, allow_type_errors: boo use std::path::PathBuf; let exec_mode = match mode { - "exec" => ExecutionMode::Executable, - "test" => ExecutionMode::TestIfCheck, + "exec" => ExecutionMode::ExecutableIgnoreErrors, + "test" => ExecutionMode::Test, // TODO: I'm not sure if I should add anything here _ => panic!("Invalid test_mono exec mode {mode}"), }; diff --git a/crates/compiler/uitest/src/mono.rs b/crates/compiler/uitest/src/mono.rs index 9920448d28f..94d9aeb6d51 100644 --- a/crates/compiler/uitest/src/mono.rs +++ b/crates/compiler/uitest/src/mono.rs @@ -29,7 +29,7 @@ pub(crate) fn write_compiled_ir<'a>( use roc_packaging::cache::RocCacheDir; use std::path::PathBuf; - let exec_mode = ExecutionMode::Executable; + let exec_mode = ExecutionMode::ExecutableIgnoreErrors; let arena = &Bump::new(); diff --git a/crates/linker/src/lib.rs b/crates/linker/src/lib.rs index 7378c8662fe..6224eafe263 100644 --- a/crates/linker/src/lib.rs +++ b/crates/linker/src/lib.rs @@ -86,7 +86,7 @@ pub fn generate_stub_lib( render: RenderTarget::Generic, palette: DEFAULT_PALETTE, threading: Threading::AllAvailable, - exec_mode: ExecutionMode::Executable, + exec_mode: ExecutionMode::ExecutableIgnoreErrors, }, ) .unwrap_or_else(|problem| todo!("{:?}", problem)); diff --git a/crates/repl_eval/src/gen.rs b/crates/repl_eval/src/gen.rs index 8fbf00fe920..b1e2e56c474 100644 --- a/crates/repl_eval/src/gen.rs +++ b/crates/repl_eval/src/gen.rs @@ -67,7 +67,7 @@ pub fn compile_to_mono<'a, 'i, I: Iterator>( render: roc_reporting::report::RenderTarget::ColorTerminal, palette, threading: Threading::Single, - exec_mode: ExecutionMode::Executable, + exec_mode: ExecutionMode::ExecutableIgnoreErrors, }, ); diff --git a/crates/repl_expect/src/lib.rs b/crates/repl_expect/src/lib.rs index 31e681a7030..95fa5879858 100644 --- a/crates/repl_expect/src/lib.rs +++ b/crates/repl_expect/src/lib.rs @@ -123,7 +123,7 @@ mod test { render: RenderTarget::ColorTerminal, palette: DEFAULT_PALETTE, threading: Threading::Single, - exec_mode: ExecutionMode::TestIfCheck, + exec_mode: ExecutionMode::Test, }; let loaded = match roc_load::load_and_monomorphize_from_str( arena, From ab00d2bdc6c7a9c3eff45cde361d7274cca28146 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Fri, 5 Apr 2024 11:58:19 +0200 Subject: [PATCH 5/9] better name --- crates/cli/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 94056dac2e3..648618ab6f0 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -72,7 +72,7 @@ pub const FLAG_STDOUT: &str = "stdout"; pub const FLAG_WASM_STACK_SIZE_KB: &str = "wasm-stack-size-kb"; pub const FLAG_OUTPUT: &str = "output"; pub const FLAG_FUZZ: &str = "fuzz"; -pub const FLAG_IGNORE_ERRORS: &str = "ignore-errors"; +pub const FLAG_IGNORE_BUILD_ERRORS: &str = "ignore-build-errors"; pub const ROC_FILE: &str = "ROC_FILE"; pub const ROC_DIR: &str = "ROC_DIR"; pub const GLUE_DIR: &str = "GLUE_DIR"; @@ -150,8 +150,8 @@ pub fn build_app() -> Command { .action(ArgAction::SetTrue) .required(false); - let flag_ignore_errors = Arg::new(FLAG_IGNORE_ERRORS) - .long(FLAG_IGNORE_ERRORS) + let flag_ignore_build_errors = Arg::new(FLAG_IGNORE_BUILD_ERRORS) + .long(FLAG_IGNORE_BUILD_ERRORS) .help("Run tests even if there were build errors") .action(ArgAction::SetTrue) .required(false); @@ -244,7 +244,7 @@ pub fn build_app() -> Command { .arg(flag_linker.clone()) .arg(flag_prebuilt.clone()) .arg(flag_fuzz.clone()) - .arg(flag_ignore_errors.clone()) + .arg(flag_ignore_build_errors.clone()) .arg( Arg::new(FLAG_VERBOSE) .long(FLAG_VERBOSE) @@ -504,7 +504,7 @@ pub fn test(matches: &ArgMatches, target: Target) -> io::Result { // TODO may need to determine this dynamically based on dev builds. let function_kind = FunctionKind::LambdaSet; - let exec_mode = if matches.get_flag(FLAG_IGNORE_ERRORS) { + let exec_mode = if matches.get_flag(FLAG_IGNORE_BUILD_ERRORS) { ExecutionMode::TestIgnoreErrors } else { ExecutionMode::Test From 78b601335f85198952622fb76e85bd24c1d1574f Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Fri, 5 Apr 2024 19:36:17 +0200 Subject: [PATCH 6/9] change assertion condition --- crates/cli/src/lib.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 648618ab6f0..f5cca04040f 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -518,7 +518,7 @@ pub fn test(matches: &ArgMatches, target: Target) -> io::Result { render: roc_reporting::report::RenderTarget::ColorTerminal, palette: roc_reporting::report::DEFAULT_PALETTE, threading, - exec_mode, + exec_mode: exec_mode.clone(), }; let load_result = roc_load::load_and_monomorphize( arena, @@ -555,10 +555,12 @@ pub fn test(matches: &ArgMatches, target: Target) -> io::Result { // Print warnings before running tests. { - debug_assert_eq!( - problems.errors, 0, - "if there were errors, we would have already exited." - ); + if matches!(exec_mode, ExecutionMode::Test) { + debug_assert_eq!( + problems.errors, 0, + "if there were errors, we would have already exited." + ); + } if problems.warnings > 0 { problems.print_error_warning_count(start_time.elapsed()); println!(".\n\nRunning tests…\n\n\x1B[36m{}\x1B[39m", "─".repeat(80)); From a73f83d5dee05dd5c1563bbcc27d871e936c0568 Mon Sep 17 00:00:00 2001 From: Pei Yang Ching <59727193+horriblename@users.noreply.github.com> Date: Sat, 6 Apr 2024 18:01:20 +0200 Subject: [PATCH 7/9] add tests for `roc test --ignore-build-errors` --- crates/cli/tests/cli_run.rs | 14 ++++++++++++++ crates/cli/tests/expects/IgnoreBuildErrors.roc | 12 ++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 crates/cli/tests/expects/IgnoreBuildErrors.roc diff --git a/crates/cli/tests/cli_run.rs b/crates/cli/tests/cli_run.rs index 5fd18707d3a..e6d65b01d7c 100644 --- a/crates/cli/tests/cli_run.rs +++ b/crates/cli/tests/cli_run.rs @@ -646,6 +646,20 @@ mod cli_run { ); } + #[test] + fn expect_ignore_build_errors() { + test_roc_expect( + "crates/cli/tests/expects", + "IgnoreBuildErrors.roc", + &["--ignore-build-errors"], + indoc!( + r#" + 1 failed and 1 passed in ms. + "# + ), + ) + } + #[test] #[cfg_attr(windows, ignore)] fn transitive_expects() { diff --git a/crates/cli/tests/expects/IgnoreBuildErrors.roc b/crates/cli/tests/expects/IgnoreBuildErrors.roc new file mode 100644 index 00000000000..8f0136d7a82 --- /dev/null +++ b/crates/cli/tests/expects/IgnoreBuildErrors.roc @@ -0,0 +1,12 @@ +interface IgnoreBuildErrors + exposes [] + imports [] + +x = 1 + +expect x == 1 + +foo = \x -> x + 1 + +expect foo 2 == 3 + From cc458c0ba6f1bd98bcec0a3201e2e3af712ac647 Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Sat, 6 Apr 2024 19:21:57 +0200 Subject: [PATCH 8/9] remove TODO --- crates/compiler/test_mono/src/tests.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/compiler/test_mono/src/tests.rs b/crates/compiler/test_mono/src/tests.rs index 5d6e28bbc27..be9b77135a0 100644 --- a/crates/compiler/test_mono/src/tests.rs +++ b/crates/compiler/test_mono/src/tests.rs @@ -84,7 +84,6 @@ fn compiles_to_ir(test_name: &str, src: &str, mode: &str, allow_type_errors: boo let exec_mode = match mode { "exec" => ExecutionMode::ExecutableIgnoreErrors, "test" => ExecutionMode::Test, - // TODO: I'm not sure if I should add anything here _ => panic!("Invalid test_mono exec mode {mode}"), }; From 4816127d0ea5fc8fce371542be78faf3cec789de Mon Sep 17 00:00:00 2001 From: Anton-4 <17049058+Anton-4@users.noreply.github.com> Date: Mon, 22 Apr 2024 13:56:23 +0200 Subject: [PATCH 9/9] clippy fix Co-authored-by: Ayaz <20735482+ayazhafiz@users.noreply.github.com> Signed-off-by: Anton-4 <17049058+Anton-4@users.noreply.github.com> --- crates/cli/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index f5cca04040f..10eb20efb01 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -518,7 +518,7 @@ pub fn test(matches: &ArgMatches, target: Target) -> io::Result { render: roc_reporting::report::RenderTarget::ColorTerminal, palette: roc_reporting::report::DEFAULT_PALETTE, threading, - exec_mode: exec_mode.clone(), + exec_mode, }; let load_result = roc_load::load_and_monomorphize( arena,