Skip to content

Commit 81bcdb1

Browse files
committed
more tests
1 parent 1cb9397 commit 81bcdb1

File tree

5 files changed

+120
-4
lines changed

5 files changed

+120
-4
lines changed

jscomp/runtime/caml_builtin_exceptions.ml

+11-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ let () =
5858
Obj.set_tag (Obj.repr sys_blocked_io) object_tag;
5959
Obj.set_tag (Obj.repr assert_failure) object_tag;
6060
Obj.set_tag (Obj.repr undefined_recursive_module) object_tag
61-
(* TODO:
62-
1. is it necessary to tag [248] here
63-
2. is it okay to remove the negative value
61+
62+
(**:
63+
1. Is it necessary to tag [248] here
64+
For compatibility reasons: tag [248] will make
65+
`Printexc.to_string` happy see #1501
66+
2. Is it okay to remove the negative value
67+
For marshalling?
68+
3. Global exception is encoded the same as user defined exception
69+
(for nullary and non-nullary), except
70+
- time stamp
71+
- its name is not qualified
6472
*)

jscomp/test/.depend

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ event_ffi.cmj : ../stdlib/list.cmj ../runtime/js_unsafe.cmj \
143143
exception_alias.cmj : ../stdlib/list.cmj
144144
exception_raise_test.cmj : mt.cmj
145145
exception_rebound_err.cmj : ../runtime/js.cmj
146+
exception_repr_test.cmj : ../stdlib/printexc.cmj mt.cmj ../stdlib/format.cmj
146147
exception_value_test.cmj : ../runtime/js.cmj
147148
export_keyword.cmj :
148149
ext_array.cmj : ../stdlib/list.cmj ../stdlib/array.cmj

jscomp/test/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ OTHERS := literals a test_ari test_export2 test_internalOO test_obj_simple_ffi t
137137
exception_rebound_err\
138138
js_exception_catch_test\
139139
gpr_1503_test\
140-
gpr_1501_test
140+
gpr_1501_test\
141+
exception_repr_test
141142

142143
# bs_uncurry_test
143144
# needs Lam to get rid of Uncurry arity first

jscomp/test/exception_repr_test.js

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
'use strict';
2+
3+
var Mt = require("./mt.js");
4+
var Block = require("../../lib/js/block.js");
5+
var Curry = require("../../lib/js/curry.js");
6+
var Format = require("../../lib/js/format.js");
7+
var Printexc = require("../../lib/js/printexc.js");
8+
var Caml_exceptions = require("../../lib/js/caml_exceptions.js");
9+
10+
var suites = [/* [] */0];
11+
12+
var test_id = [0];
13+
14+
function eq(loc, x, y) {
15+
test_id[0] = test_id[0] + 1 | 0;
16+
suites[0] = /* :: */[
17+
/* tuple */[
18+
loc + (" id " + test_id[0]),
19+
function () {
20+
return /* Eq */Block.__(0, [
21+
x,
22+
y
23+
]);
24+
}
25+
],
26+
suites[0]
27+
];
28+
return /* () */0;
29+
}
30+
31+
var Hi = Caml_exceptions.create("Exception_repr_test.Hi");
32+
33+
var Hello = Caml_exceptions.create("Exception_repr_test.Hello");
34+
35+
var A = Caml_exceptions.create("Exception_repr_test.A");
36+
37+
Printexc.register_printer(function (param) {
38+
if (param === Hi) {
39+
return /* Some */["hey"];
40+
} else if (param[0] === A) {
41+
return /* Some */[Curry._1(Format.asprintf(/* Format */[
42+
/* String_literal */Block.__(11, [
43+
"A(",
44+
/* Int */Block.__(4, [
45+
/* Int_d */0,
46+
/* No_padding */0,
47+
/* No_precision */0,
48+
/* Char_literal */Block.__(12, [
49+
/* ")" */41,
50+
/* End_of_format */0
51+
])
52+
])
53+
]),
54+
"A(%d)"
55+
]), param[1])];
56+
} else {
57+
return /* None */0;
58+
}
59+
});
60+
61+
eq("File \"exception_repr_test.ml\", line 22, characters 7-14", "hey", Printexc.to_string(Hi));
62+
63+
eq("File \"exception_repr_test.ml\", line 23, characters 7-14", "A(1)", Printexc.to_string([
64+
A,
65+
1
66+
]));
67+
68+
eq("File \"exception_repr_test.ml\", line 24, characters 7-14", "Exception_repr_test.Hello", Printexc.to_string(Hello));
69+
70+
Mt.from_pair_suites("exception_repr_test.ml", suites[0]);
71+
72+
exports.suites = suites;
73+
exports.test_id = test_id;
74+
exports.eq = eq;
75+
exports.Hi = Hi;
76+
exports.Hello = Hello;
77+
exports.A = A;
78+
/* Not a pure module */

jscomp/test/exception_repr_test.ml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
let suites : Mt.pair_suites ref = ref []
2+
let test_id = ref 0
3+
let eq loc x y =
4+
incr test_id ;
5+
suites :=
6+
(loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites
7+
8+
9+
10+
exception Hi
11+
exception Hello
12+
exception A of int
13+
;; Printexc.register_printer (function
14+
| Hi -> Some "hey"
15+
| A s -> Some (Format.asprintf "A(%d)" s )
16+
| _ -> None
17+
)
18+
19+
20+
21+
let () =
22+
eq __LOC__ "hey" (Printexc.to_string Hi);
23+
eq __LOC__ "A(1)" (Printexc.to_string (A 1));
24+
eq __LOC__ "Exception_repr_test.Hello" (Printexc.to_string Hello)
25+
26+
;; Mt.from_pair_suites __FILE__ !suites
27+
28+

0 commit comments

Comments
 (0)