Commit | Line | Data |
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 | |
4 | BEGIN { |
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 |
11 | use lib 't/lib'; |
12 | use Test::More tests => 52; |
a9153838 |
13 | |
14 | # Make sure we don't mess with $@ or $!. Test at bottom. |
15 | my $Err = "this should not be touched"; |
16 | my $Errno = 42; |
17 | $@ = $Err; |
18 | $! = $Errno; |
3f2ec160 |
19 | |
6b38a9b9 |
20 | use_ok('Dummy'); |
ea2e58b9 |
21 | is( $Dummy::VERSION, '0.01', 'use_ok() loads a module' ); |
3f2ec160 |
22 | require_ok('Test::More'); |
23 | |
24 | |
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'); |
29 | |
30 | #'# |
31 | like("fooble", '/^foo/', 'foo is like fooble'); |
32 | like("FooBle", '/foo/i', 'foo is like FooBle'); |
d020a79a |
33 | like("/usr/local/pr0n/", '/^\/usr\/local/', 'regexes with slashes in like' ); |
34 | |
a9153838 |
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' ); |
38 | |
30e302f8 |
39 | my @foo = qw(foo bar baz); |
40 | unlike(@foo, '/foo/'); |
41 | |
d020a79a |
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)); |
46 | |
89c1e84a |
47 | |
d020a79a |
48 | isa_ok(bless([], "Foo"), "Foo"); |
a9153838 |
49 | isa_ok([], 'ARRAY'); |
50 | isa_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 |
69 | pass('pass() passed'); |
70 | |
71 | ok( eq_array([qw(this that whatever)], [qw(this that whatever)]), |
72 | 'eq_array with simple arrays' ); |
7483b81c |
73 | is @Test::More::Data_Stack, 0, '@Data_Stack not holding onto things'; |
74 | |
3f2ec160 |
75 | ok( eq_hash({ foo => 42, bar => 23 }, {bar => 23, foo => 42}), |
76 | 'eq_hash with simple hashes' ); |
7483b81c |
77 | is @Test::More::Data_Stack, 0; |
78 | |
3f2ec160 |
79 | ok( eq_set([qw(this that whatever)], [qw(that whatever this)]), |
80 | 'eq_set with simple sets' ); |
7483b81c |
81 | is @Test::More::Data_Stack, 0; |
3f2ec160 |
82 | |
83 | my @complex_array1 = ( |
84 | [qw(this that whatever)], |
85 | {foo => 23, bar => 42}, |
86 | "moo", |
87 | "yarrow", |
88 | [qw(498 10 29)], |
89 | ); |
90 | my @complex_array2 = ( |
91 | [qw(this that whatever)], |
92 | {foo => 23, bar => 42}, |
93 | "moo", |
94 | "yarrow", |
95 | [qw(498 10 29)], |
96 | ); |
97 | |
33459055 |
98 | is_deeply( \@complex_array1, \@complex_array2, 'is_deeply with arrays' ); |
3f2ec160 |
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' ); |
103 | |
104 | my @array1 = (qw(this that whatever), |
105 | {foo => 23, bar => 42} ); |
106 | my @array2 = (qw(this that whatever), |
107 | {foo => 24, bar => 42} ); |
108 | |
109 | ok( !eq_array(\@array1, \@array2), |
110 | 'eq_array with slightly different complicated arrays' ); |
7483b81c |
111 | is @Test::More::Data_Stack, 0; |
112 | |
3f2ec160 |
113 | ok( !eq_set(\@array1, \@array2), |
114 | 'eq_set with slightly different complicated arrays' ); |
7483b81c |
115 | is @Test::More::Data_Stack, 0; |
3f2ec160 |
116 | |
117 | my %hash1 = ( foo => 23, |
118 | bar => [qw(this that whatever)], |
119 | har => { foo => 24, bar => 42 }, |
120 | ); |
121 | my %hash2 = ( foo => 23, |
122 | bar => [qw(this that whatever)], |
123 | har => { foo => 24, bar => 42 }, |
124 | ); |
125 | |
33459055 |
126 | is_deeply( \%hash1, \%hash2, 'is_deeply with complicated hashes' ); |
127 | ok( 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 | |
138 | ok( !eq_hash(\%hash1, \%hash2), |
139 | 'eq_hash with slightly different complicated hashes' ); |
7483b81c |
140 | is @Test::More::Data_Stack, 0; |
a9153838 |
141 | |
142 | is( Test::Builder->new, Test::More->builder, 'builder()' ); |
143 | |
144 | |
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, ' ||'); |
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 | } |
160 | isa_ok( Wibble->new, 'Wibblemeister' ); |
161 | |
845d7e37 |
162 | my $sub = sub {}; |
163 | is_deeply( $sub, $sub, 'the same function ref' ); |
164 | |
165 | use Symbol; |
166 | my $glob = gensym; |
167 | is_deeply( $glob, $glob, 'the same glob' ); |
168 | |
169 | is_deeply( { foo => $sub, bar => [1, $glob] }, |
170 | { foo => $sub, bar => [1, $glob] } |
171 | ); |
a9153838 |
172 | |
173 | # These two tests must remain at the end. |
174 | is( $@, $Err, '$@ untouched' ); |
175 | cmp_ok( $!, '==', $Errno, '$! untouched' ); |