diff --git a/.merlin b/.merlin index 4e4f3b4..4ac5fc8 100644 --- a/.merlin +++ b/.merlin @@ -1,2 +1,6 @@ -B _build S . +S tests/ +B _build +B _build/tests/ +PKG oUnit +PKG bench diff --git a/Makefile b/Makefile index 3c06dfc..d4d255d 100644 --- a/Makefile +++ b/Makefile @@ -5,20 +5,19 @@ TARGETS = sequence.cma sequence.cmxa sequence.cmi sequence.a LIB = $(addprefix _build/, $(TARGETS)) INSTALL = $(LIB) sequence.mli -all: +all: tests ocamlbuild $(TARGETS) $(DOC) bench: all - ocamlbuild \ - -cflags -I,`ocamlfind query extlib` \ - -lflags -I,`ocamlfind query extlib` \ - -package extlib -package unix bench.native + ocamlbuild -use-ocamlfind -pkg bench tests/benchs.native tests: - ocamlbuild tests.native + ocamlbuild -use-ocamlfind -pkg oUnit tests/run_tests.native install: all ocamlfind install $(NAME) META $(INSTALL) clean: ocamlbuild -clean + +.PHONY: all clean tests bench diff --git a/README.md b/README.md index 47fc47a..46323a0 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,26 @@ You need OCaml, say OCaml 3.12 or OCaml 4.0. $ make -To see how to use it, check `tests.ml`. `sequence.ml` has a few examples of how to convert -data structures into sequences, and conversely. +If you have `OUnit` installed, you can build and run tests with -The module `sexpr.mli` exposes the interface of the S-expression example library. It -requires OCaml>=4.0 to compile, because of the GADT structure used in the monadic -parser combinators part of `sexpr.ml`. + $ make tests + $ ./run_tests.native + +If you have `Bench` installed, you can build and run benchmarks with + + $ make benchs + $ ./benchs.native + +To see how to use the library, check the `examples` directory. +`tests.ml` has a few examples of how to convert basic data structures into +sequences, and conversely. + +Examples +======== + +The module `examples/sexpr.mli` exposes the interface of the S-expression +example library. It requires OCaml>=4.0 to compile, because of the GADT +structure used in the monadic parser combinators part of `examples/sexpr.ml`. Documentation ============= diff --git a/tests/run_tests.ml b/tests/run_tests.ml new file mode 100644 index 0000000..0fa3d58 --- /dev/null +++ b/tests/run_tests.ml @@ -0,0 +1,9 @@ + +open OUnit + +let suite = + "run_tests" >::: + [ Test_sequence.suite; ] + +let _ = + OUnit.run_test_tt_main suite diff --git a/tests/test_sequence.ml b/tests/test_sequence.ml new file mode 100644 index 0000000..bceddd2 --- /dev/null +++ b/tests/test_sequence.ml @@ -0,0 +1,17 @@ + +open OUnit + +module S = Sequence + +let test_empty () = + let seq = S.empty in + OUnit.assert_bool "empty" (S.is_empty seq); + OUnit.assert_bool "empty" + (try S.iter (fun _ -> raise Exit) seq; true with Exit -> false); + () + +let suite = + "test_sequence" >::: + [ "test_empty" >:: test_empty; + + ]