diff --git a/Earthfile b/Earthfile index d0ab4f1977..8a1be4e1c6 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 --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 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 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, diff --git a/crates/repl_expect/src/lib.rs b/crates/repl_expect/src/lib.rs index 78a044d4c2..5240bb8a1f 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,