Skip to content

Commit f014914

Browse files
OlivierNicolevouillonhhugo
authored
Tests: Make the tests for uncaught exceptions more portable (#1652)
* Make the tests for uncaught exceptions more portable --------- Co-authored-by: Jérôme Vouillon <[email protected]> Co-authored-by: Hugo Heuzard <[email protected]>
1 parent 5cbf0b1 commit f014914

File tree

7 files changed

+62
-59
lines changed

7 files changed

+62
-59
lines changed

compiler/tests-jsoo/bin/dune

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
(executables
2-
(names error1 error2 error3)
3-
(modes byte js))
2+
(names error1 error2)
3+
(modes exe js)
4+
(foreign_stubs
5+
(language c)
6+
(names named_value_stubs))
7+
(js_of_ocaml
8+
(javascript_files runtime.js))
9+
(libraries))
410

511
(rule
6-
(target error1.actual)
12+
(target error1.js.actual)
713
(deps error1.html)
814
(alias runtest)
915
(action
@@ -14,12 +20,27 @@
1420
(run node %{dep:error1.bc.js})))))
1521

1622
(rule
23+
(target error1.exe.actual)
1724
(alias runtest)
1825
(action
19-
(diff %{dep:error1.expected} %{dep:error1.actual})))
26+
(with-accepted-exit-codes
27+
2
28+
(with-outputs-to
29+
%{target}
30+
(run %{dep:error1.exe})))))
2031

2132
(rule
22-
(target error1-unregister.actual)
33+
(alias runtest)
34+
(action
35+
(diff %{dep:error1.expected} %{dep:error1.js.actual})))
36+
37+
(rule
38+
(alias runtest)
39+
(action
40+
(diff %{dep:error1.expected} %{dep:error1.exe.actual})))
41+
42+
(rule
43+
(target error1-unregister.js.actual)
2344
(deps error1-unregister.html)
2445
(alias runtest)
2546
(action
@@ -32,10 +53,10 @@
3253
(rule
3354
(alias runtest)
3455
(action
35-
(diff %{dep:error1-unregister.expected} %{dep:error1-unregister.actual})))
56+
(diff %{dep:error1-unregister.expected} %{dep:error1-unregister.js.actual})))
3657

3758
(rule
38-
(target error2.actual)
59+
(target error2.js.actual)
3960
(deps error2.html)
4061
(alias runtest)
4162
(action
@@ -46,48 +67,41 @@
4667
(run node %{dep:error2.bc.js})))))
4768

4869
(rule
49-
(alias runtest)
50-
(enabled_if
51-
(= %{profile} dev))
52-
(action
53-
(diff %{dep:error2.expected} %{dep:error2.actual})))
54-
55-
(rule
56-
(target error2-unregister.actual)
57-
(deps error2-unregister.html)
70+
(target error2.exe.actual)
5871
(alias runtest)
5972
(action
6073
(with-accepted-exit-codes
6174
2
6275
(with-outputs-to
6376
%{target}
64-
(run node %{dep:error2.bc.js} unregister)))))
77+
(run %{dep:error2.exe})))))
6578

6679
(rule
6780
(alias runtest)
81+
(enabled_if
82+
(= %{profile} dev))
6883
(action
69-
(diff %{dep:error2-unregister.expected} %{dep:error2-unregister.actual})))
84+
(diff %{dep:error2.expected} %{dep:error2.js.actual})))
7085

71-
;; We don't expect the output of error3 as it will be flacky
86+
(rule
87+
(alias runtest)
88+
(enabled_if
89+
(= %{profile} dev))
90+
(action
91+
(diff %{dep:error2.expected} %{dep:error2.exe.actual})))
7292

7393
(rule
74-
(target error3.actual)
75-
(deps error3.html)
94+
(target error2-unregister.js.actual)
95+
(deps error2-unregister.html)
7696
(alias runtest)
7797
(action
7898
(with-accepted-exit-codes
79-
7
99+
2
80100
(with-outputs-to
81101
%{target}
82-
(run node %{dep:error3.bc.js})))))
102+
(run node %{dep:error2.bc.js} unregister)))))
83103

84104
(rule
85-
(target error3-unregister.actual)
86-
(deps error3-unregister.html)
87105
(alias runtest)
88106
(action
89-
(with-accepted-exit-codes
90-
7
91-
(with-outputs-to
92-
%{target}
93-
(run node %{dep:error3.bc.js} unregister)))))
107+
(diff %{dep:error2-unregister.expected} %{dep:error2-unregister.js.actual})))

compiler/tests-jsoo/bin/error1.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
external unregister : string -> unit = "caml_unregister_named_value"
2+
13
let () =
24
match Array.to_list Sys.argv with
3-
| _ :: "unregister" :: _ ->
4-
let null = Array.unsafe_get [| 1 |] 1 in
5-
Callback.register "Printexc.handle_uncaught_exception" null
5+
| _ :: "unregister" :: _ -> unregister "Printexc.handle_uncaught_exception"
66
| _ -> ()
77

88
exception D of int * string * Int64.t

compiler/tests-jsoo/bin/error2.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
external unregister : string -> unit = "caml_unregister_named_value"
2+
13
let () =
24
(* Make sure Printexc is linked *)
35
let _ = Printexc.to_string Not_found in
46
match Array.to_list Sys.argv with
5-
| _ :: "unregister" :: _ ->
6-
let null = Array.unsafe_get [| 1 |] 1 in
7-
Callback.register "Printexc.handle_uncaught_exception" null
7+
| _ :: "unregister" :: _ -> unregister "Printexc.handle_uncaught_exception"
88
| _ -> ()
99

1010
[@@@ocaml.warning "-8"]

compiler/tests-jsoo/bin/error3.html

Lines changed: 0 additions & 13 deletions
This file was deleted.

compiler/tests-jsoo/bin/error3.ml

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "caml/mlvalues.h"
2+
3+
CAMLprim value caml_unregister_named_value(value nm) {
4+
return Val_unit;
5+
}

compiler/tests-jsoo/bin/runtime.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//Provides: caml_unregister_named_value (const)
2+
//Requires: caml_named_values, caml_jsbytes_of_string
3+
function caml_unregister_named_value(nm) {
4+
nm = caml_jsbytes_of_string(nm);
5+
delete caml_named_values[nm];
6+
return 0;
7+
}

0 commit comments

Comments
 (0)