Author: chromatic
Date: Sat Aug 20 10:33:15 2005
New Revision: 9008
Modified:
trunk/runtime/parrot/library/Test/Builder/Tester.pir
Log:
Added test_pass() and test_fail() subs to make testing test libs much easier.
Modified: trunk/runtime/parrot/library/Test/Builder/Tester.pir
==============================================================================
--- trunk/runtime/parrot/library/Test/Builder/Tester.pir (original)
+++ trunk/runtime/parrot/library/Test/Builder/Tester.pir Sat Aug 20
10:33:15 2005
@@ -202,10 +202,11 @@ This module defines the following public
expect_out = new .PerlArray
expect_diag = new .PerlArray
- store_global 'Test::Builder::Tester', '_test', test
- store_global 'Test::Builder::Tester', '_test_output', test_output
- store_global 'Test::Builder::Tester', '_expect_out', expect_out
- store_global 'Test::Builder::Tester', '_expect_diag', expect_diag
+ store_global 'Test::Builder::Tester', '_test', test
+ store_global 'Test::Builder::Tester', '_default_test', default_test
+ store_global 'Test::Builder::Tester', '_test_output', test_output
+ store_global 'Test::Builder::Tester', '_expect_out', expect_out
+ store_global 'Test::Builder::Tester', '_expect_diag', expect_diag
.end
=item C<plan( num_tests )>
@@ -226,6 +227,68 @@ Sets the number of tests you plan to run
.sub line_num
.end
+=item C<test_pass( test_string )>
+
+Sets the expectation for a test to pass. C<test_string> is the optional
+description of the test.
+
+=cut
+
+.sub test_pass
+ .param string description
+
+ set_output( 'ok', description )
+.end
+
+=item C<test_fail( test_string )>
+
+Sets the expectation for a test to fail. C<test_string> is the optional
+description of the test.
+
+=cut
+
+.sub test_fail
+ .param string description
+
+ set_output( 'not ok', description )
+.end
+
+.sub set_output
+ .param string test_type
+ .param string description
+
+ .local pmc test
+ .local pmc results
+ .local int result_count
+ .local pmc next_result
+
+ test = find_global 'Test::Builder::Tester', '_default_test'
+ results = test.'results'()
+ result_count = results
+ inc result_count
+
+ next_result = new .String
+ set next_result, result_count
+
+ .local pmc line_string
+ line_string = new .String
+ concat line_string, test_type
+ concat line_string, ' '
+ concat line_string, next_result
+
+ .local int string_defined
+ string_defined = length description
+ unless string_defined goto SET_EXPECT_OUTPUT
+ concat line_string, ' - '
+ concat line_string, description
+
+ SET_EXPECT_OUTPUT:
+ .local pmc expect_out
+ expect_out = find_global 'Test::Builder::Tester', '_expect_out'
+
+ push expect_out, line_string
+.end
+
=item C<test_out( test_string )>
Sets the expected output for this test to a string. This should be a line of
@@ -289,9 +352,6 @@ This and C<test_err()> are effectively t
push expect_diag, line_string
.end
-.sub test_fail
-.end
-
=item C<test_test( test_description )>
Compares all of the expected test output and diagnostic output with the actual