Skip to content

Commit 36c5b80

Browse files
committed
add resize array and infra for ounit test
1 parent 7fc9578 commit 36c5b80

29 files changed

+4224
-86
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,8 @@ included with BuckleScript.
209209
* [`jscomp/test`](jscomp/test)
210210

211211
`jscomp/test` is based on [`ocaml/testsuite`](ocaml/testsuite).
212+
213+
BuckleScript unittest builds on parts of [OUnit](http://ounit.forge.ocamlcore.org/)
214+
215+
* [`jscomp/ounit`](jscomp/ounit) is adapted from ounit, the unit test
216+
utilities are only used for dev purpose, they are not required for distribution

bsconfig.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@
3232
{
3333
"dir": "acyc",
3434
"files": [
35+
"a0_a1.ml",
36+
"a1_a2.ml",
37+
"a1_a2.mli",
38+
"a2_a3.ml",
39+
"a3_a4.ml",
40+
"a4_a5.ml",
3541
"x.ml"
36-
, "a4_a5.ml"
37-
, "a3_a4.ml"
38-
, "a2_a3.ml"
39-
, "a1_a2.mli"
40-
, "a1_a2.ml"
41-
, "a0_a1.ml"
4242
]
4343

44+
4445

4546

4647

jscomp/Makefile

+22-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ COMPFLAGS= -g -w -40-30 -warn-error +a-40-30
1616

1717
print-% : ; @echo $* = $($*)
1818

19-
INCLUDES= -I +compiler-libs -I ext -I common -I syntax -I depends -I core -I bsb
19+
INCLUDES= -I +compiler-libs -I ext -I common -I syntax -I depends -I core -I bsb -I ounit -I ounit_tests
2020

2121
.mli.cmi:
2222
$(NATIVE) $(INCLUDES) $(COMPFLAGS) -c $<
@@ -46,7 +46,12 @@ common/bs_version.ml: build_version.js ../package.json
4646

4747

4848
### list files
49-
EXT_SRCS = ext_array ext_bytes ext_char ext_file_pp ext_format ext_hashtbl ext_list ext_map ext_marshal ext_option \
49+
OUNIT_SRCS = oUnit oUnitDiff oUnitLogger oUnitTypes oUnitUtils oUnitChooser
50+
OUNIT_CMXS = $(addprefix ounit/, $(addsuffix .cmx, $(OUNIT_SRCS)))
51+
OUNIT_TESTS_SRCS = ounit_tests_main
52+
OUNIT_TESTS_CMXS = $(addprefix ounit_tests/, $(addsuffix .cmx, $(OUNIT_TESTS_SRCS)))
53+
54+
EXT_SRCS = ext_array ext_bytes ext_char resize_array ext_file_pp ext_format ext_hashtbl ext_list ext_map ext_marshal ext_option \
5055
ext_pervasives ext_pp ext_ref ext_string ext_sys hash_set ident_set int_map literals string_map \
5156
string_set ext_pp_scope ext_io ext_ident ext_filename
5257

@@ -82,6 +87,9 @@ BSB_CMXS=$(addprefix bsb/, $(addsuffix .cmx, $(BSB_SRCS)))
8287
MAIN_SRCS= jsgen_main jscmj_main bsb/bsb_main
8388
MAINS_CMXS=$(addsuffix .cmx, $(MAIN_SRCS))
8489

90+
ounit.cmxa: $(OUNIT_CMXS)
91+
ocamlopt.opt -a $^ -o $@
92+
8593
ext.cmxa: $(EXT_CMXS)
8694
ocamlopt.opt -a $^ -o $@
8795
common.cmxa:$(COMMON_CMXS)
@@ -95,7 +103,7 @@ core.cmxa:$(CORE_CMXS)
95103
bsb.cmxa:$(BSB_CMXS)
96104
ocamlopt.opt -a $^ -o $@
97105

98-
check: $(EXT_CMXS) $(COMMON_CMXS) $(SYNTAX_CMXS) $(DEPENDS_CMXS) $(CORE_CMXS) $(BSB_CMXS) $(OTHER_CORE_CMXS) $(MAIN_CMXS)
106+
check: $(EXT_CMXS) $(COMMON_CMXS) $(SYNTAX_CMXS) $(DEPENDS_CMXS) $(CORE_CMXS) $(BSB_CMXS) $(OTHER_CORE_CMXS) $(MAIN_CMXS) $(OUNIT_CMXS) $(OUNIT_TESTS_CMXS)
99107

100108
bin/bsb.exe: ext.cmxa common.cmxa bsb.cmxa bsb/bsb_main.cmx
101109
$(NATIVE) -g unix.cmxa str.cmxa $^ -o $@
@@ -118,11 +126,11 @@ bin/jsgen.exe:ext.cmxa jsgen_main.cmx
118126

119127

120128
depend:
121-
$(CAMLDEP) -native -I ext -I common -I syntax -I depends -I core -I bsb ext/*.ml ext/*.mli common/*.ml common/*.mli syntax/*.ml syntax/*.mli *.ml *.mli depends/*.ml depends/*.mli core/*.ml core/*.mli bsb/*.ml bsb/*.mli > all.depend
129+
$(CAMLDEP) -native -I ext -I common -I syntax -I depends -I core -I ounit -I ounit_tests -I bsb ext/*.ml ext/*.mli common/*.ml common/*.mli syntax/*.ml syntax/*.mli *.ml *.mli depends/*.ml depends/*.mli core/*.ml core/*.mli bsb/*.ml bsb/*.mli ounit/*.mli ounit/*.ml ounit_tests/*.ml ounit_tests/*.mli > all.depend
122130

123131

124132

125-
SNAPSHOT_SRCS=$(addprefix bin/, $(addsuffix .ml, bsppx whole_compiler bsdep bsb bspp))
133+
SNAPSHOT_SRCS=$(addprefix bin/, $(addsuffix .ml, bsppx whole_compiler bsdep bsb bspp all_ounit_tests))
126134
SNAPSHOT_DEPS=$(SNAPSHOT_SRCS:.ml=.d)
127135

128136
# this target is used to make snapshotml
@@ -194,7 +202,15 @@ bin/bspp.ml:./bin/bspack.exe
194202
bin/js_compiler.ml:./bin/bspack.exe
195203
BS_COMPILER_IN_BROWSER=true bspack.exe -bs-MD -prelude-str 'module Config = Config_whole_compiler' -bs-exclude-I config -o $@ -bs-main Jsoo_main -I ../ocaml/utils/ -I ../ocaml/parsing/ -I ../ocaml/typing/ -I ../ocaml/bytecomp/ -I ../ocaml/driver/ -I ext -I syntax -I depends -I common -I core
196204

205+
bin/all_ounit_tests.ml:./bin/bspack.exe
206+
$< -bs-MD -I ounit -I ounit_tests -I common -I ext -I syntax -I depends -I bspp -I core -bs-main Ounit_tests_main -o $@
207+
-include bin/all_ounit_tests.d
208+
bin/all_ounit_tests.byte:bin/all_ounit_tests.mli bin/all_ounit_tests.ml
209+
ocamlc.opt -g -I bin -w -a unix.cma $^ -o $@
197210

211+
ounit_test:bin/all_ounit_tests.byte
212+
$^
213+
.PHONY:ounit_test
198214
# TODO: Fix Me use its own configuration
199215
bin/js_compiler.byte:bin/js_compiler.mli bin/js_compiler.ml
200216
ocamlc.opt -w -a -I bin bin/config_whole_compiler.mli bin/config_whole_compiler.ml $^ -no-check-prims -o $@
@@ -265,6 +281,7 @@ world:
265281
travis-world-test:
266282
$(MAKE) world
267283
@echo "Making test"
284+
make ounit_test
268285
$(MAKE) -C test all
269286
@echo "Making test finsihed"
270287

jscomp/all.depend

+17-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ext/hash_set.cmx : ext/hash_set.cmi
2323
ext/ident_set.cmx : ext/ext_format.cmx ext/ident_set.cmi
2424
ext/int_map.cmx : ext/int_map.cmi
2525
ext/literals.cmx : ext/literals.cmi
26+
ext/resize_array.cmx : ext/resize_array.cmi
2627
ext/string_map.cmx : ext/string_map.cmi
2728
ext/string_set.cmx : ext/string_set.cmi
2829
ext/ext_array.cmi :
@@ -48,6 +49,7 @@ ext/hash_set.cmi :
4849
ext/ident_set.cmi : ext/ext_format.cmi
4950
ext/int_map.cmi :
5051
ext/literals.cmi :
52+
ext/resize_array.cmi :
5153
ext/string_map.cmi :
5254
ext/string_set.cmi :
5355
common/binary_ast.cmx : common/binary_ast.cmi
@@ -475,9 +477,9 @@ core/ocaml_parse.cmi :
475477
core/type_util.cmi :
476478
bsb/bsb_build_schemas.cmx :
477479
bsb/bsb_build_ui.cmx : ext/string_set.cmx ext/string_map.cmx \
478-
ext/ext_filename.cmx ext/ext_file_pp.cmx bsb/bsb_json.cmx bsb/bsb_dir.cmx \
479-
bsb/bsb_build_util.cmx bsb/bsb_build_schemas.cmx common/binary_cache.cmx \
480-
bsb/bsb_build_ui.cmi
480+
ext/resize_array.cmx ext/ext_filename.cmx ext/ext_file_pp.cmx \
481+
bsb/bsb_json.cmx bsb/bsb_dir.cmx bsb/bsb_build_util.cmx \
482+
bsb/bsb_build_schemas.cmx common/binary_cache.cmx bsb/bsb_build_ui.cmi
481483
bsb/bsb_build_util.cmx : ext/ext_list.cmx ext/ext_filename.cmx \
482484
ext/ext_array.cmx bsb/bsb_json.cmx bsb/bsb_config.cmx \
483485
bsb/bsb_build_util.cmi
@@ -512,3 +514,15 @@ bsb/bsb_json.cmi : ext/string_map.cmi
512514
bsb/bsb_main.cmi :
513515
bsb/bsb_ninja.cmi : bsb/bsb_build_ui.cmi
514516
bsb/sexp_lexer.cmi :
517+
ounit/oUnit.cmi :
518+
ounit/oUnitDiff.cmi :
519+
ounit/oUnit.cmx : ounit/oUnitUtils.cmx ounit/oUnitTypes.cmx \
520+
ounit/oUnitLogger.cmx ounit/oUnitChooser.cmx ounit/oUnit.cmi
521+
ounit/oUnitChooser.cmx : ounit/oUnitTypes.cmx
522+
ounit/oUnitDiff.cmx : ounit/oUnit.cmx ounit/oUnitDiff.cmi
523+
ounit/oUnitLogger.cmx : ounit/oUnitUtils.cmx ounit/oUnitTypes.cmx
524+
ounit/oUnitTypes.cmx :
525+
ounit/oUnitUtils.cmx : ounit/oUnitTypes.cmx
526+
ounit_tests/ounit_tests_main.cmx : ext/resize_array.cmx ounit/oUnit.cmx \
527+
ounit_tests/ounit_tests_main.cmi
528+
ounit_tests/ounit_tests_main.cmi :

jscomp/bin/all_ounit_tests.d

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
bin/all_ounit_tests.ml : ounit/oUnitTypes.ml
2+
bin/all_ounit_tests.ml : ounit/oUnitChooser.ml
3+
bin/all_ounit_tests.ml : ounit/oUnitUtils.ml
4+
bin/all_ounit_tests.ml : ounit/oUnitLogger.ml
5+
bin/all_ounit_tests.ml : ounit/oUnit.ml
6+
bin/all_ounit_tests.ml : ounit/oUnit.mli
7+
bin/all_ounit_tests.ml : ext/resize_array.ml
8+
bin/all_ounit_tests.ml : ext/resize_array.mli
9+
bin/all_ounit_tests.ml : ounit_tests/ounit_tests_main.ml
10+
bin/all_ounit_tests.ml : ounit_tests/ounit_tests_main.mli

0 commit comments

Comments
 (0)