]>
git.cameronkatri.com Git - mandoc.git/blob - regress/regress.pl
3 # $Id: regress.pl,v 1.6 2017/05/30 19:30:40 schwarze Exp $
5 # Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
7 # Permission to use, copy, modify, and distribute this software for any
8 # purpose with or without fee is hereby granted, provided that the above
9 # copyright notice and this permission notice appear in all copies.
11 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 # Used because open(3p) and open2(3p) provide no way for handling
23 # STDERR of the child process, neither for appending it to STDOUT,
24 # nor for piping it into the Perl program.
25 use IPC
::Open3
qw(open3);
27 # Define this at one place such that it can easily be changed
28 # if diff(1) does not support the -a option.
29 my @diff = qw(diff -au);
31 # --- utility functions ------------------------------------------------
35 print STDERR
"usage: $0 [directory[:test] [modifier ...]]\n";
39 # Run a command and send STDOUT and STDERR to a file.
40 # 1st argument: path to the output file
41 # 2nd argument: command name
42 # The remaining arguments are passed to the command.
46 open OUT_FH
, '>', $outfile or die "$outfile: $!";
47 my $pid = open3
undef, ">&OUT_FH", undef, @_;
53 # Simlar, but filter the output as needed for the lint test.
56 open my $outfd, '>', $outfile or die "$outfile: $!";
58 my $pid = open3
undef, $infd, undef, @_;
60 s/^mandoc: [^:]+\//mandoc
: /;
69 # Simlar, but filter the output as needed for the html test.
72 open my $outfd, '>', $outfile or die "$outfile: $!";
74 my $pid = open3
undef, $infd, undef, @_;
78 if (!$state && s/.*<math class="eqn">//) {
82 $state = 1 if /^BEGINTEST/;
83 if ($state && s/<\/math>.*//) {
85 print $outfd "$_\n" if length;
90 print $outfd "$_\n" if $state;
91 undef $state if /^ENDTEST/;
102 push @failures, [@_];
106 # --- process command line arguments -----------------------------------
108 my ($subdir, $onlytest) = split ':', (shift // '.');
109 my $displaylevel = 2;
116 /^(all|ascii|utf8|man|html|markdown|lint|clean|verbose)$/
117 or usage
"$_: invalid modifier";
121 unless $targets{ascii
} || $targets{utf8
} || $targets{man
} ||
122 $targets{html
} || $targets{markdown
} ||
123 $targets{lint
} || $targets{clean
};
124 $targets{ascii
} = $targets{utf8
} = $targets{man
} = $targets{html
} =
125 $targets{markdown
} = $targets{lint
} = 1 if $targets{all
};
126 $displaylevel = 3 if $targets{verbose
};
129 # --- parse Makefiles --------------------------------------------------
131 my %vars = (MOPTS
=> '');
132 sub parse_makefile
($) {
133 my $filename = shift;
134 open my $fh, '<', $filename or die "$filename: $!";
138 last if /^# OpenBSD only/;
140 next if /^\.include/;
141 /^(\w+)\s*([?+]?)=\s*(.*)/
142 or die "$filename: parse error: $_";
146 $val =~ s/\$\{(\w+)\}/$vars{$1}/;
147 $val = "$vars{$var} $val" if $opt eq '+';
149 unless $opt eq '?' && defined $vars{$var};
154 if ($subdir eq '.') {
155 $vars{SUBDIR
} = 'roff char mdoc man tbl eqn';
157 parse_makefile
"$subdir/Makefile";
158 parse_makefile
"$subdir/../Makefile.inc"
159 if -e
"$subdir/../Makefile.inc";
162 my @mandoc = '../mandoc';
164 my (@regress_testnames, @utf8_testnames, @lint_testnames);
165 my (@html_testnames, @markdown_testnames);
166 my (%skip_ascii, %skip_man, %skip_markdown);
168 push @mandoc, split ' ', $vars{MOPTS
} if $vars{MOPTS
};
170 delete $vars{SKIP_GROFF
};
171 delete $vars{SKIP_GROFF_ASCII
};
174 if (defined $vars{SUBDIR
}) {
175 @subdir_names = split ' ', $vars{SUBDIR
};
176 delete $vars{SUBDIR
};
178 if (defined $vars{REGRESS_TARGETS
}) {
179 @regress_testnames = split ' ', $vars{REGRESS_TARGETS
};
180 delete $vars{REGRESS_TARGETS
};
182 if (defined $vars{UTF8_TARGETS
}) {
183 @utf8_testnames = split ' ', $vars{UTF8_TARGETS
};
184 delete $vars{UTF8_TARGETS
};
186 if (defined $vars{HTML_TARGETS
}) {
187 @html_testnames = split ' ', $vars{HTML_TARGETS
};
188 delete $vars{HTML_TARGETS
};
190 if (defined $vars{MARKDOWN_TARGETS
}) {
191 @markdown_testnames = split ' ', $vars{MARKDOWN_TARGETS
};
192 delete $vars{MARKDOWN_TARGETS
};
194 if (defined $vars{LINT_TARGETS
}) {
195 @lint_testnames = split ' ', $vars{LINT_TARGETS
};
196 delete $vars{LINT_TARGETS
};
198 if (defined $vars{SKIP_ASCII
}) {
199 for (split ' ', $vars{SKIP_ASCII
}) {
203 delete $vars{SKIP_ASCII
};
205 if (defined $vars{SKIP_TMAN
}) {
206 $skip_man{$_} = 1 for split ' ', $vars{SKIP_TMAN
};
207 delete $vars{SKIP_TMAN
};
209 if (defined $vars{SKIP_MARKDOWN
}) {
210 $skip_markdown{$_} = 1 for split ' ', $vars{SKIP_MARKDOWN
};
211 delete $vars{SKIP_MARKDOWN
};
214 my @vars = keys %vars;
215 die "unknown var(s) @vars";
217 map { $skip_ascii{$_} = 1; } @regress_testnames if $skip_ascii{ALL
};
218 map { $skip_man{$_} = 1; } @regress_testnames if $skip_man{ALL
};
219 map { $skip_markdown{$_} = 1; } @regress_testnames if $skip_markdown{ALL
};
221 # --- run targets ------------------------------------------------------
224 for my $dirname (@subdir_names) {
226 print "\n" if $targets{verbose
};
227 system './regress.pl', "$subdir/$dirname", keys %targets,
228 ($displaylevel ? $displaylevel - 1 : 0),
229 and fail
$subdir, $dirname, 'subdir';
234 for my $testname (@regress_testnames) {
235 next if $onlytest && $testname ne $onlytest;
236 my $i = "$subdir/$testname.in";
237 my $o = "$subdir/$testname.mandoc_ascii";
238 my $w = "$subdir/$testname.out_ascii";
239 if ($targets{ascii
} && !$skip_ascii{$testname}) {
242 print "@mandoc -T ascii $i\n" if $targets{verbose
};
243 sysout
$o, @mandoc, qw(-T ascii), $i
244 and fail
$subdir, $testname, 'ascii:mandoc';
246 and fail
$subdir, $testname, 'ascii:diff';
248 my $m = "$subdir/$testname.in_man";
249 my $mo = "$subdir/$testname.mandoc_man";
250 if ($targets{man
} && !$skip_man{$testname}) {
253 print "@mandoc -T man $i\n" if $targets{verbose
};
254 sysout
$m, @mandoc, qw(-T man), $i
255 and fail
$subdir, $testname, 'man:man';
256 print "@mandoc -man -T ascii $m\n" if $targets{verbose
};
257 sysout
$mo, @mandoc, qw(-man -T ascii -O mdoc), $m
258 and fail
$subdir, $testname, 'man:mandoc';
259 system @diff, $w, $mo
260 and fail
$subdir, $testname, 'man:diff';
262 if ($targets{clean
}) {
264 if $targets{verbose
} && !$skip_ascii{$testname};
267 if $targets{verbose
} && !$skip_man{$testname};
273 for my $testname (@utf8_testnames) {
274 next if $onlytest && $testname ne $onlytest;
275 my $i = "$subdir/$testname.in";
276 my $o = "$subdir/$testname.mandoc_utf8";
277 my $w = "$subdir/$testname.out_utf8";
278 if ($targets{utf8
}) {
281 print "@mandoc -T utf8 $i\n" if $targets{verbose
};
282 sysout
$o, @mandoc, qw(-T utf8), $i
283 and fail
$subdir, $testname, 'utf8:mandoc';
285 and fail
$subdir, $testname, 'utf8:diff';
287 if ($targets{clean
}) {
288 print "rm $o\n" if $targets{verbose
};
294 for my $testname (@html_testnames) {
295 next if $onlytest && $testname ne $onlytest;
296 my $i = "$subdir/$testname.in";
297 my $o = "$subdir/$testname.mandoc_html";
298 my $w = "$subdir/$testname.out_html";
299 if ($targets{html
}) {
302 print "@mandoc -T html $i\n" if $targets{verbose
};
303 syshtml
$o, @mandoc, qw(-T html), $i
304 and fail
$subdir, $testname, 'html:mandoc';
306 and fail
$subdir, $testname, 'html:diff';
308 if ($targets{clean
}) {
309 print "rm $o\n" if $targets{verbose
};
314 my $count_markdown = 0;
315 for my $testname (@regress_testnames) {
316 next if $onlytest && $testname ne $onlytest;
317 my $i = "$subdir/$testname.in";
318 my $o = "$subdir/$testname.mandoc_markdown";
319 my $w = "$subdir/$testname.out_markdown";
320 if ($targets{markdown
} && !$skip_markdown{$testname}) {
323 print "@mandoc -T markdown $i\n" if $targets{verbose
};
324 sysout
$o, @mandoc, qw(-T markdown), $i
325 and fail
$subdir, $testname, 'markdown:mandoc';
327 and fail
$subdir, $testname, 'markdown:diff';
329 if ($targets{clean
}) {
330 print "rm $o\n" if $targets{verbose
};
336 for my $testname (@lint_testnames) {
337 next if $onlytest && $testname ne $onlytest;
338 my $i = "$subdir/$testname.in";
339 my $o = "$subdir/$testname.mandoc_lint";
340 my $w = "$subdir/$testname.out_lint";
341 if ($targets{lint
}) {
344 print "@mandoc -T lint -W all $i\n" if $targets{verbose
};
345 syslint
$o, @mandoc, qw(-T lint -W all), $i
346 and fail
$subdir, $testname, 'lint:mandoc';
348 and fail
$subdir, $testname, 'lint:diff';
350 if ($targets{clean
}) {
351 print "rm $o\n" if $targets{verbose
};
356 exit 0 unless $displaylevel or @failures;
358 print "\n" if $targets{verbose
};
360 print "test $subdir:$onlytest finished";
362 print "testsuite $subdir finished";
364 print ' ', (scalar @subdir_names), ' subdirectories' if @subdir_names;
365 print " $count_ascii ascii" if $count_ascii;
366 print " $count_man man" if $count_man;
367 print " $count_utf8 utf8" if $count_utf8;
368 print " $count_html html" if $count_html;
369 print " $count_markdown markdown" if $count_markdown;
370 print " $count_lint lint" if $count_lint;
373 print " (FAIL)\n\nSOME TESTS FAILED:\n\n";
374 print "@$_\n" for @failures;
377 } elsif ($count_total == 1) {
379 } elsif ($count_total) {
380 print " (all $count_total tests OK)\n";
382 print " (no tests run)\n";