From ade087b31835c531cb2fa7803dd03e5fd3653961 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sat, 26 Oct 2024 11:57:04 +0100 Subject: [PATCH] refactor: move runtest to own module Signed-off-by: Rudi Grinberg --- bin/build_cmd.ml | 40 -------------------------------------- bin/build_cmd.mli | 2 -- bin/main.ml | 49 +++++++++++++++++++++++------------------------ bin/runtest.ml | 44 ++++++++++++++++++++++++++++++++++++++++++ bin/runtest.mli | 3 +++ 5 files changed, 71 insertions(+), 67 deletions(-) create mode 100644 bin/runtest.ml create mode 100644 bin/runtest.mli diff --git a/bin/build_cmd.ml b/bin/build_cmd.ml index fec6191252a..bad613a2ec9 100644 --- a/bin/build_cmd.ml +++ b/bin/build_cmd.ml @@ -127,46 +127,6 @@ let run_build_command ~(common : Common.t) ~config ~request = ~request ;; -let runtest_info = - let doc = "Run tests." in - let man = - [ `S "DESCRIPTION" - ; `P {|This is a short-hand for calling:|} - ; `Pre {| dune build @runtest|} - ; `Blocks Common.help_secs - ; Common.examples - [ ( "Run all tests in the current source tree (including those that passed on \ - the last run)" - , "dune runtest --force" ) - ; ( "Run tests sequentially without output buffering" - , "dune runtest --no-buffer -j 1" ) - ] - ] - in - Cmd.info "runtest" ~doc ~man ~envs:Common.envs -;; - -let runtest_term = - let name_ = Arg.info [] ~docv:"DIR" in - let+ builder = Common.Builder.term - and+ dirs = Arg.(value & pos_all string [ "." ] name_) in - let common, config = Common.init builder in - let request (setup : Import.Main.build_system) = - Action_builder.all_unit - (List.map dirs ~f:(fun dir -> - let dir = Path.(relative root) (Common.prefix_target common dir) in - Alias.in_dir - ~name:Dune_rules.Alias.runtest - ~recursive:true - ~contexts:setup.contexts - dir - |> Alias.request)) - in - run_build_command ~common ~config ~request -;; - -let runtest = Cmd.v runtest_info runtest_term - let build = let doc = "Build the given targets, or the default ones if none are given." in let man = diff --git a/bin/build_cmd.mli b/bin/build_cmd.mli index 6bc397890a3..4c39af7db03 100644 --- a/bin/build_cmd.mli +++ b/bin/build_cmd.mli @@ -5,8 +5,6 @@ val run_build_system -> request:(Dune_rules.Main.build_system -> unit Action_builder.t) -> (unit, [ `Already_reported ]) result Fiber.t -val runtest : unit Cmd.t -val runtest_term : unit Term.t val build : unit Cmd.t val fmt : unit Cmd.t diff --git a/bin/main.ml b/bin/main.ml index 96bd2b6c8bc..3c8bb2d8a91 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -2,31 +2,30 @@ open Import let all : _ Cmdliner.Cmd.t list = let terms = - [ Installed_libraries.command - ; External_lib_deps.command - ; Build_cmd.build - ; Build_cmd.runtest - ; Build_cmd.fmt - ; command_alias Build_cmd.runtest Build_cmd.runtest_term "test" - ; Clean.command - ; Install_uninstall.install - ; Install_uninstall.uninstall - ; Exec.command - ; Subst.command - ; Print_rules.command - ; Utop.command - ; Promotion.promote - ; command_alias Printenv.command Printenv.term "printenv" - ; Help.command - ; Format_dune_file.command - ; Upgrade.command - ; Cache.command - ; Top.command - ; Ocaml_merlin.command - ; Shutdown.command - ; Diagnostics.command - ; Monitor.command - ] + Runtest.commands + @ [ Installed_libraries.command + ; External_lib_deps.command + ; Build_cmd.build + ; Build_cmd.fmt + ; Clean.command + ; Install_uninstall.install + ; Install_uninstall.uninstall + ; Exec.command + ; Subst.command + ; Print_rules.command + ; Utop.command + ; Promotion.promote + ; command_alias Printenv.command Printenv.term "printenv" + ; Help.command + ; Format_dune_file.command + ; Upgrade.command + ; Cache.command + ; Top.command + ; Ocaml_merlin.command + ; Shutdown.command + ; Diagnostics.command + ; Monitor.command + ] in let groups = [ Ocaml_cmd.group diff --git a/bin/runtest.ml b/bin/runtest.ml new file mode 100644 index 00000000000..ec5fac6a422 --- /dev/null +++ b/bin/runtest.ml @@ -0,0 +1,44 @@ +open Import + +let runtest_info = + let doc = "Run tests." in + let man = + [ `S "DESCRIPTION" + ; `P {|This is a short-hand for calling:|} + ; `Pre {| dune build @runtest|} + ; `Blocks Common.help_secs + ; Common.examples + [ ( "Run all tests in the current source tree (including those that passed on \ + the last run)" + , "dune runtest --force" ) + ; ( "Run tests sequentially without output buffering" + , "dune runtest --no-buffer -j 1" ) + ] + ] + in + Cmd.info "runtest" ~doc ~man ~envs:Common.envs +;; + +let runtest_term = + let name_ = Arg.info [] ~docv:"DIR" in + let+ builder = Common.Builder.term + and+ dirs = Arg.(value & pos_all string [ "." ] name_) in + let common, config = Common.init builder in + let request (setup : Import.Main.build_system) = + Action_builder.all_unit + (List.map dirs ~f:(fun dir -> + let dir = Path.(relative root) (Common.prefix_target common dir) in + Alias.in_dir + ~name:Dune_rules.Alias.runtest + ~recursive:true + ~contexts:setup.contexts + dir + |> Alias.request)) + in + Build_cmd.run_build_command ~common ~config ~request +;; + +let commands = + let command = Cmd.v runtest_info runtest_term in + [ command; command_alias command runtest_term "test" ] +;; diff --git a/bin/runtest.mli b/bin/runtest.mli new file mode 100644 index 00000000000..00de8796dac --- /dev/null +++ b/bin/runtest.mli @@ -0,0 +1,3 @@ +open Import + +val commands : unit Cmd.t list