Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Revert "Revert "Test: Copy filehandles if we can""
This reverts commit 189d1ce.
  • Loading branch information
hoelzro committed Aug 17, 2014
1 parent a756a17 commit b175465
Showing 1 changed file with 28 additions and 12 deletions.
40 changes: 28 additions & 12 deletions lib/Test.pm
Expand Up @@ -22,6 +22,22 @@ my $die_on_fail;
my $time_before;
my $time_after;

# handles
my $output = $*OUT;
my $failure_output = $*ERR;
my $todo_output = $*OUT;

try {
# XXX do this with dup or an analogous cross-platform construct
my $output_h = open('/dev/stdout', :w);
my $failure_output_h = open('/dev/stderr', :w);
my $todo_output_h = open('/dev/stdout', :w);

( $output, $failure_output, $todo_output ) = ( $output_h, $failure_output_h, $todo_output_h );

CATCH {}
}

## 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
## plans and don't call done_testing.
Expand All @@ -47,8 +63,8 @@ multi sub plan($number_of_tests) is export {
$num_of_tests_planned = $number_of_tests;
$no_plan = 0;

print $indents;
say '1..' ~ $number_of_tests;
$output.print: $indents;
$output.say: '1..' ~ $number_of_tests;
}
# 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.
Expand All @@ -57,7 +73,7 @@ multi sub plan($number_of_tests) is export {
# lot slower than the non portable nqp::p6box_n(nqp::time_n).
$time_before = nqp::p6box_n(nqp::time_n);
$time_after = nqp::p6box_n(nqp::time_n);
print $indents
$output.print: $indents
~ '# between two timestamps '
~ ceiling(($time_after-$time_before)*1_000_000) ~ ' microseconds'
~ "\n"
Expand Down Expand Up @@ -186,7 +202,7 @@ sub diag(Mu $message) is export {
$time_after = nqp::p6box_n(nqp::time_n);
my $str-message = $message.Str.subst(rx/^^/, '# ', :g);
$str-message .= subst(rx/^^'#' \s+ $$/, '', :g);
$*ERR.say: $indents ~ $str-message;
$failure_output.say: $indents ~ $str-message;
$time_before = nqp::p6box_n(nqp::time_n);
}

Expand Down Expand Up @@ -318,22 +334,22 @@ sub proclaim($cond, $desc) {
# exclude the time spent in proclaim from the test time
$num_of_tests_run = $num_of_tests_run + 1;

print $indents;
$output.print: $indents;
unless $cond {
print "not ";
$output.print: "not ";
unless $num_of_tests_run <= $todo_upto_test_num {
$num_of_tests_failed = $num_of_tests_failed + 1
}
}
if $todo_reason and $num_of_tests_run <= $todo_upto_test_num {
# TAP parsers do not like '#' in the description, they'd miss the '# TODO'
print "ok ", $num_of_tests_run, " - ", $desc.subst('#', '', :g), $todo_reason;
$output.print: "ok ", $num_of_tests_run, " - ", $desc.subst('#', '', :g), $todo_reason;
}
else {
print "ok ", $num_of_tests_run, " - ", $desc;
$output.print: "ok ", $num_of_tests_run, " - ", $desc;
}
print "\n";
print $indents
$output.print: "\n";
$output.print: $indents
~ "# t="
~ ceiling(($time_after-$time_before)*1_000_000)
~ "\n"
Expand Down Expand Up @@ -365,8 +381,8 @@ sub done() is export {

if $no_plan {
$num_of_tests_planned = $num_of_tests_run;
print $indents;
say "1..$num_of_tests_planned";
$output.print: $indents;
$output.say: "1..$num_of_tests_planned";
}

if ($num_of_tests_planned != $num_of_tests_run) { ##Wrong quantity of tests
Expand Down

0 comments on commit b175465

Please sign in to comment.