123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177(**************************************************************************)(* The OUnit library *)(* *)(* Copyright (C) 2002-2008 Maas-Maarten Zeeman. *)(* Copyright (C) 2010 OCamlCore SARL *)(* Copyright (C) 2013 Sylvain Le Gall *)(* *)(* The package OUnit is copyright by Maas-Maarten Zeeman, OCamlCore SARL *)(* and Sylvain Le Gall. *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining *)(* a copy of this document and the OUnit software ("the Software"), to *)(* deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, *)(* sublicense, and/or sell copies of the Software, and to permit persons *)(* to whom the Software is furnished to do so, subject to the following *)(* conditions: *)(* *)(* The above copyright notice and this permission notice shall be *)(* included in all copies or substantial portions of the Software. *)(* *)(* The Software is provided ``as is'', without warranty of any kind, *)(* express or implied, including but not limited to the warranties of *)(* merchantability, fitness for a particular purpose and noninfringement. *)(* In no event shall Maas-Maarten Zeeman be liable for any claim, damages *)(* or other liability, whether in an action of contract, tort or *)(* otherwise, arising from, out of or in connection with the Software or *)(* the use or other dealings in the software. *)(* *)(* See LICENSE.txt for details. *)(**************************************************************************)openOUnitUtilsopenOUnitTestopenOUnitLogger(* Plugin initialisation. *)let()=OUnitRunnerProcesses.init()(*
* Types and global states.
*)(* Run all tests, report starts, errors, failures, and return the results *)letperform_testconfloggerrunnerchoosertest=letrecflatten_testpathacc=function|TestCase(l,f)->(path,l,f)::acc|TestList(tests)->fold_lefti(funacctcnt->flatten_test((ListItemcnt)::path)acct)acctests|TestLabel(label,t)->flatten_test((Labellabel)::path)acctinlettest_cases=List.rev(flatten_test[][]test)inrunnerconfloggerchoosertest_cases(* A simple (currently too simple) text based test runner *)letrun_test_ttconfloggerrunnerchoosertest=let()=Printexc.record_backtracetrueinlet()=(* TODO: move into perform test. *)List.iter(fun(k,v)->OUnitLogger.reportlogger(GlobalEvent(GConf(k,v))))(OUnitConf.dumpconf)in(* Now start the test *)letrunning_time,test_results=time_fun(perform_testconfloggerrunnerchooser)testin(* TODO: move into perform test. *)(* Print test report *)OUnitLogger.reportlogger(GlobalEvent(GResults(running_time,test_results,OUnitTest.test_case_counttest)));(* Reset logger. *)OUnitLogger.closelogger;(* Return the results possibly for further processing *)test_results(* Test-only override. *)letrun_test_tt_main_conf=ref(fun?(preset=[])?argvextra_specs->OUnitConf.load?argv~preset:(OUnitChooser.preset(OUnitRunner.presetpreset))extra_specs)letsuite_name=OUnitConf.make_string"suite_name""anon""The name of the test suite running."(* Call this one to act as your main() function. *)letrun_test_tt_main?(exit=Stdlib.exit)suite=letonly_test=ref[]inletlist_test=reffalseinletextra_specs=["-only-test",Arg.String(funstr->only_test:=str::!only_test),"path Run only the selected tests.";"-list-test",Arg.Setlist_test," List tests";]inletpreset=matchsuitewith|OUnitTest.TestLabel(suite_name,_)->["suite_name",suite_name]|OUnitTest.TestCase_|OUnitTest.TestList_->[]inletconf=!run_test_tt_main_conf~presetextra_specsinif!list_testthenbeginList.iter(funpth->print_endline(OUnitTest.string_of_pathpth))(OUnitTest.test_case_pathssuite)endelsebeginletnsuite=if!only_test=[]thensuiteelsebeginmatchOUnitTest.test_filter~skip:true!only_testsuitewith|Sometest->test|None->failwithf"Filtering test %s lead to no tests."(String.concat", "!only_test)endinletlogger=OUnitLogger.combine[OUnitLoggerStd.createconfshard_default;OUnitLoggerHTML.createconf;OUnitLoggerJUnit.createconf;OUnitLoggerCI.createconf;]inletrunner_name,runner=OUnitRunner.choiceconfinletchooser_name,chooser=OUnitChooser.choiceconfinlettest_results=OUnitLogger.infoflogger"Runner: %s"runner_name;OUnitLogger.infoflogger"Chooser: %s"chooser_name;run_test_ttconfloggerrunnerchoosernsuiteinifnot(OUnitResultSummary.was_successfultest_results)thenexit1end