Skip to content

Commit

Permalink
Examples compilation now returns first chars of failing code
Browse files Browse the repository at this point in the history
This closes #2048. Also fixes an error in traps.
  • Loading branch information
JJ committed May 23, 2018
1 parent e794ebb commit 94859a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions doc/Language/traps.pod6
Expand Up @@ -59,12 +59,12 @@ You can purposefully assign C<Nil> as a default value:
=begin code
my %h is default(Nil) = a => Nil;
dd %h; # OUTPUT: «Hash %h = {:a(Nil)}␤»
say %h; # OUTPUT: «Hash %h = {:a(Nil)}␤»
=end code
Or bind a value to C<Nil> if that is the result you want:
=begin code
=begin code :preamble<my @a = 1,2,3,4;>
@a[3] := Nil;
say @a; # OUTPUT: «[4 8 (Any) Nil]␤»
=end code
Expand Down
10 changes: 7 additions & 3 deletions xt/examples-compilation.t
Expand Up @@ -76,11 +76,11 @@ for @examples -> $eg {

# #1355 - don't like .WHAT in examples
if ! $eg<ok-test>.contains('WHAT') && $eg<contents>.contains('.WHAT') {
flunk "$eg<file> chunk $eg<count>" ~ ' uses .WHAT: try .^name instead';
flunk "$eg<file> chunk starting with «" ~ starts-with($eg<contents>) ~ '» uses .WHAT: try .^name instead';
next;
}
if ! $eg<ok-test>.contains('dd') && $eg<contents> ~~ / << 'dd' >> / {
flunk "$eg<file> chunk $eg<count>" ~ ' uses dd: try say instead';
flunk "$eg<file> chunk starting with «" ~ starts-with($eg<contents>) ~ '» uses dd: try say instead';
next;
}

Expand All @@ -104,7 +104,7 @@ for @examples -> $eg {
$code ~= "\{}\n" if $eg<method> eq "True";
$code ~= "\n}}";

my $msg = "$eg<file> chunk $eg<count> starts with “" ~ ($eg<contents>.lines)[0].substr(0,10).trim ~ "” compiles";
my $msg = "$eg<file> chunk $eg<count> starts with “" ~ starts-with($eg<contents>) ~ "” compiles";

my $status;
{
Expand All @@ -122,3 +122,7 @@ for @examples -> $eg {
pass $msg;
}
}

sub starts-with( Str $chunk ) {
($chunk.lines)[0].substr(0,10).trim
}

0 comments on commit 94859a3

Please sign in to comment.