123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135(**************************************************************************)(* 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. *)(**************************************************************************)(*
CI logger for OUnit (Travis, AppVeyor...).
This logger allows to print results and logs in CI tools like Travis and
AppVeyor.
*)openOUnitLoggeropenOUnitResultSummaryopenOUnitTestletprintlfcolorfmt=letansi_color=matchcolorwith|`Red->"31"|`Green->"32"|`Yellow->"33"|`None->""inPrintf.fprintfstdout"\027[%sm"ansi_color;Printf.kfprintf(funchn->Printf.fprintfchn"\027[0m\n")stdoutfmtletsuccesses_color=`Noneleterrors_color=`Redletfailures_color=`Redletskips_color=`Yellowlettodos_color=`Yellowlettimeouts_color=`Redletseverity=function|Some`Error->`Red,"E"|Some`Warning->`Yellow,"W"|Some`Info->`None,"I"|None->`None,"I"letprint_separator()=printlf`None"========================="letrenderconfevents=letsmr=OUnitResultSummary.of_log_eventsconfeventsinList.iter(funtest_data->print_separator();printlf`None"%s"test_data.test_name;beginmatchtest_data.test_resultwith|RSuccess->printlfsuccesses_color"Success"|RFailure(str,_,backtrace)->printlffailures_color"Failure: %s"str;beginmatchbacktracewith|Sometxt->printlffailures_color"Backtrace: %s"txt|None->()end|RError(str,backtrace)->printlferrors_color"Error: %s"str;beginmatchbacktracewith|Sometxt->printlferrors_color"Backtrace: %s"txt|None->()end|RSkipstr->printlfskips_color"Skipped: %s"str;|RTodostr->printlftodos_color"TODO: %s"str;|RTimeouttest_length->printlftimeouts_color"Timeout %.1fs"(delay_of_lengthtest_length)end;printlf`None"Logs:";List.iter(fun(tmstp,svrt,str)->letcolor,prefix=severitysvrtinprintlfcolor"%04.1fs %s: %s"tmstpprefixstr)test_data.log_entries;ifList.lengthtest_data.log_entries<>0thenprintlf`None"%04.1fs I: End"(test_data.timestamp_end-.test_data.timestamp_start);)(List.filter(funtest_data->test_data.test_result<>RSuccess)smr.tests);print_separator();printlf`None"Summary:";printlf`None"Tried tests: %d"smr.test_case_count;printlf`Red"Errors: %d"smr.errors;printlf`Red"Failures: %d"smr.failures;printlf`Yellow"Skipped tests: %d"smr.skips;printlf`Yellow"TODO tests: %d"smr.todos;printlf`Red"Timed-out tests: %d"smr.timeouts;()letci=OUnitConf.make_bool"ci"false"Display logs for CI, like Travis and AppVeyor, in the console with colors."letcreateconf=ifciconfthenpost_logger(renderconf)elsenull_logger