Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/lib/Test.pm b/lib/Test.pm
- index 46d3a9c..7a0cc76 100644
- --- a/lib/Test.pm
- +++ b/lib/Test.pm
- @@ -13,8 +13,8 @@ my $num_of_tests_planned;
- my $no_plan = 1;
- my $die_on_fail;
- my $perl6_test_times = ? %*ENV<PERL6_TEST_TIMES>;
- -my $time_before = 0E0;
- -my $time_after = 0E0;
- +my $time_before;
- +my $time_after;
- ## If done_testing hasn't been run when we hit our END block, we need to know
- ## so that it can be run. This allows compatibility with old tests that use
- @@ -46,39 +46,54 @@ multi sub plan($number_of_tests) {
- say '1..' ~ $number_of_tests;
- }
- - # Get two successive timestamps to measure the measurement overhead,
- - # and to reduce bias, if it exists, from the first test time.
- + # Get two successive timestamps to say how long it takes to read the
- + # clock, and to let the first test timing work just like the rest.
- + # These readings should be made with the expression now.to-posix[0],
- + # but its execution time when tried in the following two lines is a
- + # lot slower than the non portable nqp::p6box_n(pir::time__N).
- $time_before = nqp::p6box_n(pir::time__N);
- $time_after = nqp::p6box_n(pir::time__N);
- say '# between two timestamps ' ~
- ceiling(($time_after-$time_before)*1_000_000) ~ ' microseconds'
- if $perl6_test_times;
- + # Take one more reading to serve as the begin time of the first test
- $time_before = nqp::p6box_n(pir::time__N);
- - # Ideally the time readings above could be made with the expression
- - # now.to-posix[0], but the execution time showed by the difference
- - # between the two successive readings is far slower than when the
- - # non portable pir::time__N is used instead.
- }
- proto sub pass(|$) is export { * }
- multi sub pass($desc) {
- + $time_after = nqp::p6box_n(pir::time__N);
- proclaim(1, $desc);
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- proto sub ok(|$) is export { * }
- multi sub ok(Mu $cond, $desc) {
- + $time_after = nqp::p6box_n(pir::time__N);
- proclaim(?$cond, $desc);
- + $time_before = nqp::p6box_n(pir::time__N);
- +}
- +multi sub ok(Mu $cond) {
- + $time_after = nqp::p6box_n(pir::time__N);
- + proclaim(?$cond, '');
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- -multi sub ok(Mu $cond) { ok(?$cond, ''); }
- proto sub nok(|$) is export { * }
- multi sub nok(Mu $cond, $desc) {
- + $time_after = nqp::p6box_n(pir::time__N);
- proclaim(!$cond, $desc);
- + $time_before = nqp::p6box_n(pir::time__N);
- +}
- +multi sub nok(Mu $cond) {
- + $time_after = nqp::p6box_n(pir::time__N);
- + proclaim(!$cond, '');
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- -multi sub nok(Mu $cond) { nok($cond, ''); }
- proto sub is(|$) is export { * }
- multi sub is(Mu $got, Mu $expected, $desc) {
- + $time_after = nqp::p6box_n(pir::time__N);
- $got.defined; # Hack to deal with Failures
- my $test = $got eq $expected;
- proclaim(?$test, $desc);
- @@ -87,18 +102,38 @@ multi sub is(Mu $got, Mu $expected, $desc) {
- diag "expected: '$expected'";
- }
- $test;
- + $time_before = nqp::p6box_n(pir::time__N);
- +}
- +multi sub is(Mu $got, Mu $expected) {
- + $time_after = nqp::p6box_n(pir::time__N);
- + $got.defined; # Hack to deal with Failures
- + my $test = $got eq $expected;
- + proclaim(?$test, '');
- + if !$test {
- + diag " got: '$got'";
- + diag "expected: '$expected'";
- + }
- + $test;
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- -multi sub is(Mu $got, Mu $expected) { is($got, $expected, ''); }
- proto sub isnt(|$) is export { * }
- multi sub isnt(Mu $got, Mu $expected, $desc) {
- + $time_after = nqp::p6box_n(pir::time__N);
- my $test = !($got eq $expected);
- proclaim($test, $desc);
- + $time_before = nqp::p6box_n(pir::time__N);
- +}
- +multi sub isnt(Mu $got, Mu $expected) {
- + $time_after = nqp::p6box_n(pir::time__N);
- + my $test = !($got eq $expected);
- + proclaim($test, '');
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- -multi sub isnt(Mu $got, Mu $expected) { isnt($got, $expected, ''); }
- proto sub is_approx(|$) is export { * }
- multi sub is_approx(Mu $got, Mu $expected, $desc) {
- + $time_after = nqp::p6box_n(pir::time__N);
- my $test = ($got - $expected).abs <= 1/100000;
- proclaim(?$test, $desc);
- unless $test {
- @@ -106,55 +141,91 @@ multi sub is_approx(Mu $got, Mu $expected, $desc) {
- diag("expected: $expected");
- }
- ?$test;
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- multi sub is_approx(Mu $got, Mu $expected) {
- - is_approx($got, $expected, '');
- + $time_after = nqp::p6box_n(pir::time__N);
- + my $test = ($got - $expected).abs <= 1/100000;
- + proclaim(?$test, '');
- + unless $test {
- + diag("got: $got");
- + diag("expected: $expected");
- + }
- + ?$test;
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- proto sub todo(|$) is export { * }
- multi sub todo($reason, $count) {
- + $time_after = nqp::p6box_n(pir::time__N);
- $todo_upto_test_num = $num_of_tests_run + $count;
- $todo_reason = '# TODO ' ~ $reason;
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- multi sub todo($reason) {
- + $time_after = nqp::p6box_n(pir::time__N);
- $todo_upto_test_num = $num_of_tests_run + 1;
- $todo_reason = '# TODO ' ~ $reason;
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- proto sub skip(|$) is export { * }
- -multi sub skip() { proclaim(1, "# SKIP"); }
- -multi sub skip($reason) { proclaim(1, "# SKIP " ~ $reason); }
- +multi sub skip() {
- + $time_after = nqp::p6box_n(pir::time__N);
- + proclaim(1, "# SKIP");
- + $time_before = nqp::p6box_n(pir::time__N);
- +}
- +multi sub skip($reason) {
- + $time_after = nqp::p6box_n(pir::time__N);
- + proclaim(1, "# SKIP " ~ $reason);
- + $time_before = nqp::p6box_n(pir::time__N);
- +}
- multi sub skip($reason, $count) {
- + $time_after = nqp::p6box_n(pir::time__N);
- die "skip() was passed a non-numeric number of tests. Did you get the arguments backwards?" if $count !~~ Numeric;
- my $i = 1;
- while $i <= $count { proclaim(1, "# SKIP " ~ $reason); $i = $i + 1; }
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- sub skip_rest($reason = '<unknown>') is export {
- + $time_after = nqp::p6box_n(pir::time__N);
- skip($reason, $num_of_tests_planned - $num_of_tests_run);
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- sub diag($message) is export {
- + $time_after = nqp::p6box_n(pir::time__N);
- # XXX No regexes yet in nom
- #say $message.subst(rx/^^/, '# ', :g);
- say "# " ~ $message;
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- proto sub flunk(|$) is export { * }
- -multi sub flunk($reason) { proclaim(0, "flunk $reason")}
- +multi sub flunk($reason) {
- + $time_after = nqp::p6box_n(pir::time__N);
- + proclaim(0, "flunk $reason");
- + $time_before = nqp::p6box_n(pir::time__N);
- +}
- proto sub isa_ok(|$) is export { * }
- multi sub isa_ok(Mu $var, Mu $type) {
- + $time_after = nqp::p6box_n(pir::time__N);
- ok($var.isa($type), "The object is-a '" ~ $type.perl ~ "'")
- or diag('Actual type: ' ~ $var.WHAT);
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- multi sub isa_ok(Mu $var, Mu $type, $msg) {
- + $time_after = nqp::p6box_n(pir::time__N);
- ok($var.isa($type), $msg)
- or diag('Actual type: ' ~ $var.WHAT);
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- proto sub dies_ok(|$) is export { * }
- multi sub dies_ok(Callable $closure, $reason) {
- + $time_after = nqp::p6box_n(pir::time__N);
- my $death = 1;
- my $bad_death = 0;
- try {
- @@ -169,24 +240,32 @@ multi sub dies_ok(Callable $closure, $reason) {
- #}
- }
- proclaim( $death && !$bad_death, $reason );
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- multi sub dies_ok(Callable $closure) {
- + $time_after = nqp::p6box_n(pir::time__N);
- dies_ok($closure, '');
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- proto sub lives_ok(|$) is export { * }
- multi sub lives_ok(Callable $closure, $reason){
- + $time_after = nqp::p6box_n(pir::time__N);
- try {
- $closure();
- }
- proclaim((not defined $!), $reason);
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- multi sub lives_ok(Callable $closure) {
- + $time_after = nqp::p6box_n(pir::time__N);
- lives_ok($closure, '');
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- proto sub eval_dies_ok(|$) is export { * }
- multi sub eval_dies_ok(Str $code, $reason) {
- + $time_after = nqp::p6box_n(pir::time__N);
- my $ee = eval_exception($code);
- if defined $ee {
- # XXX no regexes yet in nom
- @@ -199,22 +278,30 @@ multi sub eval_dies_ok(Str $code, $reason) {
- else {
- proclaim( 0, $reason );
- }
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- multi sub eval_dies_ok(Str $code) {
- + $time_after = nqp::p6box_n(pir::time__N);
- eval_dies_ok($code, '');
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- proto sub eval_lives_ok(|$) is export { * }
- multi sub eval_lives_ok(Str $code, $reason) {
- + $time_after = nqp::p6box_n(pir::time__N);
- proclaim((not defined eval_exception($code)), $reason);
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- multi sub eval_lives_ok(Str $code) {
- - eval_lives_ok($code, '');
- + $time_after = nqp::p6box_n(pir::time__N);
- + proclaim((not defined eval_exception($code)), '');
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- proto sub is_deeply(|$) is export { * }
- multi sub is_deeply(Mu $got, Mu $expected, $reason = '')
- {
- + $time_after = nqp::p6box_n(pir::time__N);
- my $test = _is_deeply( $got, $expected );
- proclaim($test, $reason);
- if !$test {
- @@ -226,6 +313,7 @@ multi sub is_deeply(Mu $got, Mu $expected, $reason = '')
- }
- }
- $test;
- + $time_before = nqp::p6box_n(pir::time__N);
- }
- sub _is_deeply(Mu $got, Mu $expected) {
- @@ -242,7 +330,6 @@ sub eval_exception($code) {
- sub proclaim($cond, $desc) {
- # exclude the time spent in proclaim from the test time
- - $time_after = nqp::p6box_n(pir::time__N);
- $num_of_tests_run = $num_of_tests_run + 1;
- unless $cond {
- @@ -265,8 +352,6 @@ sub proclaim($cond, $desc) {
- # must clear this between tests
- if $todo_upto_test_num == $num_of_tests_run { $todo_reason = '' }
- $cond;
- - # exclude the time spent in proclaim from the test time
- - $time_before = nqp::p6box_n(pir::time__N);
- }
- sub done_testing() is export {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement