Skip to content

Commit ceb06b1

Browse files
committed
add a test case
1 parent 1487bbb commit ceb06b1

File tree

1 file changed

+56
-45
lines changed

1 file changed

+56
-45
lines changed

jscomp/ounit_tests/ounit_cmd_tests.ml

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let suites =
4343
ok (v_output.exit_code = 0) v_output
4444
end;
4545
__LOC__ >:: begin fun _ ->
46-
let v_output = perform_bsc [|"-bs-eval"; {|type 'a arra = 'a array
46+
let v_output = perform_bsc [|"-bs-eval"; {|type 'a arra = 'a array
4747
external
4848
f :
4949
int -> int -> int arra -> unit
@@ -52,8 +52,8 @@ let suites =
5252
[@@bs.splice]|}|] in
5353
OUnit.assert_bool __LOC__ (Ext_string.contain_substring v_output.stderr "variadic")
5454
end;
55-
__LOC__ >:: begin fun _ ->
56-
let v_output = perform_bsc [|"-bs-eval"; {|external
55+
__LOC__ >:: begin fun _ ->
56+
let v_output = perform_bsc [|"-bs-eval"; {|external
5757
f2 :
5858
int -> int -> ?y:int array -> unit
5959
= ""
@@ -69,13 +69,13 @@ let suites =
6969
OUnit.assert_bool __LOC__ (Ext_string.contain_substring
7070
should_be_warning.stderr "Unused")
7171
end;
72-
__LOC__ >:: begin fun _ ->
72+
__LOC__ >:: begin fun _ ->
7373
let should_be_warning =
7474
bsc_check_eval {| external mk : int -> ([`a|`b [@bs.string]]) = "mk" [@@bs.val] |} in
75-
OUnit.assert_bool __LOC__
75+
OUnit.assert_bool __LOC__
7676
(Ext_string.contain_substring
77-
should_be_warning.stderr "Unused")
78-
end;
77+
should_be_warning.stderr "Unused")
78+
end;
7979
__LOC__ >:: begin fun _ ->
8080
let should_err = bsc_check_eval {|
8181
external ff :
@@ -178,12 +178,12 @@ external ff :
178178
end;
179179

180180
(* __LOC__ >:: begin fun _ ->
181-
let should_err = bsc_check_eval {|
182-
external f : string -> unit -> unit = "x.y" [@@bs.send]
183-
|} in
184-
OUnit.assert_bool __LOC__
181+
let should_err = bsc_check_eval {|
182+
external f : string -> unit -> unit = "x.y" [@@bs.send]
183+
|} in
184+
OUnit.assert_bool __LOC__
185185
(Ext_string.contain_substring should_err.stderr "Not a valid method name")
186-
end; *)
186+
end; *)
187187

188188

189189
__LOC__ >:: begin fun _ ->
@@ -193,7 +193,7 @@ type t10 = A of t10 [@@ocaml.unboxed];;
193193
let rec x = A x;;
194194
|} in
195195
OUnit.assert_bool __LOC__
196-
(Ext_string.contain_substring should_err.stderr "This kind of expression is not allowed")
196+
(Ext_string.contain_substring should_err.stderr "This kind of expression is not allowed")
197197
end;
198198

199199
__LOC__ >:: begin fun _ ->
@@ -202,15 +202,15 @@ let rec x = A x;;
202202
let rec x = {x = y} and y = 3L;;
203203
|} in
204204
OUnit.assert_bool __LOC__
205-
(Ext_string.contain_substring should_err.stderr "This kind of expression is not allowed")
205+
(Ext_string.contain_substring should_err.stderr "This kind of expression is not allowed")
206206
end;
207207
__LOC__ >:: begin fun _ ->
208208
let should_err = bsc_check_eval {|
209209
type r = A of r [@@unboxed];;
210210
let rec y = A y;;
211211
|} in
212212
OUnit.assert_bool __LOC__
213-
(Ext_string.contain_substring should_err.stderr "This kind of expression is not allowed")
213+
(Ext_string.contain_substring should_err.stderr "This kind of expression is not allowed")
214214
end;
215215

216216
__LOC__ >:: begin fun _ ->
@@ -253,60 +253,71 @@ let rec y = A y;;
253253

254254
end;
255255
__LOC__ >:: begin fun _ ->
256-
let should_err = bsc_check_eval {|
256+
let should_err = bsc_check_eval {|
257257
external foo_bar :
258258
(_ [@bs.as "foo"]) ->
259259
string ->
260260
string = "bar"
261261
[@@bs.send]
262262
|} in
263-
OUnit.assert_bool __LOC__
264-
(Ext_string.contain_substring should_err.stderr "Ill defined attribute")
265-
end;
263+
OUnit.assert_bool __LOC__
264+
(Ext_string.contain_substring should_err.stderr "Ill defined attribute")
265+
end;
266266
__LOC__ >:: begin fun _ ->
267-
let should_err = bsc_check_eval {|
267+
let should_err = bsc_check_eval {|
268268
let bla4 foo x y = foo##(method1 x y [@bs])
269269
|} in
270-
(* Ounit_cmd_util.debug_output should_err ; *)
271-
OUnit.assert_bool __LOC__
272-
(Ext_string.contain_substring should_err.stderr
273-
"Unused")
274-
end;
270+
(* Ounit_cmd_util.debug_output should_err ; *)
271+
OUnit.assert_bool __LOC__
272+
(Ext_string.contain_substring should_err.stderr
273+
"Unused")
274+
end;
275275
__LOC__ >:: begin fun _ ->
276-
let should_err = bsc_check_eval {|
276+
let should_err = bsc_check_eval {|
277277
external mk : int ->
278278
(
279279
[`a|`b]
280280
[@bs.string]
281281
) = "mk" [@@bs.val]
282282
|} in
283-
(* Ounit_cmd_util.debug_output should_err ; *)
284-
OUnit.assert_bool __LOC__
285-
(Ext_string.contain_substring should_err.stderr
286-
"Unused")
287-
end;
288-
__LOC__ >:: begin fun _ ->
289-
let should_err = bsc_check_eval {|
283+
(* Ounit_cmd_util.debug_output should_err ; *)
284+
OUnit.assert_bool __LOC__
285+
(Ext_string.contain_substring should_err.stderr
286+
"Unused")
287+
end;
288+
__LOC__ >:: begin fun _ ->
289+
let should_err = bsc_check_eval {|
290290
type -'a t = {k : 'a } [@@bs.deriving abstract]
291291
|} in
292-
OUnit.assert_bool __LOC__
293-
(Ext_string.contain_substring should_err.stderr "contravariant")
294-
end;
295-
__LOC__ >:: begin fun _ ->
296-
let should_err = bsc_check_eval {|
292+
OUnit.assert_bool __LOC__
293+
(Ext_string.contain_substring should_err.stderr "contravariant")
294+
end;
295+
__LOC__ >:: begin fun _ ->
296+
let should_err = bsc_check_eval {|
297297
let u = [||]
298298
|} in
299-
OUnit.assert_bool __LOC__
300-
(Ext_string.contain_substring should_err.stderr "cannot be generalized")
301-
end
299+
OUnit.assert_bool __LOC__
300+
(Ext_string.contain_substring should_err.stderr "cannot be generalized")
301+
end;
302+
__LOC__ >:: begin fun _ ->
303+
let should_err = bsc_check_eval {|
304+
external push : 'a array -> 'a -> unit = "push" [@@send]
305+
let a = [||]
306+
let () =
307+
push a 3 |. ignore ;
308+
push a "3" |. ignore
309+
|} in
310+
OUnit.assert_bool __LOC__
311+
(Ext_string.contain_substring should_err.stderr "has type string")
312+
end
302313
(* __LOC__ >:: begin fun _ -> *)
303314
(* let should_infer = perform_bsc [| "-i"; "-bs-eval"|] {| *)
304-
(* let f = fun [@bs] x -> let (a,b) = x in a + b *)
305-
(* |} in *)
315+
(* let f = fun [@bs] x -> let (a,b) = x in a + b *)
316+
(* |} in *)
306317
(* let infer_type = bsc_eval (Printf.sprintf {| *)
307318

308-
(* let f : %s = fun [@bs] x -> let (a,b) = x in a + b *)
309-
(* |} should_infer.stdout ) in *)
319+
(* let f : %s = fun [@bs] x -> let (a,b) = x in a + b *)
320+
(* |} should_infer.stdout ) in *)
310321
(* begin *)
311322
(* Ounit_cmd_util.debug_output should_infer ; *)
312323
(* Ounit_cmd_util.debug_output infer_type ; *)

0 commit comments

Comments
 (0)