123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136(**************************************************************************)(* 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. *)(**************************************************************************)(**
Heuristic to pick a test to run.
@author Sylvain Le Gall
*)openOUnitTesttypet={tests_planned:pathlist;tests_running:pathlist;tests_passed:result_list;cache:OUnitCache.cache;}typechoice=|ChooseToSkipofpath|ChooseToPostpone|Chooseofpath|NoChoiceletstring_of_choice=function|ChooseToSkippath->Printf.sprintf"ChooseToSkip %S"(string_of_pathpath)|ChooseToPostpone->"ChooseToPostpone"|Choosepath->Printf.sprintf"Choose %S"(string_of_pathpath)|NoChoice->"NoChoice"typechooser=t->choice(** Most simple heuristic, just pick the first test. *)letsimplet=matcht.tests_plannedwith|hd::_->Choosehd|[]->NoChoicemodulePlugin=OUnitPlugin.Make(structtypet=chooserletname="chooser"letconf_help="Select the method to choose tests to run."letdefault_name="simple"letdefault_value=simpleend)includePluginletallskipt=matcht.tests_plannedwith|hd::_->ChooseToSkiphd|[]->NoChoiceletfailfirstt=letwas_successful=OUnitResultSummary.was_successfulinletrecfind_failing=function|path::tl->beginmatchOUnitCache.get_resultpatht.cachewith|Someresult->(* Find the first formerly failing test. *)ifwas_successful[path,result,None]thenfind_failingtlelseChoosepath|None->Choosepathend|[]->beginletwait_results_running=List.fold_left(funwaitpath->matchOUnitCache.get_resultpatht.cachewith|Someresult->(not(was_successful[path,result,None]))||wait|None->(* No former result, we need the result of
* this test.
*)true)falset.tests_runninginifwait_results_runningthen(* We need more data about currently running tests. *)ChooseToPostponeelseifwas_successfult.tests_passedthen(* All tests that were red has become green, continue. *)simpletelse(* Some tests still fail, skip the rest. *)allskiptendinfind_failingt.tests_plannedlet()=register"failfirst"~-1failfirst