ocamltest: opt-in -keep-test-dir-on-success to keep test data on success

master
Gabriel Scherer 2020-04-01 21:52:17 +02:00
parent 9eadd76ed1
commit a86943c889
3 changed files with 21 additions and 6 deletions

View File

@ -154,9 +154,11 @@ let test_file test_filename =
let hookname_prefix = Filename.concat test_source_directory test_prefix in
let test_build_directory_prefix =
get_test_build_directory_prefix test_directory in
ignore (Sys.command ("rm -rf " ^ test_build_directory_prefix));
let clean_test_build_directory () =
ignore (Sys.command ("rm -rf " ^ test_build_directory_prefix)) in
clean_test_build_directory ();
Sys.make_directory test_build_directory_prefix;
Sys.with_chdir test_build_directory_prefix
let summary = Sys.with_chdir test_build_directory_prefix
(fun () ->
let log =
if !Options.log_to_stderr then stderr else begin
@ -193,13 +195,20 @@ let test_file test_filename =
let initial_status =
if skip_test then Skip_all_tests else Run rootenv
in
let _summary =
let summary =
run_test_trees log common_prefix "" initial_status test_trees in
Actions.clear_all_hooks();
if not !Options.log_to_stderr then close_out log
);
if not !Options.log_to_stderr then close_out log;
summary
) in
(* Restore current working directory *)
Sys.chdir cwd
Sys.chdir cwd;
begin match summary with
| Some_failure -> ()
| No_failure ->
if not !Options.keep_test_dir_on_success then
clean_test_build_directory ()
end
let is_test s =
match tsl_block_of_file s with

View File

@ -49,6 +49,8 @@ let log_to_stderr = ref false
let promote = ref false
let keep_test_dir_on_success = ref false
let find_test_dirs = ref []
let list_tests = ref []
@ -68,6 +70,8 @@ let commandline_options =
" Find directories that contain tests (recursive).");
("-list-tests", Arg.String (add_to_list list_tests),
" List tests in given directory.");
("-keep-test-dir-on-success", Arg.Set keep_test_dir_on_success,
" Keep the test directory (with the generated test artefacts) on success.");
]
let files_to_test = ref []

View File

@ -26,3 +26,5 @@ val usage : string
val find_test_dirs : string list ref
val list_tests : string list ref
val keep_test_dir_on_success : bool ref