Permalink
Fetching contributors…
Cannot retrieve contributors at this time
67 lines (48 sloc) 2.01 KB
use v6;
use Test;
plan 18;
# this test file contains tests for line numbers, among other things
# so it's extremely important not to randomly insert or delete lines.
my $baseline = 10;
isa-ok callframe(), CallFrame, 'callframe() returns a CallFrame';
sub f() {
is callframe().line, $baseline + 4, 'callframe().line';
ok callframe().file ~~ /« callframe »/, '.file';
#?rakudo skip 'Unable to resolve method inline in type CallFrame'
nok callframe().inline, 'explicitly entered block (.inline)';
# Note: According to S02, these should probably fail unless
# $x is marked 'is dynamic'. We allow it for now since there's
# still some uncertainty in the spec in S06, though.
is callframe(1).my.<$x>, 42, 'can access outer lexicals via .my';
callframe(1).my.<$x> = 23;
is callframe(1).my.<$y>, 353, 'can access outer lexicals via .my';
dies-ok { callframe(1).my.<$y> = 768 }, 'cannot mutate without is dynamic';;
lower();
}
sub lower() {
ok callframe(0).code ~~ Sub, 'callframe(0).code returns this Sub';
ok callframe(1).code ~~ Sub, 'callframe(1).code returns the calling Sub';
is callframe(0).code.name, 'lower';
is callframe(1).code.name, 'f';
}
my $x is dynamic = 42;
my $y = 353;
f();
is $x, 23, '$x successfully modified';
is $y, 353, '$y not modified';
# RT #77752
#?rakudo.jvm skip 'ContextRef representation does not implement elems RT #77752'
ok callframe.perl.starts-with("CallFrame.new("), 'CallFrame.perl works';
ok callframe.gist.starts-with($*PROGRAM-NAME), 'CallFrame.gist works';
# RT #127479
#?rakudo.jvm todo 'ContextRef representation does not implement elems RT #127479'
lives-ok { sub{callframe.perl}() }, '.perl on callframe in a sub does not crash';
lives-ok {
sub foo() { callframe(1).file.ends-with('x') }
for ^300 { foo() }
}, 'No crash when using callframe(1).file many times in a loop';
lives-ok {
my $g;
for ^200 { next if $_ < 199; $g = callframe.gist }
}, 'No crash when using callframe.gist in a hot loop';
# vim: ft=perl6