Clerk: skip unchanged tests when running with '--test-flags'

To avoid duplicating runs of identical tests: other tests are unaffected by the
flags.

Also tweak the Makefile to avoid multiple dune runs
This commit is contained in:
Louis Gesbert 2024-02-26 14:47:45 +01:00
parent b43cc04e16
commit c1cd32a8f8
3 changed files with 35 additions and 22 deletions

View File

@ -203,7 +203,7 @@ unit-tests: .FORCE
dune build @for-tests @runtest
#> test : Run interpreter tests
test: .FORCE compiler
test: .FORCE unit-tests
$(CLERK_TEST)
tests: test
@ -213,15 +213,20 @@ TEST_FLAGS_LIST = ""\
--lcalc \
--lcalc,--avoid-exceptions,-O
#> testsuite : Run interpreter tests over a selection of configurations
testsuite: .FORCE unit-tests
# Does not include running dune (to avoid duplication when run among bigger rules)
testsuite-base: .FORCE
@for F in $(TEST_FLAGS_LIST); do \
echo >&2; \
echo ">> RUNNING TESTS WITH FLAGS: $$F" >&2; \
[ -z "$$F" ] || echo ">> RE-RUNNING TESTS WITH FLAGS: $$F" >&2; \
$(CLERK_TEST) --test-flags="$$F" || break; \
done
reset-tests: .FORCE
#> testsuite : Run interpreter tests over a selection of configurations
testsuite: unit-tests
$(MAKE) testsuite-base
#> reset-tests : Update the expected test results from current run
reset-tests: .FORCE $(CLERK_BIN)
$(CLERK_TEST) --reset
tests/%: .FORCE
@ -248,7 +253,7 @@ WEBSITE_ASSETS_ALL = $(WEBSITE_ASSETS) $(addprefix catala-examples.tmp/,$(WEBSIT
website-assets-base: build
$(call local_tmp_clone,catala-examples) && \
dune build $(addprefix _build/default/,$(WEBSITE_ASSETS_ALL))
dune build $(addprefix _build/default/,$(WEBSITE_ASSETS_ALL)) --profile=release
website-assets.tar:
# $(MAKE) DUNE_PROFILE=release website-assets-base

View File

@ -67,9 +67,12 @@ module Cli = struct
~doc:
"Flags to pass to the catala interpreter on $(b,catala test-scope) \
tests. Comma-separated list. A subset may also be applied to the \
compilation of modules, as needed. WARNING: flag shortcuts are \
not allowed here (i.e. don't use non-ambiguous prefixes such as \
$(b,--avoid-ex) for $(b,--avoid-exceptions))")
compilation of modules, as needed.\n\
WARNING: flag shortcuts are not allowed here (i.e. don't use \
non-ambiguous prefixes such as $(b,--avoid-ex) for \
$(b,--avoid-exceptions))\n\
NOTE: if this is set, all inline tests that are $(i,not) \
$(b,catala test-scope) are skipped to avoid redundant testing.")
module Global : sig
val term :

View File

@ -31,15 +31,17 @@ let run_catala_test test_flags catala_exe catala_opts file program args oc =
match args with
| cmd0 :: flags ->
let cmd0, flags =
if String.lowercase_ascii cmd0 = "test-scope" then (
match flags with
| [scope_name] -> "interpret", ("--scope=" ^ scope_name) :: test_flags
| _ ->
output_string oc
"[INVALID TEST] Invalid test command syntax, the 'test-scope' \
pseudo-command takes a single scope as argument\n";
"interpret", flags)
else cmd0, flags
match String.lowercase_ascii cmd0, flags, test_flags with
| "test-scope", scope_name :: flags, test_flags ->
"interpret", (("--scope=" ^ scope_name) :: flags) @ test_flags
| "test-scope", [], _ ->
output_string oc
"[INVALID TEST] Invalid test command syntax, the 'test-scope' \
pseudo-command takes a scope name as first argument\n";
"interpret", test_flags
| cmd0, flags, [] -> cmd0, flags
| _, _, _ :: _ ->
raise Exit (* Skip other tests when test-flags is specified *)
in
Array.of_list
((catala_exe :: cmd0 :: catala_opts) @ flags @ ["--name=" ^ file; "-"])
@ -103,7 +105,7 @@ let run_inline_tests catala_exe catala_opts test_flags filename =
"[INVALID TEST] Invalid test command syntax, must match '$ catala \
<args>'\n";
skip_block lines
| Some args ->
| Some args -> (
let args = String.split_on_char ' ' args in
let program =
let rec drop_last seq () =
@ -116,9 +118,12 @@ let run_inline_tests catala_exe catala_opts test_flags filename =
in
Queue.to_seq lines_until_now |> drop_last |> drop_last
in
run_catala_test test_flags catala_exe catala_opts filename program args
oc;
skip_block lines)
match
run_catala_test test_flags catala_exe catala_opts filename program
args oc
with
| () -> skip_block lines
| exception Exit -> process lines))
and skip_block lines =
match Seq.uncons lines with
| None -> ()