Skip to content

Commit c03675f

Browse files
author
Hongbo Zhang
committed
add coverage support
1 parent 09049ed commit c03675f

File tree

7 files changed

+148
-100
lines changed

7 files changed

+148
-100
lines changed

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ocaml/*.js
3939
ocaml/*/*/*.js
4040
ocaml/*.js
4141

42-
test.sh
42+
4343
test.json
4444
ocaml/bin
4545
ocaml/lib
@@ -54,4 +54,6 @@ ocaml/man
5454
osc
5555
jscomp/pre_load.js
5656
boot
57-
*.dump
57+
*.dump
58+
coverage
59+
*.log

jscomp/test/caml_format_test.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ export var from_of_string: (xs : any) => any ;
44
export var u: (v : any) => any ;
55
export var to_str: (s : any) => any ;
66
export var v: any ;
7+
export var suites: any ;
8+
export var ff: (param : any) => any ;
79

jscomp/test/caml_format_test.js

+84-63
Original file line numberDiff line numberDiff line change
@@ -202,26 +202,84 @@ var pairs$1 = /* array */[
202202
]
203203
];
204204

205-
Mt.from_pair_suites("caml_format_test.ml", Pervasives.$at(from_of_string(of_string), Pervasives.$at(/* :: */[
206-
/* tuple */[
207-
"isnan_of_string",
208-
function () {
209-
return /* Eq */{
210-
0: /* true */1,
211-
1: +(Caml_float.caml_classify_float(Caml_format.caml_float_of_string("nan")) === /* FP_nan */4),
212-
length: 2,
213-
tag: 0
214-
};
215-
}
216-
],
217-
/* [] */0
218-
], Pervasives.$at($$Array.to_list($$Array.mapi(function (i, param) {
205+
var suites = Pervasives.$at(from_of_string(of_string), Pervasives.$at(/* :: */[
206+
/* tuple */[
207+
"isnan_of_string",
208+
function () {
209+
return /* Eq */{
210+
0: /* true */1,
211+
1: +(Caml_float.caml_classify_float(Caml_format.caml_float_of_string("nan")) === /* FP_nan */4),
212+
length: 2,
213+
tag: 0
214+
};
215+
}
216+
],
217+
/* [] */0
218+
], Pervasives.$at($$Array.to_list($$Array.mapi(function (i, param) {
219+
var b = param[1];
220+
var a = param[0];
221+
return /* tuple */[
222+
Caml_curry.app1(Printf.sprintf(/* Format */{
223+
0: /* String_literal */{
224+
0: "infinity_of_string ",
225+
1: /* Int */{
226+
0: /* Int_d */0,
227+
1: /* No_padding */0,
228+
2: /* No_precision */0,
229+
3: /* End_of_format */0,
230+
length: 4,
231+
tag: 4
232+
},
233+
length: 2,
234+
tag: 11
235+
},
236+
1: "infinity_of_string %d",
237+
length: 2,
238+
tag: 0
239+
}), i),
240+
function () {
241+
return /* Eq */{
242+
0: a,
243+
1: Caml_float.caml_classify_float(Caml_format.caml_float_of_string(b)),
244+
length: 2,
245+
tag: 0
246+
};
247+
}
248+
];
249+
}, pairs)), Pervasives.$at(/* :: */[
250+
/* tuple */[
251+
"throw",
252+
function () {
253+
return /* ThrowAny */{
254+
0: function () {
255+
return Caml_format.caml_float_of_string("");
256+
},
257+
length: 1,
258+
tag: 3
259+
};
260+
}
261+
],
262+
/* :: */[
263+
/* tuple */[
264+
"format_int",
265+
function () {
266+
return /* Eq */{
267+
0: " 33",
268+
1: Caml_format.caml_format_int("%32d", 33),
269+
length: 2,
270+
tag: 0
271+
};
272+
}
273+
],
274+
/* [] */0
275+
]
276+
], $$Array.to_list($$Array.mapi(function (i, param) {
219277
var b = param[1];
220278
var a = param[0];
221279
return /* tuple */[
222280
Caml_curry.app1(Printf.sprintf(/* Format */{
223281
0: /* String_literal */{
224-
0: "infinity_of_string ",
282+
0: "normal_float_of_string ",
225283
1: /* Int */{
226284
0: /* Int_d */0,
227285
1: /* No_padding */0,
@@ -233,70 +291,33 @@ Mt.from_pair_suites("caml_format_test.ml", Pervasives.$at(from_of_string(of_stri
233291
length: 2,
234292
tag: 11
235293
},
236-
1: "infinity_of_string %d",
294+
1: "normal_float_of_string %d",
237295
length: 2,
238296
tag: 0
239297
}), i),
240298
function () {
241299
return /* Eq */{
242300
0: a,
243-
1: Caml_float.caml_classify_float(Caml_format.caml_float_of_string(b)),
301+
1: Caml_format.caml_float_of_string(b),
244302
length: 2,
245303
tag: 0
246304
};
247305
}
248306
];
249-
}, pairs)), Pervasives.$at(/* :: */[
250-
/* tuple */[
251-
"throw",
252-
function () {
253-
return /* ThrowAny */{
254-
0: function () {
255-
return Caml_format.caml_float_of_string("");
256-
},
257-
length: 1,
258-
tag: 3
259-
};
260-
}
261-
],
262-
/* [] */0
263-
], $$Array.to_list($$Array.mapi(function (i, param) {
264-
var b = param[1];
265-
var a = param[0];
266-
return /* tuple */[
267-
Caml_curry.app1(Printf.sprintf(/* Format */{
268-
0: /* String_literal */{
269-
0: "normal_float_of_string ",
270-
1: /* Int */{
271-
0: /* Int_d */0,
272-
1: /* No_padding */0,
273-
2: /* No_precision */0,
274-
3: /* End_of_format */0,
275-
length: 4,
276-
tag: 4
277-
},
278-
length: 2,
279-
tag: 11
280-
},
281-
1: "normal_float_of_string %d",
282-
length: 2,
283-
tag: 0
284-
}), i),
285-
function () {
286-
return /* Eq */{
287-
0: a,
288-
1: Caml_format.caml_float_of_string(b),
289-
length: 2,
290-
tag: 0
291-
};
292-
}
293-
];
294-
}, pairs$1)))))));
307+
}, pairs$1))))));
308+
309+
function ff(param) {
310+
return Caml_format.caml_format_int("%32d", param);
311+
}
312+
313+
Mt.from_pair_suites("caml_format_test.ml", suites);
295314

296315
exports.of_string = of_string;
297316
exports.from_float_of_string = from_float_of_string;
298317
exports.from_of_string = from_of_string;
299318
exports.u = u;
300319
exports.to_str = to_str;
301320
exports.v = v;
321+
exports.suites = suites;
322+
exports.ff = ff;
302323
/* v Not a pure module */

jscomp/test/caml_format_test.ml

+46-34
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,54 @@ let from_of_string xs =
2323
|> Array.mapi (fun i (a,b) ->
2424
(Printf.sprintf "of_string %L" i), fun _ -> Mt.Eq(int_of_string b,a ))
2525
|> Array.to_list
26+
2627
let u v = Printf.sprintf "%33d" v
28+
2729
let to_str s = int_of_string s
30+
2831
let v = Printf.sprintf "%3d" 3333
32+
external format_int : string -> int -> string = "caml_format_int"
2933

30-
;; Mt.from_pair_suites __FILE__ @@
31-
(from_of_string of_string @
32-
["isnan_of_string", (fun _ ->
33-
Mt.Eq (true,classify_float( float_of_string "nan") = FP_nan))] @
34-
(let pairs =
35-
[| FP_infinite, "infinity";
36-
FP_infinite, "+infinity";
37-
FP_infinite, "-infinity";
38-
FP_zero, "0";
39-
FP_zero, "0."
40-
|]
41-
in
42-
pairs
43-
|> Array.mapi
44-
(fun i (a,b) ->
45-
(Printf.sprintf "infinity_of_string %d" i ),
46-
(fun _ -> Mt.Eq(a,
47-
classify_float @@ float_of_string b)))
48-
|> Array.to_list ) @
49-
[ "throw", (fun _ -> Mt.ThrowAny (fun _ -> ignore @@ float_of_string ""))] @
50-
(let pairs =
51-
[| 3232., "32_32.0";
52-
1.000, "1.000";
53-
12.000, "12.000"
54-
|]
55-
in
56-
pairs
57-
|> Array.mapi
58-
(fun i (a,b) ->
59-
(Printf.sprintf "normal_float_of_string %d" i ),
60-
(fun _ -> Mt.Eq(a,
61-
float_of_string b)))
62-
|> Array.to_list )
34+
let suites : _ Mt.pair_suites =
35+
from_of_string of_string @
36+
["isnan_of_string", (fun _ ->
37+
Mt.Eq (true,classify_float( float_of_string "nan") = FP_nan))] @
38+
(let pairs =
39+
[| FP_infinite, "infinity";
40+
FP_infinite, "+infinity";
41+
FP_infinite, "-infinity";
42+
FP_zero, "0";
43+
FP_zero, "0."
44+
|]
45+
in
46+
pairs
47+
|> Array.mapi
48+
(fun i (a,b) ->
49+
(Printf.sprintf "infinity_of_string %d" i ),
50+
(fun _ -> Mt.Eq(a,
51+
classify_float @@ float_of_string b)))
52+
|> Array.to_list ) @
53+
[ "throw", (fun _ -> Mt.ThrowAny (fun _ -> ignore @@ float_of_string ""));
54+
"format_int", (fun _ ->
55+
Mt.Eq(" 33", format_int "%32d" 33))
56+
] @
57+
(let pairs =
58+
[| 3232., "32_32.0";
59+
1.000, "1.000";
60+
12.000, "12.000"
61+
|]
62+
in
63+
pairs
64+
|> Array.mapi
65+
(fun i (a,b) ->
66+
(Printf.sprintf "normal_float_of_string %d" i ),
67+
(fun _ -> Mt.Eq(a,
68+
float_of_string b)))
69+
|> Array.to_list )
6370

64-
)
71+
72+
73+
let ff = format_int "%32d"
74+
75+
;; Mt.from_pair_suites __FILE__ suites
76+

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"babel": "^6.3.13",
44
"babel-cli": "^6.3.17",
55
"benchmark": "^2.1.0",
6+
"istanbul": "^0.4.2",
67
"karma": "^0.13.9",
78
"karma-jasmine-html-reporter": "^0.1.8",
89
"lodash": "^3.10.1",
@@ -14,6 +15,10 @@
1415
"webpack": "^1.12.6"
1516
},
1617
"scripts": {
17-
"test": "./node_modules/mocha/bin/mocha './jscomp/test/**/*_test.js' -R spec"
18+
"test":
19+
"node ./node_modules/mocha/bin/mocha './jscomp/test/**/*_test.js' -R spec",
20+
"cover" :
21+
"node ./node_modules/istanbul/lib/cli.js cover --report html ./node_modules/.bin/_mocha -- jscomp/test/*test.js"
22+
1823
}
1924
}

scripts/cover.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
set -e
3+
node ./node_modules/istanbul/lib/cli.js cover --report html ./node_modules/.bin/_mocha -- jscomp/test/*test.js "$@"

scripts/test.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
set -e
3+
node ./node_modules/mocha/bin/mocha './jscomp/test/**/*_test.js' -R list "$@"

0 commit comments

Comments
 (0)