3 use Test::More tests => 18;
6 use Test::Builder::Tester;
10 # argh! now we need to test the thing we're testing. Basically we need
11 # to pretty much reimplement the whole code again. This is very
12 # annoying but can't be avoided. And onwards with the cut and paste
14 # My brain is melting. My brain is melting. ETOOMANYLAYERSOFTESTING
16 # create some private file handles
17 my $output_handle = gensym;
18 my $error_handle = gensym;
20 # and tie them to this package
21 my $out = tie *$output_handle, "Test::Builder::Tester::Tie", "STDOUT";
22 my $err = tie *$error_handle, "Test::Builder::Tester::Tie", "STDERR";
24 # ooooh, use the test suite
25 my $t = Test::Builder->new;
27 # remember the testing outputs
28 my $original_output_handle;
29 my $original_failure_handle;
30 my $original_todo_handle;
32 my $original_harness_env;
36 # remember what the handles were set to
37 $original_output_handle = $t->output();
38 $original_failure_handle = $t->failure_output();
39 $original_todo_handle = $t->todo_output();
40 $original_harness_env = $ENV{HARNESS_ACTIVE};
42 # switch out to our own handles
43 $t->output($output_handle);
44 $t->failure_output($error_handle);
45 $t->todo_output($error_handle);
47 $ENV{HARNESS_ACTIVE} = 0;
49 # clear the expected list
53 # remeber that we're testing
54 $testing_num = $t->current_test;
58 # each test test is actually two tests. This is bad and wrong
59 # but makes blood come out of my ears if I don't at least simplify
60 # it a little this way
68 $t->output($original_output_handle);
69 $t->failure_output($original_failure_handle);
70 $t->todo_output($original_todo_handle);
71 $ENV{HARNESS_ACTIVE} = $original_harness_env;
73 # reset the number of tests
74 $t->current_test($testing_num);
76 # check we got the same values
81 $t->ok($out->check, "STDOUT $text");
84 $t->ok($err->check, "STDERR $text");
87 ####################################################################
89 ####################################################################
91 # this is a quick test to check the hack that I've just implemented
92 # actually does a cut down version of Test::Builder::Tester
95 $out->expect("ok 1 - foo");
97 my_test_test("basic meta meta test");
100 $out->expect("not ok 1 - foo");
101 $err->expect("# Failed test ($0 at line ".line_num(+1).")");
103 my_test_test("basic meta meta test 2");
106 $out->expect("ok 1 - bar");
107 test_out("ok 1 - foo");
110 my_test_test("meta meta test with tbt");
113 $out->expect("ok 1 - bar");
114 test_out("not ok 1 - foo");
115 test_err("# Failed test ($0 at line ".line_num(+1).")");
118 my_test_test("meta meta test with tbt2 ");
120 ####################################################################
122 ####################################################################
124 # set up the outer wrapper again
126 $out->expect("ok 1 - bar");
128 # set up what the inner wrapper expects
129 test_out("ok 1 - foo");
131 # the actual test function that we are testing
135 test_test(name => "bar");
138 my_test_test("meta test name");
140 ####################################################################
142 # set up the outer wrapper again
144 $out->expect("ok 1 - bar");
146 # set up what the inner wrapper expects
147 test_out("ok 1 - foo");
149 # the actual test function that we are testing
153 test_test(title => "bar");
156 my_test_test("meta test title");
158 ####################################################################
160 # set up the outer wrapper again
162 $out->expect("ok 1 - bar");
164 # set up what the inner wrapper expects
165 test_out("ok 1 - foo");
167 # the actual test function that we are testing
171 test_test(label => "bar");
174 my_test_test("meta test title");
176 ####################################################################
178 # set up the outer wrapper again
180 $out->expect("ok 1 - bar");
182 # set up what the inner wrapper expects
183 test_out("not ok 1 - foo this is wrong");
186 # the actual test function that we are testing
189 # test that we got what we expect, ignoring our is wrong
190 test_test(skip_out => 1, name => "bar");
192 # check that that passed
193 my_test_test("meta test skip_out");
195 ####################################################################
197 # set up the outer wrapper again
199 $out->expect("ok 1 - bar");
201 # set up what the inner wrapper expects
202 test_out("not ok 1 - foo");
203 test_err("this is wrong");
205 # the actual test function that we are testing
208 # test that we got what we expect, ignoring err is wrong
209 test_test(skip_err => 1, name => "bar");
211 # diagnostics failing out
212 # check that that passed
213 my_test_test("meta test skip_err");
215 ####################################################################