forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.ml
67 lines (53 loc) · 2.31 KB
/
actions.ml
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
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Sebastien Hinderer, projet Gallium, INRIA Paris *)
(* *)
(* Copyright 2016 Institut National de Recherche en Informatique et *)
(* en Automatique. *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
(* Definition of actions, basic blocks for tests *)
type result =
| Pass of Environments.t
| Fail of string
| Skip of string
let string_of_reason prefix reason =
if reason="" then prefix
else prefix ^ " (" ^ reason ^ ")"
let string_of_result = function
| Pass _ -> "Pass"
| Fail reason -> string_of_reason "Fail" reason
| Skip reason -> string_of_reason "Skip" reason
type body = out_channel -> Environments.t -> result
type t = {
action_name : string;
action_environment : Environments.t -> Environments.t;
action_body : body
}
let compare a1 a2 = String.compare a1.action_name a2.action_name
let (actions : (string, t) Hashtbl.t) = Hashtbl.create 10
let register action =
Hashtbl.add actions action.action_name action
let get_registered_actions () =
let f _action_name action acc = action::acc in
let unsorted_actions = Hashtbl.fold f actions [] in
List.sort compare unsorted_actions
let lookup name =
try Some (Hashtbl.find actions name)
with Not_found -> None
let run log env action =
action.action_body log env
module ActionSet = Set.Make
(struct
type nonrec t = t
let compare = compare
end)
let update_environment initial_env actions =
let f act env = act.action_environment env in
ActionSet.fold f actions initial_env