4 if( $ENV{PERL_CORE} ) {
6 @INC = ( '../lib', 'lib' );
16 use Test::Builder::NoOutput;
18 use Test::More tests => 19;
20 # Formatting may change if we're running under Test::Harness.
21 $ENV{HARNESS_ACTIVE} = 0;
24 my $tb = Test::Builder::NoOutput->create;
26 $tb->plan( tests => 7 );
28 $tb->ok( $_, "We're on $_" );
29 $tb->diag("We ran $_");
32 my $indented = $tb->child;
33 $indented->plan('no_plan');
34 $indented->ok( 1, "We're on 1" );
35 $indented->ok( 1, "We're on 2" );
36 $indented->ok( 1, "We're on 3" );
40 $tb->ok( $_, "We're on $_" );
43 is $tb->read, <<"END", 'Output should nest properly';
62 my $tb = Test::Builder::NoOutput->create;
66 $tb->ok( $_, "We're on $_" );
67 $tb->diag("We ran $_");
70 my $indented = $tb->child;
71 $indented->plan('no_plan');
72 $indented->ok( 1, "We're on 1" );
74 my $indented2 = $indented->child('with name');
75 $indented2->plan( tests => 2 );
76 $indented2->ok( 1, "We're on 2.1" );
77 $indented2->ok( 1, "We're on 2.1" );
80 $indented->ok( 1, 'after child' );
84 $tb->ok( $_, "We're on $_" );
88 is $tb->read, <<"END", 'We should allow arbitrary nesting';
106 my $tb = Test::Builder::NoOutput->create;
109 my $child = $tb->child('expected to fail');
110 $child->plan( tests => 3 );
118 my $child = $tb->child('expected to pass');
119 $child->plan( tests => 3 );
125 is $tb->read, <<"END", 'Previous child failures should not force subsequent failures';
129 # Failed test at $0 line 114.
131 # Looks like you failed 1 test of 3.
132 not ok 1 - expected to fail
133 # Failed test 'expected to fail'
139 ok 2 - expected to pass
143 my $tb = Test::Builder::NoOutput->create;
144 my $child = $tb->child('one');
145 is $child->{$_}, $tb->{$_}, "The child should copy the ($_) filehandle"
146 foreach qw{Out_FH Todo_FH Fail_FH};
150 my $tb = Test::Builder::NoOutput->create;
151 my $child = $tb->child('one');
152 can_ok $child, 'parent';
153 is $child->parent, $tb, '... and it should return the parent of the child';
154 ok !defined $tb->parent, '... but top level builders should not have parents';
157 is $tb->name, $0, 'The top level name should be $0';
158 is $child->name, 'one', '... but child names should be whatever we set them to';
161 is $child->name, 'Child of '.$tb->name, '... or at least have a sensible default';
166 my $tb = Test::Builder::NoOutput->create;
169 my $child = $tb->child('skippy says he loves you');
170 eval { $child->plan( skip_all => 'cuz I said so' ) };
171 ok my $error = $@, 'A child which does a "skip_all" should throw an exception';
172 isa_ok $error, 'Test::Builder::Exception', '... and the exception it throws';
174 subtest 'skip all', sub {
175 plan skip_all => 'subtest with skip_all';
176 ok 0, 'This should never be run';
178 is +Test::Builder->new->{Test_Results}[-1]{type}, 'skip',
179 'Subtests which "skip_all" are reported as skipped tests';
185 my $tb = Test::Builder::NoOutput->create;
186 $tb->plan( tests => 1 );
187 my $child = $tb->child;
188 $child->plan( tests => 1 );
189 $child->todo_start( 'message' );
194 is $tb->read, <<"END", 'TODO tests should not make the parent test fail';
197 not ok 1 # TODO message
198 # Failed (TODO) test at $0 line 209.
203 my $tb = Test::Builder::NoOutput->create;
204 $tb->plan( tests => 1 );
205 my $child = $tb->child;
208 my $expected = <<"END";
210 not ok 1 - No tests run for subtest "Child of $0"
212 like $tb->read, qr/\Q$expected/,
213 'Not running subtests should make the parent test fail';