/usr/lib/ocaml/oUnit/oUnitResultSummary.ml is in libounit-ocaml-dev 2.0.0-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | (**************************************************************************)
(* 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. *)
(**************************************************************************)
(*
Summary of the results, based on captured log events.
*)
open OUnitUtils
open OUnitTest
open OUnitLogger
type log_entry =
float (* time since start of the test *) *
log_severity option *
string (* log entry without \n *)
type test_data =
{
test_name: string;
timestamp_start: float; (* UNIX timestamp *)
timestamp_end: float; (* UNIX timestamp *)
log_entries: log_entry list; (* time sorted log entry, timestamp from
timestamp_start *)
test_result: OUnitTest.result;
}
type t =
{
suite_name: string;
start_at: float;
charset: string;
conf: (string * string) list;
running_time: float;
global_results: OUnitTest.result_list;
test_case_count: int;
tests: test_data list;
errors: int;
failures: int;
skips: int;
todos: int;
timeouts: int;
successes: int;
}
let is_success =
function
| RSuccess -> true
| RFailure _ | RError _ | RSkip _ | RTodo _ | RTimeout _ -> false
let is_failure =
function
| RFailure _ -> true
| RSuccess | RError _ | RSkip _ | RTodo _ | RTimeout _ -> false
let is_error =
function
| RError _ -> true
| RSuccess | RFailure _ | RSkip _ | RTodo _ | RTimeout _ -> false
let is_skip =
function
| RSkip _ -> true
| RSuccess | RFailure _ | RError _ | RTodo _ | RTimeout _ -> false
let is_todo =
function
| RTodo _ -> true
| RSuccess | RFailure _ | RError _ | RSkip _ | RTimeout _ -> false
let is_timeout =
function
| RTimeout _ -> true
| RSuccess | RFailure _ | RError _ | RSkip _ | RTodo _ -> false
let result_flavour =
function
| RError _ -> "Error"
| RFailure _ -> "Failure"
| RSuccess -> "Success"
| RSkip _ -> "Skip"
| RTodo _ -> "Todo"
| RTimeout _ -> "Timeout"
let result_msg =
function
| RSuccess -> "Success"
| RError (msg, _)
| RFailure (msg, _, _)
| RSkip msg
| RTodo msg -> msg
| RTimeout test_length ->
Printf.sprintf "Timeout after %.1fs" (delay_of_length test_length)
let worst_cmp result1 result2 =
let rank =
function
| RSuccess -> 0
| RSkip _ -> 1
| RTodo _ -> 2
| RFailure _ -> 3
| RError _ -> 4
| RTimeout _ -> 5
in
(rank result1) - (rank result2)
let worst_result_full result_full lst =
let worst =
List.fold_left
(fun ((_, result1, _) as result_full1)
((_, result2, _) as result_full2) ->
if worst_cmp result1 result2 < 0 then
result_full2
else
result_full1)
result_full lst
in
worst,
List.filter
(fun result_full -> not (result_full == worst))
(result_full :: lst)
let was_successful lst =
List.for_all
(fun (_, rslt, _) ->
match rslt with
| RSuccess | RSkip _ -> true
| _ -> false)
lst
let encoding =
OUnitConf.make_string
"log_encoding"
"utf-8"
"Encoding of the log."
let of_log_events conf events =
let global_conf =
List.fold_left
(fun acc log_ev ->
match log_ev.event with
| GlobalEvent (GConf (k, v)) -> (k, v) :: acc
| _ -> acc)
[]
(List.rev events)
in
let running_time, global_results, test_case_count =
let rec find_results =
function
| {event =
GlobalEvent
(GResults (running_time, results, test_case_count))} :: _ ->
running_time, results, test_case_count
| _ :: tl ->
find_results tl
| [] ->
failwith "Cannot find results in OUnitResult.of_log_events."
in
find_results events
in
let tests =
let rec split_raw tmstp str lst =
try
let idx = String.index str '\n' in
split_raw tmstp
(String.sub str (idx + 1) (String.length str - idx - 1))
((tmstp, None, String.sub str 0 idx) :: lst)
with Not_found ->
(tmstp, None, str) :: lst
in
let finalize t =
let log_entries =
List.sort
(fun (f1, _, _) (f2, _, _) -> Pervasives.compare f2 f1)
t.log_entries
in
let log_entries =
List.rev_map
(fun (f, a, b) -> f -. t.timestamp_start, a, b)
log_entries
in
{t with log_entries = log_entries}
in
let default_timestamp = 0.0 in
let rec process_log_event tests log_event =
let timestamp = log_event.timestamp in
match log_event.event with
| GlobalEvent _ ->
tests
| TestEvent (path, ev) ->
begin
let t =
try
MapPath.find path tests
with Not_found ->
{
test_name = string_of_path path;
timestamp_start = default_timestamp;
timestamp_end = default_timestamp;
log_entries = [];
test_result = RFailure ("Not finished", None, None);
}
in
let alt0 t1 t2 =
if t1 = default_timestamp then
t2
else
t1
in
let t' =
match ev with
| EStart ->
{t with
timestamp_start = timestamp;
timestamp_end = alt0 t.timestamp_end timestamp}
| EEnd ->
{t with
timestamp_end = timestamp;
timestamp_start = alt0 t.timestamp_start timestamp}
| EResult rslt ->
{t with test_result = rslt}
| ELog (svrt, str) ->
{t with log_entries = (timestamp, Some svrt, str)
:: t.log_entries}
| ELogRaw str ->
{t with log_entries =
split_raw timestamp str t.log_entries}
in
MapPath.add path t' tests
end
and group_test tests =
function
| hd :: tl ->
group_test
(process_log_event tests hd)
tl
| [] ->
let lst =
MapPath.fold
(fun _ test lst ->
finalize test :: lst)
tests []
in
List.sort
(fun t1 t2 ->
Pervasives.compare t1.timestamp_start t2.timestamp_start)
lst
in
group_test MapPath.empty events
in
let start_at =
List.fold_left
(fun start_at log_ev ->
min start_at log_ev.timestamp)
(now ())
events
in
let suite_name =
match global_results with
| (path, _, _) :: _ ->
List.fold_left
(fun acc nd ->
match nd with
| ListItem _ -> acc
| Label str -> str)
"noname"
path
| [] ->
"noname"
in
let count f =
List.length
(List.filter (fun (_, test_result, _) -> f test_result)
global_results)
in
let charset = encoding conf in
{
suite_name = suite_name;
start_at = start_at;
charset = charset;
conf = global_conf;
running_time = running_time;
global_results = global_results;
test_case_count = test_case_count;
tests = tests;
errors = count is_error;
failures = count is_failure;
skips = count is_skip;
todos = count is_todo;
timeouts = count is_timeout;
successes = count is_success;
}
|