parrotcode: Parrot extension for testing modules | |
Contents | Libraries |
Test::More - Parrot extension for testing modules
# load this library
load_bytecode 'library/Test/More.pbc'
# get the testing functions
.local pmc exports, curr_namespace, test_namespace
curr_namespace = get_namespace
test_namespace = get_namespace [ 'Test'; 'More' ]
exports = split ' ', 'plan diag ok is is_deeply like isa_ok isnt'
test_namespace.'export_to'(curr_namespace, exports)
# set a test plan
plan( 12 )
# run your tests
ok( 1 )
ok( 0, 'failing test with diagnostic' )
is( 100, 100 )
is( 200, 100, 'failing integer compare with diagnostic' )
is( 1.001, 1.001, 'passing float compare with diagnostic' )
is( 8.008, 4.004 )
is( 'foo', 'foo', 'passing string compare with diagnostic' )
is( 'foo', 'bar', 'failing string compare with diagnostic' )
is( some_pmc, another_pmc, 'pmc comparison uses "eq" op' )
diag( 'this may take a while' )
is_deeply( some_deep_pmc, another_deep_pmc, 'deep structure comparison' )
like( 'foo', 'f o**{2}', 'passing regex compare with diagnostic' )
skip(1, 'reason for skipping')
todo(0, 'this is a failed test', 'reason for todo')
$P0 = get_class "Squirrel"
$P0.new()
isa_ok($P0, "Squirrel", "new Squirrel")
Test::More
is a pure-Parrot library for testing modules. It provides the ok()
, is()
, isnt()
, is_deeply()
, and like()
comparison functions for you. It also provides the plan()
and diag()
helper functions. It uses Test::Builder
, a simple, single backend for multiple test modules to use within your tests.
This class defines the following functions:
plan( number_or_no_plan )
no_plan
. This will throw an exception if you have already declared a plan or if you pass an invalid argument.ok( passed, description )
passed
, recording it with the optional test description in description
.nok( passed, description )
passed
, recording it with the optional test description in description
.is( left, right, description )
left
and right
, passing if they are equal and failing otherwise. This will report the results with the optional test description in description
.eq
opcode for comparison.left
as the proper type for the comparison, converting any numeric arguments to floats. Note that there is a hard-coded precision check to avoid certain rounding errors. It's not entirely robust, but it's not completely awful either.isnt( left, right, description )
is
, but succeeds if the arguments don't match.diag( diagnostic )
diagnostic
to the screen, without affecting test comparisons.is_deeply( left, right, description )
left
and right
. If data structures are passed, is_deeply
does a deep comparison by walking each structure. It passes if they are equal and fails otherwise. This will report the results with the optional test description in description
.like( target, pattern, description )
target
to the pattern passed as pattern
. It passes if the pattern matches and fails otherwise. This will report the results with the optional test description in description
.skip( how_many, why )
todo( passed, description, reason )
ok
, but marks it as TODO so it always appears as a success. This also records the optional description
of the test and the reason
you have marked it as TODO.isa_ok( object, class_name, object_name )
isa
class of the given class name. The object name passed in is not a full description, but a name to be included in the description. The description is presented as "<object_name> isa <class>".new MyObject
", "return from bar()
"test that the return from Foo is correct type
"Written and maintained by chromatic, chromatic at wgz dot org
, based on the Perl 6 port he wrote, based on the original Perl 5 version he wrote with ideas from Michael G. Schwern. Please send patches, feedback, and suggestions to the Perl 6 internals mailing list.
Copyright (C) 2005-2008, The Perl Foundation.
|