module TestSimple:A simple unit-testing framework based on Perl's Test::Simplesig..end
This is a very simple, but easy to use unit testing framework based on
Perl's very successful Test::* modules. It produces output using the
TAP protocol, which is easily read by the Perl module Test::Harness. This
means that OCaml tests can take advantage of many of the nice TAP based
tools that Perl has to offer.
Here is an example usage of TestSimple taken from the TestSimple test suite itself.
#!/usr/local/bin/ocamlrun /usr/local/bin/ocaml
#load "testSimple.cma";;
open TestSimple;;
plan 9;;
diag "... testing O'Caml TestSimple v0.01 ";;
ok true "... ok passed";;
is 2 2 "... is <int> <int> passed";;
is 2. 2. "... is <float> <float> passed";;
is "foo" "foo" "... is <string> <string> passed";;
is [] [] "... is <'a list> <'a list> passed";;
is [1;2;3] [1;2;3] "... is <int list> <int list> passed";;
is ["foo";"bar"] ["foo";"bar"] "... is <string list> <string list> passed";;
is (1,"foo") (1,"foo") "... is <int * string> <int * string> passed";;
is TAPDocument.Ok TAPDocument.Ok "... is <type> <type> passed";;
This file can then be run either from the command line as a
script, or run using the prove utility provided by Perl's
Test::Harness module. The prove command to run all the files
in the tests directory would look like this:
> prove tests/*.ml
For more information on prove or the TAP protocol in general see
the Test::Harness module documentation on CPAN here
http://search.cpan.org/~petdance/Test-Harness/val plan : int -> unitplan the number of tests you plan to run, like so:
plan 10;;
val no_plan : unit -> unitval ok : ?todo:string -> bool -> string -> unitok tests is the most basic test, it is similar to assert in that
it expects a boolean value, or an expression which reduces to a boolean,
as it's basic test. It also expects a string for use as the test description.
And lastly, there is the optional ?todo parameter, this can be used when
you have a test which you know will fail, and you want to mark it as TODO
for later.val is : ?todo:string -> 'a -> 'a -> string -> unitok test except that it takes two values and performs
it's own comparison on them using =. The benefit of using this over doing
the comparison yourself with ok is that is will give a more informative
diagnostic message message (it uses ExtLib.dump to print the values passed)val diag : string -> unit