1#!./perl -w 2 3use Test::More tests => 12; 4 5# Keep this before the use Errno. 6my $has_einval = exists &Errno::EINVAL; 7 8BEGIN { 9 use_ok("Errno"); 10} 11 12BAIL_OUT("No errno's are exported") unless @Errno::EXPORT_OK; 13 14my $err = $Errno::EXPORT_OK[0]; 15my $num = &{"Errno::$err"}; 16 17is($num, &{"Errno::$err"}, 18 'element in @Errno::EXPORT_OK found via sub call'); 19 20$! = $num; 21ok(exists $!{$err}, 'entry in %! reflects current value of $!'); 22 23$! = 0; 24ok(! $!{$err}, 'entry in %! reflects the current value of $!'); 25 26ok(join(",",sort keys(%!)) eq join(",",sort @Errno::EXPORT_OK), 27 'keys of %! match keys of @Errno::EXPORT_OK'); 28 29eval { exists $!{[]} }; 30ok(! $@, "no exception recorded in %! when element's key is '[]'"); 31 32eval {$!{$err} = "qunckkk" }; 33like($@, qr/^ERRNO hash is read only!/, 34 "can't assign to ERRNO hash: 'ERRNO hash is read only!'"); 35 36eval {delete $!{$err}}; 37like($@, qr/^ERRNO hash is read only!/, 38 "can't delete from ERRNO hash: 'ERRNO hash is read only!'"); 39 40# The following tests are in trouble if some OS picks errno values 41# through Acme::MetaSyntactic::batman 42is($!{EFLRBBB}, "", "non-existent entry in ERRNO hash"); 43ok(! exists($!{EFLRBBB}), "non-existent entry in ERRNO hash"); 44 45SKIP: { 46 skip("Errno does not have EINVAL", 1) 47 unless grep {$_ eq 'EINVAL'} @Errno::EXPORT_OK; 48 is($has_einval, 1, 49 'exists &Errno::EINVAL compiled before Errno is loaded works fine'); 50} 51 52SKIP: { 53 skip("Errno does not have EBADF", 1) 54 unless grep {$_ eq 'EBADF'} @Errno::EXPORT_OK; 55 is(exists &Errno::EBADF, 1, 56 'exists &Errno::EBADF compiled after Errno is loaded works fine'); 57} 58