Skip to content
Browse files

fix the rest of the Test functions to return their truth and test them

  • Loading branch information...
1 parent 61807a6 commit 792c782287c2414d75b7093751fb4d0defcfdd74 @szabgab szabgab committed Jul 12, 2012
Showing with 38 additions and 10 deletions.
  1. +10 −6 lib/Test.pm
  2. +28 −4 t/01-sanity/99-test-basic.t
View
16 lib/Test.pm
@@ -178,40 +178,44 @@ multi sub lives_ok(Callable $closure, $reason = '') is export {
try {
$closure();
}
- proclaim((not defined $!), $reason) or diag($!);
+ my $ok = proclaim((not defined $!), $reason) or diag($!);
$time_before = nqp::p6box_n(nqp::time_n);
+ return $ok;
}
multi sub eval_dies_ok(Str $code, $reason = '') is export {
$time_after = nqp::p6box_n(nqp::time_n);
my $ee = eval_exception($code);
+ my $ok;
if defined $ee {
# XXX no regexes yet in nom
my $bad_death = $ee.Str.index('Null PMC access ').defined;
if $bad_death {
diag "wrong way to die: '$ee'";
}
- proclaim( !$bad_death, $reason );
+ $ok = proclaim( !$bad_death, $reason );
}
else {
- proclaim( 0, $reason );
+ $ok = proclaim( 0, $reason );
}
$time_before = nqp::p6box_n(nqp::time_n);
+ return $ok;
}
multi sub eval_lives_ok(Str $code, $reason = '') is export {
$time_after = nqp::p6box_n(nqp::time_n);
my $ee = eval_exception($code);
- proclaim((not defined $ee), $reason)
+ my $ok = proclaim((not defined $ee), $reason)
or diag("Error: $ee");
$time_before = nqp::p6box_n(nqp::time_n);
+ return $ok;
}
multi sub is_deeply(Mu $got, Mu $expected, $reason = '') is export
{
$time_after = nqp::p6box_n(nqp::time_n);
my $test = _is_deeply( $got, $expected );
- proclaim($test, $reason);
+ my $ok = proclaim($test, $reason);
if !$test {
my $got_perl = try { $got.perl };
my $expected_perl = try { $expected.perl };
@@ -220,8 +224,8 @@ multi sub is_deeply(Mu $got, Mu $expected, $reason = '') is export
diag "expected: $expected_perl";
}
}
- $test;
$time_before = nqp::p6box_n(nqp::time_n);
+ return $ok;
}
sub _is_deeply(Mu $got, Mu $expected) {
View
32 t/01-sanity/99-test-basic.t
@@ -104,15 +104,33 @@ nok $dies_ok2, 'dies_ok returns False if code did not die';
dies_ok { die }, 'dies_ok';
dies_ok { die };
-lives_ok { 1 }, 'lives_ok';
+my $lives_ok1 = lives_ok { 1 }, 'lives_ok';
+ok $lives_ok1, 'lives_ok returns True';
lives_ok { 1 };
-eval_dies_ok 'die', 'eval_dies_ok';
+# NOT_TODO
+todo( 'failing lives_ok returns False' );
+my $lives_ok2 = lives_ok { die }, 'lives_ok { die }';
+nok $lives_ok2, 'failing lives_ok returns False';
+
+my $ed_ok1 = eval_dies_ok 'die', 'eval_dies_ok';
+ok $ed_ok1, 'eavl_dies_ok returns True';
eval_dies_ok 'die';
-eval_lives_ok '1', 'eval_lives_ok';
+# NOT_TODO
+todo( 'eval_dies_ok 1 returns False' );
+my $ed_ok2 = eval_dies_ok '1', 'eval_dies_ok 1 fails';
+nok $ed_ok2, 'eval_dies_ok 1 returns False';
+
+my $el_ok1 = eval_lives_ok '1', 'eval_lives_ok';
+ok $el_ok1, 'eval_lives_ok 1 returns True';
eval_lives_ok '1';
+# NOT_TODO
+todo( 'failing eval_lives_ok returns False' );
+my $el_ok2 = eval_lives_ok 'die', 'lives_ok { die }';
+nok $el_ok2, 'failing eval_lives_ok returns False';
+
{
my $deeply = {
list => (1, 2),
@@ -125,10 +143,16 @@ eval_lives_ok '1';
bool => Bool::True,
array => [3, 4],
};
- is_deeply $deeply, $deeply, 'is_deeply';
+ my $is_deeply = is_deeply $deeply, $deeply, 'is_deeply';
+ ok $is_deeply, 'is_deeply returns True';
is_deeply $deeply, $deeply;
}
+# NOT_TODO
+todo( 'failing is_deeply returns False' );
+my $is_deeply = is_deeply {a => 1}, {}, 'is_deeply with exta key fails';
+nok $is_deeply, 'failing is_deeply returns False';
+
done;
# vim: ft=perl6

0 comments on commit 792c782

Please sign in to comment.
Something went wrong with that request. Please try again.