|
1 | 1 | use v6;
|
2 | 2 | use Test;
|
3 |
| -use lib 'lib'; |
4 |
| -use File::Find; |
| 3 | +use File::Temp; |
5 | 4 |
|
6 |
| -# Extract examples |
7 |
| -chdir $?FILE.IO.dirname.IO.dirname; |
8 |
| -my $p1 = shell "$*EXECUTABLE-NAME util/extract-examples.p6 --source-path=./doc/ --prefix=./examples/"; |
9 |
| -chdir 'examples'; |
| 5 | +use lib 'lib'; |
| 6 | +use Pod::Convenience; |
10 | 7 |
|
11 | 8 | my @files;
|
12 | 9 |
|
13 | 10 | if @*ARGS {
|
14 |
| - # don't pass examples/ as part of the path name |
15 | 11 | @files = @*ARGS;
|
16 | 12 | } else {
|
17 |
| - @files = find( |
18 |
| - dir => '.', |
19 |
| - type => 'file', |
20 |
| - exclude => / |
21 |
| - | 'Language/5to6-nutshell.p6' |
22 |
| - | 'Language/5to6-perlfunc.p6' |
23 |
| - | 'Language/5to6-perlop.p6' |
24 |
| - | 'Language/5to6-perlsyn.p6' |
25 |
| - | 'Language/5to6-perlvar.p6' |
26 |
| - | 'Language/modules.p6' |
27 |
| - | 'Language/nativecall.p6' |
28 |
| - | 'Language/packages.p6' |
29 |
| - | 'Language/phasers.p6' |
30 |
| - | 'Language/rb-nutshell.p6' |
31 |
| - | 'Language/tables.p6' |
32 |
| - | 'Language/testing.p6' |
33 |
| - | 'Language/traps.p6' |
| 13 | + for qx<git ls-files doc>.lines -> $file { |
| 14 | + next unless $file ~~ / '.pod6' $/; |
| 15 | + next if $file ~~ / |
| 16 | + | 'doc/Language/5to6-nutshell.pod6' |
| 17 | + | 'doc/Language/5to6-perlfunc.pod6' |
| 18 | + | 'doc/Language/5to6-perlop.pod6' |
| 19 | + | 'doc/Language/5to6-perlsyn.pod6' |
| 20 | + | 'doc/Language/5to6-perlvar.pod6' |
| 21 | + | 'doc/Language/modules.pod6' |
| 22 | + | 'doc/Language/nativecall.pod6' |
| 23 | + | 'doc/Language/packages.pod6' |
| 24 | + | 'doc/Language/phasers.pod6' |
| 25 | + | 'doc/Language/rb-nutshell.pod6' |
| 26 | + | 'doc/Language/tables.pod6' |
| 27 | + | 'doc/Language/testing.pod6' |
| 28 | + | 'doc/Language/traps.pod6' |
34 | 29 | /,
|
35 |
| - ); |
| 30 | + push @files, $file; |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +# Extract all the examples from the given files |
| 35 | +my @examples; |
| 36 | +my $counts = BagHash.new; |
| 37 | +for @files -> $file { |
| 38 | + for extract-pod($file.IO).contents -> $chunk { |
| 39 | + if $chunk ~~ Pod::Block::Code { |
| 40 | + next if $chunk.config<skip-test>; |
| 41 | + @examples.push: %( |
| 42 | + 'contents', $chunk.contents.join("\n"), |
| 43 | + 'file', $file, |
| 44 | + 'count', $counts{$file}++ |
| 45 | + ); |
| 46 | + } |
| 47 | + } |
36 | 48 | }
|
37 | 49 |
|
38 | 50 | my $proc;
|
39 |
| -plan +@files; |
| 51 | +plan +@examples; |
40 | 52 |
|
41 |
| -for @files -> $file { |
42 |
| - $proc = run 'perl6', '-c', $file, out => '/dev/null', err => '/dev/null'; |
| 53 | +for @examples -> $eg { |
| 54 | + my ($filename, $filehandle) = tempfile; |
| 55 | + |
| 56 | + # Wrap each snippet in an anonymous class, and add in empty routine bodies if needed |
| 57 | + |
| 58 | + my $code = "class :: \{\n" ~ $eg<contents>.trim.map({ |
| 59 | + .starts-with('multi') || |
| 60 | + .starts-with('method') || |
| 61 | + .starts-with('proto') || |
| 62 | + .starts-with('only') || |
| 63 | + .starts-with('sub') |
| 64 | + }).join("\n") ~ "\n\}"; |
| 65 | + |
| 66 | + $filehandle.print: $code; |
| 67 | + $filehandle.close; |
| 68 | + |
| 69 | + $proc = run $*EXECUTABLE-NAME, '-c', $filename, out => '/dev/null', err => '/dev/null'; |
| 70 | + my $msg = "$eg<file> chunk $eg<count> compiles"; |
43 | 71 | if $proc.exitcode == 0 {
|
44 |
| - pass "$file is compilable"; |
| 72 | + pass $msg; |
45 | 73 | } else {
|
46 |
| - flunk "$file examples check isn't successful"; |
| 74 | + diag $eg<contents>; |
| 75 | + flunk $msg; |
47 | 76 | }
|
48 | 77 | }
|
0 commit comments