refactor the is() :multi for integers into a _cmp_ok() function, and then use that to provide is() and isnt() --- runtime/parrot/library/Test/More.pir | 53 ++++++++++++++++++++++++++++------ t/library/test_more.t | 16 +++++++++- 2 files changed, 59 insertions(+), 10 deletions(-)
diff --git a/runtime/parrot/library/Test/More.pir b/runtime/parrot/library/Test/More.pir index fd297ab..dea010c 100644 --- a/runtime/parrot/library/Test/More.pir +++ b/runtime/parrot/library/Test/More.pir @@ -16,11 +16,12 @@ Test::More - Parrot extension for testing modules .IMPORT( 'Test::More', 'diag', _ ) .IMPORT( 'Test::More', 'ok', _ ) .IMPORT( 'Test::More', 'is', _ ) + .IMPORT( 'Test::More', 'isnt', _ ) .IMPORT( 'Test::More', 'is_deeply', _ ) .IMPORT( 'Test::More', 'like', _ ) # set a test plan - plan( 12 ) + plan( 13 ) # run your tests ok( 1 ) @@ -28,6 +29,7 @@ Test::More - Parrot extension for testing modules is( 100, 100 ) is( 200, 100, 'failing integer compare with diagnostic' ) + isnt( 200, 100, 'passing integer negative compare' ) is( 1.001, 1.001, 'passing float compare with diagnostic' ) is( 8.008, 4.004 ) @@ -148,22 +150,17 @@ add more. =cut -.sub is :multi( int, int ) +.sub _cmp_ok :multi( int, int, pmc ) .param int left .param int right + .param pmc comp .param string description :optional .local pmc test find_global test, 'Test::More', '_test' .local int pass - pass = 0 - - if left == right goto pass_it - goto report - - pass_it: - pass = 1 + pass = comp(left, right) report: test.ok( pass, description ) @@ -181,6 +178,22 @@ add more. done: .end +.sub is :multi( int, int ) + .param int left + .param int right + .param string description :optional + .local pmc comp + comp = find_name "_eq_int" + _cmp_ok(left,right,comp,description) +.end + +.sub _eq_int + .param int left + .param int right + $I0 = iseq left, right + .return($I0) +.end + .sub is :multi( float, float ) .param float left .param float right @@ -306,6 +319,28 @@ add more. done: .end +=item C<isnt( left, right, description )> + +As C<is()>, but the test passes if the arguments I<don't> match. + +=cut + +.sub isnt :multi( int, int ) + .param int left + .param int right + .param string description :optional + .local pmc comp + comp = find_name "_ne_int" + _cmp_ok(left,right,comp,description) +.end + +.sub _ne_int + .param int left + .param int right + $I0 = isne left, right + .return($I0) +.end + =item C<diag( diagnostic )> Prints C<diagnostic> to the screen, without affecting test comparisons. diff --git a/t/library/test_more.t b/t/library/test_more.t index 23576eb..4bc08b8 100644 --- a/t/library/test_more.t +++ b/t/library/test_more.t @@ -21,6 +21,7 @@ .local pmc import_sub .IMPORT( 'Test::More', 'ok' ) .IMPORT( 'Test::More', 'is' ) + .IMPORT( 'Test::More', 'isnt' ) .IMPORT( 'Test::More', 'diag' ) .IMPORT( 'Test::More', 'like' ) .IMPORT( 'Test::More', 'skip' ) @@ -32,13 +33,14 @@ .IMPORT( 'Test::Builder::Tester', 'test_pass' ) .IMPORT( 'Test::Builder::Tester', 'test_test' ) - plan( 47 ) + plan( 49 ) test_skip() test_ok() test_is() test_like() test_is_deeply() test_diagnostics() + test_isnt() test.'finish'() .end @@ -360,3 +362,15 @@ skip() test_test( 'skip()' ) .end + +.sub test_isnt + test_fail() + isnt( 100, 100 ) + test_diag( 'Received: 100' ) + test_diag( 'Expected: 100' ) + test_test( 'failing test isnt() for ints') + + test_pass() + isnt( -100, 200 ) + test_test( 'passing test isnt() for ints') +.end -- 1.5.0.759.g41ffe