ac5f4142a3edd23acefa3826ed935a8143ef25eb
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / Tester / tbt_07args.t
1 #!/usr/bin/perl -w
2 # $Id: /mirror/googlecode/test-more/t/Tester/tbt_07args.t 60331 2008-09-09T12:17:12.607612Z schwern  $
3
4 use Test::More tests => 18;
5 use Symbol;
6 use Test::Builder;
7 use Test::Builder::Tester;
8
9 use strict;
10
11 # argh! now we need to test the thing we're testing.  Basically we need
12 # to pretty much reimplement the whole code again.  This is very
13 # annoying but can't be avoided.  And onwards with the cut and paste
14
15 # My brain is melting.  My brain is melting.  ETOOMANYLAYERSOFTESTING
16
17 # create some private file handles
18 my $output_handle = gensym;
19 my $error_handle  = gensym;
20
21 # and tie them to this package
22 my $out = tie *$output_handle, "Test::Builder::Tester::Tie", "STDOUT";
23 my $err = tie *$error_handle,  "Test::Builder::Tester::Tie", "STDERR";
24
25 # ooooh, use the test suite
26 my $t = Test::Builder->new;
27
28 # remember the testing outputs
29 my $original_output_handle;
30 my $original_failure_handle;
31 my $original_todo_handle;
32 my $testing_num;
33 my $original_harness_env;
34
35 sub start_testing
36 {
37     # remember what the handles were set to
38     $original_output_handle  = $t->output();
39     $original_failure_handle = $t->failure_output();
40     $original_todo_handle    = $t->todo_output();
41     $original_harness_env    = $ENV{HARNESS_ACTIVE};
42
43     # switch out to our own handles
44     $t->output($output_handle);
45     $t->failure_output($error_handle);
46     $t->todo_output($error_handle);
47
48     $ENV{HARNESS_ACTIVE} = 0;
49
50     # clear the expected list
51     $out->reset();
52     $err->reset();
53
54     # remeber that we're testing
55     $testing_num = $t->current_test;
56     $t->current_test(0);
57 }
58
59 # each test test is actually two tests.  This is bad and wrong
60 # but makes blood come out of my ears if I don't at least simplify
61 # it a little this way
62
63 sub my_test_test
64 {
65   my $text = shift;
66   local $^W = 0;
67
68   # reset the outputs 
69   $t->output($original_output_handle);
70   $t->failure_output($original_failure_handle);
71   $t->todo_output($original_todo_handle);
72   $ENV{HARNESS_ACTIVE} = $original_harness_env;
73
74   # reset the number of tests
75   $t->current_test($testing_num);
76
77   # check we got the same values
78   my $got;
79   my $wanted;
80
81   # stdout
82   $t->ok($out->check, "STDOUT $text");
83
84   # stderr
85   $t->ok($err->check, "STDERR $text");
86 }
87
88 ####################################################################
89 # Meta meta tests
90 ####################################################################
91
92 # this is a quick test to check the hack that I've just implemented
93 # actually does a cut down version of Test::Builder::Tester
94
95 start_testing();
96 $out->expect("ok 1 - foo");
97 pass("foo");
98 my_test_test("basic meta meta test");
99
100 start_testing();
101 $out->expect("not ok 1 - foo");
102 $err->expect("#     Failed test ($0 at line ".line_num(+1).")");
103 fail("foo");
104 my_test_test("basic meta meta test 2");
105
106 start_testing();
107 $out->expect("ok 1 - bar");
108 test_out("ok 1 - foo");
109 pass("foo");
110 test_test("bar");
111 my_test_test("meta meta test with tbt");
112
113 start_testing();
114 $out->expect("ok 1 - bar");
115 test_out("not ok 1 - foo");
116 test_err("#     Failed test ($0 at line ".line_num(+1).")");
117 fail("foo");
118 test_test("bar");
119 my_test_test("meta meta test with tbt2 ");
120
121 ####################################################################
122 # Actual meta tests
123 ####################################################################
124
125 # set up the outer wrapper again
126 start_testing();
127 $out->expect("ok 1 - bar");
128
129 # set up what the inner wrapper expects
130 test_out("ok 1 - foo");
131
132 # the actual test function that we are testing
133 ok("1","foo");
134
135 # test the name
136 test_test(name => "bar");
137
138 # check that passed
139 my_test_test("meta test name");
140
141 ####################################################################
142
143 # set up the outer wrapper again
144 start_testing();
145 $out->expect("ok 1 - bar");
146
147 # set up what the inner wrapper expects
148 test_out("ok 1 - foo");
149
150 # the actual test function that we are testing
151 ok("1","foo");
152
153 # test the name
154 test_test(title => "bar");
155
156 # check that passed
157 my_test_test("meta test title");
158
159 ####################################################################
160
161 # set up the outer wrapper again
162 start_testing();
163 $out->expect("ok 1 - bar");
164
165 # set up what the inner wrapper expects
166 test_out("ok 1 - foo");
167
168 # the actual test function that we are testing
169 ok("1","foo");
170
171 # test the name
172 test_test(label => "bar");
173
174 # check that passed
175 my_test_test("meta test title");
176
177 ####################################################################
178
179 # set up the outer wrapper again
180 start_testing();
181 $out->expect("ok 1 - bar");
182
183 # set up what the inner wrapper expects
184 test_out("not ok 1 - foo this is wrong");
185 test_fail(+3);
186
187 # the actual test function that we are testing
188 ok("0","foo");
189
190 # test that we got what we expect, ignoring our is wrong
191 test_test(skip_out => 1, name => "bar");
192
193 # check that that passed
194 my_test_test("meta test skip_out");
195
196 ####################################################################
197
198 # set up the outer wrapper again
199 start_testing();
200 $out->expect("ok 1 - bar");
201
202 # set up what the inner wrapper expects
203 test_out("not ok 1 - foo");
204 test_err("this is wrong");
205
206 # the actual test function that we are testing
207 ok("0","foo");
208
209 # test that we got what we expect, ignoring err is wrong
210 test_test(skip_err => 1, name => "bar");
211
212 # diagnostics failing out
213 # check that that passed
214 my_test_test("meta test skip_err");
215
216 ####################################################################