Skip to content

Commit a759bbb

Browse files
committed
Test improvements
Revert test_fun_call and test_poly_compare and don't run them in Wasm. Add additional tests test_fun_call2 and test_poly_equal that make sense in Wasm.
1 parent 614cc25 commit a759bbb

File tree

6 files changed

+559
-39
lines changed

6 files changed

+559
-39
lines changed

lib/tests/dune.inc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,23 @@
3232
(library
3333
;; lib/tests/test_fun_call.ml
3434
(name test_fun_call_75)
35-
(enabled_if (<> %{profile} using-effects))
35+
(enabled_if (and (<> %{profile} using-effects) (<> %{profile} wasm) (<> %{profile} wasm-effects)))
3636
(modules test_fun_call)
3737
(libraries js_of_ocaml unix)
3838
(inline_tests (modes js))
3939
(preprocess
4040
(pps ppx_js_internal ppx_expect)))
4141

42+
(library
43+
;; lib/tests/test_fun_call_2.ml
44+
(name test_fun_call_2_75)
45+
(enabled_if true)
46+
(modules test_fun_call_2)
47+
(libraries js_of_ocaml unix)
48+
(inline_tests (modes js))
49+
(preprocess
50+
(pps ppx_js_internal ppx_expect)))
51+
4252
(library
4353
;; lib/tests/test_json.ml
4454
(name test_json_75)
@@ -62,13 +72,23 @@
6272
(library
6373
;; lib/tests/test_poly_compare.ml
6474
(name test_poly_compare_75)
65-
(enabled_if true)
75+
(enabled_if (and (<> %{profile} wasm) (<> %{profile} wasm-effects)))
6676
(modules test_poly_compare)
6777
(libraries js_of_ocaml unix)
6878
(inline_tests (modes js))
6979
(preprocess
7080
(pps ppx_js_internal ppx_expect)))
7181

82+
(library
83+
;; lib/tests/test_poly_equal.ml
84+
(name test_poly_equal_75)
85+
(enabled_if true)
86+
(modules test_poly_equal)
87+
(libraries js_of_ocaml unix)
88+
(inline_tests (modes js))
89+
(preprocess
90+
(pps ppx_js_internal ppx_expect)))
91+
7292
(library
7393
;; lib/tests/test_regexp.ml
7494
(name test_regexp_75)

lib/tests/gen-rules/gen.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ let prefix : string =
4747

4848
type enabled_if =
4949
| GE5
50-
| No_effects
5150
| Not_wasm
51+
| No_effects_not_wasm
5252
| Any
5353

5454
let enabled_if = function
5555
| "test_sys" -> GE5
56-
| "test_fun_call" -> No_effects
57-
| "test_json" -> Not_wasm
56+
| "test_fun_call" -> No_effects_not_wasm
57+
| "test_json" | "test_poly_compare" -> Not_wasm
5858
| _ -> Any
5959

6060
let () =
@@ -85,6 +85,8 @@ let () =
8585
(* ZZZ /static not yet implemented *)
8686
"(and (>= %{ocaml_version} 5) (<> %{profile} wasm) (<> %{profile} \
8787
wasm-effects))"
88-
| No_effects -> "(<> %{profile} using-effects)"
89-
| Not_wasm -> "(and (<> %{profile} wasm) (<> %{profile} wasm-effects))")
88+
| Not_wasm -> "(and (<> %{profile} wasm) (<> %{profile} wasm-effects))"
89+
| No_effects_not_wasm ->
90+
"(and (<> %{profile} using-effects) (<> %{profile} wasm) (<> %{profile} \
91+
wasm-effects))")
9092
basename)

lib/tests/test_fun_call.ml

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ let s x =
2929
return "undefined"
3030
if(typeof x === "function")
3131
return "function#" + x.length + "#" + x.l
32-
if (x.toString) return x.toString();
33-
return "other"
32+
if(x.toString() == "[object Arguments]")
33+
return "(Arguments: " + Array.prototype.slice.call(x).toString() + ")";
34+
return x.toString()
3435
})
3536
|}
3637
in
@@ -146,7 +147,7 @@ let%expect_test "wrap_callback_strict" =
146147
(Js.Unsafe.callback_with_arity 2 cb3)
147148
{| (function(f){ return f(1,2,3) }) |};
148149
[%expect {|
149-
Result: other |}];
150+
Result: function#1#1 |}];
150151
call_and_log
151152
(Js.Unsafe.callback_with_arity 2 cb3)
152153
~cont:(fun g -> g 4)
@@ -163,7 +164,7 @@ let%expect_test "wrap_callback_strict" =
163164
Result: 0 |}];
164165
call_and_log (Js.Unsafe.callback_with_arity 2 cb3) {| (function(f){ return f(1,2) }) |};
165166
[%expect {|
166-
Result: other |}]
167+
Result: function#1#1 |}]
167168

