package Test::Builder; use 5.008001; use strict; use warnings; use Test::Builder::Util qw/try/; use Scalar::Util(); use Test::Builder::Stream; use Test::Builder::Result; use Test::Builder::Result::Ok; use Test::Builder::Result::Diag; use Test::Builder::Result::Note; use Test::Builder::Result::Plan; use Test::Builder::Result::Bail; use Test::Builder::Result::Child; use Test::Builder::Trace; our $VERSION = '1.301001_010'; $VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) # The mostly-singleton, and other package vars. our $Test = Test::Builder->new; our $Level = 1; our $BLevel = 1; #################### # {{{ MAGIC things # #################### sub DESTROY { my $self = shift; if ( $self->parent and $$ == $self->{Original_Pid} ) { my $name = $self->name; $self->diag(<<"FAIL"); Child ($name) exited without calling finalize() FAIL $self->parent->{In_Destroy} = 1; $self->parent->ok(0, $name); } } require Test::Builder::ExitMagic; my $final = Test::Builder::ExitMagic->new( tb => Test::Builder->create(shared_stream => 1), ); END { $final->do_magic() } #################### # }}} MAGIC things # #################### #################### # {{{ Constructors # #################### sub new { my $class = shift; my %params = @_; $Test ||= $class->create(shared_stream => 1); return $Test; } sub create { my $class = shift; my %params = @_; my $self = bless {}, $class; $self->reset(%params); return $self; } # Copy an object, currently a shallow. # This does *not* bless the destination. This keeps the destructor from # firing when we're just storing a copy of the object to restore later. sub _copy { my($src, $dest) = @_; %$dest = %$src; #_share_keys($dest); # Not sure the implications here. return; } #################### # }}} Constructors # #################### ############################################## # {{{ Simple accessors/generators/deligators # ############################################## sub listen { shift->stream->listen(@_) } sub munge { shift->stream->munge(@_) } sub tap { shift->stream->tap } sub lresults { shift->stream->lresults } sub is_passing { shift->stream->is_passing(@_) } sub use_fork { shift->stream->use_fork } sub no_fork { shift->stream->no_fork } BEGIN { Test::Builder::Util::accessors(qw/Parent Name _old_level _bailed_out/); Test::Builder::Util::accessor(modern => sub {$ENV{TB_MODERN} || 0}); Test::Builder::Util::accessor(depth => sub { 0 }); } ############################################## # }}} Simple accessors/generators/deligators # ############################################## ######################### # {{{ Stream Management # ######################### sub stream { my $self = shift; ($self->{stream}) = @_ if @_; # If no stream is set use shared. We do not want to cache that we use # shared cause shared is a stack, not a constant, and we always want the # top. return $self->{stream} || Test::Builder::Stream->shared; } sub intercept { my $self = shift; my ($code) = @_; Carp::croak("argument to intercept must be a coderef, got: $code") unless reftype $code eq 'CODE'; my $stream = Test::Builder::Stream->new(no_follow => 1) || die "Internal Error!"; $stream->exception_followup; local $self->{stream} = $stream; my @results; $stream->listen(INTERCEPTOR => sub { my ($item) = @_; push @results => $item; }); $code->($stream); return \@results; } ######################### # }}} Stream Management # ######################### ############################# # {{{ Children and subtests # ############################# sub child { my( $self, $name, $is_subtest ) = @_; $self->croak("You already have a child named ($self->{Child_Name}) running") if $self->{Child_Name}; my $parent_in_todo = $self->in_todo; # Clear $TODO for the child. my $orig_TODO = $self->find_TODO(undef, 1, undef); my $class = Scalar::Util::blessed($self); my $child = $class->create; $child->{stream} = $self->stream->spawn; # Ensure the child understands if they're inside a TODO $child->tap->failure_output($self->tap->todo_output) if $parent_in_todo && $self->tap; # This will be reset in finalize. We do this here lest one child failure # cause all children to fail. $child->{Child_Error} = $?; $? = 0; $child->{Parent} = $self; $child->{Parent_TODO} = $orig_TODO; $child->{Name} = $name || "Child of " . $self->name; $self->{Child_Name} = $child->name; $child->depth($self->depth + 1); my $res = Test::Builder::Result::Child->new( $self->context, name => $name || undef, action => 'push', in_todo => $self->in_todo || 0, is_subtest => $is_subtest || 0, ); $self->stream->send($res); return $child; } sub subtest { my $self = shift; my($name, $subtests, @args) = @_; $self->croak("subtest()'s second argument must be a code ref") unless $subtests && 'CODE' eq Scalar::Util::reftype($subtests); # Turn the child into the parent so anyone who has stored a copy of # the Test::Builder singleton will get the child. my ($success, $error, $child); my $parent = {}; { local $Level = $Level + 1; local $BLevel = $BLevel + 1; # Store the guts of $self as $parent and turn $child into $self. $child = $self->child($name, 1); _copy($self, $parent); _copy($child, $self); Test::Builder::Stream->intercept_start($self->stream); my $run_the_subtests = sub { $subtests->(@args); $self->done_testing unless defined $self->stream->plan; 1; }; ($success, $error) = try { Test::Builder::Trace->nest($run_the_subtests) }; } # Restore the parent and the copied child. Test::Builder::Stream->intercept_stop($self->stream); _copy($self, $child); _copy($parent, $self); # Restore the parent's $TODO $self->find_TODO(undef, 1, $child->{Parent_TODO}); # Die *after* we restore the parent. die $error if $error && !(Scalar::Util::blessed($error) && $error->isa('Test::Builder::Exception')); local $Level = $Level + 1; local $BLevel = $BLevel + 1; my $finalize = $child->finalize(1); $self->BAIL_OUT($child->{Bailed_Out_Reason}) if $child->_bailed_out; return $finalize; } sub finalize { my $self = shift; my ($is_subtest) = @_; return unless $self->parent; if( $self->{Child_Name} ) { $self->croak("Can't call finalize() with child ($self->{Child_Name}) active"); } local $? = 0; # don't fail if $subtests happened to set $? nonzero $self->_ending; local $Level = $Level + 1; local $BLevel = $BLevel + 1; my $ok = 1; $self->parent->{Child_Name} = undef; unless ($self->_bailed_out) { if ( $self->{Skip_All} ) { $self->parent->skip($self->{Skip_All}); } elsif ( ! $self->stream->tests_run ) { $self->parent->ok( 0, sprintf q[No tests run for subtest "%s"], $self->name ); } else { $self->parent->ok( $self->is_passing, $self->name ); } } $? = $self->{Child_Error}; delete $self->{Parent}; my $res = Test::Builder::Result::Child->new( $self->context, name => $self->{Name} || undef, action => 'pop', in_todo => $self->in_todo || 0, is_subtest => $is_subtest || 0, ); $self->stream->send($res); return $self->is_passing; } ############################# # }}} Children and subtests # ############################# ##################################### # {{{ Finding Testers and Providers # ##################################### sub trace_test { return Test::Builder::Trace->new; } sub find_TODO { my( $self, $pack, $set, $new_value ) = @_; $pack ||= $self->trace_test->todo_package || $self->exported_to; return unless $pack; no strict 'refs'; ## no critic no warnings 'once'; my $old_value = ${ $pack . '::TODO' }; $set and ${ $pack . '::TODO' } = $new_value; return $old_value; } ##################################### # }}} Finding Testers and Providers # ##################################### ################ # {{{ Planning # ################ my %PLAN_CMDS = ( no_plan => 'no_plan', skip_all => 'skip_all', tests => '_plan_tests', ); sub plan { my( $self, $cmd, $arg ) = @_; return unless $cmd; local $Level = $Level + 1; local $BLevel = $BLevel + 1; if( my $method = $PLAN_CMDS{$cmd} ) { local $Level = $Level + 1; local $BLevel = $BLevel + 1; $self->$method($arg); } else { my @args = grep { defined } ( $cmd, $arg ); $self->croak("plan() doesn't understand @args"); } return 1; } sub skip_all { my( $self, $reason ) = @_; $self->{Skip_All} = $self->parent ? $reason : 1; die bless {} => 'Test::Builder::Exception' if $self->parent; $self->_issue_plan(0, "SKIP", $reason); } sub no_plan { my($self, $arg) = @_; $self->carp("no_plan takes no arguments") if $arg; $self->_issue_plan(undef, "NO_PLAN"); return 1; } sub _plan_tests { my($self, $arg) = @_; if($arg) { $self->croak("Number of tests must be a positive integer. You gave it '$arg'") unless $arg =~ /^\+?\d+$/; $self->_issue_plan($arg); } elsif( !defined $arg ) { $self->croak("Got an undefined number of tests"); } else { $self->croak("You said to run 0 tests"); } return; } sub _issue_plan { my($self, $max, $directive, $reason) = @_; if ($directive && $directive eq 'OVERRIDE') { $directive = undef; } elsif ($self->stream->plan) { $self->croak("You tried to plan twice"); } my $plan = Test::Builder::Result::Plan->new( $self->context, directive => $directive || undef, reason => $reason || undef, in_todo => $self->in_todo || 0, max => defined($max) ? $max : undef, ); $self->stream->send($plan); return $plan; } sub done_testing { my($self, $num_tests) = @_; my $expected = $self->stream->expected_tests; my $total = $self->stream->tests_run; # If done_testing() specified the number of tests, shut off no_plan. if(defined $num_tests && !defined $expected) { $self->_issue_plan($num_tests, 'OVERRIDE'); $expected = $num_tests; } if( $self->{Done_Testing} ) { my($file, $line) = @{$self->{Done_Testing}}[1,2]; my $ok = Test::Builder::Result::Ok->new( $self->context, real_bool => 0, name => "done_testing() was already called at $file line $line", bool => $self->in_todo ? 1 : 0, in_todo => $self->in_todo || 0, todo => $self->in_todo ? $self->todo() || "" : "", ); $self->stream->send($ok); $self->is_passing(0) unless $self->in_todo; return; } $self->{Done_Testing} = [caller]; if ($expected && defined($num_tests) && $num_tests != $expected) { my $ok = Test::Builder::Result::Ok->new( $self->context, real_bool => 0, name => "planned to run $expected but done_testing() expects $num_tests", bool => $self->in_todo ? 1 : 0, in_todo => $self->in_todo || 0, todo => $self->in_todo ? $self->todo() || "" : "", ); $self->stream->send($ok); $self->is_passing(0) unless $self->in_todo; } $self->_issue_plan($total) unless $expected; # The wrong number of tests were run $self->is_passing(0) if defined $expected && $expected != $total; # No tests were run $self->is_passing(0) unless $total; return 1; } ################ # }}} Planning # ################ ############################# # {{{ Base Result Producers # ############################# sub ok { my( $self, $test, $name ) = @_; if ( $self->{Child_Name} and not $self->{In_Destroy} ) { $name = 'unnamed test' unless defined $name; $self->is_passing(0); $self->croak("Cannot run test ($name) with active children"); } # $test might contain an object which we don't want to accidentally # store, so we turn it into a boolean. $test = $test ? 1 : 0; # In case $name is a string overloaded object, force it to stringify. $self->_unoverload_str( \$name ); $self->diag(<<"ERR") if defined $name and $name =~ /^[\d\s]+$/; You named your test '$name'. You shouldn't use numbers for your test names. Very confusing. ERR # Capture the value of $TODO for the rest of this ok() call # so it can more easily be found by other routines. my $todo = $self->todo(); my $in_todo = $self->in_todo; local $self->{Todo} = $todo if $in_todo; $self->_unoverload_str( \$todo ); my $ok = Test::Builder::Result::Ok->new( $self->context, real_bool => $test, bool => $self->in_todo ? 1 : $test, name => $name || undef, in_todo => $self->in_todo || 0, ); # # in a name can confuse Test::Harness. $name =~ s|#|\\#|g if defined $name; if( $self->in_todo ) { $ok->todo($todo); $ok->in_todo(1); } $self->stream->send($ok); $self->is_passing(0) unless $test || $self->in_todo; # Check that we haven't violated the plan $self->_check_is_passing_plan(); return $test ? 1 : 0; } sub BAIL_OUT { my( $self, $reason ) = @_; $self->_bailed_out(1); if ($self->parent) { $self->{Bailed_Out_Reason} = $reason; $self->no_ending(1); die bless {} => 'Test::Builder::Exception'; } my $bail = Test::Builder::Result::Bail->new( $self->context, reason => $reason, in_todo => $self->in_todo || 0, ); $self->stream->send($bail); } sub skip { my( $self, $why ) = @_; $why ||= ''; $self->_unoverload_str( \$why ); my $ok = Test::Builder::Result::Ok->new( $self->context, real_bool => 1, bool => 1, in_todo => $self->in_todo || 0, skip => $why, ); $self->stream->send($ok); } sub todo_skip { my( $self, $why ) = @_; $why ||= ''; my $ok = Test::Builder::Result::Ok->new( $self->context, real_bool => 0, bool => 1, in_todo => $self->in_todo || 0, skip => $why, todo => $why, ); $self->stream->send($ok); } sub diag { my $self = shift; my $msg = join '', map { defined($_) ? $_ : 'undef' } @_; my $r = Test::Builder::Result::Diag->new( $self->context, in_todo => $self->in_todo || 0, message => $msg, ); $self->stream->send($r); } sub note { my $self = shift; my $msg = join '', map { defined($_) ? $_ : 'undef' } @_; my $r = Test::Builder::Result::Note->new( $self->context, in_todo => $self->in_todo || 0, message => $msg, ); $self->stream->send($r); } ############################# # }}} Base Result Producers # ############################# ################################# # {{{ Advanced Result Producers # ################################# my %numeric_cmps = map { ( $_, 1 ) } ( "<", "<=", ">", ">=", "==", "!=", "<=>" ); # Bad, these are not comparison operators. Should we include more? my %cmp_ok_bl = map { ( $_, 1 ) } ( "=", "+=", ".=", "x=", "^=", "|=", "||=", "&&=", "..."); sub cmp_ok { my( $self, $got, $type, $expect, $name ) = @_; if ($cmp_ok_bl{$type}) { $self->croak("$type is not a valid comparison operator in cmp_ok()"); } my $test; my $error; my($pack, $file, $line) = $self->trace_test->report->call; (undef, $error) = try { # This is so that warnings come out at the caller's level ## no critic (BuiltinFunctions::ProhibitStringyEval) eval qq[ #line $line "(eval in cmp_ok) $file" \$test = \$got $type \$expect; 1; ] || die $@; }; local $Level = $Level + 1; local $BLevel = $BLevel + 1; my $ok = $self->ok( $test, $name ); # Treat overloaded objects as numbers if we're asked to do a # numeric comparison. my $unoverload = $numeric_cmps{$type} ? '_unoverload_num' : '_unoverload_str'; $self->diag(<<"END") if $error; An error occurred while using $type: ------------------------------------ $error ------------------------------------ END unless($ok) { $self->$unoverload( \$got, \$expect ); if( $type =~ /^(eq|==)$/ ) { $self->_is_diag( $got, $type, $expect ); } elsif( $type =~ /^(ne|!=)$/ ) { $self->_isnt_diag( $got, $type ); } else { $self->_cmp_diag( $got, $type, $expect ); } } return $ok; } sub is_eq { my( $self, $got, $expect, $name ) = @_; local $Level = $Level + 1; local $BLevel = $BLevel + 1; if( !defined $got || !defined $expect ) { # undef only matches undef and nothing else my $test = !defined $got && !defined $expect; $self->ok( $test, $name ); $self->_is_diag( $got, 'eq', $expect ) unless $test; return $test; } return $self->cmp_ok( $got, 'eq', $expect, $name ); } sub is_num { my( $self, $got, $expect, $name ) = @_; local $Level = $Level + 1; local $BLevel = $BLevel + 1; if( !defined $got || !defined $expect ) { # undef only matches undef and nothing else my $test = !defined $got && !defined $expect; $self->ok( $test, $name ); $self->_is_diag( $got, '==', $expect ) unless $test; return $test; } return $self->cmp_ok( $got, '==', $expect, $name ); } sub isnt_eq { my( $self, $got, $dont_expect, $name ) = @_; local $Level = $Level + 1; local $BLevel = $BLevel + 1; if( !defined $got || !defined $dont_expect ) { # undef only matches undef and nothing else my $test = defined $got || defined $dont_expect; $self->ok( $test, $name ); $self->_isnt_diag( $got, 'ne' ) unless $test; return $test; } return $self->cmp_ok( $got, 'ne', $dont_expect, $name ); } sub isnt_num { my( $self, $got, $dont_expect, $name ) = @_; local $Level = $Level + 1; local $BLevel = $BLevel + 1; if( !defined $got || !defined $dont_expect ) { # undef only matches undef and nothing else my $test = defined $got || defined $dont_expect; $self->ok( $test, $name ); $self->_isnt_diag( $got, '!=' ) unless $test; return $test; } return $self->cmp_ok( $got, '!=', $dont_expect, $name ); } sub like { my( $self, $thing, $regex, $name ) = @_; local $Level = $Level + 1; local $BLevel = $BLevel + 1; return $self->_regex_ok( $thing, $regex, '=~', $name ); } sub unlike { my( $self, $thing, $regex, $name ) = @_; local $Level = $Level + 1; local $BLevel = $BLevel + 1; return $self->_regex_ok( $thing, $regex, '!~', $name ); } ################################# # }}} Advanced Result Producers # ################################# ####################### # {{{ Public helpers # ####################### sub explain { my $self = shift; return map { ref $_ ? do { $self->_try(sub { require Data::Dumper }, die_on_fail => 1); my $dumper = Data::Dumper->new( [$_] ); $dumper->Indent(1)->Terse(1); $dumper->Sortkeys(1) if $dumper->can("Sortkeys"); $dumper->Dump; } : $_ } @_; } sub carp { my $self = shift; return warn $self->_message_at_caller(@_); } sub croak { my $self = shift; return die $self->_message_at_caller(@_); } sub context { my $self = shift; my $trace = $self->trace_test; return ( depth => $self->depth, source => $self->name || "", trace => $trace, ); } sub has_plan { my $self = shift; return($self->stream->expected_tests) if $self->stream->expected_tests; return('no_plan') if $self->stream->plan; return(undef); } sub reset { ## no critic (Subroutines::ProhibitBuiltinHomonyms) my $self = shift; my %params; if (@_) { %params = @_; $self->{reset_params} = \%params; } else { %params = %{$self->{reset_params} || {}}; } my $modern = $params{modern} || $self->modern || 0; $self->modern($modern); # We leave this a global because it has to be localized and localizing # hash keys is just asking for pain. Also, it was documented. $Level = 1; $BLevel = 1; if ($params{new_stream} || !$params{shared_stream}) { $self->{stream} = Test::Builder::Stream->new; } $final->pid($$) if $final; $self->stream->use_tap unless $params{no_tap} || $ENV{TB_NO_TAP}; $self->stream->plan(undef) unless $params{no_reset_plan}; # Don't reset stream stuff when reseting/creating a modern TB object unless ($modern) { $self->stream->use_lresults unless $modern || $params{no_legacy} || $ENV{TB_NO_LEGACY}; $self->stream->no_ending(0); $self->tap->reset if $self->tap; $self->lresults->reset if $self->lresults; } $self->{Name} = $0; $self->{Have_Issued_Plan} = 0; $self->{Done_Testing} = 0; $self->{Skip_All} = 0; $self->{Original_Pid} = $$; $self->{Child_Name} = undef; $self->{Indent} ||= ''; $self->{Depth} = 0; $self->{Exported_To} = undef; $self->{Expected_Tests} = 0; $self->{Todo} = undef; $self->{Todo_Stack} = []; $self->{Start_Todo} = 0; $self->{Opened_Testhandles} = 0; return; } ####################### # }}} Public helpers # ####################### #################### # {{{ TODO related # #################### sub todo { my( $self, $pack ) = @_; return $self->{Todo} if defined $self->{Todo}; local $Level = $Level + 1; local $BLevel = $BLevel + 1; my $todo = $self->find_TODO($pack); return $todo if defined $todo; return ''; } sub in_todo { my $self = shift; local $Level = $Level + 1; local $BLevel = $BLevel + 1; return( defined $self->{Todo} || $self->find_TODO ) ? 1 : 0; } sub todo_start { my $self = shift; my $message = @_ ? shift : ''; $self->{Start_Todo}++; if( $self->in_todo ) { push @{ $self->{Todo_Stack} } => $self->todo; } $self->{Todo} = $message; return; } sub todo_end { my $self = shift; if( !$self->{Start_Todo} ) { $self->croak('todo_end() called without todo_start()'); } $self->{Start_Todo}--; if( $self->{Start_Todo} && @{ $self->{Todo_Stack} } ) { $self->{Todo} = pop @{ $self->{Todo_Stack} }; } else { delete $self->{Todo}; } return; } #################### # }}} TODO related # #################### ####################### # {{{ Private helpers # ####################### # Check that we haven't yet violated the plan and set # is_passing() accordingly sub _check_is_passing_plan { my $self = shift; my $plan = $self->stream->expected_tests; return unless defined $plan; # no plan yet defined return unless $plan !~ /\D/; # no numeric plan $self->is_passing(0) if $plan < $self->stream->tests_run; } sub _is_object { my( $self, $thing ) = @_; return $self->_try( sub { ref $thing && $thing->isa('UNIVERSAL') } ) ? 1 : 0; } sub _unoverload { my $self = shift; my $type = shift; $self->_try(sub { require overload; }, die_on_fail => 1); foreach my $thing (@_) { if( $self->_is_object($$thing) ) { if( my $string_meth = overload::Method( $$thing, $type ) ) { $$thing = $$thing->$string_meth(); } } } return; } sub _unoverload_str { my $self = shift; return $self->_unoverload( q[""], @_ ); } sub _unoverload_num { my $self = shift; $self->_unoverload( '0+', @_ ); for my $val (@_) { next unless $self->_is_dualvar($$val); $$val = $$val + 0; } return; } # This is a hack to detect a dualvar such as $! sub _is_dualvar { my( $self, $val ) = @_; # Objects are not dualvars. return 0 if ref $val; no warnings 'numeric'; my $numval = $val + 0; return ($numval != 0 and $numval ne $val ? 1 : 0); } sub _diag_fmt { my( $self, $type, $val ) = @_; if( defined $$val ) { if( $type eq 'eq' or $type eq 'ne' ) { # quote and force string context $$val = "'$$val'"; } else { # force numeric context $self->_unoverload_num($val); } } else { $$val = 'undef'; } return; } sub _is_diag { my( $self, $got, $type, $expect ) = @_; local $Level = $Level + 1; local $BLevel = $BLevel + 1; $self->_diag_fmt( $type, $_ ) for \$got, \$expect; return $self->diag(<<"DIAGNOSTIC"); got: $got expected: $expect DIAGNOSTIC } sub _isnt_diag { my( $self, $got, $type ) = @_; local $Level = $Level + 1; local $BLevel = $BLevel + 1; $self->_diag_fmt( $type, \$got ); return $self->diag(<<"DIAGNOSTIC"); got: $got expected: anything else DIAGNOSTIC } sub _cmp_diag { my( $self, $got, $type, $expect ) = @_; $got = defined $got ? "'$got'" : 'undef'; $expect = defined $expect ? "'$expect'" : 'undef'; local $Level = $Level + 1; local $BLevel = $BLevel + 1; return $self->diag(<<"DIAGNOSTIC"); $got $type $expect DIAGNOSTIC } sub _caller_context { my $self = shift; my($pack, $file, $line) = $self->trace_test->report->call; my $code = ''; $code .= "#line $line $file\n" if defined $file and defined $line; return $code; } sub _regex_ok { my( $self, $thing, $regex, $cmp, $name ) = @_; my $ok = 0; my $usable_regex = _is_qr($regex) ? $regex : $self->maybe_regex($regex); unless( defined $usable_regex ) { local $Level = $Level + 1; local $BLevel = $BLevel + 1; $ok = $self->ok( 0, $name ); $self->diag(" '$regex' doesn't look much like a regex to me."); return $ok; } { my $test; my $context = $self->_caller_context; try { # No point in issuing an uninit warning, they'll see it in the diagnostics no warnings 'uninitialized'; ## no critic (BuiltinFunctions::ProhibitStringyEval) $test = eval $context . q{$test = $thing =~ /$usable_regex/ ? 1 : 0}; }; $test = !$test if $cmp eq '!~'; local $Level = $Level + 1; local $BLevel = $BLevel + 1; $ok = $self->ok( $test, $name ); } unless($ok) { $thing = defined $thing ? "'$thing'" : 'undef'; my $match = $cmp eq '=~' ? "doesn't match" : "matches"; local $Level = $Level + 1; local $BLevel = $BLevel + 1; $self->diag( sprintf <<'DIAGNOSTIC', $thing, $match, $regex ); %s %13s '%s' DIAGNOSTIC } return $ok; } # I'm not ready to publish this. It doesn't deal with array return # values from the code or context. sub _try { my( $self, $code, %opts ) = @_; my $result; my ($ok, $error) = try { $result = $code->() }; die $error if $opts{die_on_fail} && !$ok; return wantarray ? ( $result, $error ) : $result; } sub _message_at_caller { my $self = shift; local $Level = $Level + 1; local $BLevel = $BLevel + 1; my $trace = $self->trace_test; my( $pack, $file, $line ) = $trace->report->call; return join( "", @_ ) . " at $file line $line.\n"; } #'# sub _sanity_check { my $self = shift; $self->_whoa( $self->stream->tests_run < 0, 'Says here you ran a negative number of tests!' ); $self->lresults->sanity_check($self) if $self->lresults; return; } sub _whoa { my( $self, $check, $desc ) = @_; if($check) { local $Level = $Level + 1; local $BLevel = $BLevel + 1; $self->croak(<<"WHOA"); WHOA! $desc This should never happen! Please contact the author immediately! WHOA } return; } sub _ending { my $self = shift; require Test::Builder::ExitMagic; my $ending = Test::Builder::ExitMagic->new(tb => $self, stream => $self->stream); $ending->do_magic; } sub _is_qr { my $regex = shift; # is_regexp() checks for regexes in a robust manner, say if they're # blessed. return re::is_regexp($regex) if defined &re::is_regexp; return ref $regex eq 'Regexp'; } ####################### # }}} Private helpers # ####################### ################################################ # {{{ Everything below this line is deprecated # # But it must be maintained for legacy... # ################################################ BEGIN { my %generate = ( lresults => [qw/summary details/], stream => [qw/no_ending/], tap => [qw/ no_header no_diag output failure_output todo_output reset_outputs use_numbers _new_fh /], ); for my $delegate (keys %generate) { for my $method (@{$generate{$delegate}}) { #print STDERR "Adding: $method ($delegate)\n"; my $code = sub { my $self = shift; $self->carp("Use of \$TB->$method() is deprecated.") if $self->modern; my $d = $self->$delegate || $self->croak("$method() method only applies when $delegate is in use"); $d->$method(@_); }; no strict 'refs'; ## no critic *{$method} = $code; } } } sub exported_to { my($self, $pack) = @_; $self->carp("exported_to() is deprecated") if $self->modern; $self->{Exported_To} = $pack if defined $pack; return $self->{Exported_To}; } sub _indent { my $self = shift; $self->carp("_indent() is deprecated") if $self->modern; return '' unless $self->depth; return ' ' x $self->depth } sub _output_plan { my ($self) = @_; $self->carp("_output_plan() is deprecated") if $self->modern; goto &_issue_plan; } sub _diag_fh { my $self = shift; $self->carp("Use of \$TB->_diag_fh() is deprecated.") if $self->modern; my $tap = $self->tap || $self->croak("_diag_fh() method only applies when TAP is in use"); local $Level = $Level + 1; local $BLevel = $BLevel + 1; return $tap->_diag_fh($self->in_todo) } sub _print { my $self = shift; $self->carp("Use of \$TB->_print() is deprecated.") if $self->modern; my $tap = $self->tap || $self->croak("_print() method only applies when TAP is in use"); return $tap->_print($self->_indent, @_); } sub _print_to_fh { my( $self, $fh, @msgs ) = @_; $self->carp("Use of \$TB->_print_to_fh() is deprecated.") if $self->modern; my $tap = $self->tap || $self->croak("_print_to_fh() method only applies when TAP is in use"); return $tap->_print_to_fh($fh, $self->_indent, @msgs); } sub is_fh { my $self = shift; $self->carp("Use of \$TB->is_fh() is deprecated.") if Scalar::Util::blessed($self) && $self->modern; require Test::Builder::Formatter::TAP; return Test::Builder::Formatter::TAP->is_fh(@_); } sub current_test { my $self = shift; $self->carp('Use of $TB->current_test() is deprecated.') if $self->modern; my $lresults = $self->lresults || $self->croak("current_test() method only applies when legacy results are in use"); return $lresults->current_test($self, @_); } sub BAILOUT { my ($self) = @_; $self->carp("Use of \$TB->BAILOUT() is deprecated.") if $self->modern; goto &BAIL_OUT; } sub expected_tests { my $self = shift; if(@_) { my ($max) = @_; $self->carp("Use of \$TB->expected_tests(\$max) is deprecated.") if $self->modern; $self->_issue_plan($max); } return $self->stream->expected_tests || 0; } sub caller { ## no critic (Subroutines::ProhibitBuiltinHomonyms) my $self = shift; Carp::confess("Use of Test::Builder->caller() is deprecated.\n") if $self->modern; local $Level = $Level + 1; local $BLevel = $BLevel + 1; my $trace = $self->trace_test; return unless $trace && $trace->report; my @call = $trace->report->call; return wantarray ? @call : $call[0]; } sub level { my( $self, $level ) = @_; $Level = $level if defined $level; return $Level; } sub maybe_regex { my ($self, $regex) = @_; my $usable_regex = undef; $self->carp("Use of \$TB->maybe_regex() is deprecated.") if $self->modern; return $usable_regex unless defined $regex; my( $re, $opts ); # Check for qr/foo/ if( _is_qr($regex) ) { $usable_regex = $regex; } # Check for '/foo/' or 'm,foo,' elsif(( $re, $opts ) = $regex =~ m{^ /(.*)/ (\w*) $ }sx or ( undef, $re, $opts ) = $regex =~ m,^ m([^\w\s]) (.+) \1 (\w*) $,sx ) { $usable_regex = length $opts ? "(?$opts)$re" : $re; } return $usable_regex; } ################################### # }}} End of deprecations section # ################################### #################### # {{{ TB1.5 stuff # #################### # This is just a list of method Test::Builder current does not have that Test::Builder 1.5 does. my @TB15_METHODS = qw{ _file_and_line _join_message _make_default _my_exit _reset_todo_state _result_to_hash _results _todo_state formatter history in_subtest in_test no_change_exit_code post_event post_result set_formatter set_plan test_end test_exit_code test_start test_state }; for my $m (@TB15_METHODS) { # Don't set this if the method actually exists in this version. next if __PACKAGE__->can($m); no strict 'refs'; *$m = sub { die <<" EOT"; ************************************************************************* '$m' is a Test::Builder 1.5 method. Test::Builder 1.5 is a dead branch. You need to update your code so that it no longer treats Test::Builders over a specific version number as anything special. See: http://blogs.perl.org/users/chad_exodist_granum/2014/03/testmore---new-maintainer-also-stop-version-checking.html ************************************************************************* EOT }; } #################### # }}} TB1.5 stuff # #################### 1; __END__ =head1 NAME Test::Builder - Backend for building test libraries =head1 SYNOPSIS In general you probably do not want to use this module directly, but instead want to use L which will help you roll out a testing library. package My::Test::Module; use Test::Builder::Provider; # Export a test tool from an anonymous sub provide ok => sub { my ($test, $name) = @_; builder()->ok($test, $name); }; # Export tools that are package subs provides qw/is is_deeply/; sub is { ... } sub is_deeply { ... } See L for more details. B You MUST use 'provide', or 'provides' to export testing tools, this allows you to use the C<< builder()->trace_test >> tools to determine what file/line a failed test came from. =head2 LOW-LEVEL use Test::Builder; my $tb = Test::Builder->create(modern => 1, shared_stream => 1); $tb->ok(1); .... =head2 DEPRECATED use Test::Builder; my $tb = Test::Builder->new; $tb->ok(1); ... =head1 DESCRIPTION L and L have proven to be popular testing modules, but they're not always flexible enough. Test::Builder provides a building block upon which to write your own test libraries I. =head1 TEST COMPONENT MAP [Test Script] > [Test Tool] > [Test::Builder] > [Test::Bulder::Stream] > [Result Formatter] ^ You are here A test script uses a test tool such as L, which uses Test::Builder to produce results. The results are sent to L which then forwards them on to one or more formatters. The default formatter is L which produces TAP output. =head1 METHODS =head2 CONSTRUCTION =over 4 =item $Test = Test::Builder->create(%params) Create a completely independant Test::Builder object. my $Test = Test::Builder->create; Create a Test::Builder object that sends results to the shared output stream (usually what you want). my $Test = Test::Builder->create(shared_stream => 1); Create a Test::Builder object that does not include any legacy cruft. my $Test = Test::Builder->create(modern => 1); B: C<$Level> is tied to the package, not the instance. Basically this means you should avoid using $Level in favor of the trace_test method. $Level still exists purely for legacy support. =item $Test = Test::Builder->new B<***DEPRECATED***> my $Test = Test::Builder->new; B Returns the Test::Builder singleton object representing the current state of the test. Since you only run one test per program C always returns the same Test::Builder object. No matter how many times you call C, you're getting the same object. This is called a singleton. This is done so that multiple modules share such global information as the test counter and where test output is going. B If you want a completely new Test::Builder object different from the singleton, use C. =back =head2 SIMPLE ACCESSORS AND SHORTCUTS =head3 READ/WRITE ATTRIBUTES =over 4 =item $parent = $Test->parent Returns the parent C instance, if any. Only used with child builders for nested TAP. =item $Test->name Defaults to $0, but subtests and child tests will set this. =item $Test->modern Defaults to $ENV{TB_MODERN}, or 0. True when the builder object was constructed with modern practices instead of deprecated ones. =item $Test->depth Get/Set the depth. This is usually set for Child tests. =back =head3 DELEGATES TO STREAM Each of these is a shortcut to C<< $Test->stream->NAME >> See the L documentation for details. =over 4 =item $Test->is_passing(...) =item $Test->listen(...) =item $Test->munge(...) =item $Test->tap =item $Test->lresults =item $Test->use_fork =item $Test->no_fork =back =head2 CHILDREN AND SUBTESTS =over 4 =item $Test->subtest($name, \&subtests, @args) See documentation of C in Test::More. C also, and optionally, accepts arguments which will be passed to the subtests reference. =item $child = $Test->child($name) my $child = $builder->child($name_of_child); $child->plan( tests => 4 ); $child->ok(some_code()); ... $child->finalize; Returns a new instance of C. Any output from this child will be indented four spaces more than the parent's indentation. When done, the C method I be called explicitly. Trying to create a new child with a previous child still active (i.e., C not called) will C. Trying to run a test when you have an open child will also C and cause the test suite to fail. =item $ok = $Child->finalize When your child is done running tests, you must call C to clean up and tell the parent your pass/fail status. Calling C on a child with open children will C. If the child falls out of scope before C is called, a failure diagnostic will be issued and the child is considered to have failed. No attempt to call methods on a child after C is called is guaranteed to succeed. Calling this on the root builder is a no-op. =back =head2 STREAM MANAGEMENT =over 4 =item $stream = $Test->stream =item $Test->stream($stream) =item $Test->stream(undef) Get/Set the stream. When no stream is set, or is undef it will return the shared stream. B Do not set this to the shared stream yourself, set it to undef. This is because the shared stream is actually a stack, and this always returns the top of the stack. =item $results = $Test->intercept(\&code) Any tests run inside the codeblock will be intercepted and not sent to the normal stream. Instead they will be added to C<$results> which is an array of L objects. B This will also intercept BAIL_OUT and skipall. B This will only intercept results generated with the Test::Builder object on which C was called. Other builders will still send to the normal places. See L for a method of capturing results sent to the global stream. =back =head2 TRACING THE TEST/PROVIDER BOUNDRY When a test fails it will report the filename and line where the failure occured. In order to do this it needs to look at the stack and figure out where your tests stop, and the tools you are using begin. These methods help you find the desired caller frame. See the L module for more details. =over 4 =item $trace = $Test->trace_test() Returns an L object. =item $reason = $Test->find_TODO =item $reason = $Test->find_TODO($pack) =item $old_reason = $Test->find_TODO($pack, 1, $new_reason); Like C but only returns the value of C<$TODO> ignoring C. Can also be used to set C<$TODO> to a new value while returning the old value. =back =head2 TEST PLAN =over 4 =item $Test->plan('no_plan'); =item $Test->plan( skip_all => $reason ); =item $Test->plan( tests => $num_tests ); A convenient way to set up your tests. Call this and Test::Builder will print the appropriate headers and take the appropriate actions. If you call C, don't call any of the other methods below. If a child calls "skip_all" in the plan, a C is thrown. Trap this error, call C and don't run any more tests on the child. my $child = $Test->child('some child'); eval { $child->plan( $condition ? ( skip_all => $reason ) : ( tests => 3 ) ) }; if ( eval { $@->isa('Test::Builder::Exception') } ) { $child->finalize; return; } # run your tests =item $Test->no_plan; Declares that this test will run an indeterminate number of tests. =item $Test->skip_all =item $Test->skip_all($reason) Skips all the tests, using the given C<$reason>. Exits immediately with 0. =item $Test->done_testing =item $Test->done_testing($count) Declares that you are done testing, no more tests will be run after this point. If a plan has not yet been output, it will do so. $num_tests is the number of tests you planned to run. If a numbered plan was already declared, and if this contradicts, a failing result will be run to reflect the planning mistake. If C was declared, this will override. If C is called twice, the second call will issue a failing result. If C<$num_tests> is omitted, the number of tests run will be used, like no_plan. C is, in effect, used when you'd want to use C, but safer. You'd use it like so: $Test->ok($a == $b); $Test->done_testing(); Or to plan a variable number of tests: for my $test (@tests) { $Test->ok($test); } $Test->done_testing(scalar @tests); =back =head2 SIMPLE RESULT PRODUCERS Each of these produces 1 or more L objects which are fed into the result stream. =over 4 =item $Test->ok($test) =item $Test->ok($test, $name) Your basic test. Pass if C<$test> is true, fail if $test is false. Just like L's C. =item $Test->BAIL_OUT($reason); Indicates to the L that things are going so badly all testing should terminate. This includes running any additional test scripts. It will exit with 255. =item $Test->skip =item $Test->skip($why) Skips the current test, reporting C<$why>. =item $Test->todo_skip =item $Test->todo_skip($why) Like C, only it will declare the test as failing and TODO. Similar to print "not ok $tnum # TODO $why\n"; =item $Test->diag(@msgs) Prints out the given C<@msgs>. Like C, arguments are simply appended together. Normally, it uses the C handle, but if this is for a TODO test, the C handle is used. Output will be indented and marked with a # so as not to interfere with test output. A newline will be put on the end if there isn't one already. We encourage using this rather than calling print directly. Returns false. Why? Because C is often used in conjunction with a failing test (C) it "passes through" the failure. return ok(...) || diag(...); =item $Test->note(@msgs) Like C, but it prints to the C handle so it will not normally be seen by the user except in verbose mode. =back =head2 ADVANCED RESULT PRODUCERS =over 4 =item $Test->is_eq($got, $expected, $name) Like Test::More's C. Checks if C<$got eq $expected>. This is the string version. C only ever matches another C. =item $Test->is_num($got, $expected, $name) Like Test::More's C. Checks if C<$got == $expected>. This is the numeric version. C only ever matches another C. =item $Test->isnt_eq($got, $dont_expect, $name) Like L's C. Checks if C<$got ne $dont_expect>. This is the string version. =item $Test->isnt_num($got, $dont_expect, $name) Like L's C. Checks if C<$got ne $dont_expect>. This is the numeric version. =item $Test->like($thing, qr/$regex/, $name) =item $Test->like($thing, '/$regex/', $name) Like L's C. Checks if $thing matches the given C<$regex>. =item $Test->unlike($thing, qr/$regex/, $name) =item $Test->unlike($thing, '/$regex/', $name) Like L's C. Checks if $thing $Test->does not match the given C<$regex>. =item $Test->cmp_ok($thing, $type, $that, $name) Works just like L's C. $Test->cmp_ok($big_num, '!=', $other_big_num); =back =head2 PUBLIC HELPERS =over 4 =item @dump = $Test->explain(@msgs) Will dump the contents of any references in a human readable format. Handy for things like... is_deeply($have, $want) || diag explain $have; or is_deeply($have, $want) || note explain $have; =item $tb->carp(@message) Warns with C<@message> but the message will appear to come from the point where the original test function was called (C<< $tb->caller >>). =item $tb->croak(@message) Dies with C<@message> but the message will appear to come from the point where the original test function was called (C<< $tb->caller >>). =item $plan = $Test->has_plan Find out whether a plan has been defined. C<$plan> is either C (no plan has been set), C (indeterminate # of tests) or an integer (the number of expected tests). =item $Test->reset Reinitializes the Test::Builder singleton to its original state. Mostly useful for tests run in persistent environments where the same test might be run multiple times in the same process. =item %context = $Test->context Returns a hash of contextual info. ( depth => DEPTH, source => NAME, trace => TRACE, ) =back =head2 TODO MANAGEMENT =over 4 =item $todo_reason = $Test->todo =item $todo_reason = $Test->todo($pack) If the current tests are considered "TODO" it will return the reason, if any. This reason can come from a C<$TODO> variable or the last call to C. Since a TODO test does not need a reason, this function can return an empty string even when inside a TODO block. Use C<< $Test->in_todo >> to determine if you are currently inside a TODO block. C is about finding the right package to look for C<$TODO> in. It's pretty good at guessing the right package to look at. It first looks for the caller based on C<$Level + 1>, since C is usually called inside a test function. As a last resort it will use C. Sometimes there is some confusion about where C should be looking for the C<$TODO> variable. If you want to be sure, tell it explicitly what $pack to use. =item $in_todo = $Test->in_todo Returns true if the test is currently inside a TODO block. =item $Test->todo_start() =item $Test->todo_start($message) This method allows you declare all subsequent tests as TODO tests, up until the C method has been called. The C and C<$TODO> syntax is generally pretty good about figuring out whether or not we're in a TODO test. However, often we find that this is not possible to determine (such as when we want to use C<$TODO> but the tests are being executed in other packages which can't be inferred beforehand). Note that you can use this to nest "todo" tests $Test->todo_start('working on this'); # lots of code $Test->todo_start('working on that'); # more code $Test->todo_end; $Test->todo_end; This is generally not recommended, but large testing systems often have weird internal needs. We've tried to make this also work with the TODO: syntax, but it's not guaranteed and its use is also discouraged: TODO: { local $TODO = 'We have work to do!'; $Test->todo_start('working on this'); # lots of code $Test->todo_start('working on that'); # more code $Test->todo_end; $Test->todo_end; } Pick one style or another of "TODO" to be on the safe side. =item $Test->todo_end Stops running tests as "TODO" tests. This method is fatal if called without a preceding C method call. =back =head2 DEPRECATED/LEGACY All of these will issue warnings if called on a modern Test::Builder object. That is any Test::Builder instance that was created with the 'modern' flag. =over =item $self->no_ending B Moved to the L object. $Test->no_ending($no_ending); Normally, Test::Builder does some extra diagnostics when the test ends. It also changes the exit code as described below. If this is true, none of that will be done. =item $self->summary B Moved to the L object. The style of result recording used here is deprecated. The functionality was moved to its own object to contain the legacy code. my @tests = $Test->summary; A simple summary of the tests so far. True for pass, false for fail. This is a logical pass/fail, so todos are passes. Of course, test #1 is $tests[0], etc... =item $self->details B Moved to the L object. The style of result recording used here is deprecated. The functionality was moved to its own object to contain the legacy code. my @tests = $Test->details; Like C, but with a lot more detail. $tests[$test_num - 1] = { 'ok' => is the test considered a pass? actual_ok => did it literally say 'ok'? name => name of the test (if any) type => type of test (if any, see below). reason => reason for the above (if any) }; 'ok' is true if Test::Harness will consider the test to be a pass. 'actual_ok' is a reflection of whether or not the test literally printed 'ok' or 'not ok'. This is for examining the result of 'todo' tests. 'name' is the name of the test. 'type' indicates if it was a special test. Normal tests have a type of ''. Type can be one of the following: skip see skip() todo see todo() todo_skip see todo_skip() unknown see below Sometimes the Test::Builder test counter is incremented without it printing any test output, for example, when C is changed. In these cases, Test::Builder doesn't know the result of the test, so its type is 'unknown'. These details for these tests are filled in. They are considered ok, but the name and actual_ok is left C. For example "not ok 23 - hole count # TODO insufficient donuts" would result in this structure: $tests[22] = # 23 - 1, since arrays start from 0. { ok => 1, # logically, the test passed since its todo actual_ok => 0, # in absolute terms, it failed name => 'hole count', type => 'todo', reason => 'insufficient donuts' }; =item $self->no_header B moved to the L object. $Test->no_header($no_header); If set to true, no "1..N" header will be printed. =item $self->no_diag B moved to the L object. If set true no diagnostics will be printed. This includes calls to C. =item $self->output =item $self->failure_output =item $self->todo_output B moved to the L object. my $filehandle = $Test->output; $Test->output($filehandle); $Test->output($filename); $Test->output(\$scalar); These methods control where Test::Builder will print its output. They take either an open C<$filehandle>, a C<$filename> to open and write to or a C<$scalar> reference to append to. It will always return a C<$filehandle>. B is where normal "ok/not ok" test output goes. Defaults to STDOUT. B is where diagnostic output on test failures and C goes. It is normally not read by Test::Harness and instead is displayed to the user. Defaults to STDERR. C is used instead of C for the diagnostics of a failing TODO test. These will not be seen by the user. Defaults to STDOUT. =item $self->reset_outputs B moved to the L object. $tb->reset_outputs; Resets all the output filehandles back to their defaults. =item $self->use_numbers B moved to the L object. $Test->use_numbers($on_or_off); Whether or not the test should output numbers. That is, this if true: ok 1 ok 2 ok 3 or this if false ok ok ok Most useful when you can't depend on the test output order, such as when threads or forking is involved. Defaults to on. =item $pack = $Test->exported_to =item $Test->exported_to($pack) B Use C<< Test::Builder::Trace->anoint($package) >> and C<< $Test->trace_anointed >> instead. Tells Test::Builder what package you exported your functions to. This method isn't terribly useful since modules which share the same Test::Builder object might get exported to different packages and only the last one will be honored. =item $is_fh = $Test->is_fh($thing); Determines if the given C<$thing> can be used as a filehandle. =item $curr_test = $Test->current_test; =item $Test->current_test($num); Gets/sets the current test number we're on. You usually shouldn't have to set this. If set forward, the details of the missing tests are filled in as 'unknown'. if set backward, the details of the intervening tests are deleted. You can erase history if you really want to. =item $Test->BAIL_OUT($reason); Indicates to the L that things are going so badly all testing should terminate. This includes running any additional test scripts. It will exit with 255. =item $max = $Test->expected_tests =item $Test->expected_tests($max) Gets/sets the number of tests we expect this test to run and prints out the appropriate headers. =item $package = $Test->caller =item ($pack, $file, $line) = $Test->caller =item ($pack, $file, $line) = $Test->caller($height) Like the normal C, except it reports according to your C. C<$height> will be added to the C. If C winds up off the top of the stack it report the highest context. =item $Test->level($how_high) How far up the call stack should C<$Test> look when reporting where the test failed. Defaults to 1. Setting L<$Test::Builder::Level> overrides. This is typically useful localized: sub my_ok { my $test = shift; local $Test::Builder::Level = $Test::Builder::Level + 1; $TB->ok($test); } To be polite to other functions wrapping your own you usually want to increment C<$Level> rather than set it to a constant. =item $Test->maybe_regex(qr/$regex/) =item $Test->maybe_regex('/$regex/') This method used to be useful back when Test::Builder worked on Perls before 5.6 which didn't have qr//. Now its pretty useless. Convenience method for building testing functions that take regular expressions as arguments. Takes a quoted regular expression produced by C, or a string representing a regular expression. Returns a Perl value which may be used instead of the corresponding regular expression, or C if its argument is not recognised. For example, a version of C, sans the useful diagnostic messages, could be written as: sub laconic_like { my ($self, $thing, $regex, $name) = @_; my $usable_regex = $self->maybe_regex($regex); die "expecting regex, found '$regex'\n" unless $usable_regex; $self->ok($thing =~ m/$usable_regex/, $name); } =back =head1 EXIT CODES If all your tests passed, Test::Builder will exit with zero (which is normal). If anything failed it will exit with how many failed. If you run less (or more) tests than you planned, the missing (or extras) will be considered failures. If no tests were ever run Test::Builder will throw a warning and exit with 255. If the test died, even after having successfully completed all its tests, it will still be considered a failure and will exit with 255. So the exit codes are... 0 all tests successful 255 test died or all passed but wrong # of tests run any other number how many failed (including missing or extras) If you fail more than 254 tests, it will be reported as 254. B The magic that accomplishes this has been moved to L =head1 THREADS In perl 5.8.1 and later, Test::Builder is thread-safe. The test number is shared amongst all threads. While versions earlier than 5.8.1 had threads they contain too many bugs to support. Test::Builder is only thread-aware if threads.pm is loaded I Test::Builder. =head1 MEMORY An informative hash, accessible via C, is stored for each test you perform. So memory usage will scale linearly with each test run. Although this is not a problem for most test suites, it can become an issue if you do large (hundred thousands to million) combinatorics tests in the same run. In such cases, you are advised to either split the test file into smaller ones, or use a reverse approach, doing "normal" (code) compares and triggering C should anything go unexpected. You can turn this off: $Test->stream->no_lresults; The shared stream has it on by default. =head1 EXAMPLES CPAN can provide the best examples. L, L, L and L all use Test::Builder. =head1 SEE ALSO L, L, L, L =head1 AUTHORS Original code by chromatic, maintained by Michael G Schwern Eschwern@pobox.comE until 2014. Currently maintained by Chad Granum Eexodist7@gmail.comE. =head1 MAINTAINERS =over 4 =item Chad Granum Eexodist@cpan.orgE =back =head1 COPYRIGHT Copyright 2002-2014 by chromatic Echromatic@wgz.orgE and Michael G Schwern Eschwern@pobox.comE and Chad Granum Eexodist7@gmail.comE This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See F