From 807f73fecfd74851014b73e5c883b93a16d91993 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 4 Aug 2022 22:29:17 -0400 Subject: [PATCH 1/5] Add some expects to Str --- crates/compiler/builtins/roc/Str.roc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/compiler/builtins/roc/Str.roc b/crates/compiler/builtins/roc/Str.roc index 166f5f9a60..43cd4bec8a 100644 --- a/crates/compiler/builtins/roc/Str.roc +++ b/crates/compiler/builtins/roc/Str.roc @@ -330,6 +330,15 @@ splitLast = \haystack, needle -> None -> Err NotFound +# splitLast when needle isn't in haystack +expect Str.splitLast "foo" "z" == Err NotFound + +# splitLast when haystack ends with needle repeated +expect Str.splitLast "foo" "o" == Ok { before: "fo", after: "" } + +# splitLast with multi-byte needle +expect Str.splitLast "hullabaloo" "ab" == Ok { before: "hull", after: "aloo" } + lastMatch : Str, Str -> [Some Nat, None] lastMatch = \haystack, needle -> haystackLength = Str.countUtf8Bytes haystack From 12e377744d4ef915262f54ca09292535428204d6 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Thu, 4 Aug 2022 22:32:27 -0400 Subject: [PATCH 2/5] Run `roc test` on `Str` builtins --- Earthfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Earthfile b/Earthfile index d0ab4f1977..ca70ce7610 100644 --- a/Earthfile +++ b/Earthfile @@ -89,6 +89,9 @@ test-rust: # gen-wasm has some multithreading problems to do with the wasmer runtime. Run it single-threaded as a separate job RUN --mount=type=cache,target=$SCCACHE_DIR \ cargo test --locked --release --package test_gen --no-default-features --features gen-wasm -- --test-threads=1 && sccache --show-stats + # run `roc test` on Str builtins + RUN --mount=type=cache,target=$SCCACHE_DIR \ + cargo run test --release -- crates/compiler/builtins/roc/Str.roc && sccache --show-stats # repl_test: build the compiler for wasm target, then run the tests on native target RUN --mount=type=cache,target=$SCCACHE_DIR \ crates/repl_test/test_wasm.sh && sccache --show-stats From 2d3f10fd35ac10d9b75c8e95b8db82b3f5b5419c Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Fri, 5 Aug 2022 09:11:10 -0400 Subject: [PATCH 3/5] Fix Earthfile command for testing Str builtins --- Earthfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Earthfile b/Earthfile index ca70ce7610..8a1be4e1c6 100644 --- a/Earthfile +++ b/Earthfile @@ -91,7 +91,7 @@ test-rust: cargo test --locked --release --package test_gen --no-default-features --features gen-wasm -- --test-threads=1 && sccache --show-stats # run `roc test` on Str builtins RUN --mount=type=cache,target=$SCCACHE_DIR \ - cargo run test --release -- crates/compiler/builtins/roc/Str.roc && sccache --show-stats + cargo run --release -- test crates/compiler/builtins/roc/Str.roc && sccache --show-stats # repl_test: build the compiler for wasm target, then run the tests on native target RUN --mount=type=cache,target=$SCCACHE_DIR \ crates/repl_test/test_wasm.sh && sccache --show-stats From 68888c79ae24afa05ad981306b8357fbdc3b1c7d Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 6 Aug 2022 22:03:56 +0200 Subject: [PATCH 4/5] skip expect codegen when not running tests --- crates/compiler/load_internal/src/file.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs index 0151e3a130..444343f3a8 100644 --- a/crates/compiler/load_internal/src/file.rs +++ b/crates/compiler/load_internal/src/file.rs @@ -445,6 +445,7 @@ fn start_phase<'a>( BuildTask::BuildPendingSpecializations { layout_cache, + execution_mode: state.exec_mode, module_id, module_timing, solved_subs, @@ -1090,6 +1091,7 @@ enum BuildTask<'a> { }, BuildPendingSpecializations { module_timing: ModuleTiming, + execution_mode: ExecutionMode, layout_cache: LayoutCache<'a>, solved_subs: Solved, imported_module_thunks: &'a [Symbol], @@ -4736,6 +4738,7 @@ fn make_specializations<'a>( #[allow(clippy::too_many_arguments)] fn build_pending_specializations<'a>( arena: &'a Bump, + execution_mode: ExecutionMode, solved_subs: Solved, imported_module_thunks: &'a [Symbol], home: ModuleId, @@ -4993,6 +4996,12 @@ fn build_pending_specializations<'a>( // the declarations of this group will be treaded individually by later iterations } Expectation => { + // skip expectations if we're not going to run them + match execution_mode { + ExecutionMode::Test => { /* fall through */ } + ExecutionMode::Check | ExecutionMode::Executable => continue, + } + // mark this symbol as a top-level thunk before any other work on the procs module_thunks.push(symbol); @@ -5265,6 +5274,7 @@ fn run_task<'a>( )), BuildPendingSpecializations { module_id, + execution_mode, ident_ids, decls, module_timing, @@ -5277,6 +5287,7 @@ fn run_task<'a>( derived_module, } => Ok(build_pending_specializations( arena, + execution_mode, solved_subs, imported_module_thunks, module_id, From 45c15bf1f147b1c40d5fb2065d6195f5416267e9 Mon Sep 17 00:00:00 2001 From: Folkert Date: Sat, 6 Aug 2022 23:00:58 +0200 Subject: [PATCH 5/5] expect tests need to run with test execution mode --- crates/repl_expect/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/repl_expect/src/lib.rs b/crates/repl_expect/src/lib.rs index f3be3326ab..5c001a108a 100644 --- a/crates/repl_expect/src/lib.rs +++ b/crates/repl_expect/src/lib.rs @@ -108,7 +108,7 @@ mod test { target_info, render: RenderTarget::ColorTerminal, threading: Threading::Single, - exec_mode: ExecutionMode::Executable, + exec_mode: ExecutionMode::Test, }; let loaded = roc_load::load_and_monomorphize_from_str( arena,