Skip to content

Commit be85e6f

Browse files
authored
Tests: better constraint for tests (#1773)
1 parent 0b995da commit be85e6f

File tree

9 files changed

+216
-107
lines changed

9 files changed

+216
-107
lines changed

compiler/tests-check-prim/dune

Lines changed: 20 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,32 @@
1-
(executables
2-
(names main)
1+
(include dune.inc)
2+
3+
(rule
4+
(action
5+
(with-stdout-to
6+
dune.inc.gen
7+
(run ./gen_dune.exe))))
8+
9+
(rule
10+
(alias runtest)
11+
(action
12+
(diff dune.inc dune.inc.gen)))
13+
14+
(executable
15+
(name main)
316
(libraries js_of_ocaml num str)
417
(link_flags
518
(:standard -linkall))
619
(modules main)
720
(modes byte))
821

9-
(executables
10-
(names unix)
22+
(executable
23+
(name unix)
1124
(libraries js_of_ocaml num str unix)
1225
(link_flags
1326
(:standard -linkall))
1427
(modules unix)
1528
(modes byte))
1629

17-
(rule
18-
(targets main.output)
19-
(mode
20-
(promote (until-clean)))
21-
(enabled_if
22-
(< %{ocaml_version} 5))
23-
(action
24-
(with-stdout-to
25-
%{targets}
26-
(run
27-
%{bin:js_of_ocaml}
28-
check-runtime
29-
+dynlink.js
30-
+toplevel.js
31-
%{dep:main.bc}))))
32-
33-
(rule
34-
(targets unix-unix.output)
35-
(enabled_if
36-
(and
37-
(< %{ocaml_version} 5)
38-
(= %{os_type} Unix)))
39-
(mode
40-
(promote (until-clean)))
41-
(action
42-
(with-stdout-to
43-
%{targets}
44-
(run
45-
%{bin:js_of_ocaml}
46-
check-runtime
47-
+dynlink.js
48-
+toplevel.js
49-
%{dep:unix.bc}))))
50-
51-
(rule
52-
(targets unix-win32.output)
53-
(enabled_if
54-
(and
55-
(< %{ocaml_version} 5)
56-
(= %{os_type} Win32)))
57-
(mode
58-
(promote (until-clean)))
59-
(action
60-
(with-stdout-to
61-
%{targets}
62-
(run
63-
%{bin:js_of_ocaml}
64-
check-runtime
65-
+dynlink.js
66-
+toplevel.js
67-
%{dep:unix.bc}))))
68-
69-
(rule
70-
(targets main.output5)
71-
(mode
72-
(promote (until-clean)))
73-
(enabled_if
74-
(>= %{ocaml_version} 5))
75-
(action
76-
(with-stdout-to
77-
%{targets}
78-
(run
79-
%{bin:js_of_ocaml}
80-
check-runtime
81-
+dynlink.js
82-
+toplevel.js
83-
%{dep:main.bc}))))
84-
85-
(rule
86-
(targets unix-unix.output5)
87-
(enabled_if
88-
(and
89-
(>= %{ocaml_version} 5)
90-
(= %{os_type} Unix)))
91-
(mode
92-
(promote (until-clean)))
93-
(action
94-
(with-stdout-to
95-
%{targets}
96-
(run
97-
%{bin:js_of_ocaml}
98-
check-runtime
99-
+dynlink.js
100-
+toplevel.js
101-
%{dep:unix.bc}))))
102-
103-
(rule
104-
(targets unix-win32.output5)
105-
(enabled_if
106-
(and
107-
(>= %{ocaml_version} 5)
108-
(= %{os_type} Win32)))
109-
(mode
110-
(promote (until-clean)))
111-
(action
112-
(with-stdout-to
113-
%{targets}
114-
(run
115-
%{bin:js_of_ocaml}
116-
check-runtime
117-
+dynlink.js
118-
+toplevel.js
119-
%{dep:unix.bc}))))
30+
(executable
31+
(name gen_dune)
32+
(modules gen_dune))

compiler/tests-check-prim/dune.inc

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
(rule
2+
(targets main.4.14.output)
3+
(mode
4+
(promote (until-clean)))
5+
(enabled_if (and (>= %{ocaml_version} 4.14)(< %{ocaml_version} 5.0)))
6+
(action
7+
(with-stdout-to
8+
%{targets}
9+
(run
10+
%{bin:js_of_ocaml}
11+
check-runtime
12+
+dynlink.js
13+
+toplevel.js
14+
%{dep:main.bc}))))
15+
16+
(rule
17+
(targets unix-Win32.4.14.output)
18+
(mode
19+
(promote (until-clean)))
20+
(enabled_if (and (>= %{ocaml_version} 4.14)(< %{ocaml_version} 5.0)(= %{os_type} Win32)))
21+
(action
22+
(with-stdout-to
23+
%{targets}
24+
(run
25+
%{bin:js_of_ocaml}
26+
check-runtime
27+
+dynlink.js
28+
+toplevel.js
29+
%{dep:unix.bc}))))
30+
31+
(rule
32+
(targets unix-Unix.4.14.output)
33+
(mode
34+
(promote (until-clean)))
35+
(enabled_if (and (>= %{ocaml_version} 4.14)(< %{ocaml_version} 5.0)(= %{os_type} Unix)))
36+
(action
37+
(with-stdout-to
38+
%{targets}
39+
(run
40+
%{bin:js_of_ocaml}
41+
check-runtime
42+
+dynlink.js
43+
+toplevel.js
44+
%{dep:unix.bc}))))
45+
46+
(rule
47+
(targets main.5.2.output)
48+
(mode
49+
(promote (until-clean)))
50+
(enabled_if (and (>= %{ocaml_version} 5.2)(< %{ocaml_version} 5.3)))
51+
(action
52+
(with-stdout-to
53+
%{targets}
54+
(run
55+
%{bin:js_of_ocaml}
56+
check-runtime
57+
+dynlink.js
58+
+toplevel.js
59+
%{dep:main.bc}))))
60+
61+
(rule
62+
(targets unix-Win32.5.2.output)
63+
(mode
64+
(promote (until-clean)))
65+
(enabled_if (and (>= %{ocaml_version} 5.2)(< %{ocaml_version} 5.3)(= %{os_type} Win32)))
66+
(action
67+
(with-stdout-to
68+
%{targets}
69+
(run
70+
%{bin:js_of_ocaml}
71+
check-runtime
72+
+dynlink.js
73+
+toplevel.js
74+
%{dep:unix.bc}))))
75+
76+
(rule
77+
(targets unix-Unix.5.2.output)
78+
(mode
79+
(promote (until-clean)))
80+
(enabled_if (and (>= %{ocaml_version} 5.2)(< %{ocaml_version} 5.3)(= %{os_type} Unix)))
81+
(action
82+
(with-stdout-to
83+
%{targets}
84+
(run
85+
%{bin:js_of_ocaml}
86+
check-runtime
87+
+dynlink.js
88+
+toplevel.js
89+
%{dep:unix.bc}))))
90+
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
(** *)
2+
3+
type version =
4+
[ `V4_08
5+
| `V4_09
6+
| `V4_10
7+
| `V4_11
8+
| `V4_12
9+
| `V4_13
10+
| `V4_14
11+
| `V5_0
12+
| `V5_1
13+
| `V5_2
14+
| `V5_3
15+
| `V5_4
16+
]
17+
18+
let string_of_version : version -> string = function
19+
| `V4_08 -> "4.08"
20+
| `V4_09 -> "4.09"
21+
| `V4_10 -> "4.10"
22+
| `V4_11 -> "4.11"
23+
| `V4_12 -> "4.12"
24+
| `V4_13 -> "4.13"
25+
| `V4_14 -> "4.14"
26+
| `V5_0 -> "5.0"
27+
| `V5_1 -> "5.1"
28+
| `V5_2 -> "5.2"
29+
| `V5_3 -> "5.3"
30+
| `V5_4 -> "5.4"
31+
32+
let next_version : version -> version option = function
33+
| `V4_08 -> Some `V4_09
34+
| `V4_09 -> Some `V4_10
35+
| `V4_10 -> Some `V4_11
36+
| `V4_11 -> Some `V4_12
37+
| `V4_12 -> Some `V4_13
38+
| `V4_13 -> Some `V4_14
39+
| `V4_14 -> Some `V5_0
40+
| `V5_0 -> Some `V5_1
41+
| `V5_1 -> Some `V5_2
42+
| `V5_2 -> Some `V5_3
43+
| `V5_3 -> Some `V5_4
44+
| `V5_4 -> None
45+
46+
type os_type =
47+
| Unix
48+
| Win32
49+
50+
let string_of_os_type = function
51+
| Unix -> "Unix"
52+
| Win32 -> "Win32"
53+
54+
let rule bc ocaml_version os_type =
55+
let vl =
56+
[ Printf.sprintf "(>= %%{ocaml_version} %s)" (string_of_version ocaml_version) ]
57+
in
58+
let vu =
59+
match next_version ocaml_version with
60+
| None -> []
61+
| Some up -> [ Printf.sprintf "(< %%{ocaml_version} %s)" (string_of_version up) ]
62+
in
63+
let os =
64+
match os_type with
65+
| None -> []
66+
| Some os_type -> [ Printf.sprintf "(= %%{os_type} %s)" (string_of_os_type os_type) ]
67+
in
68+
let enabled_if = Printf.sprintf "(and %s)" (String.concat "" (vl @ vu @ os)) in
69+
70+
let target =
71+
Filename.chop_extension bc
72+
^ (match os_type with
73+
| None -> ""
74+
| Some os_type -> "-" ^ string_of_os_type os_type)
75+
^ "."
76+
^ string_of_version ocaml_version
77+
^ ".output"
78+
in
79+
Printf.sprintf
80+
{|(rule
81+
(targets %s)
82+
(mode
83+
(promote (until-clean)))
84+
(enabled_if %s)
85+
(action
86+
(with-stdout-to
87+
%%{targets}
88+
(run
89+
%%{bin:js_of_ocaml}
90+
check-runtime
91+
+dynlink.js
92+
+toplevel.js
93+
%%{dep:%s}))))
94+
|}
95+
target
96+
enabled_if
97+
bc
98+
99+
let () =
100+
let versions : version list = [ `V4_14; `V5_2 ] in
101+
List.iter
102+
(fun ocaml_version ->
103+
List.iter
104+
(fun (bc, os_type) -> print_endline (rule bc ocaml_version os_type))
105+
[ "main.bc", None; "unix.bc", Some Win32; "unix.bc", Some Unix ])
106+
versions
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)