]>
git.cameronkatri.com Git - mandoc.git/blob - regress/regress.pl
3 # $Id: regress.pl,v 1.16 2021/09/19 12:15:34 schwarze Exp $
5 # Copyright (c) 2017,2018,2019,2020,2021 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);
30 system @diff, '/dev/null', '/dev/null' and @diff = qw(diff -u);
32 # --- utility functions ------------------------------------------------
36 print STDERR
"usage: $0 [directory[:test] [modifier ...]]\n";
40 # Modifier arguments provided on the command line,
41 # inspected by the main program and by the utility functions.
44 # Run a command and send STDOUT and STDERR to a file.
45 # 1st argument: path to the output file
46 # 2nd argument: command name
47 # The remaining arguments are passed to the command.
50 print "@_\n" if $targets{verbose
};
52 open OUT_FH
, '>', $outfile or die "$outfile: $!";
53 my $pid = open3
undef, ">&OUT_FH", undef, @_;
59 # Simlar, but filter the output as needed for the lint test.
62 print "@_\n" if $targets{verbose
};
63 open my $outfd, '>', $outfile or die "$outfile: $!";
65 my $pid = open3
undef, $infd, undef, @_;
67 s/^mandoc: [^:]+\//mandoc
: /;
76 # Simlar, but filter the output as needed for the html test.
79 print "@_\n" if $targets{verbose
};
80 open my $outfd, '>', $outfile or die "$outfile: $!";
82 my $pid = open3
undef, $infd, undef, @_;
86 if (!$state && s/.*<math class="eqn">//) {
89 } elsif (/BEGINTEST/) {
96 if ($state eq 'math') {
99 print $outfd "$_\n" if length;
104 print $outfd "$_\n" if $state;
115 push @failures, [@_];
119 # --- process command line arguments -----------------------------------
121 my $onlytest = shift // '';
123 /^(all|ascii|tag|man|utf8|html|markdown|lint|clean|verbose)$/
124 or usage
"$_: invalid modifier";
128 unless $targets{ascii
} || $targets{tag
} || $targets{man
} ||
129 $targets{utf8
} || $targets{html
} || $targets{markdown
} ||
130 $targets{lint
} || $targets{clean
};
131 $targets{ascii
} = $targets{tag
} = $targets{man
} = $targets{utf8
} =
132 $targets{html
} = $targets{markdown
} = $targets{lint
} = 1
136 # --- parse Makefiles --------------------------------------------------
138 sub parse_makefile
($%) {
139 my ($filename, $vars) = @_;
140 open my $fh, '<', $filename or die "$filename: $!";
144 last if /^# OpenBSD only/;
146 next if /^\.include/;
147 /^(\w+)\s*([?+]?)=\s*(.*)/
148 or die "$filename: parse error: $_";
152 $val =~ s/\$\{(\w+)\}/$vars->{$1}/;
153 $val = "$vars->{$var} $val" if $opt eq '+';
155 unless $opt eq '?' && defined $vars->{$var};
160 my (@regress_tests, @utf8_tests, @lint_tests, @html_tests);
161 my (%tag_tests, %skip_ascii, %skip_man, %skip_markdown);
162 foreach my $module (qw(roff char mdoc man tbl eqn)) {
164 parse_makefile
"$module/Makefile", \
%modvars;
165 foreach my $subdir (split ' ', $modvars{SUBDIR
}) {
166 my %subvars = (MOPTS
=> '');
167 parse_makefile
"$module/$subdir/Makefile", \
%subvars;
168 parse_makefile
"$module/Makefile.inc", \
%subvars;
169 delete $subvars{GOPTS
};
170 delete $subvars{SKIP_GROFF
};
171 delete $subvars{SKIP_GROFF_ASCII
};
172 my @mopts = split ' ', $subvars{MOPTS
};
173 delete $subvars{MOPTS
};
174 my @regress_testnames;
175 if (defined $subvars{TAG_TARGETS
}) {
176 $tag_tests{"$module/$subdir/$_"} = 1
177 for split ' ', $subvars{TAG_TARGETS
};
178 delete $subvars{TAG_TARGETS
};
180 if (defined $subvars{REGRESS_TARGETS
}) {
181 push @regress_testnames,
182 split ' ', $subvars{REGRESS_TARGETS
};
183 push @regress_tests, {
184 NAME
=> "$module/$subdir/$_",
186 } foreach @regress_testnames;
187 delete $subvars{REGRESS_TARGETS
};
189 if (defined $subvars{UTF8_TARGETS
}) {
191 NAME
=> "$module/$subdir/$_",
193 } foreach split ' ', $subvars{UTF8_TARGETS
};
194 delete $subvars{UTF8_TARGETS
};
196 if (defined $subvars{HTML_TARGETS
}) {
198 NAME
=> "$module/$subdir/$_",
200 } foreach split ' ', $subvars{HTML_TARGETS
};
201 delete $subvars{HTML_TARGETS
};
203 if (defined $subvars{LINT_TARGETS
}) {
205 NAME
=> "$module/$subdir/$_",
207 } foreach split ' ', $subvars{LINT_TARGETS
};
208 delete $subvars{LINT_TARGETS
};
210 if (defined $subvars{SKIP_ASCII
}) {
211 for (split ' ', $subvars{SKIP_ASCII
}) {
212 $skip_ascii{"$module/$subdir/$_"} = 1;
213 $skip_man{"$module/$subdir/$_"} = 1;
215 delete $subvars{SKIP_ASCII
};
217 if (defined $subvars{SKIP_TMAN
}) {
218 $skip_man{"$module/$subdir/$_"} = 1
219 for split ' ', $subvars{SKIP_TMAN
};
220 delete $subvars{SKIP_TMAN
};
222 if (defined $subvars{SKIP_MARKDOWN
}) {
223 $skip_markdown{"$module/$subdir/$_"} = 1
224 for split ' ', $subvars{SKIP_MARKDOWN
};
225 delete $subvars{SKIP_MARKDOWN
};
228 my @vars = keys %subvars;
229 die "unknown var(s) @vars in dir $module/$subdir";
232 $skip_ascii{"$module/$subdir/$_"} = 1;
233 } @regress_testnames if $skip_ascii{"$module/$subdir/ALL"};
235 $skip_man{"$module/$subdir/$_"} = 1;
236 } @regress_testnames if $skip_man{"$module/$subdir/ALL"};
238 $skip_markdown{"$module/$subdir/$_"} = 1;
239 } @regress_testnames if $skip_markdown{"$module/$subdir/ALL"};
241 delete $modvars{SUBDIR
};
243 my @vars = keys %modvars;
244 die "unknown var(s) @vars in module $module";
248 # --- run targets ------------------------------------------------------
255 if ($targets{ascii
} || $targets{tag
} || $targets{man
}) {
256 print "Running ascii, tag, and man tests ";
257 print "...\n" if $targets{verbose
};
259 for my $test (@regress_tests) {
260 my $i = "$test->{NAME}.in";
261 my $o = "$test->{NAME}.mandoc_ascii";
262 my $w = "$test->{NAME}.out_ascii";
263 my $to = "$test->{NAME}.mandoc_tag";
264 my $tos = "$test->{NAME}.mandoc_tag_s";
265 my $tw = "$test->{NAME}.out_tag";
267 if ($targets{tag
} && $tag_tests{$test->{NAME
}} &&
268 $test->{NAME
} =~ /^$onlytest/) {
271 my @cmd = (qw(../man -l), @{$test->{MOPTS
}},
272 qw(-I os=OpenBSD -T ascii -O),
273 "outfilename=$o,tagfilename=$to", "$i");
274 print "@cmd\n" if $targets{verbose
};
276 and fail
$test->{NAME
}, 'tag:man';
277 system "sed 's: .*/: :' $to > $tos";
278 system @diff, $tw, $tos
279 and fail
$test->{NAME
}, 'tag:diff';
280 print "." unless $targets{verbose
};
281 $diff_ascii = $targets{ascii
};
282 } elsif ($targets{ascii
} && !$skip_ascii{$test->{NAME
}} &&
283 $test->{NAME
} =~ /^$onlytest/) {
284 sysout
$o, '../mandoc', @{$test->{MOPTS
}},
285 qw(-I os=OpenBSD -T ascii), $i
286 and fail
$test->{NAME
}, 'ascii:mandoc';
293 and fail
$test->{NAME
}, 'ascii:diff';
294 print "." unless $targets{verbose
};
296 my $m = "$test->{NAME}.in_man";
297 my $mo = "$test->{NAME}.mandoc_man";
298 if ($targets{man
} && !$skip_man{$test->{NAME
}} &&
299 $test->{NAME
} =~ /^$onlytest/) {
302 sysout
$m, '../mandoc', @{$test->{MOPTS
}},
303 qw(-I os=OpenBSD -T man), $i
304 and fail
$test->{NAME
}, 'man:man';
305 sysout
$mo, '../mandoc', @{$test->{MOPTS
}},
306 qw(-man -I os=OpenBSD -T ascii -O mdoc), $m
307 and fail
$test->{NAME
}, 'man:mandoc';
308 system @diff, $w, $mo
309 and fail
$test->{NAME
}, 'man:diff';
310 print "." unless $targets{verbose
};
312 if ($targets{clean
}) {
313 print "rm $o $to $tos $m $mo\n" if $targets{verbose
};
314 $count_rm += unlink $o, $to, $tos, $m, $mo;
317 if ($targets{ascii
} || $targets{tag
} || $targets{man
}) {
318 print "Number of ascii, tag, and man tests:" if $targets{verbose
};
319 print " $count_ascii + $count_tag + $count_man tests run.\n";
323 if ($targets{utf8
}) {
324 print "Running utf8 tests ";
325 print "...\n" if $targets{verbose
};
327 for my $test (@utf8_tests) {
328 my $i = "$test->{NAME}.in";
329 my $o = "$test->{NAME}.mandoc_utf8";
330 my $w = "$test->{NAME}.out_utf8";
331 if ($targets{utf8
} && $test->{NAME
} =~ /^$onlytest/o) {
334 sysout
$o, '../mandoc', @{$test->{MOPTS
}},
335 qw(-I os=OpenBSD -T utf8), $i
336 and fail
$test->{NAME
}, 'utf8:mandoc';
338 and fail
$test->{NAME
}, 'utf8:diff';
339 print "." unless $targets{verbose
};
341 if ($targets{clean
}) {
342 print "rm $o\n" if $targets{verbose
};
343 $count_rm += unlink $o;
346 if ($targets{utf8
}) {
347 print "Number of utf8 tests:" if $targets{verbose
};
348 print " $count_utf8 tests run.\n";
352 if ($targets{html
}) {
353 print "Running html tests ";
354 print "...\n" if $targets{verbose
};
356 for my $test (@html_tests) {
357 my $i = "$test->{NAME}.in";
358 my $o = "$test->{NAME}.mandoc_html";
359 my $w = "$test->{NAME}.out_html";
360 if ($targets{html
} && $test->{NAME
} =~ /^$onlytest/) {
363 syshtml
$o, '../mandoc', @{$test->{MOPTS
}},
365 and fail
$test->{NAME
}, 'html:mandoc';
367 and fail
$test->{NAME
}, 'html:diff';
368 print "." unless $targets{verbose
};
370 if ($targets{clean
}) {
371 print "rm $o\n" if $targets{verbose
};
372 $count_rm += unlink $o;
375 if ($targets{html
}) {
376 print "Number of html tests:" if $targets{verbose
};
377 print " $count_html tests run.\n";
380 my $count_markdown = 0;
381 if ($targets{markdown
}) {
382 print "Running markdown tests ";
383 print "...\n" if $targets{verbose
};
385 for my $test (@regress_tests) {
386 my $i = "$test->{NAME}.in";
387 my $o = "$test->{NAME}.mandoc_markdown";
388 my $w = "$test->{NAME}.out_markdown";
389 if ($targets{markdown
} && !$skip_markdown{$test->{NAME
}} &&
390 $test->{NAME
} =~ /^$onlytest/) {
393 sysout
$o, '../mandoc', @{$test->{MOPTS
}},
394 qw(-I os=OpenBSD -T markdown), $i
395 and fail
$test->{NAME
}, 'markdown:mandoc';
397 and fail
$test->{NAME
}, 'markdown:diff';
398 print "." unless $targets{verbose
};
400 if ($targets{clean
}) {
401 print "rm $o\n" if $targets{verbose
};
402 $count_rm += unlink $o;
405 if ($targets{markdown
}) {
406 print "Number of markdown tests:" if $targets{verbose
};
407 print " $count_markdown tests run.\n";
411 if ($targets{lint
}) {
412 print "Running lint tests ";
413 print "...\n" if $targets{verbose
};
415 for my $test (@lint_tests) {
416 my $i = "$test->{NAME}.in";
417 my $o = "$test->{NAME}.mandoc_lint";
418 my $w = "$test->{NAME}.out_lint";
419 if ($targets{lint
} && $test->{NAME
} =~ /^$onlytest/) {
422 syslint
$o, '../mandoc', @{$test->{MOPTS
}},
423 qw(-I os=OpenBSD -T lint -W all), $i
424 and fail
$test->{NAME
}, 'lint:mandoc';
426 and fail
$test->{NAME
}, 'lint:diff';
427 print "." unless $targets{verbose
};
429 if ($targets{clean
}) {
430 print "rm $o\n" if $targets{verbose
};
431 $count_rm += unlink $o;
434 if ($targets{lint
}) {
435 print "Number of lint tests:" if $targets{verbose
};
436 print " $count_lint tests run.\n";
439 # --- final report -----------------------------------------------------
442 print "\nNUMBER OF FAILED TESTS: ", scalar @failures,
443 " (of $count_total tests run.)\n";
444 print "@$_\n" for @failures;
448 print "\n" if $targets{verbose
};
449 if ($count_total == 1) {
450 print "Test succeeded.\n";
451 } elsif ($count_total) {
452 print "All $count_total tests OK:";
453 print " $count_ascii ascii" if $count_ascii;
454 print " $count_tag tag" if $count_tag;
455 print " $count_man man" if $count_man;
456 print " $count_utf8 utf8" if $count_utf8;
457 print " $count_html html" if $count_html;
458 print " $count_markdown markdown" if $count_markdown;
459 print " $count_lint lint" if $count_lint;
462 print "No tests were run.\n";
464 if ($targets{clean
}) {
466 print "Deleted $count_rm test output files.\n";
467 print "The tree is now clean.\n";
469 print "No test output files were found.\n";
470 print "The tree was already clean.\n";