[manual index][section index]


tap: plan, skip_all, bail_out, done, diag, skip, todo, ok, eq, ne, eq_int, ne_int, eq_real, ne_real, eq_list, eq_arr, catched, raised, stopwatch_start, stopwatch_min, stopwatch_max, getmem, ok_mem - test library compatible with Test Anything Protocol


implement T;

include "opt/powerman/tap/module/tap.m";
        tap: TAP;
tap = load TAP TAP->PATH;
# -- OR --
include "opt/powerman/tap/module/t.m";
    # your tests here

init: fn();

plan:           fn(tests: int);
done:           fn();
skip_all:       fn(reason: string);
bail_out:       fn(reason: string);

skip:           fn(howmany: int, reason: string);
todo:           fn(reason: string);

diag:           fn(msg: string);

ok:             fn(bool:int,    msg: string);
eq:             fn(a,b: string, msg: string);
ne:             fn(a,b: string, msg: string);
eq_int:         fn(a,b: int,    msg: string);
ne_int:         fn(a,b: int,    msg: string);
eq_real:        fn(a,b: real,   msg: string);
ne_real:        fn(a,b: real,   msg: string);
eq_list:        fn[T](cmp: ref fn(a,b: T): int, a,b: list  of T, msg: string);
eq_arr:         fn[T](cmp: ref fn(a,b: T): int, a,b: array of T, msg: string);
catched:        fn(e: string);
raised:         fn(e: string,   msg: string);
stopwatch_min:  fn(min: int, msg: string);
stopwatch_max:  fn(max: int, msg: string);
getmem:         fn(): UsedMem;
ok_mem:         fn(was: UsedMem);


Test Anything Protocol ( http://testanything.org/) module (TAP producer) provides ability to implement tests.

Using mkfiles and helper script runtest.sh provided by opt-mkfiles project ( https://github.com/powerman/inferno-opt-mkfiles) you can run mk test both in host OS and Inferno. While there no available TAP consumer for Inferno yet, if you run tests in host OS you can use existing consumer like prove command from perl module Test::Harness ( https://metacpan.org/pod/distribution/Test-Harness/bin/prove).

This module can be loaded in two ways - traditional (include tap.m; load; tap->init()) or simplified (include t.m; place your code inside function named test() instead of init(refDraw->Context,listofstring) ).

init must be called before using module only if you include tap.m and load module manually.

Terminology: "test app" is single t/ .b file which usually contain many "tests" (calls to functions like *ok or eq_int) ; "test suite" consists of all test apps. mk test and (in host os) prove -r will run full test suite - all test apps, one by one. To run single test app use t/someapp and (in host os) ./t/someapp.t or prove t/someapp.t

Each test app must define how many tests it's going to do - this is needed to detect exit/crash in the middle of app when not all tests was executed yet. Use either plan before all tests if you know how many tests you'll do, or done after all tests. It's safe to call done even if you already called plan (in this case done will be ignored).

There are several ways of flow control for your tests: refuse to run tests (usually because of unsatisfied dependencies/requirements), skipping all/some tests, marking some tests as "TODO" (not working yet).

skip_all should be used before plan or running any tests, and result in exit from test app with "All tests successful." status.

bail_out should be used if some critical error happens and there is no sense in executing any tests. It will not only stop current test app, but also prevent execution of next test apps in test suite.

skip let you skip (with success status) few tests. This function will raise "SKIP", so here is example how to use it:

ok(1, "first test");
{ skip(2, "skip next two tests");
ok(1, "second test");
ok(1, "third test");
} exception { "SKIP" => ; * => raise ; }
ok(1, "fourth test");

todo let you mark next tests as "expected to fail" and provide a reason. As result these tests will be executed, but their failures won't affect final status of test app (so it's still can be "All tests successful."). To switch off this mode, call todo(nil) after these tests.

diag can be used to output anything (usually debug info) without breaking TAP (use it in your tests instead of sys->print() ).

ok, eq, ne, eq_int, ne_int, eq_real, ne_real, eq_list, eq_arr are basic tests. eq_list and eq_arr will sort both lists/arrays before comparison.

catched, raised let you test for exceptions raised (or not) in tested code:

{ code1_which_may_raise(); } exception e { "*"=>catched(e); }
raised("myerr:*", "should raise string with 'myerr:' prefix");
{ code2_which_may_raise(); } exception e { "*"=>catched(e); }
raised(nil, "shouldn't raise");

stopwatch_start, stopwatch_min, stopwatch_max let you test how much time it took to execute some code. stopwatch_start should be called before running that code, and one of stopwatch_min (test code took no less than n millisec) or stopwatch_max (test code took no greater than n millisec) should be called after that code. stopwatch_min and stopwatch_max will call stopwatch_start, so there is no needs in calling it manually if you'll run next chunk of code to test right after them.

getmem, ok_mem let you test for memory leaks: save value returned by getmem into variable, run code to test, call ok_mem with that variable and it will check amount of used main/heap/image memory not change.


implement T;

include "opt/powerman/tap/module/t.m";


    ok(1==1,            "true test");
    eq("abc", "def",    "abc == def?");
    eq_int(2, 3,        "2 == 3?");




itest(1), itslib(2)

Host OS command prove(1) provided by Perl module Test::Harness.


Failed test apps exits with empty $status.

In host os mk test won't stop test suite after bail_out.

TAP(2 ) Rev:  Tue Mar 31 02:36:25 GMT 2015