1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl test.pl'
4 my $Has_PH = $] < 5.009;
6 $SIG{__WARN__} = sub { return if $_[0] =~ /^Pseudo-hashes are deprecated/ };
8 ######################### We start with some black magic to print on failure.
10 # Change 1..1 below to 1..last_test_to_print .
11 # (It may become useful if the test is moved to ./t subdirectory.)
14 use vars qw($Total_tests);
18 BEGIN { $| = 1; $^W = 1; }
19 END {print "not ok $test_num\n" unless $loaded;}
20 print "1..$Total_tests\n";
23 print "ok $test_num\n";
25 ######################### End of black magic.
27 # Insert your test code below (better if it prints "ok 13"
28 # (correspondingly "not ok 13") depending on the success of chunk 13
31 my($test, $name) = @_;
32 print "not " unless $test;
34 print " - $name" if defined $name;
41 return 0 unless @$a1 == @$a2;
44 unless($a1->[$_] eq $a2->[$_]) {
52 # Change this to your # of ok() calls + 1
53 BEGIN { $Total_tests = 10 }
58 use fields qw(_no Pants who _up_yours);
61 sub new { fields::new(shift) }
62 sub magic_new { bless [] } # Doesn't 100% work, perl's problem.
66 ok( eqarray( [sort keys %Foo::FIELDS],
67 [sort qw(_no Pants who _up_yours what)] )
71 my($base, $mask) = @_;
73 my $fields = \%{$base.'::FIELDS'};
74 return grep { ($fields::attr{$base}[$fields->{$_}] & $mask) == $mask}
78 ok( eqarray( [sort &show_fields('Foo', fields::PUBLIC)],
79 [sort qw(Pants who what)]) );
80 ok( eqarray( [sort &show_fields('Foo', fields::PRIVATE)],
81 [sort qw(_no _up_yours)]) );
83 # We should get compile time failures field name typos
84 eval q(my Foo $obj = Foo->new; $obj->{notthere} = "");
86 my $error = $Has_PH ? 'No such(?: [\w-]+)? field "notthere"'
87 : q[Attempt to access disallowed key 'notthere' in a ].
88 q[restricted hash at ];
89 ok( $@ && $@ =~ /^$error/i );
94 my %test = ( Pants => 'Whatever', _no => 'Yeah',
95 what => 'Ahh', who => 'Moo',
98 $obj->{Pants} = 'Whatever';
100 @{$obj}{qw(what who _up_yours)} = ('Ahh', 'Moo', 'Yip');
102 while(my($k,$v) = each %test) {
103 ok($obj->{$k} eq $v);