Index: src/pmc/env.pmc =================================================================== --- src/pmc/env.pmc (révision 41317) +++ src/pmc/env.pmc (copie de travail) @@ -99,6 +99,19 @@ /* +=item C + +Returns whether the environment has any elements. + +=cut + +*/ + VTABLE INTVAL get_bool() { + return SELF.elements() ? 1 : 0; + } + +/* + =item C Returns the size of the hash. Index: runtime/parrot/library/Test/More.pir =================================================================== --- runtime/parrot/library/Test/More.pir (révision 41317) +++ runtime/parrot/library/Test/More.pir (copie de travail) @@ -92,19 +92,20 @@ =item C -Records a test as pass or fail depending on the truth of the integer C, +Records a test as pass or fail depending on the truth of the PMC C, recording it with the optional test description in C. =cut .sub ok - .param int passed + .param pmc passed .param string description :optional .local pmc test get_hll_global test, [ 'Test'; 'More' ], '_test' - test.'ok'( passed, description ) + $I0 = istrue passed + test.'ok'( $I0, description ) .end =item C @@ -115,14 +116,14 @@ =cut .sub nok - .param int passed + .param pmc passed .param string description :optional .local pmc test get_hll_global test, [ 'Test'; 'More' ], '_test' .local int reverse_passed - reverse_passed = not passed + reverse_passed = isfalse passed test.'ok'( reverse_passed, description ) .end Index: t/library/test_more.t =================================================================== --- t/library/test_more.t (révision 41317) +++ t/library/test_more.t (copie de travail) @@ -15,18 +15,19 @@ .local pmc exports, curr_namespace, test_namespace curr_namespace = get_namespace test_namespace = get_namespace [ 'Test'; 'More' ] - exports = split " ", "ok is diag like skip todo is_deeply isa_ok isnt throws_like" + exports = split " ", "ok nok is diag like skip todo is_deeply isa_ok isnt throws_like" 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( 81 ) + plan( 89 ) test_skip() test_todo() test_ok() + test_nok() test_is() test_isnt() test_like() @@ -72,6 +73,36 @@ .end +.namespace ['MyFalseClass'] + +.sub '' :anon :load :init + $P0 = newclass ['MyFalseClass'] +.end + +.sub 'get_bool' :vtable + .return(0) +.end + +.sub 'get_integer' :vtable + .return(1) +.end + +.namespace ['MyTrueClass'] + +.sub '' :anon :load :init + $P0 = newclass ['MyTrueClass'] +.end + +.sub 'get_bool' :vtable + .return(1) +.end + +.sub 'get_integer' :vtable + .return(0) +.end + +.namespace [] + .sub test_ok test_pass() ok( 1 ) @@ -88,8 +119,46 @@ test_fail( 'with description' ) ok( 0, 'with description' ) test_test( 'failing test ok() with description') + + $P0 = new ['MyFalseClass'] + test_fail() + ok( $P0 ) + test_test( 'failing ok() calls get_bool') + + $P0 = new ['MyTrueClass'] + test_pass() + ok( $P0 ) + test_test( 'passing ok() calls get_bool') .end +.sub test_nok + test_fail() + nok( 1 ) + test_test( 'failing test nok()') + + test_pass() + nok( 0 ) + test_test( 'passing test nok()') + + test_fail( 'with description' ) + nok( 1, 'with description' ) + test_test( 'failing test nok() with description') + + test_pass( 'with description' ) + nok( 0, 'with description' ) + test_test( 'passing test nok() with description') + + $P0 = new ['MyFalseClass'] + test_pass() + nok( $P0 ) + test_test( 'passing nok() calls get_bool') + + $P0 = new ['MyTrueClass'] + test_fail() + nok( $P0 ) + test_test( 'failing nok() calls get_bool') +.end + .sub test_is test_pass() is( 100, 100 )