Upgrade to Test-Simple-0.82.
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / More.t
CommitLineData
33459055 1#!perl -w
ccbd73a4 2# $Id: /mirror/googlecode/test-more/t/More.t 57943 2008-08-18T02:09:22.275428Z brooklyn.kid51 $
33459055 3
4BEGIN {
a9153838 5 if( $ENV{PERL_CORE} ) {
6 chdir 't';
da0c1bbe 7 @INC = qw(../lib ../lib/Test/Simple/t/lib);
a9153838 8 }
33459055 9}
10
6b38a9b9 11use lib 't/lib';
12use Test::More tests => 52;
a9153838 13
14# Make sure we don't mess with $@ or $!. Test at bottom.
15my $Err = "this should not be touched";
16my $Errno = 42;
17$@ = $Err;
18$! = $Errno;
3f2ec160 19
6b38a9b9 20use_ok('Dummy');
ea2e58b9 21is( $Dummy::VERSION, '0.01', 'use_ok() loads a module' );
3f2ec160 22require_ok('Test::More');
23
24
25ok( 2 eq 2, 'two is two is two is two' );
26is( "foo", "foo", 'foo is foo' );
27isnt( "foo", "bar", 'foo isnt bar');
28isn't("foo", "bar", 'foo isn\'t bar');
29
30#'#
31like("fooble", '/^foo/', 'foo is like fooble');
32like("FooBle", '/foo/i', 'foo is like FooBle');
d020a79a 33like("/usr/local/pr0n/", '/^\/usr\/local/', 'regexes with slashes in like' );
34
a9153838 35unlike("fbar", '/^bar/', 'unlike bar');
36unlike("FooBle", '/foo/', 'foo is unlike FooBle');
37unlike("/var/local/pr0n/", '/^\/usr\/local/','regexes with slashes in unlike' );
38
30e302f8 39my @foo = qw(foo bar baz);
40unlike(@foo, '/foo/');
41
d020a79a 42can_ok('Test::More', qw(require_ok use_ok ok is isnt like skip can_ok
43 pass fail eq_array eq_hash eq_set));
44can_ok(bless({}, "Test::More"), qw(require_ok use_ok ok is isnt like skip
45 can_ok pass fail eq_array eq_hash eq_set));
46
89c1e84a 47
d020a79a 48isa_ok(bless([], "Foo"), "Foo");
a9153838 49isa_ok([], 'ARRAY');
50isa_ok(\42, 'SCALAR');
d020a79a 51
3f2ec160 52
89c1e84a 53# can_ok() & isa_ok should call can() & isa() on the given object, not
54# just class, in case of custom can()
55{
56 local *Foo::can;
57 local *Foo::isa;
58 *Foo::can = sub { $_[0]->[0] };
59 *Foo::isa = sub { $_[0]->[0] };
60 my $foo = bless([0], 'Foo');
61 ok( ! $foo->can('bar') );
62 ok( ! $foo->isa('bar') );
63 $foo->[0] = 1;
64 can_ok( $foo, 'blah');
65 isa_ok( $foo, 'blah');
66}
67
68
3f2ec160 69pass('pass() passed');
70
71ok( eq_array([qw(this that whatever)], [qw(this that whatever)]),
72 'eq_array with simple arrays' );
7483b81c 73is @Test::More::Data_Stack, 0, '@Data_Stack not holding onto things';
74
3f2ec160 75ok( eq_hash({ foo => 42, bar => 23 }, {bar => 23, foo => 42}),
76 'eq_hash with simple hashes' );
7483b81c 77is @Test::More::Data_Stack, 0;
78
3f2ec160 79ok( eq_set([qw(this that whatever)], [qw(that whatever this)]),
80 'eq_set with simple sets' );
7483b81c 81is @Test::More::Data_Stack, 0;
3f2ec160 82
83my @complex_array1 = (
84 [qw(this that whatever)],
85 {foo => 23, bar => 42},
86 "moo",
87 "yarrow",
88 [qw(498 10 29)],
89 );
90my @complex_array2 = (
91 [qw(this that whatever)],
92 {foo => 23, bar => 42},
93 "moo",
94 "yarrow",
95 [qw(498 10 29)],
96 );
97
33459055 98is_deeply( \@complex_array1, \@complex_array2, 'is_deeply with arrays' );
3f2ec160 99ok( eq_array(\@complex_array1, \@complex_array2),
100 'eq_array with complicated arrays' );
101ok( eq_set(\@complex_array1, \@complex_array2),
102 'eq_set with complicated arrays' );
103
104my @array1 = (qw(this that whatever),
105 {foo => 23, bar => 42} );
106my @array2 = (qw(this that whatever),
107 {foo => 24, bar => 42} );
108
109ok( !eq_array(\@array1, \@array2),
110 'eq_array with slightly different complicated arrays' );
7483b81c 111is @Test::More::Data_Stack, 0;
112
3f2ec160 113ok( !eq_set(\@array1, \@array2),
114 'eq_set with slightly different complicated arrays' );
7483b81c 115is @Test::More::Data_Stack, 0;
3f2ec160 116
117my %hash1 = ( foo => 23,
118 bar => [qw(this that whatever)],
119 har => { foo => 24, bar => 42 },
120 );
121my %hash2 = ( foo => 23,
122 bar => [qw(this that whatever)],
123 har => { foo => 24, bar => 42 },
124 );
125
33459055 126is_deeply( \%hash1, \%hash2, 'is_deeply with complicated hashes' );
127ok( eq_hash(\%hash1, \%hash2), 'eq_hash with complicated hashes');
3f2ec160 128
129%hash1 = ( foo => 23,
130 bar => [qw(this that whatever)],
131 har => { foo => 24, bar => 42 },
132 );
133%hash2 = ( foo => 23,
134 bar => [qw(this tha whatever)],
135 har => { foo => 24, bar => 42 },
136 );
137
138ok( !eq_hash(\%hash1, \%hash2),
139 'eq_hash with slightly different complicated hashes' );
7483b81c 140is @Test::More::Data_Stack, 0;
a9153838 141
142is( Test::Builder->new, Test::More->builder, 'builder()' );
143
144
145cmp_ok(42, '==', 42, 'cmp_ok ==');
146cmp_ok('foo', 'eq', 'foo', ' eq');
147cmp_ok(42.5, '<', 42.6, ' <');
148cmp_ok(0, '||', 1, ' ||');
149
150
151# Piers pointed out sometimes people override isa().
152{
153 package Wibble;
154 sub isa {
155 my($self, $class) = @_;
156 return 1 if $class eq 'Wibblemeister';
157 }
158 sub new { bless {} }
159}
160isa_ok( Wibble->new, 'Wibblemeister' );
161
845d7e37 162my $sub = sub {};
163is_deeply( $sub, $sub, 'the same function ref' );
164
165use Symbol;
166my $glob = gensym;
167is_deeply( $glob, $glob, 'the same glob' );
168
169is_deeply( { foo => $sub, bar => [1, $glob] },
170 { foo => $sub, bar => [1, $glob] }
171 );
a9153838 172
173# These two tests must remain at the end.
174is( $@, $Err, '$@ untouched' );
175cmp_ok( $!, '==', $Errno, '$! untouched' );