2 # Copyright (C) 2009-2010, Parrot Foundation.
7 use lib qw( . lib ../lib ../../lib );
9 use File::Temp qw(tempfile);
10 use Test::More qw(no_plan);
13 use Parrot::Test::Pod;
14 use Parrot::Config qw(%PConfig);
19 my $podTester = Parrot::Test::Pod->new( {
22 @files = @{$podTester->identify_files_for_POD_testing()};
25 foreach my $file ( @files ) {
26 foreach my $snippet (get_samples($file)) {
31 #################### SUBROUTINES ####################
36 # If it's a PIR fragment, wrap it in a sub.
37 if ($snippet->{type} eq "PIR" && $snippet->{modifier} =~ /FRAGMENT/) {
38 $snippet->{code} = ".sub 'testing'\n" .
39 $snippet->{code} . "\n.end";
42 # Generate a temp file for the source.
43 my ($fh,$tempfile) = tempfile(
44 SUFFIX => '.' . lc $snippet->{type},
47 print {$fh} $snippet->{code};
50 # Generate a temp file for stderr
51 my ($err_fh,$err_tempfile) = tempfile(
57 # Send the output to /dev/null; similar to perl5's -c
58 my $cmd = File::Spec->curdir() . $PConfig{slash} .
59 $PConfig{test_prog} . " -o " . File::Spec->devnull() . " " .
60 $tempfile . ' 2> ' . $err_tempfile;
62 my $description = join (':', map {$snippet->{$_}}
63 qw(file line type modifier));
65 my $rc = system($cmd);
66 open my $errout_fh, '<', $err_tempfile;
71 $error_output = <$errout_fh>;
75 $todo = 1 if ($snippet->{modifier} =~ /TODO|INVALID/);
77 # conditionally todo the file.
78 local $TODO = 'invalid code' if $todo;
80 is ($error_output,'',$description);
87 open my $fh, '<', $file;
95 while (my $line = <$fh>) {
98 if ($line =~ /^=end $target$/) {
99 $snippet->{code} = $code;
100 push @snippets, $snippet;
109 elsif ( $line =~ /^=begin ((PIR|PASM)(_(.*))?)$/ ) {
111 $snippet->{file} = $file;
112 $snippet->{line} = $.;
113 $snippet->{type} = $2;
114 $snippet->{modifier} = defined($4) ? $4 : '';
119 # We don't check for an example in progress here because no file
120 # should end with =end.
128 t/examples/pod.t - Compile examples found in POD
133 % prove t/examples/pod.t
135 # test specific files
136 % perl t/examples/pod.t docs/compiler_faq.pod
140 Tests the syntax for any embedded PIR in POD, for all files in the
141 repository that contain POD. Any invalid examples are reported in the
144 To test a snippet of parrot code, wrap it in C<=begin> and C<=end> blocks
153 C<PASM> and C<PIR> are both valid target languages.
155 Additionally, you can add the following modifiers (prepending with an
162 For PIR, wraps the code in a C<.sub> block.
168 Either of these will force the test to be marked TODO.
172 For example, this PIR fragment uses an old, invalid opcode and needs
175 =begin PIR_FRAGMENT_INVALID
177 find_type $I1, 'Integer'
179 =end PIR_FRAGMENT_INVALID
181 As shown, you can "stack" the modifiers. Take care to make the begin and
182 and end POD targets identical. Always begin with the target language.
188 # cperl-indent-level: 4
191 # vim: expandtab shiftwidth=4: