|
3 | 3 | use lib 't/spec/packages';
|
4 | 4 |
|
5 | 5 | use Test;
|
6 |
| -plan 30; |
| 6 | +plan 31; |
7 | 7 |
|
8 | 8 | use Test::Util;
|
9 | 9 |
|
@@ -131,3 +131,30 @@ is_run 'sub MAIN(*@arg where { False }) { }; sub USAGE { print "USAGE called" }'
|
131 | 131 | # RT #127621
|
132 | 132 | is_run 'sub MAIN($, *%) { }', { err => '', }, :args['--help'],
|
133 | 133 | 'use of anon slurpy hash does not cause a crash';
|
| 134 | + |
| 135 | +subtest '$*USAGE tests' => { |
| 136 | + # Original speculations had $?USAGE, but later we realized generating |
| 137 | + # it at compile time is not worth the price, so it was changed to be |
| 138 | + # a run time variable instead: |
| 139 | + # https://irclog.perlgeek.de/perl6-dev/2017-09-23#i_15206569 |
| 140 | + plan 4; |
| 141 | + |
| 142 | + is_run 「sub MAIN($meow, :$moo) {}; sub USAGE { $*USAGE.uc.say }」, |
| 143 | + {:out(/MEOW/ & /MOO/), :err(''), :0status }, |
| 144 | + 'default $*USAGE is available inside `sub USAGE`'; |
| 145 | + |
| 146 | + is_run 「sub MAIN($meow, :$moo) {$*USAGE.uc.say; $meow.say; $moo.say}」, |
| 147 | + :args<--moo=31337 42>, |
| 148 | + {:out(/MEOW/ & /MOO/ & /42/ & /31337/), :err(''), :0status }, |
| 149 | + 'default $*USAGE is available inside `sub MAIN`'; |
| 150 | + |
| 151 | + is_run 「sub MAIN { try $*USAGE = "meow"; $! and "PASS".print }」, |
| 152 | + {:out<PASS>, :err(''), :0status }, |
| 153 | + 'trying to assign to $*USAGE inside sub MAIN throws'; |
| 154 | + |
| 155 | + is_run 「 |
| 156 | + sub MAIN ($foo) {} |
| 157 | + sub USAGE { try $*USAGE = "meow"; $! and "PASS".print } |
| 158 | + 」, {:out<PASS>, :err(''), :0status }, |
| 159 | + 'trying to assign to $*USAGE inside sub MAIN throws'; |
| 160 | +} |
0 commit comments