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