This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Elaborate a bit on Storable.
[perl5.git] / lib / Test / Simple / t / More.t
CommitLineData
33459055
MS
1#!perl -w
2
3BEGIN {
a9153838
MS
4 if( $ENV{PERL_CORE} ) {
5 chdir 't';
6 @INC = '../lib';
7 }
33459055
MS
8}
9
a9153838
MS
10use Test::More tests => 37;
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
JH
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
JH
30like("/usr/local/pr0n/", '/^\/usr\/local/', 'regexes with slashes in like' );
31
a9153838
MS
32unlike("fbar", '/^bar/', 'unlike bar');
33unlike("FooBle", '/foo/', 'foo is unlike FooBle');
34unlike("/var/local/pr0n/", '/^\/usr\/local/','regexes with slashes in unlike' );
35
d020a79a
JH
36can_ok('Test::More', qw(require_ok use_ok ok is isnt like skip can_ok
37 pass fail eq_array eq_hash eq_set));
38can_ok(bless({}, "Test::More"), qw(require_ok use_ok ok is isnt like skip
39 can_ok pass fail eq_array eq_hash eq_set));
40
41isa_ok(bless([], "Foo"), "Foo");
a9153838
MS
42isa_ok([], 'ARRAY');
43isa_ok(\42, 'SCALAR');
d020a79a 44
3f2ec160
JH
45
46pass('pass() passed');
47
48ok( eq_array([qw(this that whatever)], [qw(this that whatever)]),
49 'eq_array with simple arrays' );
50ok( eq_hash({ foo => 42, bar => 23 }, {bar => 23, foo => 42}),
51 'eq_hash with simple hashes' );
52ok( eq_set([qw(this that whatever)], [qw(that whatever this)]),
53 'eq_set with simple sets' );
54
55my @complex_array1 = (
56 [qw(this that whatever)],
57 {foo => 23, bar => 42},
58 "moo",
59 "yarrow",
60 [qw(498 10 29)],
61 );
62my @complex_array2 = (
63 [qw(this that whatever)],
64 {foo => 23, bar => 42},
65 "moo",
66 "yarrow",
67 [qw(498 10 29)],
68 );
69
33459055 70is_deeply( \@complex_array1, \@complex_array2, 'is_deeply with arrays' );
3f2ec160
JH
71ok( eq_array(\@complex_array1, \@complex_array2),
72 'eq_array with complicated arrays' );
73ok( eq_set(\@complex_array1, \@complex_array2),
74 'eq_set with complicated arrays' );
75
76my @array1 = (qw(this that whatever),
77 {foo => 23, bar => 42} );
78my @array2 = (qw(this that whatever),
79 {foo => 24, bar => 42} );
80
81ok( !eq_array(\@array1, \@array2),
82 'eq_array with slightly different complicated arrays' );
83ok( !eq_set(\@array1, \@array2),
84 'eq_set with slightly different complicated arrays' );
85
86my %hash1 = ( foo => 23,
87 bar => [qw(this that whatever)],
88 har => { foo => 24, bar => 42 },
89 );
90my %hash2 = ( foo => 23,
91 bar => [qw(this that whatever)],
92 har => { foo => 24, bar => 42 },
93 );
94
33459055
MS
95is_deeply( \%hash1, \%hash2, 'is_deeply with complicated hashes' );
96ok( eq_hash(\%hash1, \%hash2), 'eq_hash with complicated hashes');
3f2ec160
JH
97
98%hash1 = ( foo => 23,
99 bar => [qw(this that whatever)],
100 har => { foo => 24, bar => 42 },
101 );
102%hash2 = ( foo => 23,
103 bar => [qw(this tha whatever)],
104 har => { foo => 24, bar => 42 },
105 );
106
107ok( !eq_hash(\%hash1, \%hash2),
108 'eq_hash with slightly different complicated hashes' );
a9153838
MS
109
110is( Test::Builder->new, Test::More->builder, 'builder()' );
111
112
113cmp_ok(42, '==', 42, 'cmp_ok ==');
114cmp_ok('foo', 'eq', 'foo', ' eq');
115cmp_ok(42.5, '<', 42.6, ' <');
116cmp_ok(0, '||', 1, ' ||');
117
118
119# Piers pointed out sometimes people override isa().
120{
121 package Wibble;
122 sub isa {
123 my($self, $class) = @_;
124 return 1 if $class eq 'Wibblemeister';
125 }
126 sub new { bless {} }
127}
128isa_ok( Wibble->new, 'Wibblemeister' );
129
130
131# These two tests must remain at the end.
132is( $@, $Err, '$@ untouched' );
133cmp_ok( $!, '==', $Errno, '$! untouched' );