This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
POSIX: test that all subroutines are exported
[perl5.git] / ext / POSIX / t / export.t
CommitLineData
57159ffe
NC
1#!./perl -w
2
3use strict;
4use Test::More;
5use Config;
6
7plan(skip_all => "POSIX is unavailable")
8 unless $Config{extensions} =~ /\bPOSIX\b/;
9
10require POSIX;
11POSIX->import();
12
13# @POSIX::EXPORT and @POSIX::EXPORT_OK are generated. The intent of this test is
14# to catch *unintended* changes to them introduced by bugs in refactoring.
15
86c35584
AP
16# N.B. the data must be sorted at runtime even though it appears sorted here
17# because it is given in ASCII order and we might be on a non-ASCII platform
57159ffe 18my %expect = (
7658eeca
AP
19 EXPORT => [sort
20 # this stuff was in 5.20.2
21 qw(
22 %SIGRT ARG_MAX B0 B110 B1200 B134 B150 B1800 B19200 B200
23 B2400 B300 B38400 B4800 B50 B600 B75 B9600 BRKINT BUFSIZ
24 CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX CLK_TCK CLOCAL
25 CLOCKS_PER_SEC CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB DBL_DIG
26 DBL_EPSILON DBL_MANT_DIG DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
27 DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP E2BIG EACCES EADDRINUSE
28 EADDRNOTAVAIL EAFNOSUPPORT EAGAIN EALREADY EBADF EBADMSG EBUSY
29 ECANCELED ECHILD ECHO ECHOE ECHOK ECHONL ECONNABORTED
30 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
31 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EIDRM EILSEQ
32 EINPROGRESS EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE
33 EMLINK EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
34 ENFILE ENOBUFS ENODATA ENODEV ENOENT ENOEXEC ENOLCK ENOLINK
35 ENOMEM ENOMSG ENOPROTOOPT ENOSPC ENOSR ENOSTR ENOSYS ENOTBLK
36 ENOTCONN ENOTDIR ENOTEMPTY ENOTRECOVERABLE ENOTSOCK ENOTSUP
37 ENOTTY ENXIO EOF EOPNOTSUPP EOTHER EOVERFLOW EOWNERDEAD EPERM
38 EPFNOSUPPORT EPIPE EPROCLIM EPROTO EPROTONOSUPPORT EPROTOTYPE
39 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT ESPIPE
40 ESRCH ESTALE ETIME ETIMEDOUT ETOOMANYREFS ETXTBSY EUSERS
41 EWOULDBLOCK EXDEV
42 EXIT_FAILURE EXIT_SUCCESS FD_CLOEXEC FILENAME_MAX
43 FLT_DIG FLT_EPSILON FLT_MANT_DIG FLT_MAX FLT_MAX_10_EXP
44 FLT_MAX_EXP FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP FLT_RADIX
45 FLT_ROUNDS F_DUPFD F_GETFD F_GETFL F_GETLK F_OK F_RDLCK
46 F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK HUGE_VAL
47 HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR INLCR INPCK
48 INT_MAX INT_MIN ISIG ISTRIP IXOFF IXON LC_ALL LC_COLLATE
49 LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LDBL_DIG
50 LDBL_EPSILON LDBL_MANT_DIG LDBL_MAX LDBL_MAX_10_EXP
51 LDBL_MAX_EXP LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP LINK_MAX
1cb852db 52 LONG_MAX LONG_MIN L_ctermid L_cuserid MAX_CANON
7658eeca
AP
53 MAX_INPUT MB_CUR_MAX MB_LEN_MAX NAME_MAX NCCS NDEBUG
54 NGROUPS_MAX NOFLSH NULL OPEN_MAX OPOST O_ACCMODE O_APPEND
55 O_CREAT O_EXCL O_NOCTTY O_NONBLOCK O_RDONLY O_RDWR O_TRUNC
56 O_WRONLY PARENB PARMRK PARODD PATH_MAX PIPE_BUF RAND_MAX R_OK
57 SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK SA_RESETHAND
58 SA_RESTART SA_SIGINFO SCHAR_MAX SCHAR_MIN SEEK_CUR SEEK_END
59 SEEK_SET SHRT_MAX SHRT_MIN SIGABRT SIGALRM SIGBUS SIGCHLD
60 SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGPOLL
61 SIGPROF SIGQUIT SIGRTMAX SIGRTMIN SIGSEGV SIGSTOP SIGSYS
62 SIGTERM SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGURG SIGUSR1
63 SIGUSR2 SIGVTALRM SIGXCPU SIGXFSZ SIG_BLOCK SIG_DFL SIG_ERR
64 SIG_IGN SIG_SETMASK SIG_UNBLOCK SSIZE_MAX STDERR_FILENO
65 STDIN_FILENO STDOUT_FILENO STREAM_MAX S_IRGRP S_IROTH S_IRUSR
66 S_IRWXG S_IRWXO S_IRWXU S_ISBLK S_ISCHR S_ISDIR S_ISFIFO
67 S_ISGID S_ISREG S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP
68 S_IXOTH S_IXUSR TCIFLUSH TCIOFF TCIOFLUSH TCION TCOFLUSH
69 TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW TMP_MAX TOSTOP
70 TZNAME_MAX UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX VEOF VEOL
71 VERASE VINTR VKILL VMIN VQUIT VSTART VSTOP VSUSP VTIME
72 WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED WNOHANG WSTOPSIG
73 WTERMSIG WUNTRACED W_OK X_OK _PC_CHOWN_RESTRICTED
74 _PC_LINK_MAX _PC_MAX_CANON _PC_MAX_INPUT _PC_NAME_MAX
75 _PC_NO_TRUNC _PC_PATH_MAX _PC_PIPE_BUF _PC_VDISABLE
76 _POSIX_ARG_MAX _POSIX_CHILD_MAX _POSIX_CHOWN_RESTRICTED
77 _POSIX_JOB_CONTROL _POSIX_LINK_MAX _POSIX_MAX_CANON
78 _POSIX_MAX_INPUT _POSIX_NAME_MAX _POSIX_NGROUPS_MAX
79 _POSIX_NO_TRUNC _POSIX_OPEN_MAX _POSIX_PATH_MAX
80 _POSIX_PIPE_BUF _POSIX_SAVED_IDS _POSIX_SSIZE_MAX
81 _POSIX_STREAM_MAX _POSIX_TZNAME_MAX _POSIX_VDISABLE
82 _POSIX_VERSION _SC_ARG_MAX _SC_CHILD_MAX _SC_CLK_TCK
83 _SC_JOB_CONTROL _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_PAGESIZE
84 _SC_SAVED_IDS _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION _exit
85 abort access acos asctime asin assert atan atexit atof atoi
86 atol bsearch calloc ceil cfgetispeed cfgetospeed cfsetispeed
87 cfsetospeed clearerr clock cosh creat ctermid ctime cuserid
88 difftime div dup dup2 errno execl execle execlp execv execve
89 execvp fabs fclose fdopen feof ferror fflush fgetc fgetpos
90 fgets floor fmod fopen fpathconf fprintf fputc fputs fread
91 free freopen frexp fscanf fseek fsetpos fstat fsync ftell
92 fwrite getchar getcwd getegid getenv geteuid getgid getgroups
93 getpid gets getuid isalnum isalpha isatty iscntrl isdigit
94 isgraph islower isprint ispunct isspace isupper isxdigit labs
95 ldexp ldiv localeconv log10 longjmp lseek malloc mblen
96 mbstowcs mbtowc memchr memcmp memcpy memmove memset mkfifo
97 mktime modf offsetof pathconf pause perror pow putc putchar
98 puts qsort raise realloc remove rewind scanf setbuf setgid
99 setjmp setlocale setpgid setsid setuid setvbuf sigaction
100 siglongjmp signal sigpending sigprocmask sigsetjmp sigsuspend
101 sinh sscanf stderr stdin stdout strcat strchr strcmp strcoll
102 strcpy strcspn strerror strftime strlen strncat strncmp
103 strncpy strpbrk strrchr strspn strstr strtod strtok strtol
104 strtoul strxfrm sysconf tan tanh tcdrain tcflow tcflush
105 tcgetattr tcgetpgrp tcsendbreak tcsetattr tcsetpgrp tmpfile
106 tmpnam tolower toupper ttyname tzname tzset uname ungetc
107 vfprintf vprintf vsprintf wcstombs wctomb
108 ),
109 # this stuff was added in 5.21
110 qw(
111 FP_ILOGB0 FP_ILOGBNAN FP_INFINITE FP_NAN FP_NORMAL FP_SUBNORMAL FP_ZERO
112 M_1_PI M_2_PI M_2_SQRTPI M_E M_LN10 M_LN2 M_LOG10E M_LOG2E M_PI
113 M_PI_2 M_PI_4 M_SQRT1_2 M_SQRT2 INFINITY NAN
114 ),
a28fff51
SH
115 # this stuff was added for Windows in 5.23
116 ($^O eq 'MSWin32' ? qw(
117 WSAEINTR WSAEBADF WSAEACCES WSAEFAULT WSAEINVAL WSAEMFILE WSAEWOULDBLOCK
118 WSAEINPROGRESS WSAEALREADY WSAENOTSOCK WSAEDESTADDRREQ WSAEMSGSIZE
119 WSAEPROTOTYPE WSAENOPROTOOPT WSAEPROTONOSUPPORT WSAESOCKTNOSUPPORT
120 WSAEOPNOTSUPP WSAEPFNOSUPPORT WSAEAFNOSUPPORT WSAEADDRINUSE
121 WSAEADDRNOTAVAIL WSAENETDOWN WSAENETUNREACH WSAENETRESET WSAECONNABORTED
122 WSAECONNRESET WSAENOBUFS WSAEISCONN WSAENOTCONN WSAESHUTDOWN
123 WSAETOOMANYREFS WSAETIMEDOUT WSAECONNREFUSED WSAELOOP WSAENAMETOOLONG
124 WSAEHOSTDOWN WSAEHOSTUNREACH WSAENOTEMPTY WSAEPROCLIM WSAEUSERS
125 WSAEDQUOT WSAESTALE WSAEREMOTE WSAEDISCON WSAENOMORE WSAECANCELLED
126 WSAEINVALIDPROCTABLE WSAEINVALIDPROVIDER WSAEPROVIDERFAILEDINIT
127 WSAEREFUSED
128 ) : ()),
7658eeca
AP
129 # adding new functions to EXPORT is a BACKWARD COMPATIBILITY BREAKING CHANGE
130 # it is OK to add new constants, but new functions may only go in EXPORT_OK
131 ],
132 EXPORT_OK => [sort
b40d1aa2
AC
133 # this stuff was added in 5.9, but not exported until 5.25
134 qw(
135 MSG_CTRUNC MSG_DONTROUTE MSG_EOR MSG_OOB MSG_PEEK
136 MSG_TRUNC MSG_WAITALL
137 ),
9a0b3f36
AC
138 # this stuff was added in 5.11, but not exported until 5.25
139 qw(
140 EAI_AGAIN EAI_BADFLAGS EAI_FAIL EAI_FAMILY EAI_MEMORY
141 EAI_NONAME EAI_OVERFLOW EAI_SERVICE EAI_SOCKTYPE EAI_SYSTEM
142 ),
7658eeca
AP
143 # this stuff was in 5.20.2
144 qw(
145 abs alarm atan2 chdir chmod chown close closedir cos exit
146 exp fcntl fileno fork getc getgrgid getgrnam getlogin
147 getpgrp getppid getpwnam getpwuid gmtime kill lchown link
148 localtime log mkdir nice open opendir pipe printf rand
149 read readdir rename rewinddir rmdir sin sleep sprintf sqrt
150 srand stat system time times umask unlink utime wait
1cb852db 151 waitpid write L_tmpnam
7658eeca
AP
152 ),
153 # this stuff was added in 5.21
decf70bc
AC
154 # (though an oversight meant that lround wasn't listed here
155 # initially; it was added to @EXPORT_OK in 5.23, and to the
156 # :math_h_c99 tag in 5.25)
7658eeca
AP
157 qw(
158 FE_DOWNWARD FE_TONEAREST FE_TOWARDZERO FE_UPWARD
159 fegetround fesetround
160 Inf NaN
161 acosh asinh atanh cbrt copysign erf erfc exp2 expm1 fdim
162 fma fmax fmin fpclassify hypot ilogb isfinite isgreater
163 isgreaterequal isinf isless islessequal islessgreater isnan
decf70bc 164 isnormal isunordered j0 j1 jn lgamma log1p log2 logb lrint lround nan
7658eeca
AP
165 nearbyint nextafter nexttoward remainder remquo rint round scalbn
166 signbit tgamma trunc y0 y1 yn strtold
167 ),
07bb61ac
JH
168 # this stuff was added in 5.23
169 qw(
170 getpayload issignaling setpayload setpayloadsig
34e79b75
DIM
171 ILL_ILLOPC ILL_ILLOPN ILL_ILLADR ILL_ILLTRP ILL_PRVOPC ILL_PRVREG
172 ILL_COPROC ILL_BADSTK
173 FPE_INTDIV FPE_INTOVF FPE_FLTDIV FPE_FLTOVF FPE_FLTUND
174 FPE_FLTRES FPE_FLTINV FPE_FLTSUB
175 SEGV_MAPERR SEGV_ACCERR
176 BUS_ADRALN BUS_ADRERR BUS_OBJERR
177 TRAP_BRKPT TRAP_TRACE
178 CLD_EXITED CLD_KILLED CLD_DUMPED CLD_TRAPPED CLD_STOPPED CLD_CONTINUED
179 POLL_IN POLL_OUT POLL_MSG POLL_ERR POLL_PRI POLL_HUP
180 SI_USER SI_QUEUE SI_TIMER SI_ASYNCIO SI_MESGQ
07bb61ac 181 ),
7658eeca 182 ],
86c35584 183);
57159ffe 184
a26223c9 185plan (tests => 2 * keys(%expect) + keys(%POSIX::));
57159ffe
NC
186
187while (my ($var, $expect) = each %expect) {
188 my $have = *{$POSIX::{$var}}{ARRAY};
189 cmp_ok(@$have, '==', @$expect,
190 "Correct number of entries for \@POSIX::$var");
86c35584 191 is_deeply([sort @$have], $expect, "Correct entries for \@POSIX::$var");
57159ffe 192}
a26223c9
AC
193
194my %no_export_needed = map +($_ => 1),
195 qw(AUTOLOAD bootstrap constant croak import load_imports
196 unimplemented_message usage);
197
198my %exported = map +($_ => 1),
199 (@POSIX::EXPORT, @POSIX::EXPORT_OK, map @$_, values %POSIX::EXPORT_TAGS);
200
201for my $name (sort keys %POSIX::) {
202 my $code = do { no strict 'refs'; \&{"POSIX::$name"} };
203 if (!defined &$code) {
204 pass("$name need not be exported as it does not name a subroutine");
205 }
206 elsif ($no_export_needed{$name}) {
207 pass("$name need not be exported as it is part of the internals");
208 }
209 else {
210 ok($exported{$name}, "subroutine POSIX::$name is exported somehow");
211 }
212}