# New Ticket Created by  Sam Vilain 
# Please include the string:  [perl #41805]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=41805 >


This transaction appears to have no content
[library/Test::More] add isnt() to test inequality - ints only

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 |   54 ++++++++++++++++++++++++++++-----
 t/library/test_more.t                |   16 +++++++++-
 2 files changed, 60 insertions(+), 10 deletions(-)

diff --git a/runtime/parrot/library/Test/More.pir b/runtime/parrot/library/Test/More.pir
index 28c4eac..fb6c315 100644
--- a/runtime/parrot/library/Test/More.pir
+++ b/runtime/parrot/library/Test/More.pir
@@ -12,6 +12,7 @@ Test::More - Parrot extension for testing modules
     .local pmc diag
     .local pmc ok
     .local pmc is
+    .local pmc isnt
     .local pmc is_deeply
     .local pmc like
 
@@ -19,11 +20,12 @@ Test::More - Parrot extension for testing modules
     diag      = find_global 'Test::More', 'diag'
     ok        = find_global 'Test::More', 'ok'
     is        = find_global 'Test::More', 'is'
+    isnt      = find_global 'Test::More', 'isnt'
     is_deeply = find_global 'Test::More', 'is_deeply'
     like      = find_global 'Test::More', 'like'
 
     # set a test plan
-    plan( 12 )
+    plan( 13 )
 
     # run your tests
     ok( 1 )
@@ -31,6 +33,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 )
@@ -150,22 +153,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 )
@@ -183,6 +181,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
@@ -308,6 +322,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.2.21.gdcde2

Reply via email to