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