Commit | Line | Data |
---|---|---|
7fa5bd9b FC |
1 | #!./perl |
2 | ||
3 | # This file tests the results of calling subroutines in the CORE:: | |
4 | # namespace with ampersand syntax. In other words, it tests the bodies of | |
5 | # the subroutines themselves, not the ops that they might inline themselves | |
6 | # as when called as barewords. | |
7 | ||
8 | # coreinline.t tests the inlining of these subs as ops. Since it was | |
9 | # convenient, I also put the prototype and undefinedness checking in that | |
10 | # file, even though those have nothing to do with inlining. (coreinline.t | |
11 | # reads the list in keywords.pl, which is why it’s convenient.) | |
12 | ||
13 | BEGIN { | |
14 | chdir 't' if -d 't'; | |
15 | @INC = qw(. ../lib); | |
16 | require "test.pl"; | |
17 | $^P |= 0x100; | |
18 | } | |
19 | # Since tests inside evals can too easily fail silently, we cannot rely | |
20 | # on done_testing. It’s much easier to count the tests as we go than to | |
21 | # declare the plan up front, so this script ends with a test that makes | |
22 | # sure the right number of tests have happened. | |
23 | ||
24 | sub lis($$;$) { | |
25 | &is(map(@$_ ? "[@{[map $_//'~~u~~', @$_]}]" : 'nought', @_[0,1]), $_[2]); | |
26 | } | |
27 | ||
28 | # This tests that the &{} syntax respects the number of arguments implied | |
29 | # by the prototype. | |
30 | sub test_proto { | |
31 | my($o) = shift; | |
32 | ||
33 | # Create an alias, for the caller’s convenience. | |
34 | *{"my$o"} = \&{"CORE::$o"}; | |
35 | ||
36 | my $p = prototype "CORE::$o"; | |
37 | ||
38 | if ($p eq '') { | |
39 | $tests ++; | |
40 | ||
41 | eval " &CORE::$o(1) "; | |
42 | like $@, qr/^Too many arguments for $o at /, "&$o with too many args"; | |
43 | ||
44 | } | |
45 | ||
46 | else { | |
47 | die "Please add tests for the $p prototype"; | |
48 | } | |
49 | } | |
50 | ||
51 | test_proto '__FILE__'; | |
52 | test_proto '__LINE__'; | |
53 | test_proto '__PACKAGE__'; | |
54 | ||
55 | is file(), 'frob' , '__FILE__ does check its caller' ; ++ $tests; | |
56 | is line(), 5 , '__LINE__ does check its caller' ; ++ $tests; | |
57 | is pakg(), 'stribble', '__PACKAGE__ does check its caller'; ++ $tests; | |
58 | ||
59 | test_proto 'continue'; | |
60 | $tests ++; | |
61 | CORE::given(1) { | |
62 | CORE::when(1) { | |
63 | &mycontinue(); | |
64 | } | |
65 | pass "&continue"; | |
66 | } | |
67 | ||
68 | test_proto $_ for qw( | |
69 | endgrent endhostent endnetent endprotoent endpwent endservent | |
70 | ); | |
71 | ||
72 | test_proto "get$_" for qw ' | |
73 | grent hostent login | |
74 | netent ppid protoent | |
75 | servent | |
76 | '; | |
77 | ||
78 | test_proto "set$_" for qw ' | |
79 | grent pwent | |
80 | '; | |
81 | ||
82 | test_proto 'time'; | |
83 | $tests += 2; | |
84 | like &mytime, '^\d+\z', '&time in scalar context'; | |
85 | like join('-', &mytime), '^\d+\z', '&time in list context'; | |
86 | ||
87 | test_proto 'times'; | |
88 | $tests += 2; | |
89 | like &mytimes, '^[\d.]+\z', '× in scalar context'; | |
90 | like join('-',&mytimes), '^[\d.]+-[\d.]+-[\d.]+-[\d.]+\z', | |
91 | '× in list context'; | |
92 | ||
93 | test_proto 'wait'; | |
94 | ||
95 | ||
96 | # Add new tests above this line. | |
97 | ||
98 | # ------------ END TESTING ----------- # | |
99 | ||
100 | is curr_test, $tests+1, 'right number of tests'; | |
101 | done_testing; | |
102 | ||
103 | #line 3 frob | |
104 | ||
105 | sub file { &CORE::__FILE__ } | |
106 | sub line { &CORE::__LINE__ } # 5 | |
107 | package stribble; | |
108 | sub main::pakg { &CORE::__PACKAGE__ } | |
109 | ||
110 | # Please do not add new tests here. |