Move Test::Simple from lib to ext.
[p5sagit/p5-mst-13.2.git] / ext / Test-Simple / t / Builder / reset.t
1 #!/usr/bin/perl -w
2
3 # Test Test::Builder->reset;
4
5 BEGIN {
6     if( $ENV{PERL_CORE} ) {
7         chdir 't';
8         @INC = ('../lib', 'lib');
9     }
10     else {
11         unshift @INC, 't/lib';
12     }
13 }
14 chdir 't';
15
16
17 use Test::Builder;
18 my $Test = Test::Builder->new;
19 my $tb = Test::Builder->create;
20
21 # We'll need this later to know the outputs were reset
22 my %Original_Output;
23 $Original_Output{$_} = $tb->$_ for qw(output failure_output todo_output);
24
25 # Alter the state of Test::Builder as much as possible.
26 my $output = '';
27 $tb->output(\$output);
28 $tb->failure_output(\$output);
29 $tb->todo_output(\$output);
30
31 $tb->plan(tests => 14);
32 $tb->level(0);
33
34 $tb->ok(1, "Running a test to alter TB's state");
35
36 # This won't print since we just sent output off to oblivion.
37 $tb->ok(0, "And a failure for fun");
38
39 $Test::Builder::Level = 3;
40
41 $tb->exported_to('Foofer');
42
43 $tb->use_numbers(0);
44 $tb->no_header(1);
45 $tb->no_ending(1);
46
47
48 # Now reset it.
49 $tb->reset;
50
51
52 $Test->ok( !defined $tb->exported_to, 'exported_to' );
53 $Test->is_eq( $tb->expected_tests, 0, 'expected_tests' );
54 $Test->is_eq( $tb->level,          1, 'level' );
55 $Test->is_eq( $tb->use_numbers,    1, 'use_numbers' );
56 $Test->is_eq( $tb->no_header,      0, 'no_header' );
57 $Test->is_eq( $tb->no_ending,      0, 'no_ending' );
58 $Test->is_eq( $tb->current_test,   0, 'current_test' );
59 $Test->is_eq( scalar $tb->summary, 0, 'summary' );
60 $Test->is_eq( scalar $tb->details, 0, 'details' );
61 $Test->is_eq( fileno $tb->output,
62               fileno $Original_Output{output},         'output' );
63 $Test->is_eq( fileno $tb->failure_output,
64               fileno $Original_Output{failure_output}, 'failure_output' );
65 $Test->is_eq( fileno $tb->todo_output,
66               fileno $Original_Output{todo_output},    'todo_output' );
67
68 $tb->current_test(12);
69 $tb->level(0);
70 $tb->ok(1, 'final test to make sure output was reset');
71
72 $Test->current_test(13);
73 $Test->done_testing(13);