-
Notifications
You must be signed in to change notification settings - Fork 465
/
Copy pathounit_cmd_tests.ml
178 lines (142 loc) · 4.76 KB
/
ounit_cmd_tests.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
let (//) = Filename.concat
let ((>::),
(>:::)) = OUnit.((>::),(>:::))
let (=~) = OUnit.assert_equal
(* let output_of_exec_command command args =
let readme, writeme = Unix.pipe () in
let pid = Unix.create_process command args Unix.stdin writeme Unix.stderr in
let in_chan = Unix.in_channel_of_descr readme *)
let react = {|
type u
external a : u = "react" [@@bs.module]
external b : unit -> int = "bool" [@@bs.module "react"]
let v = a
let h = b ()
|}
let foo_react = {|
type bla
external foo : bla = "foo.react" [@@bs.module]
external bar : unit -> bla = "bar" [@@bs.val] [@@bs.module "foo.react"]
let c = foo
let d = bar ()
|}
let perform_bsc = Ounit_cmd_util.perform_bsc
let bsc_eval = Ounit_cmd_util.bsc_eval
let suites =
__FILE__
>::: [
__LOC__ >:: begin fun _ ->
let v_output = perform_bsc [| "-v" |] in
OUnit.assert_bool __LOC__ ((perform_bsc [| "-h" |]).exit_code <> 0 );
OUnit.assert_bool __LOC__ (v_output.exit_code = 0);
(* Printf.printf "\n*>%s" v_output.stdout; *)
(* Printf.printf "\n*>%s" v_output.stderr ; *)
end;
__LOC__ >:: begin fun _ ->
let simple_quote =
perform_bsc [| "-bs-eval"; {|let str = "'a'" |}|] in
OUnit.assert_bool __LOC__ (simple_quote.exit_code = 0)
end;
__LOC__ >:: begin fun _ ->
let should_be_warning =
bsc_eval {|let bla4 foo x y= foo##(method1 x y [@bs]) |} in
(* debug_output should_be_warning; *)
OUnit.assert_bool __LOC__ (Ext_string.contain_substring
should_be_warning.stderr Literals.unused_attribute)
end;
__LOC__ >:: begin fun _ ->
let dedupe_require =
bsc_eval (react ^ foo_react) in
OUnit.assert_bool __LOC__ (Ext_string.non_overlap_count
dedupe_require.stdout ~sub:"require" = 2
)
end;
__LOC__ >:: begin fun _ ->
let dedupe_require =
bsc_eval react in
OUnit.assert_bool __LOC__ (Ext_string.non_overlap_count
dedupe_require.stdout ~sub:"require" = 1
)
end;
__LOC__ >:: begin fun _ ->
let dedupe_require =
bsc_eval foo_react in
OUnit.assert_bool __LOC__ (Ext_string.non_overlap_count
dedupe_require.stdout ~sub:"require" = 1
)
end;
__LOC__ >:: begin fun _ ->
let should_err = bsc_eval {|
external ff :
resp -> (_ [@bs.as "x"]) -> int -> unit =
"x" [@@bs.set]
|} in
OUnit.assert_bool __LOC__
(Ext_string.contain_substring should_err.stderr
"Ill defined"
)
end;
__LOC__ >:: begin fun _ ->
(** used in return value
This should fail, we did not
support uncurry return value yet
*)
let should_err = bsc_eval {|
external v3 :
int -> int -> (int -> int -> int [@bs.uncurry])
= ""[@@bs.val]
|} in
(* Ounit_cmd_util.debug_output should_err;*)
OUnit.assert_bool __LOC__
(Ext_string.contain_substring
should_err.stderr "bs.uncurry")
end ;
__LOC__ >:: begin fun _ ->
let should_err = bsc_eval {|
external v4 :
(int -> int -> int [@bs.uncurry]) = ""
[@@bs.val]
|} in
(* Ounit_cmd_util.debug_output should_err ; *)
OUnit.assert_bool __LOC__
(Ext_string.contain_substring
should_err.stderr "bs.uncurry")
end ;
__LOC__ >:: begin fun _ ->
let should_err = bsc_eval {|
{js| \uFFF|js}
|} in
OUnit.assert_bool __LOC__ (not @@ Ext_string.is_empty should_err.stderr)
end;
__LOC__ >:: begin fun _ ->
let should_err = bsc_eval {|
external mk : int -> ([`a|`b] [@bs.string]) = "" [@@bs.val]
|} in
OUnit.assert_bool __LOC__ (not @@ Ext_string.is_empty should_err.stderr)
end;
__LOC__ >:: begin fun _ ->
let should_err = bsc_eval {|
external mk : int -> ([`a|`b] ) = "" [@@bs.val]
|} in
OUnit.assert_bool __LOC__ ( Ext_string.is_empty should_err.stderr)
(* give a warning or ?
( [`a | `b ] [@bs.string] )
(* auto-convert to ocaml poly-variant *)
*)
end;
__LOC__ >:: begin fun _ ->
let should_err = bsc_eval {|
type t
external mk : int -> (_ [@bs.as {json| { x : 3 } |json}]) -> t = "" [@@bs.val]
|} in
OUnit.assert_bool __LOC__ (Ext_string.contain_substring should_err.stderr "Invalid json literal")
end
;
__LOC__ >:: begin fun _ ->
let should_err = bsc_eval {|
type t
external mk : int -> (_ [@bs.as {json| { "x" : 3 } |json}]) -> t = "" [@@bs.val]
|} in
OUnit.assert_bool __LOC__ (Ext_string.is_empty should_err.stderr)
end
]