4 if( $ENV{PERL_CORE} ) {
6 @INC = ('../lib', 'lib');
15 require Test::Simple::Catch;
16 my($out, $err) = Test::Simple::Catch::caught();
19 # Can't use Test.pm, that's a 5.005 thing.
25 # Utility testing functions.
27 my($test, $name) = @_;
29 $ok .= "not " unless $test;
30 $ok .= "ok $test_num";
31 $ok .= " - $name" if defined $name;
44 Test::More->import(tests => $Total);
46 # Preserve the line numbers.
51 is( "foo", "bar", 'foo is bar?');
52 is( undef, '', 'undef is empty string?');
53 is( undef, 0, 'undef is 0?');
54 is( '', 0, 'empty string is 0?' );
56 isnt("foo", "foo", 'foo isnt foo?' );
57 isn't("foo", "foo",'foo isn\'t foo?' );
59 like( "foo", '/that/', 'is foo like that' );
60 unlike( "foo", '/foo/', 'is foo unlike foo' );
62 # Nick Clark found this was a bug. Fixed in 0.40.
63 like( "bug", '/(%)/', 'regex with % in it' );
68 can_ok('Mooble::Hooble::Yooble', qw(this that));
69 can_ok('Mooble::Hooble::Yooble', ());
71 isa_ok(bless([], "Foo"), "Wibble");
72 isa_ok(42, "Wibble", "My Wibble");
73 isa_ok(undef, "Wibble", "Another Wibble");
77 cmp_ok( 'foo', 'eq', 'bar', 'cmp_ok eq' );
78 cmp_ok( 42.1, '==', 23, , ' ==' );
79 cmp_ok( 42, '!=', 42 , ' !=' );
80 cmp_ok( 1, '&&', 0 , ' &&' );
81 cmp_ok( 42, '==', "foo", ' == with strings' );
82 cmp_ok( 42, 'eq', "foo", ' eq with numbers' );
83 cmp_ok( undef, 'eq', 'foo', ' eq with undef' );
85 # generate a $!, it changes its value by context.
87 my $Errno_Number = $!+0;
88 my $Errno_String = $!.'';
89 cmp_ok( $!, 'eq', '', ' eq with stringified errno' );
90 cmp_ok( $!, '==', -1, ' eq with numerified errno' );
93 use_ok('Hooble::mooble::yooble');
94 require_ok('ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble');
98 My::Test::ok($$out eq <<OUT, 'failing output');
101 not ok 2 - foo is bar?
102 not ok 3 - undef is empty string?
103 not ok 4 - undef is 0?
104 not ok 5 - empty string is 0?
105 not ok 6 - foo isnt foo?
106 not ok 7 - foo isn't foo?
107 not ok 8 - is foo like that
108 not ok 9 - is foo unlike foo
109 not ok 10 - regex with % in it
111 not ok 12 - Mooble::Hooble::Yooble->can(...)
112 not ok 13 - Mooble::Hooble::Yooble->can(...)
113 not ok 14 - The object isa Wibble
114 not ok 15 - My Wibble isa Wibble
115 not ok 16 - Another Wibble isa Wibble
116 not ok 17 - The object isa HASH
117 not ok 18 - cmp_ok eq
121 not ok 22 - == with strings
122 not ok 23 - eq with numbers
123 not ok 24 - eq with undef
124 not ok 25 - eq with stringified errno
125 not ok 26 - eq with numerified errno
126 not ok 27 - use Hooble::mooble::yooble;
127 not ok 28 - require ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble;
131 # Failed test ($0 at line 38)
132 # Failed test ($0 at line 40)
135 # Failed test ($0 at line 41)
138 # Failed test ($0 at line 42)
141 # Failed test ($0 at line 43)
144 # Failed test ($0 at line 45)
148 # Failed test ($0 at line 46)
152 # Failed test ($0 at line 48)
154 # doesn't match '/that/'
155 # Failed test ($0 at line 49)
158 # Failed test ($0 at line 52)
160 # doesn't match '/(%)/'
161 # Failed test ($0 at line 54)
162 # Failed test ($0 at line 52)
163 # Mooble::Hooble::Yooble->can('this') failed
164 # Mooble::Hooble::Yooble->can('that') failed
165 # Failed test ($0 at line 53)
166 # can_ok() called with no methods
167 # Failed test ($0 at line 55)
168 # The object isn't a 'Wibble' it's a 'Foo'
169 # Failed test ($0 at line 56)
170 # My Wibble isn't a reference
171 # Failed test ($0 at line 57)
172 # Another Wibble isn't defined
173 # Failed test ($0 at line 58)
174 # The object isn't a 'HASH' it's a 'ARRAY'
175 # Failed test ($0 at line 68)
178 # Failed test ($0 at line 69)
181 # Failed test ($0 at line 70)
185 # Failed test ($0 at line 71)
189 # Failed test ($0 at line 72)
192 # Failed test ($0 at line 73)
195 # Failed test ($0 at line 74)
198 # Failed test ($0 at line 80)
199 # got: '$Errno_String'
201 # Failed test ($0 at line 81)
206 my $filename = quotemeta $0;
207 my $more_err_re = <<ERR;
208 # Failed test \\($filename at line 84\\)
209 # Tried to use 'Hooble::mooble::yooble'.
210 # Error: Can't locate file Hooble.* in \\\@INC .*
211 # Failed test \\($filename at line 85\\)
212 # Tried to require 'ALL::YOUR::BASE::ARE::BELONG::TO::US::wibble'.
213 # Error: Can't locate file ALL.* in \\\@INC .*
214 # Looks like you failed $Total tests of $Total.
217 unless( My::Test::ok($$err =~ /^\Q$err_re\E$more_err_re$/,
218 'failing errors') ) {