Skip to content

Commit 04b03b1

Browse files
committed
Spec $*USAGE
Rakudo impl: rakudo/rakudo@0b15f6728a
1 parent 2f9a131 commit 04b03b1

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

S06-other/main-usage.t

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use v6;
33
use lib 't/spec/packages';
44

55
use Test;
6-
plan 30;
6+
plan 31;
77

88
use Test::Util;
99

@@ -131,3 +131,30 @@ is_run 'sub MAIN(*@arg where { False }) { }; sub USAGE { print "USAGE called" }'
131131
# RT #127621
132132
is_run 'sub MAIN($, *%) { }', { err => '', }, :args['--help'],
133133
'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

Comments
 (0)