4 if( $ENV{PERL_CORE} ) {
10 use Test::More tests => 18;
13 use Test::Builder::Tester;
17 # argh! now we need to test the thing we're testing. Basically we need
18 # to pretty much reimplement the whole code again. This is very
19 # annoying but can't be avoided. And onwards with the cut and paste
21 # My brain is melting. My brain is melting. ETOOMANYLAYERSOFTESTING
23 # create some private file handles
24 my $output_handle = gensym;
25 my $error_handle = gensym;
27 # and tie them to this package
28 my $out = tie *$output_handle, "Test::Tester::Tie", "STDOUT";
29 my $err = tie *$error_handle, "Test::Tester::Tie", "STDERR";
31 # ooooh, use the test suite
32 my $t = Test::Builder->new;
34 # remember the testing outputs
35 my $original_output_handle;
36 my $original_failure_handle;
37 my $original_todo_handle;
39 my $original_harness_env;
43 # remember what the handles were set to
44 $original_output_handle = $t->output();
45 $original_failure_handle = $t->failure_output();
46 $original_todo_handle = $t->todo_output();
47 $original_harness_env = $ENV{HARNESS_ACTIVE};
49 # switch out to our own handles
50 $t->output($output_handle);
51 $t->failure_output($error_handle);
52 $t->todo_output($error_handle);
54 $ENV{HARNESS_ACTIVE} = 0;
56 # clear the expected list
60 # remeber that we're testing
61 $testing_num = $t->current_test;
65 # each test test is actually two tests. This is bad and wrong
66 # but makes blood come out of my ears if I don't at least simplify
67 # it a little this way
75 $t->output($original_output_handle);
76 $t->failure_output($original_failure_handle);
77 $t->todo_output($original_todo_handle);
78 $ENV{HARNESS_ACTIVE} = $original_harness_env;
80 # reset the number of tests
81 $t->current_test($testing_num);
83 # check we got the same values
88 $t->ok($out->check, "STDOUT $text");
91 $t->ok($err->check, "STDERR $text");
94 ####################################################################
96 ####################################################################
98 # this is a quick test to check the hack that I've just implemented
99 # actually does a cut down version of Test::Builder::Tester
102 $out->expect("ok 1 - foo");
104 my_test_test("basic meta meta test");
107 $out->expect("not ok 1 - foo");
108 $err->expect("# Failed test ($0 at line ".line_num(+1).")");
110 my_test_test("basic meta meta test 2");
113 $out->expect("ok 1 - bar");
114 test_out("ok 1 - foo");
117 my_test_test("meta meta test with tbt");
120 $out->expect("ok 1 - bar");
121 test_out("not ok 1 - foo");
122 test_err("# Failed test ($0 at line ".line_num(+1).")");
125 my_test_test("meta meta test with tbt2 ");
127 ####################################################################
129 ####################################################################
131 # set up the outer wrapper again
133 $out->expect("ok 1 - bar");
135 # set up what the inner wrapper expects
136 test_out("ok 1 - foo");
138 # the actual test function that we are testing
142 test_test(name => "bar");
145 my_test_test("meta test name");
147 ####################################################################
149 # set up the outer wrapper again
151 $out->expect("ok 1 - bar");
153 # set up what the inner wrapper expects
154 test_out("ok 1 - foo");
156 # the actual test function that we are testing
160 test_test(title => "bar");
163 my_test_test("meta test title");
165 ####################################################################
167 # set up the outer wrapper again
169 $out->expect("ok 1 - bar");
171 # set up what the inner wrapper expects
172 test_out("ok 1 - foo");
174 # the actual test function that we are testing
178 test_test(label => "bar");
181 my_test_test("meta test title");
183 ####################################################################
185 # set up the outer wrapper again
187 $out->expect("ok 1 - bar");
189 # set up what the inner wrapper expects
190 test_out("not ok 1 - foo this is wrong");
193 # the actual test function that we are testing
196 # test that we got what we expect, ignoring our is wrong
197 test_test(skip_out => 1, name => "bar");
199 # check that that passed
200 my_test_test("meta test skip_out");
202 ####################################################################
204 # set up the outer wrapper again
206 $out->expect("ok 1 - bar");
208 # set up what the inner wrapper expects
209 test_out("not ok 1 - foo");
210 test_err("this is wrong");
212 # the actual test function that we are testing
215 # test that we got what we expect, ignoring err is wrong
216 test_test(skip_err => 1, name => "bar");
218 # diagnostics failing out
219 # check that that passed
220 my_test_test("meta test skip_err");
222 ####################################################################