basic building blocks for testing

This commit is contained in:
Simon Cruanes 2013-03-08 16:18:52 +01:00
parent 6443648f56
commit ec8a865500
5 changed files with 55 additions and 12 deletions

View file

@ -1,2 +1,6 @@
B _build
S .
S tests/
B _build
B _build/tests/
PKG oUnit
PKG bench

View file

@ -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

View file

@ -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
=============

9
tests/run_tests.ml Normal file
View file

@ -0,0 +1,9 @@
open OUnit
let suite =
"run_tests" >:::
[ Test_sequence.suite; ]
let _ =
OUnit.run_test_tt_main suite

17
tests/test_sequence.ml Normal file
View file

@ -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;
]