168169
let%expect_test "wrap_callback_strict" =
169170
call_and_log
@@ -290,7 +291,7 @@ let%expect_test "wrap_meth_callback_strict" =
290291
(Js.Unsafe.meth_callback_with_arity 2 cb4)
291292
{| (function(f){ return f.apply("this",[1,2,3]) }) |};
292293
[%expect {|
293-
Result: other |}];
294+
Result: function#1#1 |}];
294295
call_and_log
295296
(Js.Unsafe.meth_callback_with_arity 2 cb4)
296297
~cont:(fun g -> g 4)
@@ -308,7 +309,7 @@ let%expect_test "wrap_meth_callback_strict" =
308309
call_and_log
309310
(Js.Unsafe.meth_callback_with_arity 2 cb4)
310311
{| (function(f){ return f.apply("this",[1,2]) }) |};
311-
[%expect {| Result: other |}]
312+
[%expect {| Result: function#1#1 |}]
312313

313314
let%expect_test "wrap_meth_callback_strict" =
314315
call_and_log
@@ -353,15 +354,13 @@ let%expect_test "partial application, extra arguments set to undefined" =
353354
let%expect_test _ =
354355
call_and_log cb3 ~cont:(fun g -> g 1) {| (function(f){ return f }) |};
355356
[%expect {|
356-
Result: other |}]
357+
Result: function#2#2 |}]
357358

358-
(*
359359
let%expect_test _ =
360360
call_and_log cb3 ~cont:(fun g -> g 1 2 3 4) {| (function(f){ return f }) |};
361361
[%expect {|
362362
got 1, 2, 3, done
363363
Result: 0 |}]
364-
*)
365364

366365
let%expect_test _ =
367366
let f cb =
@@ -370,25 +369,22 @@ let%expect_test _ =
370369
| _ -> Printf.printf "Error: unknown"
371370
in
372371
f cb5;
373-
[%expect {| Result: other |}];
372+
[%expect {| Result: function#1#1 |}];
374373
f cb4;
375374
[%expect {|
376375
got 1, 1, 2, 3, done
377376
Result: 0 |}];
378-
()
379-
(* f cb3;
380-
[%expect {|
381-
got 1, 1, 2, done
382-
Result: 0 |}]
383-
*)
377+
f cb3;
378+
[%expect {|
379+
got 1, 1, 2, done
380+
Result: 0 |}]
384381

385382
let%expect_test _ =
386383
let f cb =
387384
try call_and_log (cb 1 2 3) {| (function(f){ return f }) |} with
388385
| Invalid_argument s | Failure s -> Printf.printf "Error: %s" s
389386
| _ -> Printf.printf "Error: unknown"
390387
in
391-
(*
392388
f (Obj.magic cb1);
393389
[%expect {|
394390
got 1, done
@@ -397,21 +393,20 @@ let%expect_test _ =
397393
[%expect {|
398394
got 1, 2, done
399395
Result: 0 |}];
400-
*)
401396
f (Obj.magic cb3);
402397
[%expect {|
403398
got 1, 2, 3, done
404399
Result: 0 |}];
405400
f (Obj.magic cb4);
406401
[%expect {|
407-
Result: other |}];
402+
Result: function#1#1 |}];
408403
f (Obj.magic cb5);
409404
[%expect {|
410-
Result: other |}]
405+
Result: function#2#2 |}]
411406

412407
let%expect_test _ =
413408
let open Js_of_ocaml in
414-
let f = Js.wrap_callback (fun s -> print_endline (Js.to_string s)) in
409+
let f = Js.wrap_callback (fun s -> print_endline s) in
415410
Js.export "f" f;
416411
let () =
417412
Js.Unsafe.fun_call

0 commit comments

Comments
 (0)