diff --git a/ocamltest/OCAMLTEST.org b/ocamltest/OCAMLTEST.org index 097f8a81e90..077b76e0cf9 100644 --- a/ocamltest/OCAMLTEST.org +++ b/ocamltest/OCAMLTEST.org @@ -581,19 +581,9 @@ namely: *) #+end_src -<<<<<<< HEAD:ocamltest/ocamltest.org -The braces make explicit the scope of variable assignments: an -assignement modifies a variable for the rest of its block and for all -sub-blocks (unless overridden at some point). -||||||| 121bedcfd2:ocamltest/ocamltest.org -The fact that the language is inspired by org-mode should also be -helpful in understanding the scope of variable assignments. Roughly -speaking: -======= The braces make explicit the scope of variable assignments: an assignment modifies a variable for the rest of its block and for all sub-blocks (unless overridden at some point). ->>>>>>> 5.2.0:ocamltest/OCAMLTEST.org For instance, given the following blocks: #+begin_src diff --git a/ocamltest/actions.ml b/ocamltest/actions.ml index 42b0fa53218..aa336b06a22 100644 --- a/ocamltest/actions.ml +++ b/ocamltest/actions.ml @@ -80,4 +80,4 @@ module ActionSet = Set.Make let compare = compare end) -let _ = Variables.register_variable action_name +let init () = Variables.register_variable action_name diff --git a/ocamltest/actions.mli b/ocamltest/actions.mli index 13ea33861ec..4bea374b06c 100644 --- a/ocamltest/actions.mli +++ b/ocamltest/actions.mli @@ -47,3 +47,5 @@ val run : out_channel -> Environments.t -> t -> Result.t * Environments.t val does_something : t -> bool module ActionSet : Set.S with type elt = t + +val init : unit -> unit diff --git a/ocamltest/builtin_actions.ml b/ocamltest/builtin_actions.ml index 5336ad7b3ce..b00906269e5 100644 --- a/ocamltest/builtin_actions.ml +++ b/ocamltest/builtin_actions.ml @@ -245,7 +245,6 @@ let frame_pointers = make "frame-pointers available" "frame-pointers not available") -<<<<<<< HEAD let probes = make ~name:"probes" ~description:"Pass if probes are available" @@ -262,23 +261,22 @@ let naked_pointers = make "Runtime system supports naked pointers" "Runtime system does not support naked pointers") -||||||| 121bedcfd2 -======= let tsan = make ~name:"tsan" ~description:"Pass if thread sanitizer is supported" - (Actions_helpers.pass_or_skip (Ocamltest_config.tsan) + ~does_something:false + (Actions_helpers.predicate (Ocamltest_config.tsan) "tsan available" "tsan not available") let no_tsan = make ~name:"no-tsan" ~description:"Pass if thread sanitizer is not supported" - (Actions_helpers.pass_or_skip (not Ocamltest_config.tsan) + ~does_something:false + (Actions_helpers.predicate (not Ocamltest_config.tsan) "tsan not available" "tsan available") ->>>>>>> 5.2.0 let has_symlink = make ~name:"has_symlink" ~description:"Pass if symbolic links are available" @@ -386,7 +384,7 @@ let initialize_test_exit_status_variables _log env = Builtin_variables.test_skip, "125"; ] env -let _ = +let init () = Environments.register_initializer Environments.Post "test_exit_status_variables" initialize_test_exit_status_variables; List.iter register @@ -425,12 +423,7 @@ let _ = naked_pointers; file_exists; copy; -<<<<<<< HEAD probes; - naked_pointers -||||||| 121bedcfd2 -======= tsan; no_tsan; ->>>>>>> 5.2.0 ] diff --git a/ocamltest/builtin_actions.mli b/ocamltest/builtin_actions.mli index 8797377d1c4..2497c775f82 100644 --- a/ocamltest/builtin_actions.mli +++ b/ocamltest/builtin_actions.mli @@ -51,3 +51,5 @@ val check_program_output : Actions.t val file_exists : Actions.t val copy : Actions.t + +val init : unit -> unit diff --git a/ocamltest/builtin_variables.ml b/ocamltest/builtin_variables.ml index c6b19d0d8db..6ba7bb0c5a7 100644 --- a/ocamltest/builtin_variables.ml +++ b/ocamltest/builtin_variables.ml @@ -114,7 +114,8 @@ let test_fail = Variables.make ("TEST_FAIL", let timeout = Variables.make ("timeout", "Maximal execution time for every command (in seconds)") -let _ = List.iter Variables.register_variable +let init () = + List.iter Variables.register_variable [ arguments; cwd; diff --git a/ocamltest/builtin_variables.mli b/ocamltest/builtin_variables.mli index b7ebf56feaa..86fe93d3a4d 100644 --- a/ocamltest/builtin_variables.mli +++ b/ocamltest/builtin_variables.mli @@ -75,3 +75,5 @@ val test_skip : Variables.t val test_fail : Variables.t val timeout : Variables.t + +val init : unit -> unit diff --git a/ocamltest/dune b/ocamltest/dune index a75d6b05b74..27d20bef18b 100644 --- a/ocamltest/dune +++ b/ocamltest/dune @@ -22,25 +22,6 @@ ;; FIXME: handle UNIX_OR_WIN32 or something similar -(library - (name ocamltest_core_and_plugin) - (modes byte) - (wrapped false) - ; -linkall so we don't fail to include e.g. ocaml_modifiers.ml, which only - ; has top-level side effects. - (flags - (:standard -linkall -w +a-40-41-42-44-70)) - (libraries ocamlcommon unix) - (modules - (:standard \ options main ocamltest_unix_dummy ocamltest_unix_real)) - (foreign_stubs - (language c) - (names run_unix run_stubs) - (flags - ((-DCAML_INTERNALS) - (:include %{project_root}/oc_cflags.sexp) - (:include %{project_root}/oc_cppflags.sexp))))) - (rule (targets empty.ml) (deps @@ -50,15 +31,25 @@ (executable (name main) - (modes byte) + (modes native) (flags (:standard -w +a-40-41-42-44-70 -cclib "-I../%{env:RUNTIME_DIR=runtime-dir-env-var-not-set}")) - (modules options main) - (libraries ocamltest_core_and_plugin)) + (libraries ocamlcommon) + ; This executable is built using the *system* compiler, so we can't use + ; our own otherlibs/unix/, and neither can we depend on the "unix" library + ; or this same one will be used. + (ocamlopt_flags unix.cmxa) + (foreign_stubs + (language c) + (names run_unix run_stubs) + (flags + ((-DCAML_INTERNALS) + (:include %{project_root}/oc_cflags.sexp) + (:include %{project_root}/oc_cppflags.sexp))))) (rule - (copy main.exe ocamltest.byte)) + (copy main.exe ocamltest.native)) diff --git a/ocamltest/main.ml b/ocamltest/main.ml index bcb388438cd..2422c86dd58 100644 --- a/ocamltest/main.ml +++ b/ocamltest/main.ml @@ -20,35 +20,9 @@ open Tsl_ast open Tsl_semantics type behavior = -<<<<<<< HEAD - | Skip_all_tests - | Run of Environments.t - -||||||| 121bedcfd2 - | Skip_all_tests - | Run of Environments.t - -(* -let first_token filename = - let input_channel = open_in filename in - let lexbuf = Lexing.from_channel input_channel in - Location.init lexbuf filename; - let token = - try Tsl_lexer.token lexbuf with e -> close_in input_channel; raise e - in close_in input_channel; token - -let is_test filename = - match first_token filename with - | exception _ -> false - | Tsl_parser.TSL_BEGIN_C_STYLE | TSL_BEGIN_OCAML_STYLE -> true - | _ -> false -*) - -======= | Skip_all | Run ->>>>>>> 5.2.0 (* this primitive announce should be used for tests that were aborted on system error before ocamltest could parse them *) @@ -56,13 +30,6 @@ let announce_test_error test_filename error = Printf.printf " ... testing '%s' => unexpected error (%s)\n%!" (Filename.basename test_filename) error -<<<<<<< HEAD -exception Syntax_error of Lexing.position - -let tsl_parse_file test_filename = -||||||| 121bedcfd2 -let tsl_block_of_file test_filename = -======= let print_exn loc e = let open Printf in let locstring = @@ -92,7 +59,6 @@ let print_exn loc e = exception Syntax_error of Lexing.position let tsl_parse_file test_filename = ->>>>>>> 5.2.0 let input_channel = open_in test_filename in let lexbuf = Lexing.from_channel input_channel in Location.init lexbuf test_filename; @@ -141,7 +107,6 @@ let join_summaries sa sb = | No_failure, (No_failure | All_skipped) | All_skipped, No_failure -> No_failure -<<<<<<< HEAD let rec run_test_tree log common_prefix behavior env summ ast = match ast with | Ast (Environment_statement s :: stmts, subs) -> @@ -155,16 +120,22 @@ let rec run_test_tree log common_prefix behavior env summ ast = Some_failure end | Ast (Test (_, name, mods) :: stmts, subs) -> + let skip_all = + match behavior with + | Skip_all -> true + | Run -> false + in let locstr = if name.loc = Location.none then "default" else Printf.sprintf "line %d" name.loc.Location.loc_start.Lexing.pos_lnum in - Printf.printf "%s %s (%s) %!" common_prefix locstr name.node; + if not skip_all then + Printf.printf "%s %s (%s) %!" common_prefix locstr name.node; let (msg, children_behavior, newenv, result) = match behavior with - | Skip_all -> ("=> n/a", Skip_all, env, Result.skip) + | Skip_all -> ("", Skip_all, env, Result.skip) | Run -> begin try let testenv = List.fold_left apply_modifiers env mods in @@ -176,72 +147,13 @@ let rec run_test_tree log common_prefix behavior env summ ast = with e -> (report_error name.loc e, Skip_all, env, Result.fail) end in - Printf.printf "%s\n%!" msg; + if not skip_all then Printf.printf "%s\n%!" msg; let newsumm = join_result summ result in let newast = Ast (stmts, subs) in run_test_tree log common_prefix children_behavior newenv newsumm newast | Ast ([], subs) -> List.fold_left join_summaries summ (List.map (run_test_tree log common_prefix behavior env All_skipped) subs) -||||||| 2572783060 -let rec run_test log common_prefix path behavior = function - Node (testenvspec, test, env_modifiers, subtrees) -> - Printf.printf "%s %s (%s) %!" common_prefix path test.Tests.test_name; - let (msg, children_behavior, result) = match behavior with - | Skip_all_tests -> "=> n/a", Skip_all_tests, Result.skip - | Run env -> - let testenv0 = interpret_environment_statements env testenvspec in - let testenv = List.fold_left apply_modifiers testenv0 env_modifiers in - let (result, newenv) = Tests.run log testenv test in - let msg = Result.string_of_result result in - let children_behavior = - if Result.is_pass result then Run newenv else Skip_all_tests in - (msg, children_behavior, result) in - Printf.printf "%s\n%!" msg; - join_result - (run_test_trees log common_prefix path children_behavior subtrees) result - -and run_test_trees log common_prefix path behavior trees = - List.fold_left join_summaries All_skipped - (List.mapi (run_test_i log common_prefix path behavior) trees) - -and run_test_i log common_prefix path behavior i test_tree = - let path_prefix = if path="" then "" else path ^ "." in - let new_path = Printf.sprintf "%s%d" path_prefix (i+1) in - run_test log common_prefix new_path behavior test_tree -======= -let rec run_test log common_prefix path behavior = function - Node (testenvspec, test, env_modifiers, subtrees) -> - let skip_all = - match behavior with - | Skip_all_tests -> true - | Run _ -> false - in - if not skip_all then - Printf.printf "%s %s (%s) %!" common_prefix path test.Tests.test_name; - let (msg, children_behavior, result) = match behavior with - | Skip_all_tests -> "", Skip_all_tests, Result.skip - | Run env -> - let testenv0 = interpret_environment_statements env testenvspec in - let testenv = List.fold_left apply_modifiers testenv0 env_modifiers in - let (result, newenv) = Tests.run log testenv test in - let msg = Result.string_of_result result in - let children_behavior = - if Result.is_pass result then Run newenv else Skip_all_tests in - (msg, children_behavior, result) in - if not skip_all then Printf.printf "%s\n%!" msg; - join_result - (run_test_trees log common_prefix path children_behavior subtrees) result - -and run_test_trees log common_prefix path behavior trees = - List.fold_left join_summaries All_skipped - (List.mapi (run_test_i log common_prefix path behavior) trees) - -and run_test_i log common_prefix path behavior i test_tree = - let path_prefix = if path="" then "" else path ^ "." in - let new_path = Printf.sprintf "%s%d" path_prefix (i+1) in - run_test log common_prefix new_path behavior test_tree ->>>>>>> ocaml-jst/flambda-patches let get_test_source_directory test_dirname = if (Filename.is_relative test_dirname) then @@ -269,22 +181,10 @@ let extract_rootenv (Ast (stmts, subs)) = let test_file test_filename = let start = if Options.show_timings then Unix.gettimeofday () else 0.0 in let skip_test = List.mem test_filename !tests_to_skip in -<<<<<<< HEAD - let tsl_ast = tsl_parse_file_safe test_filename in - let (rootenv_statements, test_trees) = test_trees_of_tsl_ast tsl_ast in - let test_trees = match test_trees with - | [] -> -||||||| 121bedcfd2 - let tsl_block = tsl_block_of_file_safe test_filename in - let (rootenv_statements, test_trees) = test_trees_of_tsl_block tsl_block in - let test_trees = match test_trees with - | [] -> -======= let tsl_ast = tsl_parse_file_safe test_filename in let (rootenv_statements, tsl_ast) = extract_rootenv tsl_ast in - let tsl_ast = match tsl_ast with + let tsl_ast = match[@ocaml.warning "-fragile-match"] tsl_ast with | Ast ([], []) -> ->>>>>>> 5.2.0 let default_tests = Tests.default_tests() in let make_tree test = let id = make_identifier test.Tests.test_name in @@ -434,6 +334,14 @@ let list_tests dir = sort_strings !res let () = + Actions.init (); + Builtin_actions.init (); + Builtin_variables.init (); + Ocaml_actions.init (); + Ocaml_modifiers.init (); + Ocaml_tests.init (); + Ocaml_variables.init (); + Strace.init (); init_tests_to_skip() let () = diff --git a/ocamltest/ocaml_actions.ml b/ocamltest/ocaml_actions.ml index 5167b9c8390..47df5c30d06 100644 --- a/ocamltest/ocaml_actions.ml +++ b/ocamltest/ocaml_actions.ml @@ -732,7 +732,7 @@ let run_codegen log env = let env = Environments.add Builtin_variables.output output env in let commandline = [ - Ocaml_commands.ocamlrun_codegen; + Ocaml_commands.codegen; flags env; "-S " ^ testfile ] in @@ -812,7 +812,7 @@ let run_expect_once input_file principal log env = let principal_flag = if principal then "-principal" else "" in let commandline = [ - Ocaml_commands.ocamlrun_expect; + Ocaml_commands.expect; expect_flags; Ocaml_flags.toplevel_default_flags; Ocaml_flags.stdlib; @@ -1513,7 +1513,7 @@ let run_ocamldoc = (Result.fail_with_reason reason, env) end -let _ = +let init () = Environments.register_initializer Environments.Post "find_source_modules" find_source_modules; Environments.register_initializer Environments.Pre diff --git a/ocamltest/ocaml_actions.mli b/ocamltest/ocaml_actions.mli index b28ea972f13..569b33dc9df 100644 --- a/ocamltest/ocaml_actions.mli +++ b/ocamltest/ocaml_actions.mli @@ -57,3 +57,5 @@ val no_afl_instrument : Actions.t val codegen : Actions.t val cc : Actions.t + +val init : unit -> unit diff --git a/ocamltest/ocaml_commands.ml b/ocamltest/ocaml_commands.ml index ef213876ad4..e0787535d26 100644 --- a/ocamltest/ocaml_commands.ml +++ b/ocamltest/ocaml_commands.ml @@ -24,8 +24,8 @@ let ocamlrun_ocamlopt = ocamlrun Ocaml_files.ocamlopt let ocamlrun_ocaml = ocamlrun Ocaml_files.ocaml -let ocamlrun_expect = - ocamlrun Ocaml_files.expect +let expect = + Ocaml_files.expect let ocamlrun_ocamllex = ocamlrun Ocaml_files.ocamllex @@ -41,5 +41,5 @@ let ocamlrun_ocamlobjinfo = let ocamlrun_ocamlmklib = ocamlrun Ocaml_files.ocamlmklib -let ocamlrun_codegen = - ocamlrun Ocaml_files.codegen +let codegen = + Ocaml_files.codegen diff --git a/ocamltest/ocaml_commands.mli b/ocamltest/ocaml_commands.mli index 200c3143082..eb3c43c6d5a 100644 --- a/ocamltest/ocaml_commands.mli +++ b/ocamltest/ocaml_commands.mli @@ -21,7 +21,7 @@ val ocamlrun_ocamlopt : string val ocamlrun_ocaml : string -val ocamlrun_expect : string +val expect : string val ocamlrun_ocamllex : string @@ -32,4 +32,5 @@ val ocamlrun_ocamldebug : string val ocamlrun_ocamlobjinfo : string val ocamlrun_ocamlmklib : string -val ocamlrun_codegen : string + +val codegen : string diff --git a/ocamltest/ocaml_modifiers.ml b/ocamltest/ocaml_modifiers.ml index e738c016e8f..ef97ae7b456 100644 --- a/ocamltest/ocaml_modifiers.ml +++ b/ocamltest/ocaml_modifiers.ml @@ -131,7 +131,7 @@ let debugger = [add_compiler_subdir ("debugger" ^ runtime_suffix)] let extension_universe_lib name = make_library_modifier name [compiler_subdir ["otherlibs"; name]] -let _ = +let init () = register_modifiers "principal" principal; register_modifiers "config" config; register_modifiers "testing" testing; diff --git a/ocamltest/ocaml_modifiers.mli b/ocamltest/ocaml_modifiers.mli index a6d2adc2f5c..6799dd75b43 100644 --- a/ocamltest/ocaml_modifiers.mli +++ b/ocamltest/ocaml_modifiers.mli @@ -26,3 +26,5 @@ val str : Environments.modifiers val latex: Environments.modifiers val man: Environments.modifiers val html: Environments.modifiers + +val init : unit -> unit diff --git a/ocamltest/ocaml_tests.ml b/ocamltest/ocaml_tests.ml index 0fa73241ebd..d65a4d14c12 100644 --- a/ocamltest/ocaml_tests.ml +++ b/ocamltest/ocaml_tests.ml @@ -177,7 +177,7 @@ let asmgen = test_actions = asmgen_actions } -let _ = +let init () = List.iter register [ bytecode; diff --git a/ocamltest/ocaml_tests.mli b/ocamltest/ocaml_tests.mli index 8ace884a4bf..def1780198e 100644 --- a/ocamltest/ocaml_tests.mli +++ b/ocamltest/ocaml_tests.mli @@ -26,3 +26,5 @@ val expect : Tests.t val ocamldoc : Tests.t val asmgen : Tests.t + +val init : unit -> unit diff --git a/ocamltest/ocaml_variables.ml b/ocamltest/ocaml_variables.ml index bbc6b05931b..1f7193210dc 100644 --- a/ocamltest/ocaml_variables.ml +++ b/ocamltest/ocaml_variables.ml @@ -247,7 +247,8 @@ let use_runtime = Variables.make ("use_runtime", "Whether the -use-runtime option should be used" ) -let _ = List.iter register_variable +let init () = + List.iter register_variable [ all_modules; arch; diff --git a/ocamltest/ocaml_variables.mli b/ocamltest/ocaml_variables.mli index ec44c9496fa..d1c6e390b91 100644 --- a/ocamltest/ocaml_variables.mli +++ b/ocamltest/ocaml_variables.mli @@ -140,3 +140,5 @@ val shared_library_cflags : Variables.t val sharedobjext : Variables.t val use_runtime : Variables.t + +val init : unit -> unit diff --git a/ocamltest/ocamltest_config.ml.in b/ocamltest/ocamltest_config.ml.in index e3523b0e9f8..9a2b9b9bcde 100644 --- a/ocamltest/ocamltest_config.ml.in +++ b/ocamltest/ocamltest_config.ml.in @@ -86,13 +86,7 @@ let exe = {@QS@|@exeext@|@QS@} let mkdll = {@QS@|@mkdll_exp@|@QS@} let mkexe = {@QS@|@mkexe_exp@|@QS@} -<<<<<<< HEAD -let bytecc_libs = {@QS@|@cclibs@|@QS@} -||||||| 121bedcfd2 -let bytecc_libs = {@QS@|@bytecclibs@|@QS@} -======= let bytecc_libs = {@QS@|@zstd_libs@ @cclibs@|@QS@} ->>>>>>> 5.2.0 let nativecc_libs = {@QS@|@cclibs@|@QS@} @@ -103,7 +97,6 @@ let function_sections = @function_sections@ let instrumented_runtime = @instrumented_runtime@ let frame_pointers = @frame_pointers@ -<<<<<<< HEAD let probes = @probes@ @@ -112,8 +105,5 @@ let stack_allocation = @stack_allocation@ let poll_insertion = @poll_insertion@ let naked_pointers = @naked_pointers@ -||||||| 121bedcfd2 -======= let tsan = @tsan@ ->>>>>>> 5.2.0 diff --git a/ocamltest/ocamltest_config.mli b/ocamltest/ocamltest_config.mli index c08a5413ba7..f34332c3249 100644 --- a/ocamltest/ocamltest_config.mli +++ b/ocamltest/ocamltest_config.mli @@ -145,13 +145,9 @@ val poll_insertion : bool val frame_pointers : bool (** Whether frame-pointers have been enabled at configure time *) -<<<<<<< HEAD val naked_pointers : bool (** Whether the runtime system supports naked pointers outside the heap *) -||||||| 121bedcfd2 -======= val tsan : bool (** Whether ThreadSanitizer support has been enabled at configure time *) ->>>>>>> 5.2.0 diff --git a/ocamltest/run_stubs.c b/ocamltest/run_stubs.c index f27a0139a5a..6e419de48bf 100644 --- a/ocamltest/run_stubs.c +++ b/ocamltest/run_stubs.c @@ -56,8 +56,10 @@ static void free_cstringvect(array v) caml_stat_free(v); } +#ifndef CAML_RUNTIME_5 #define caml_channel_lock Lock #define caml_channel_unlock Unlock +#endif static void logToChannel(void *voidchannel, const char *fmt, va_list ap) { diff --git a/ocamltest/strace.ml b/ocamltest/strace.ml index f289adbaf8a..b2302555a53 100644 --- a/ocamltest/strace.ml +++ b/ocamltest/strace.ml @@ -27,6 +27,6 @@ let get_logfile_name base = Hashtbl.replace counters base (n+1); filename -let _ = +let init () = Variables.register_variable strace; Variables.register_variable strace_flags diff --git a/ocamltest/strace.mli b/ocamltest/strace.mli index ac21db361ae..14d1401f87b 100644 --- a/ocamltest/strace.mli +++ b/ocamltest/strace.mli @@ -20,3 +20,5 @@ val strace : Variables.t val strace_flags : Variables.t val get_logfile_name : string -> string + +val init : unit -> unit diff --git a/ocamltest/tsl_ast.ml b/ocamltest/tsl_ast.ml index d0f8ed9b92c..370539f7618 100644 --- a/ocamltest/tsl_ast.ml +++ b/ocamltest/tsl_ast.ml @@ -35,20 +35,14 @@ type tsl_item = type tsl_block = tsl_item list -<<<<<<< HEAD -type t = Ast of tsl_item list * t list - -||||||| 121bedcfd2 -======= type t = Ast of tsl_item list * t list let rec split_env l = - match l with + match[@ocaml.warning "-fragile-match"] l with | Environment_statement env :: tl -> let (env2, rest) = split_env tl in (env :: env2, rest) | _ -> ([], l) ->>>>>>> 5.2.0 let make ?(loc = Location.none) foo = { node = foo; loc = loc } let make_identifier = make diff --git a/ocamltest/tsl_ast.mli b/ocamltest/tsl_ast.mli index 18b60e98a98..a5c9602657d 100644 --- a/ocamltest/tsl_ast.mli +++ b/ocamltest/tsl_ast.mli @@ -36,18 +36,11 @@ type tsl_item = type tsl_block = tsl_item list -<<<<<<< HEAD -(* New syntax *) -type t = Ast of tsl_item list * t list - -||||||| 121bedcfd2 -======= (* New syntax *) type t = Ast of tsl_item list * t list val split_env : tsl_item list -> environment_statement located list * tsl_item list ->>>>>>> 5.2.0 val make_identifier : ?loc:Location.t -> string -> string located val make_string : ?loc:Location.t -> string -> string located val make_environment_statement : diff --git a/ocamltest/tsl_semantics.ml b/ocamltest/tsl_semantics.ml index 06583bab8c8..375c2b02a3c 100644 --- a/ocamltest/tsl_semantics.ml +++ b/ocamltest/tsl_semantics.ml @@ -110,17 +110,6 @@ let lookup_test located_name = end | Some test -> test -let lookup_test located_name = - let name = located_name.node in - match Tests.lookup name with - | None -> - begin match Actions.lookup name with - | None -> no_such_test_or_action located_name - | Some action -> - Tests.test_of_action action - end - | Some test -> test - let test_trees_of_tsl_block tsl_block = let rec env_of_lines = function [@ocaml.warning "-fragile-match"] | [] -> ([], []) @@ -164,6 +153,21 @@ let test_trees_of_tsl_block tsl_block = | (Environment_statement s)::_ -> unexpected_environment_statement s | _ -> assert false +let test_trees_of_tsl_block tsl_block = + let (env, trees) = test_trees_of_tsl_block tsl_block in + let does_something = + List.for_all test_tree_does_something_on_all_branches trees + in + if does_something then env, trees + else + let tree = + match trees with + | [] -> [] + | Node (_, _, name, _) :: _ -> + [Node ([], Tests.does_nothing, name, [])] + in + env, tree + let tests_in_stmt set stmt = match stmt with | Environment_statement _ -> set @@ -187,46 +191,6 @@ let actions_in_tests tests = let f test action_set = Actions.ActionSet.union (actions_in_test test) action_set in Tests.TestSet.fold f tests Actions.ActionSet.empty -<<<<<<< HEAD - -let rec split_env l = - match[@ocaml.warning "-fragile-match"] l with - | Environment_statement env :: tl -> - let (env2, rest) = split_env tl in (env :: env2, rest) - | _ -> ([], l) - -let rec test_trees_of_tsl_ast (Ast (seq, subs)) = - let (env, rest) = split_env seq in - let trees = - match rest with - | [] -> List.map test_tree_of_tsl_ast subs - | [ Test (_, name, mods) ] -> - [Node ([], lookup_test name, mods, List.map test_tree_of_tsl_ast subs)] - | Test (_, name, mods) :: seq1 -> - let sub = test_tree_of_tsl_ast (Ast (seq1, subs)) in - [Node ([], lookup_test name, mods, [sub])] - | Environment_statement _ :: _ -> assert false - in (env, trees) - -and test_tree_of_tsl_ast ast = - match[@ocaml.warning "-fragile-match"] test_trees_of_tsl_ast ast with - | (env, [Node (env1, t, m, s)]) -> Node (env @ env1, t, m, s) - | (env, trees) -> Node (env, Tests.null, [], trees) - -let test_trees_of_tsl_ast ast = - let (env, trees) = test_trees_of_tsl_ast ast in - let does_something = - List.for_all test_tree_does_something_on_all_branches trees - in - if does_something then env, trees - else - let tree = - match trees with - | [] -> [] - | Node (_, _, name, _) :: _ -> - [Node ([], Tests.does_nothing, name, [])] - in - env, tree let rec ast_of_tree (Node (env, test, mods, subs)) = let tst = [Test (0, Tsl_ast.make_identifier test.Tests.test_name, mods)] in @@ -255,75 +219,7 @@ let print_tsl_ast ~compact oc ast = pr "%s}" indent; and print_statements indent stmts = - match stmts with - | Test (_, name, mods) :: tl -> - pr "%s%s" indent name.node; - begin match mods with - | m :: tl -> - pr " with %s" m.node; - List.iter (fun m -> pr ", %s" m.node) tl; - | [] -> () - end; - pr ";\n"; - if tl <> [] && not compact then pr "\n"; - print_statements indent tl; - | Environment_statement env :: tl-> - print_env indent env; - print_statements indent tl; - | [] -> () - - and print_forest indent subs = - if subs <> [] then begin - pr "%s" indent; - List.iter (print_sub indent) subs; - pr "\n"; - end - - and print_env indent e = - match e.node with - | Assignment (set, variable, value) -> - pr "%s" indent; - if set then pr "set "; - pr "%s = \"%s\";\n" variable.node value.node; - | Append (variable, value) -> - pr "%s%s += \"%s\";\n" indent variable.node value.node; - | Include ls -> - pr "%sinclude %s;\n" indent ls.node; - | Unset ls -> - pr "%sunset %s;\n" indent ls.node; - in - print_ast " " ast; -||||||| 121bedcfd2 -======= - -let rec ast_of_tree (Node (env, test, mods, subs)) = - let tst = [Test (0, Tsl_ast.make_identifier test.Tests.test_name, mods)] in - ast_of_tree_aux env tst subs - -and ast_of_tree_aux env tst subs = - let env = List.map (fun x -> Environment_statement x) env in - match List.map ast_of_tree subs with - | [ Ast (stmts, subs) ] -> Ast (env @ tst @ stmts, subs) - | asts -> Ast (env @ tst, asts) - -let tsl_ast_of_test_trees (env, trees) = ast_of_tree_aux env [] trees - -open Printf - -let print_tsl_ast ~compact oc ast = - let pr fmt (*args*) = fprintf oc fmt (*args*) in - - let rec print_ast indent (Ast (stmts, subs)) = - print_statements indent stmts; - print_forest indent subs; - - and print_sub indent ast = - pr "{\n"; - print_ast (indent ^ " ") ast; - pr "%s}" indent; - - and print_statements indent stmts = - match stmts with + match[@ocaml.warning "-fragile-match"] stmts with | Test (_, name, mods) :: tl -> pr "%s%s" indent name.node; begin match mods with @@ -361,4 +257,3 @@ let print_tsl_ast ~compact oc ast = pr "%sunset %s;\n" indent ls.node; in print_ast " " ast; ->>>>>>> 5.2.0 diff --git a/ocamltest/tsl_semantics.mli b/ocamltest/tsl_semantics.mli index 9ed18419785..be755e7feae 100644 --- a/ocamltest/tsl_semantics.mli +++ b/ocamltest/tsl_semantics.mli @@ -37,35 +37,14 @@ val test_trees_of_tsl_block : Tsl_ast.tsl_item list -> Tsl_ast.environment_statement located list * test_tree list -<<<<<<< HEAD -val test_trees_of_tsl_ast : - Tsl_ast.t -> - Tsl_ast.environment_statement located list * test_tree list - val tsl_ast_of_test_trees : Tsl_ast.environment_statement located list * test_tree list -> Tsl_ast.t -val tests_in_tree : test_tree -> Tests.TestSet.t -||||||| 121bedcfd2 -val tests_in_tree : test_tree -> Tests.TestSet.t -======= -val tsl_ast_of_test_trees : - Tsl_ast.environment_statement located list * test_tree list -> - Tsl_ast.t ->>>>>>> 5.2.0 - val tests_in_tree : Tsl_ast.t -> Tests.TestSet.t val actions_in_test : Tests.t -> Actions.ActionSet.t val actions_in_tests : Tests.TestSet.t -> Actions.ActionSet.t -<<<<<<< HEAD - - -val print_tsl_ast : compact:bool -> out_channel -> Tsl_ast.t -> unit -||||||| 121bedcfd2 -======= val print_tsl_ast : compact:bool -> out_channel -> Tsl_ast.t -> unit ->>>>>>> 5.2.0