2 # $Id: /mirror/googlecode/test-more/t/More.t 57943 2008-08-18T02:09:22.275428Z brooklyn.kid51 $
5 if( $ENV{PERL_CORE} ) {
7 @INC = qw(../lib ../lib/Test/Simple/t/lib);
12 use Test::More tests => 52;
14 # Make sure we don't mess with $@ or $!. Test at bottom.
15 my $Err = "this should not be touched";
21 is( $Dummy::VERSION, '0.01', 'use_ok() loads a module' );
22 require_ok('Test::More');
25 ok( 2 eq 2, 'two is two is two is two' );
26 is( "foo", "foo", 'foo is foo' );
27 isnt( "foo", "bar", 'foo isnt bar');
28 isn't("foo", "bar", 'foo isn\'t bar');
31 like("fooble", '/^foo/', 'foo is like fooble');
32 like("FooBle", '/foo/i', 'foo is like FooBle');
33 like("/usr/local/pr0n/", '/^\/usr\/local/', 'regexes with slashes in like' );
35 unlike("fbar", '/^bar/', 'unlike bar');
36 unlike("FooBle", '/foo/', 'foo is unlike FooBle');
37 unlike("/var/local/pr0n/", '/^\/usr\/local/','regexes with slashes in unlike' );
39 my @foo = qw(foo bar baz);
40 unlike(@foo, '/foo/');
42 can_ok('Test::More', qw(require_ok use_ok ok is isnt like skip can_ok
43 pass fail eq_array eq_hash eq_set));
44 can_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));
48 isa_ok(bless([], "Foo"), "Foo");
50 isa_ok(\42, 'SCALAR');
53 # can_ok() & isa_ok should call can() & isa() on the given object, not
54 # just class, in case of custom can()
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') );
64 can_ok( $foo, 'blah');
65 isa_ok( $foo, 'blah');
69 pass('pass() passed');
71 ok( eq_array([qw(this that whatever)], [qw(this that whatever)]),
72 'eq_array with simple arrays' );
73 is @Test::More::Data_Stack, 0, '@Data_Stack not holding onto things';
75 ok( eq_hash({ foo => 42, bar => 23 }, {bar => 23, foo => 42}),
76 'eq_hash with simple hashes' );
77 is @Test::More::Data_Stack, 0;
79 ok( eq_set([qw(this that whatever)], [qw(that whatever this)]),
80 'eq_set with simple sets' );
81 is @Test::More::Data_Stack, 0;
83 my @complex_array1 = (
84 [qw(this that whatever)],
85 {foo => 23, bar => 42},
90 my @complex_array2 = (
91 [qw(this that whatever)],
92 {foo => 23, bar => 42},
98 is_deeply( \@complex_array1, \@complex_array2, 'is_deeply with arrays' );
99 ok( eq_array(\@complex_array1, \@complex_array2),
100 'eq_array with complicated arrays' );
101 ok( eq_set(\@complex_array1, \@complex_array2),
102 'eq_set with complicated arrays' );
104 my @array1 = (qw(this that whatever),
105 {foo => 23, bar => 42} );
106 my @array2 = (qw(this that whatever),
107 {foo => 24, bar => 42} );
109 ok( !eq_array(\@array1, \@array2),
110 'eq_array with slightly different complicated arrays' );
111 is @Test::More::Data_Stack, 0;
113 ok( !eq_set(\@array1, \@array2),
114 'eq_set with slightly different complicated arrays' );
115 is @Test::More::Data_Stack, 0;
117 my %hash1 = ( foo => 23,
118 bar => [qw(this that whatever)],
119 har => { foo => 24, bar => 42 },
121 my %hash2 = ( foo => 23,
122 bar => [qw(this that whatever)],
123 har => { foo => 24, bar => 42 },
126 is_deeply( \%hash1, \%hash2, 'is_deeply with complicated hashes' );
127 ok( eq_hash(\%hash1, \%hash2), 'eq_hash with complicated hashes');
129 %hash1 = ( foo => 23,
130 bar => [qw(this that whatever)],
131 har => { foo => 24, bar => 42 },
133 %hash2 = ( foo => 23,
134 bar => [qw(this tha whatever)],
135 har => { foo => 24, bar => 42 },
138 ok( !eq_hash(\%hash1, \%hash2),
139 'eq_hash with slightly different complicated hashes' );
140 is @Test::More::Data_Stack, 0;
142 is( Test::Builder->new, Test::More->builder, 'builder()' );
145 cmp_ok(42, '==', 42, 'cmp_ok ==');
146 cmp_ok('foo', 'eq', 'foo', ' eq');
147 cmp_ok(42.5, '<', 42.6, ' <');
148 cmp_ok(0, '||', 1, ' ||');
151 # Piers pointed out sometimes people override isa().
155 my($self, $class) = @_;
156 return 1 if $class eq 'Wibblemeister';
160 isa_ok( Wibble->new, 'Wibblemeister' );
163 is_deeply( $sub, $sub, 'the same function ref' );
167 is_deeply( $glob, $glob, 'the same glob' );
169 is_deeply( { foo => $sub, bar => [1, $glob] },
170 { foo => $sub, bar => [1, $glob] }
173 # These two tests must remain at the end.
174 is( $@, $Err, '$@ untouched' );
175 cmp_ok( $!, '==', $Errno, '$! untouched' );