Author: allison
Date: Fri Mar 16 15:17:48 2007
New Revision: 17521

Modified:
   trunk/runtime/parrot/library/Test/More.pir
   trunk/t/library/test_more.t

Log:
[Test::More]: Apply patch #41807 to add isa_ok() testing, with some
refactors.


Modified: trunk/runtime/parrot/library/Test/More.pir
==============================================================================
--- trunk/runtime/parrot/library/Test/More.pir  (original)
+++ trunk/runtime/parrot/library/Test/More.pir  Fri Mar 16 15:17:48 2007
@@ -45,6 +45,11 @@
 
     like( 'foo', 'f o**{2}', 'passing regex compare with diagnostic' )
 
+    $P0 = getclass "Squirrel"
+    $P0.new()
+
+    isa_ok($P0, "Squirrel", "new Squirrel")
+
 =head1 DESCRIPTION
 
 C<Test::More> is a pure-Parrot library for testing modules.  It provides
@@ -775,6 +780,51 @@
     test.'skip'()
 .end
 
+=item C<isa_ok( object, class_name, object_name )>
+
+Pass if the object C<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>".
+
+Good input: "C<new MyObject>", "C<return from bar()>"
+
+Bad input: "C<test that the return from Foo is correct type>"
+
+=cut
+
+.sub isa_ok
+    .param pmc thingy
+    .param pmc class_name
+    .param pmc object_name :optional
+    .param int got_name :opt_flag
+
+    .local pmc test
+    find_global test, 'Test::More', '_test'
+
+    .local string description, diagnostic
+    description = "The object"
+    unless got_name goto keep_default
+    description = object_name
+  keep_default:        
+    diagnostic = description
+    description .= " isa "
+    $S0 = class_name
+    description .= $S0
+
+    $I0 = isa thingy, class_name
+    test.'ok'($I0, description)
+    if $I0 goto out
+    diagnostic .= " isn't a "
+    $S1 = class_name
+    diagnostic .= $S1
+    diagnostic .= " it's a "
+    $S2 = typeof thingy
+    diagnostic .= $S2
+    test.'diag'(diagnostic)
+out:   
+.end
+
 .sub _make_diagnostic
     .param string received
     .param string expected

Modified: trunk/t/library/test_more.t
==============================================================================
--- trunk/t/library/test_more.t (original)
+++ trunk/t/library/test_more.t Fri Mar 16 15:17:48 2007
@@ -25,6 +25,7 @@
        .IMPORT( 'Test::More', 'like' )
        .IMPORT( 'Test::More', 'skip' )
        .IMPORT( 'Test::More', 'is_deeply' )
+       .IMPORT( 'Test::More', 'isa_ok' )
        .IMPORT( 'Test::Builder::Tester', 'plan' )
        .IMPORT( 'Test::Builder::Tester', 'test_out' )
        .IMPORT( 'Test::Builder::Tester', 'test_diag' )
@@ -32,13 +33,14 @@
        .IMPORT( 'Test::Builder::Tester', 'test_pass' )
        .IMPORT( 'Test::Builder::Tester', 'test_test' )
 
-       plan( 47 )
+       plan( 53 )
        test_skip()
        test_ok()
        test_is()
        test_like()
        test_is_deeply()
        test_diagnostics()
+       test_isa_ok()
 
        test.'finish'()
 .end
@@ -360,3 +362,44 @@
        skip()
        test_test( 'skip()' )
 .end
+
+.sub test_isa_ok
+       .local pmc dog, terrier, daschund, Spot, Sossy
+
+       dog = newclass "dog"
+       terrier = subclass dog, "terrier"
+       daschund = subclass dog, "daschund"
+
+       Spot = new "terrier"
+       Sossy = new "daschund"
+
+       test_pass( 'Spot isa terrier' )
+       isa_ok(Spot, "terrier", "Spot")
+       test_test( 'passing isa_ok for PMC/string (class =)' )
+
+       test_pass( 'Spot isa dog' )
+       isa_ok(Spot, "dog", "Spot")
+       test_test( 'passing isa_ok for PMC/string (super)')
+
+       test_pass( 'Sossy isa daschund' )
+       $P1 = new String
+        $P1 = "daschund"
+       isa_ok(Sossy, $P1, "Sossy")
+       test_test( 'passing isa_ok for PMC/PMC (class =)' )
+
+       test_pass( 'Sossy isa dog' )
+       $P2 = new String
+        $P2 = "dog"
+       isa_ok(Sossy, $P2, "Sossy")
+       test_test( 'passing isa_ok for PMC/PMC (super)')
+
+       test_pass( 'The object isa terrier' )
+       isa_ok(Spot, "terrier")
+       test_test( 'passing isa_ok with no object description (class =)' )
+
+       test_fail( 'Spot isa daschund' )
+       test_diag( "Spot isn't a daschund it's a terrier" )
+       isa_ok(Spot, 'daschund', "Spot")
+       test_test( 'failing test isnt() for PMC/string')
+
+.end

Reply via email to