Move Test::Simple from lib to ext.
[p5sagit/p5-mst-13.2.git] / ext / Test-Simple / t / Tester / tbt_06errormess.t
CommitLineData
845d7e37 1#!/usr/bin/perl -w
2
3use Test::More tests => 8;
4use Symbol;
5use Test::Builder;
6use Test::Builder::Tester;
7
8use strict;
9
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
13
14# My brain is melting. My brain is melting. ETOOMANYLAYERSOFTESTING
15
16# create some private file handles
17my $output_handle = gensym;
18my $error_handle = gensym;
19
20# and tie them to this package
1be77ff7 21my $out = tie *$output_handle, "Test::Builder::Tester::Tie", "STDOUT";
22my $err = tie *$error_handle, "Test::Builder::Tester::Tie", "STDERR";
845d7e37 23
24# ooooh, use the test suite
25my $t = Test::Builder->new;
26
27# remember the testing outputs
28my $original_output_handle;
29my $original_failure_handle;
30my $original_todo_handle;
31my $original_harness_env;
32my $testing_num;
33
34sub start_testing
35{
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};
41
42 # switch out to our own handles
43 $t->output($output_handle);
44 $t->failure_output($error_handle);
45 $t->todo_output($error_handle);
46
47 $ENV{HARNESS_ACTIVE} = 0;
48
49 # clear the expected list
50 $out->reset();
51 $err->reset();
52
53 # remeber that we're testing
54 $testing_num = $t->current_test;
55 $t->current_test(0);
56}
57
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
61
62sub my_test_test
63{
64 my $text = shift;
65 local $^W = 0;
66
67 # reset the outputs
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;
72
73 # reset the number of tests
74 $t->current_test($testing_num);
75
76 # check we got the same values
77 my $got;
78 my $wanted;
79
80 # stdout
81 $t->ok($out->check, "STDOUT $text");
82
83 # stderr
84 $t->ok($err->check, "STDERR $text");
85}
86
87####################################################################
88# Meta meta tests
89####################################################################
90
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
93
94start_testing();
95$out->expect("ok 1 - foo");
96pass("foo");
97my_test_test("basic meta meta test");
98
99start_testing();
100$out->expect("not ok 1 - foo");
101$err->expect("# Failed test ($0 at line ".line_num(+1).")");
102fail("foo");
103my_test_test("basic meta meta test 2");
104
105start_testing();
106$out->expect("ok 1 - bar");
107test_out("ok 1 - foo");
108pass("foo");
109test_test("bar");
110my_test_test("meta meta test with tbt");
111
112start_testing();
113$out->expect("ok 1 - bar");
114test_out("not ok 1 - foo");
115test_err("# Failed test ($0 at line ".line_num(+1).")");
116fail("foo");
117test_test("bar");
118my_test_test("meta meta test with tbt2 ");
119
120####################################################################