2 # $Id: /mirror/googlecode/test-more/t/Tester/tbt_07args.t 60331 2008-09-09T12:17:12.607612Z schwern $
4 use Test::More tests => 18;
7 use Test::Builder::Tester;
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
15 # My brain is melting. My brain is melting. ETOOMANYLAYERSOFTESTING
17 # create some private file handles
18 my $output_handle = gensym;
19 my $error_handle = gensym;
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";
25 # ooooh, use the test suite
26 my $t = Test::Builder->new;
28 # remember the testing outputs
29 my $original_output_handle;
30 my $original_failure_handle;
31 my $original_todo_handle;
33 my $original_harness_env;
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};
43 # switch out to our own handles
44 $t->output($output_handle);
45 $t->failure_output($error_handle);
46 $t->todo_output($error_handle);
48 $ENV{HARNESS_ACTIVE} = 0;
50 # clear the expected list
54 # remeber that we're testing
55 $testing_num = $t->current_test;
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
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;
74 # reset the number of tests
75 $t->current_test($testing_num);
77 # check we got the same values
82 $t->ok($out->check, "STDOUT $text");
85 $t->ok($err->check, "STDERR $text");
88 ####################################################################
90 ####################################################################
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
96 $out->expect("ok 1 - foo");
98 my_test_test("basic meta meta test");
101 $out->expect("not ok 1 - foo");
102 $err->expect("# Failed test ($0 at line ".line_num(+1).")");
104 my_test_test("basic meta meta test 2");
107 $out->expect("ok 1 - bar");
108 test_out("ok 1 - foo");
111 my_test_test("meta meta test with tbt");
114 $out->expect("ok 1 - bar");
115 test_out("not ok 1 - foo");
116 test_err("# Failed test ($0 at line ".line_num(+1).")");
119 my_test_test("meta meta test with tbt2 ");
121 ####################################################################
123 ####################################################################
125 # set up the outer wrapper again
127 $out->expect("ok 1 - bar");
129 # set up what the inner wrapper expects
130 test_out("ok 1 - foo");
132 # the actual test function that we are testing
136 test_test(name => "bar");
139 my_test_test("meta test name");
141 ####################################################################
143 # set up the outer wrapper again
145 $out->expect("ok 1 - bar");
147 # set up what the inner wrapper expects
148 test_out("ok 1 - foo");
150 # the actual test function that we are testing
154 test_test(title => "bar");
157 my_test_test("meta test title");
159 ####################################################################
161 # set up the outer wrapper again
163 $out->expect("ok 1 - bar");
165 # set up what the inner wrapper expects
166 test_out("ok 1 - foo");
168 # the actual test function that we are testing
172 test_test(label => "bar");
175 my_test_test("meta test title");
177 ####################################################################
179 # set up the outer wrapper again
181 $out->expect("ok 1 - bar");
183 # set up what the inner wrapper expects
184 test_out("not ok 1 - foo this is wrong");
187 # the actual test function that we are testing
190 # test that we got what we expect, ignoring our is wrong
191 test_test(skip_out => 1, name => "bar");
193 # check that that passed
194 my_test_test("meta test skip_out");
196 ####################################################################
198 # set up the outer wrapper again
200 $out->expect("ok 1 - bar");
202 # set up what the inner wrapper expects
203 test_out("not ok 1 - foo");
204 test_err("this is wrong");
206 # the actual test function that we are testing
209 # test that we got what we expect, ignoring err is wrong
210 test_test(skip_err => 1, name => "bar");
212 # diagnostics failing out
213 # check that that passed
214 my_test_test("meta test skip_err");
216 ####################################################################