Add the original source packages to maemo, source lenny
[dh-make-perl] / dev / i386 / libtest-simple-perl / libtest-simple-perl-0.80 / t / 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 $tb = Test::Builder->new;
19
20 my %Original_Output;
21 $Original_Output{$_} = $tb->$_ for qw(output failure_output todo_output);
22
23
24 $tb->plan(tests => 14);
25 $tb->level(0);
26
27 # Alter the state of Test::Builder as much as possible.
28 $tb->ok(1, "Running a test to alter TB's state");
29
30 my $tmpfile = 'foo.tmp';
31
32 $tb->output($tmpfile);
33 $tb->failure_output($tmpfile);
34 $tb->todo_output($tmpfile);
35 END { 1 while unlink $tmpfile }
36
37 # This won't print since we just sent output off to oblivion.
38 $tb->ok(0, "And a failure for fun");
39
40 $Test::Builder::Level = 3;
41
42 $tb->exported_to('Foofer');
43
44 $tb->use_numbers(0);
45 $tb->no_header(1);
46 $tb->no_ending(1);
47
48
49 # Now reset it.
50 $tb->reset;
51
52 my $test_num = 2;   # since we already printed 1
53 # Utility testing functions.
54 sub ok ($;$) {
55     my($test, $name) = @_;
56     my $ok = '';
57     $ok .= "not " unless $test;
58     $ok .= "ok $test_num";
59     $ok .= " - $name" if defined $name;
60     $ok .= "\n";
61     print $ok;
62     $test_num++;
63
64     return $test;
65 }
66
67
68 ok( !defined $tb->exported_to,          'exported_to' );
69 ok( $tb->expected_tests == 0,           'expected_tests' );
70 ok( $tb->level          == 1,           'level' );
71 ok( $tb->use_numbers    == 1,           'use_numbers' );
72 ok( $tb->no_header      == 0,           'no_header' );
73 ok( $tb->no_ending      == 0,           'no_ending' );
74 ok( fileno $tb->output         == fileno $Original_Output{output},    
75                                         'output' );
76 ok( fileno $tb->failure_output == fileno $Original_Output{failure_output},    
77                                         'failure_output' );
78 ok( fileno $tb->todo_output    == fileno $Original_Output{todo_output},
79                                         'todo_output' );
80 ok( $tb->current_test   == 0,           'current_test' );
81 ok( $tb->summary        == 0,           'summary' );
82 ok( $tb->details        == 0,           'details' );
83
84 $tb->no_ending(1);
85 $tb->no_header(1);
86 $tb->plan(tests => 14);
87 $tb->current_test(13);
88 $tb->level(0);
89 $tb->ok(1, 'final test to make sure output was reset');