[svn:parrot] r44058 - in trunk: . runtime/parrot/include runtime/parrot/library/Test t/library
Austin_Hastings at svn.parrot.org
Austin_Hastings at svn.parrot.org
Wed Feb 17 02:49:14 UTC 2010
Author: Austin_Hastings
Date: Wed Feb 17 02:49:11 2010
New Revision: 44058
URL: https://trac.parrot.org/parrot/changeset/44058
Log:
TT #1453.
Add null support to Test::more::is(*,*) multisub. Add is_null assertion. Update my info in CREDITS.
Modified:
trunk/CREDITS
trunk/runtime/parrot/include/test_more.pir
trunk/runtime/parrot/library/Test/More.pir
trunk/t/library/test_more.t
Modified: trunk/CREDITS
==============================================================================
--- trunk/CREDITS Wed Feb 17 02:19:58 2010 (r44057)
+++ trunk/CREDITS Wed Feb 17 02:49:11 2010 (r44058)
@@ -136,10 +136,12 @@
N: Austin Hastings
U: Austin
+U: Austin_Hastings
A: austin_hastings at yahoo.com
A: austin_h... at yahoo.com
E: austin_hastings at yahoo.com
D: Close
+D: Kakapo
N: Benjamin Goldberg
D: Numerous improvements and proposals.
Modified: trunk/runtime/parrot/include/test_more.pir
==============================================================================
--- trunk/runtime/parrot/include/test_more.pir Wed Feb 17 02:19:58 2010 (r44057)
+++ trunk/runtime/parrot/include/test_more.pir Wed Feb 17 02:49:11 2010 (r44058)
@@ -20,7 +20,7 @@
.local pmc exports, curr_namespace, test_namespace
curr_namespace = get_namespace
test_namespace = get_root_namespace [ 'parrot'; 'Test'; 'More' ]
- exports = split ' ', 'plan diag ok nok is is_deeply like substring isa_ok skip isnt todo throws_like lives_ok dies_ok throws_substring'
+ exports = split ' ', 'plan diag ok nok is is_deeply is_null like substring isa_ok skip isnt todo throws_like lives_ok dies_ok throws_substring'
test_namespace.'export_to'(curr_namespace, exports)
Modified: trunk/runtime/parrot/library/Test/More.pir
==============================================================================
--- trunk/runtime/parrot/library/Test/More.pir Wed Feb 17 02:19:58 2010 (r44057)
+++ trunk/runtime/parrot/library/Test/More.pir Wed Feb 17 02:49:11 2010 (r44058)
@@ -35,6 +35,8 @@
is( some_pmc, another_pmc, 'pmc comparison uses "eq" op' )
+ is_null( some_pmc, 'pmc was null' )
+
diag( 'this may take a while' )
is_deeply( some_deep_pmc, another_deep_pmc, 'deep structure comparison' )
@@ -155,6 +157,20 @@
=cut
+.sub one_or_both_null
+ .param pmc left
+ .param pmc right
+
+ .local int one
+ .local int both
+
+ $I0 = isnull left
+ $I1 = isnull right
+ or one, $I0, $I1
+ and both, $I0, $I1
+ .return (one, both)
+.end
+
.sub is :multi(PMC, Integer)
.param pmc left
.param pmc right
@@ -164,11 +180,17 @@
.local pmc test
get_hll_global test, [ 'Test'; 'More' ], '_test'
- .local int l, r, pass
+ .local int pass
+ ($I0, pass) = one_or_both_null(left, right)
+ if $I0 goto report
+
+ .local int l, r
l = left
r = right
+
pass = iseq l, r
-
+
+report:
test.'ok'( pass, description )
if pass goto done
@@ -176,17 +198,27 @@
.local string l_string
.local string r_string
+ l_string = 'null'
+ if null left goto r_str
l_string = left
+
+r_str:
+ r_string = 'null'
+ if null right goto diag
r_string = right
-
+
+diag:
diagnostic = _make_diagnostic( l_string, r_string )
test.'diag'( diagnostic )
done:
.end
-.sub is :multi(_, Float)
- .param num left
- .param num right
+#.sub is :multi(_, Float)
+# .param num left
+# .param num right
+.sub is :multi(PMC, Float)
+ .param pmc left
+ .param pmc right
.param string description :optional
.param int have_desc :opt_flag
.param num precision :optional
@@ -195,15 +227,23 @@
.local pmc test
get_hll_global test, [ 'Test'; 'More' ], '_test'
+ .local int pass
+
+ ($I0, pass) = one_or_both_null(left, right)
+ if $I0 goto report
+
+ .local num l, r
+ l = left
+ r = right
+
if have_prec goto check_precision
- .local int pass
- pass = iseq left, right
+ pass = iseq l, r
goto report
check_precision:
.local num diff
- diff = left - right
+ diff = l - r
diff = abs diff
pass = isle diff, precision
@@ -215,10 +255,17 @@
.local string l_string
.local string r_string
+ l_string = 'null'
+ if null left goto r_str
l_string = left
+
+r_str:
+ r_string = 'null'
+ if null right goto diag
r_string = right
-
- diagnostic = _make_diagnostic( left, right )
+
+diag:
+ diagnostic = _make_diagnostic( l_string, r_string )
test.'diag'( diagnostic )
done:
.end
@@ -232,12 +279,16 @@
.local pmc test
get_hll_global test, [ 'Test'; 'More' ], '_test'
- .local string l, r
.local int pass
- l = left
- r = right
+ ($I0, pass) = one_or_both_null(left, right)
+ if $I0 goto report
+
+ .local string l, r
+ l = left
+ r = right
pass = iseq l, r
+report:
test.'ok'( pass, description )
if pass goto done
@@ -245,9 +296,16 @@
.local string l_string
.local string r_string
+ l_string = 'null'
+ if null left goto r_str
l_string = left
+
+r_str:
+ r_string = 'null'
+ if null right goto diag
r_string = right
+diag:
diagnostic = _make_diagnostic( l_string, r_string )
test.'diag'( diagnostic )
done:
@@ -263,8 +321,11 @@
get_hll_global test, [ 'Test'; 'More' ], '_test'
.local int pass
- .local int does_type
+
+ ($I0, pass) = one_or_both_null(left, right)
+ if $I0 goto result
+ .local int does_type
does_type = does right, 'String'
if does_type goto check_string
@@ -300,9 +361,16 @@
.local string l_string
.local string r_string
+ l_string = 'null'
+ if null left goto r_str
l_string = left
+
+r_str:
+ r_string = 'null'
+ if null right goto diag
r_string = right
+diag:
diagnostic = _make_diagnostic( l_string, r_string )
test.'diag'( diagnostic )
done:
@@ -324,7 +392,9 @@
get_hll_global test, [ 'Test'; 'More' ], '_test'
.local int pass
- pass = 0
+
+ ($I0, pass) = one_or_both_null(left, right)
+ if $I0 goto report
if left != right goto pass_it
goto report
@@ -359,7 +429,9 @@
get_hll_global test, [ 'Test'; 'More' ], '_test'
.local int pass
- pass = 0
+
+ ($I0, pass) = one_or_both_null(left, right)
+ if $I0 goto report
ne left, right, pass_it
goto report
@@ -394,7 +466,9 @@
get_hll_global test, [ 'Test'; 'More' ], '_test'
.local int pass
- pass = 0
+
+ ($I0, pass) = one_or_both_null(left, right)
+ if $I0 goto report
ne left, right, pass_it
goto report
@@ -428,8 +502,12 @@
.local pmc test
get_hll_global test, [ 'Test'; 'More' ], '_test'
- # this comparison may not work in general, but it's worth trying
.local int pass
+
+ ($I0, pass) = one_or_both_null(left, right)
+ if $I0 goto report
+
+ # this comparison may not work in general, but it's worth trying
pass = isne left, right
report:
@@ -848,6 +926,37 @@
.return( equal )
.end
+=item C<is_null( pmc, description )>
+
+Records a passing test if the PMC passed in is null, fails otherwise.
+
+=cut
+
+.sub is_null
+ .param pmc victim
+ .param string description :optional
+
+ .local pmc test
+ get_hll_global test, [ 'Test'; 'More' ], '_test'
+
+ .local int passed
+ passed = isnull victim
+
+ test.'ok'( passed, description )
+ if passed goto done
+
+ .local string v_string
+ v_string = 'null'
+ if null victim goto diag
+ v_string = victim
+
+ diag:
+ .local string diagnostic
+ diagnostic = _make_diagnostic( v_string, 'null')
+ test.'diag'( diagnostic )
+ done:
+.end
+
=item C<dies_ok( codestring, description )>
Takes PIR code in C<codestring> and an optional message in C<description>.
Modified: trunk/t/library/test_more.t
==============================================================================
--- trunk/t/library/test_more.t Wed Feb 17 02:19:58 2010 (r44057)
+++ trunk/t/library/test_more.t Wed Feb 17 02:49:11 2010 (r44058)
@@ -15,14 +15,14 @@
.local pmc exports, curr_namespace, test_namespace
curr_namespace = get_namespace
test_namespace = get_namespace [ 'Test'; 'More' ]
- exports = split " ", "ok nok is diag like skip todo is_deeply isa_ok isnt throws_like lives_ok dies_ok"
+ exports = split " ", "ok nok is diag like skip todo is_deeply is_null isa_ok isnt throws_like lives_ok dies_ok"
test_namespace.'export_to'(curr_namespace, exports)
test_namespace = get_namespace [ 'Test'; 'Builder'; 'Tester' ]
exports = split " ", "plan test_out test_diag test_fail test_pass test_test"
test_namespace.'export_to'(curr_namespace, exports)
- plan( 108 )
+ plan( 117 )
test_skip()
test_todo()
@@ -32,6 +32,7 @@
test_isnt()
test_like()
test_is_deeply()
+ test_is_null()
test_diagnostics()
test_lives_ok()
test_dies_ok()
@@ -369,7 +370,62 @@
test_diag( 'Have: 1' )
test_diag( expected )
is( left, right, 'comparing two pmcs' )
- test_test( 'failing test is() for pmcs with description')
+ test_test( 'failing test is() for pmcs with description' )
+
+ test_pass( 'comparing two nulls' )
+ null left
+ null right
+ is( left, right, 'comparing two nulls' )
+ test_test( 'passing test is() for nulls')
+
+ test_fail('comparing null with Int')
+ null left
+ right = box 1
+ is( left, right, 'comparing null with Int')
+ test_diag( 'Have: null' )
+ test_diag( 'Want: 1' )
+ test_test('failing test is() for null vs. pmc 1')
+
+ test_fail('comparing Int with null')
+ left = box 10
+ null right
+ is( left, right, 'comparing Int with null')
+ test_diag( 'Have: 10' )
+ test_diag( 'Want: null' )
+ test_test('failing test is() for pmc 10 vs. null')
+
+ test_fail('comparing null with Float')
+ null left
+ right = box 1.01
+ is( left, right, 'comparing null with Float')
+ test_diag( 'Have: null' )
+ test_diag( 'Want: 1.01' )
+ test_test('failing test is() for null vs. pmc 1.01')
+
+ test_fail('comparing Float with null')
+ left = box 2.787
+ null right
+ is( left, right, 'comparing Float with null')
+ test_diag( 'Have: 2.787' )
+ test_diag( 'Want: null' )
+ test_test('failing test is() for pmc 2.787 vs. null')
+
+ test_fail('comparing null with String')
+ null left
+ right = box 'September, when it comes'
+ is( left, right, 'comparing null with String')
+ test_diag( 'Have: null' )
+ test_diag( 'Want: September, when it comes' )
+ test_test('failing test is() for null vs. String pmc')
+
+ test_fail('comparing String with null')
+ left = box 'I cannot move a mountain now'
+ null right
+ is( left, right, 'comparing String with null')
+ test_diag( 'Have: I cannot move a mountain now' )
+ test_diag( 'Want: null' )
+ test_test('failing test is() for String pmc vs. null')
+
.end
.sub test_isnt
@@ -803,6 +859,20 @@
test_test( 'failing test isnt() for PMC/string')
.end
+
+.sub test_is_null
+ test_pass( 'null is_null')
+ null $P0
+ is_null($P0, 'null is_null')
+ test_test( 'passing is_null with null')
+
+ test_fail( 'String is not null' )
+ $P0 = box 'Concerto'
+ is_null($P0, 'String is not null')
+ test_diag( "Have: Concerto" )
+ test_diag( "Want: null" )
+ test_test( 'failing test is_null for String pmc')
+.end
# Local Variables:
# mode: pir
# fill-column: 100
More information about the parrot-commits
mailing list