Copyright 2007, 2024 Anthony Howe. All rights reserved.
To use this extension word set:
include-path post4/assert.p4
A test case typically takes the form of
T{ <perform test> -> <expected stack results> }T
For example:
T{ 1 2.71828 3 -> 1 2.71828 3 }T
T{ 1 2 + -> 3 }T
( -- )
Start a test case.
( -- )
Separate the test case results from the expected data and float stack.
( -- )
Compare the test results on the stacks against the expected data and float stacks, counting a pass, fail, or skipped result if the stacks fail to match.
An example of a test group:
.( INVERT ) test_group
t{ FALSE INVERT -> TRUE }t
t{ TRUE INVERT -> FALSE }t
t{ 0 INVERT -> -1 }t
test_group_end
See the Post4 unit test suite (test/units.p4
) based on the Forth Standard section F for examples.
( bool
-- )
If bool
is TRUE
then count a pass result, otherwise count a failed result.
( bool
-- )
If bool
is FALSE
then count a pass result, otherwise count a failed result.
( bool
-- )
If bool
is TRUE
then count a pass result, otherwise count a skipped result.
( bool
-- )
If bool
is FALSE
then count a pass result, otherwise count a skipped result.
( -- )
Start a test group and set a marker rm_test_group
.
( -- )
End a test group and execute rm_test_group
to clean-up the environment of test data and words.
( -- )
Start a test suite, which is a collection of test groups and test cases. The stacks and counts are also cleared.
( -- )
End a test suite and report the results, stack size, passed, failed, and skipped. If there were any failures, then Post4 exits with status code 1
; skipped results do not terminate Post4.
( -- )
Start a test case and if the result is a failure, count it as skipped instead. Test-skip is useful while developing a test case or if a test case is expected fail, but the test suite should continue.