123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137(*
* Copyright (c) 2013-2016 Thomas Gazagnaire <thomas@gazagnaire.org>
* Copyright (c) 2019 Craig Ferguson <me@craigfe.io>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)includeCli_intfopen!ImportopenCmdlinermoduleMake(P:Platform.MAKER)(M:Monad.S):V1_types.Swithtypereturn=unitM.t=struct(** *)(** The priority order for determining options should be as follows:
+ 1. if a CLI flag/option is _explicitly_ set, use that;
+ 2. if the corresponding environment variable is _explicitly_ set, use
that;
+ 3. if the flag/option is set by [run ?argv]
+ 4. if the flag/option is passed to [run] directly, use that;
+ 5. otherwise, use the default behaviour set by {!Alcotest.Core}. *)moduleC=Core.V1.Make(P)(M)includeCmoduleP=P(M)openCmdliner_syntaxletset_color=letenv=Cmd.Env.info"ALCOTEST_COLOR"inlet+color_flag=letenum=[("auto",`Auto);("always",`Ansi_tty);("never",`None)]inletcolor=Arg.enumenuminletenum_alts=Arg.doc_alts_enumenuminletdoc=Fmt.str"Colorize the output. $(docv) must be %s. Defaults to %s when \
running inside Dune, otherwise defaults to %s."enum_alts(Arg.doc_quote"always")(Arg.doc_quote"auto")inArg.(value&opt(somecolor)None&info["color"]~env~doc~docv:"WHEN")inletstyle_renderer=matchcolor_flagwith|Some`Auto->None|Some(`Ansi_tty|`None)asa->a|None->(try(* Default to [always] when running inside Dune *)let(_:string)=Sys.getenv"INSIDE_DUNE"inSome`Ansi_ttywithNot_found->None)inP.setup_std_outputs?style_renderer()letdefault_cmdconfigargslibrary_nametests=letand_exit=Config.User.and_exitconfigandrecord_backtrace=Config.User.record_backtraceconfiginletexec_name=Filename.basenameSys.argv.(0)inletdoc="Run all the tests."inletterm=let+()=set_colorand+cli_config=Config.User.term~and_exit~record_backtraceand+args=argsinletconfig=Config.User.(cli_config||config)inrun_with_args'configlibrary_nameargstestsin(term,Cmd.infoexec_name~doc)lettest_cmdconfigargslibrary_nametests=letdoc="Run a subset of the tests."inletterm=let+()=set_colorand+cli_config=Config.User.term~and_exit:true~record_backtrace:trueand+args=argsinletconfig=Config.User.(cli_config||config)inrun_with_args'configlibrary_nameargstestsin(term,Cmd.info"test"~doc)letlist_cmdtests=letdoc="List all available tests."in((let+()=set_colorinlist_teststests),Cmd.info"list"~doc)letrun_with_args'(typea)~argvconfigname(args:aTerm.t)(tl:atestlist)=let(>>=)=M.bindinletchoices=List.map(fun(term,info)->Cmd.vinfoterm)[list_cmdtl;test_cmdconfigargsnametl]inletand_exit=Config.User.and_exitconfiginletexit_or_returnexit_code=ifand_exitthenexitexit_codeelseM.return()inletresult=letdefault,info=default_cmdconfigargsnametlinCmd.eval_value?argv~catch:and_exit(* Only log exceptions not raised to the user code *)(Cmd.group~defaultinfochoices)inmatchresultwith|Ok(`Okunit_m)->unit_m>>=fun()->exit_or_returnCmd.Exit.ok|Ok(`Help|`Version)->exit_or_returnCmd.Exit.ok|Error(`Parse|`Term)->exit_or_returnCmd.Exit.cli_error|Error`Exn->exitCmd.Exit.internal_errorletrun_with_args?and_exit?verbose?compact?tail_errors?quick_only?show_errors?json?filter?log_dir?bail?record_backtrace?argv=Config.User.kcreate(run_with_args'~argv)?and_exit?verbose?compact?tail_errors?quick_only?show_errors?json?filter?log_dir?bail?record_backtraceletrun=Config.User.kcreate(funconfig?argvnametl->run_with_args'config~argvname(Term.const())tl)endmoduleV1=structincludeV1_typesmoduleMake=Makeend