This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Ensure that the C<exists &Errno::EFOO> idiom continues to work as documented.
[perl5.git] / ext / Errno / t / Errno.t
CommitLineData
eb0f98c9 1#!./perl -w
eab60bb1 2
5d8ab953
NC
3use Test::More tests => 12;
4
5# Keep this before the use Errno.
6my $has_einval = exists &Errno::EINVAL;
eab60bb1 7
eb0f98c9
SP
8BEGIN {
9 use_ok("Errno");
10}
eab60bb1 11
eb0f98c9 12BAIL_OUT("No errno's are exported") unless @Errno::EXPORT_OK;
eab60bb1 13
eb0f98c9
SP
14my $err = $Errno::EXPORT_OK[0];
15my $num = &{"Errno::$err"};
eab60bb1 16
eb0f98c9 17is($num, &{"Errno::$err"});
eab60bb1
GS
18
19$! = $num;
eb0f98c9 20ok(exists $!{$err});
eab60bb1
GS
21
22$! = 0;
eb0f98c9 23ok(! $!{$err});
3d64f815 24
eb0f98c9 25ok(join(",",sort keys(%!)) eq join(",",sort @Errno::EXPORT_OK));
f8ed3476
RGS
26
27eval { exists $!{[]} };
eb0f98c9
SP
28ok(! $@);
29
30eval {$!{$err} = "qunckkk" };
31like($@, qr/^ERRNO hash is read only!/);
32
33eval {delete $!{$err}};
34like($@, qr/^ERRNO hash is read only!/);
35
36# The following tests are in trouble if some OS picks errno values
37# through Acme::MetaSyntactic::batman
38is($!{EFLRBBB}, "");
39ok(! exists($!{EFLRBBB}));
5d8ab953
NC
40
41SKIP: {
42 skip("Errno does not have EINVAL", 1)
43 unless grep {$_ eq 'EINVAL'} @Errno::EXPORT_OK;
44 is($has_einval, 1,
45 'exists &Errno::EINVAL compiled before Errno is loaded works fine');
46}
47
48SKIP: {
49 skip("Errno does not have EBADF", 1)
50 unless grep {$_ eq 'EBADF'} @Errno::EXPORT_OK;
51 is(exists &Errno::EBADF, 1,
52 'exists &Errno::EBADF compiled after Errno is loaded works fine');
53}