Add the original source packages to maemo, source lenny
[dh-make-perl] / dev / i386 / libtest-simple-perl / libtest-simple-perl-0.80 / t / More.t
1 #!perl -w
2
3 BEGIN {
4     if( $ENV{PERL_CORE} ) {
5         chdir 't';
6         @INC = '../lib';
7     }
8 }
9
10 use lib 't/lib';
11 use Test::More tests => 52;
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;
18
19 use_ok('Dummy');
20 is( $Dummy::VERSION, '0.01', 'use_ok() loads a module' );
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');
32 like("/usr/local/pr0n/", '/^\/usr\/local/',   'regexes with slashes in like' );
33
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
38 my @foo = qw(foo bar baz);
39 unlike(@foo, '/foo/');
40
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
46
47 isa_ok(bless([], "Foo"), "Foo");
48 isa_ok([], 'ARRAY');
49 isa_ok(\42, 'SCALAR');
50
51
52 # can_ok() & isa_ok should call can() & isa() on the given object, not 
53 # just class, in case of custom can()
54 {
55        local *Foo::can;
56        local *Foo::isa;
57        *Foo::can = sub { $_[0]->[0] };
58        *Foo::isa = sub { $_[0]->[0] };
59        my $foo = bless([0], 'Foo');
60        ok( ! $foo->can('bar') );
61        ok( ! $foo->isa('bar') );
62        $foo->[0] = 1;
63        can_ok( $foo, 'blah');
64        isa_ok( $foo, 'blah');
65 }
66
67
68 pass('pass() passed');
69
70 ok( eq_array([qw(this that whatever)], [qw(this that whatever)]),
71     'eq_array with simple arrays' );
72 is @Test::More::Data_Stack, 0, '@Data_Stack not holding onto things';
73
74 ok( eq_hash({ foo => 42, bar => 23 }, {bar => 23, foo => 42}),
75     'eq_hash with simple hashes' );
76 is @Test::More::Data_Stack, 0;
77
78 ok( eq_set([qw(this that whatever)], [qw(that whatever this)]),
79     'eq_set with simple sets' );
80 is @Test::More::Data_Stack, 0;
81
82 my @complex_array1 = (
83                       [qw(this that whatever)],
84                       {foo => 23, bar => 42},
85                       "moo",
86                       "yarrow",
87                       [qw(498 10 29)],
88                      );
89 my @complex_array2 = (
90                       [qw(this that whatever)],
91                       {foo => 23, bar => 42},
92                       "moo",
93                       "yarrow",
94                       [qw(498 10 29)],
95                      );
96
97 is_deeply( \@complex_array1, \@complex_array2,    'is_deeply with arrays' );
98 ok( eq_array(\@complex_array1, \@complex_array2),
99     'eq_array with complicated arrays' );
100 ok( eq_set(\@complex_array1, \@complex_array2),
101     'eq_set with complicated arrays' );
102
103 my @array1 = (qw(this that whatever),
104               {foo => 23, bar => 42} );
105 my @array2 = (qw(this that whatever),
106               {foo => 24, bar => 42} );
107
108 ok( !eq_array(\@array1, \@array2),
109     'eq_array with slightly different complicated arrays' );
110 is @Test::More::Data_Stack, 0;
111
112 ok( !eq_set(\@array1, \@array2),
113     'eq_set with slightly different complicated arrays' );
114 is @Test::More::Data_Stack, 0;
115
116 my %hash1 = ( foo => 23,
117               bar => [qw(this that whatever)],
118               har => { foo => 24, bar => 42 },
119             );
120 my %hash2 = ( foo => 23,
121               bar => [qw(this that whatever)],
122               har => { foo => 24, bar => 42 },
123             );
124
125 is_deeply( \%hash1, \%hash2,    'is_deeply with complicated hashes' );
126 ok( eq_hash(\%hash1, \%hash2),  'eq_hash with complicated hashes');
127
128 %hash1 = ( foo => 23,
129            bar => [qw(this that whatever)],
130            har => { foo => 24, bar => 42 },
131          );
132 %hash2 = ( foo => 23,
133            bar => [qw(this tha whatever)],
134            har => { foo => 24, bar => 42 },
135          );
136
137 ok( !eq_hash(\%hash1, \%hash2),
138     'eq_hash with slightly different complicated hashes' );
139 is @Test::More::Data_Stack, 0;
140
141 is( Test::Builder->new, Test::More->builder,    'builder()' );
142
143
144 cmp_ok(42, '==', 42,        'cmp_ok ==');
145 cmp_ok('foo', 'eq', 'foo',  '       eq');
146 cmp_ok(42.5, '<', 42.6,     '       <');
147 cmp_ok(0, '||', 1,          '       ||');
148
149
150 # Piers pointed out sometimes people override isa().
151 {
152     package Wibble;
153     sub isa {
154         my($self, $class) = @_;
155         return 1 if $class eq 'Wibblemeister';
156     }
157     sub new { bless {} }
158 }
159 isa_ok( Wibble->new, 'Wibblemeister' );
160
161 my $sub = sub {};
162 is_deeply( $sub, $sub, 'the same function ref' );
163
164 use Symbol;
165 my $glob = gensym;
166 is_deeply( $glob, $glob, 'the same glob' );
167
168 is_deeply( { foo => $sub, bar => [1, $glob] },
169            { foo => $sub, bar => [1, $glob] }
170          );
171
172 # These two tests must remain at the end.
173 is( $@, $Err,               '$@ untouched' );
174 cmp_ok( $!, '==', $Errno,   '$! untouched' );