]>
git.cameronkatri.com Git - mandoc.git/blob - regress/regress.pl
3 # $Id: regress.pl,v 1.12 2019/09/03 18:19:37 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);
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|utf8|man|html|markdown|lint|clean|verbose)$/
124 or usage
"$_: invalid modifier";
128 unless $targets{ascii
} || $targets{utf8
} || $targets{man
} ||
129 $targets{html
} || $targets{markdown
} ||
130 $targets{lint
} || $targets{clean
};
131 $targets{ascii
} = $targets{utf8
} = $targets{man
} = $targets{html
} =
132 $targets{markdown
} = $targets{lint
} = 1 if $targets{all
};
135 # --- parse Makefiles --------------------------------------------------
137 sub parse_makefile
($%) {
138 my ($filename, $vars) = @_;
139 open my $fh, '<', $filename or die "$filename: $!";
143 last if /^# OpenBSD only/;
145 next if /^\.include/;
146 /^(\w+)\s*([?+]?)=\s*(.*)/
147 or die "$filename: parse error: $_";
151 $val =~ s/\$\{(\w+)\}/$vars->{$1}/;
152 $val = "$vars->{$var} $val" if $opt eq '+';
154 unless $opt eq '?' && defined $vars->{$var};
159 my (@regress_tests, @utf8_tests, @lint_tests, @html_tests);
160 my (%skip_ascii, %skip_man, %skip_markdown);
161 foreach my $module (qw(roff char mdoc man tbl eqn)) {
163 parse_makefile
"$module/Makefile", \
%modvars;
164 foreach my $subdir (split ' ', $modvars{SUBDIR
}) {
165 my %subvars = (MOPTS
=> '');
166 parse_makefile
"$module/$subdir/Makefile", \
%subvars;
167 parse_makefile
"$module/Makefile.inc", \
%subvars;
168 delete $subvars{SKIP_GROFF
};
169 delete $subvars{SKIP_GROFF_ASCII
};
170 delete $subvars{TBL
};
171 delete $subvars{EQN
};
172 my @mandoc = ('../mandoc', split ' ', $subvars{MOPTS
});
173 delete $subvars{MOPTS
};
174 my @regress_testnames;
175 if (defined $subvars{REGRESS_TARGETS
}) {
176 push @regress_testnames,
177 split ' ', $subvars{REGRESS_TARGETS
};
178 push @regress_tests, {
179 NAME
=> "$module/$subdir/$_",
181 } foreach @regress_testnames;
182 delete $subvars{REGRESS_TARGETS
};
184 if (defined $subvars{UTF8_TARGETS
}) {
186 NAME
=> "$module/$subdir/$_",
188 } foreach split ' ', $subvars{UTF8_TARGETS
};
189 delete $subvars{UTF8_TARGETS
};
191 if (defined $subvars{HTML_TARGETS
}) {
193 NAME
=> "$module/$subdir/$_",
195 } foreach split ' ', $subvars{HTML_TARGETS
};
196 delete $subvars{HTML_TARGETS
};
198 if (defined $subvars{LINT_TARGETS
}) {
200 NAME
=> "$module/$subdir/$_",
202 } foreach split ' ', $subvars{LINT_TARGETS
};
203 delete $subvars{LINT_TARGETS
};
205 if (defined $subvars{SKIP_ASCII
}) {
206 for (split ' ', $subvars{SKIP_ASCII
}) {
207 $skip_ascii{"$module/$subdir/$_"} = 1;
208 $skip_man{"$module/$subdir/$_"} = 1;
210 delete $subvars{SKIP_ASCII
};
212 if (defined $subvars{SKIP_TMAN
}) {
213 $skip_man{"$module/$subdir/$_"} = 1
214 for split ' ', $subvars{SKIP_TMAN
};
215 delete $subvars{SKIP_TMAN
};
217 if (defined $subvars{SKIP_MARKDOWN
}) {
218 $skip_markdown{"$module/$subdir/$_"} = 1
219 for split ' ', $subvars{SKIP_MARKDOWN
};
220 delete $subvars{SKIP_MARKDOWN
};
223 my @vars = keys %subvars;
224 die "unknown var(s) @vars in dir $module/$subdir";
227 $skip_ascii{"$module/$subdir/$_"} = 1;
228 } @regress_testnames if $skip_ascii{"$module/$subdir/ALL"};
230 $skip_man{"$module/$subdir/$_"} = 1;
231 } @regress_testnames if $skip_man{"$module/$subdir/ALL"};
233 $skip_markdown{"$module/$subdir/$_"} = 1;
234 } @regress_testnames if $skip_markdown{"$module/$subdir/ALL"};
236 delete $modvars{SUBDIR
};
238 my @vars = keys %modvars;
239 die "unknown var(s) @vars in module $module";
243 # --- run targets ------------------------------------------------------
249 if ($targets{ascii
} || $targets{man
}) {
250 print "Running ascii and man tests ";
251 print "...\n" if $targets{verbose
};
253 for my $test (@regress_tests) {
254 my $i = "$test->{NAME}.in";
255 my $o = "$test->{NAME}.mandoc_ascii";
256 my $w = "$test->{NAME}.out_ascii";
257 if ($targets{ascii
} && !$skip_ascii{$test->{NAME
}} &&
258 $test->{NAME
} =~ /^$onlytest/) {
261 sysout
$o, @{$test->{MANDOC
}}, qw(-I os=OpenBSD -T ascii), $i
262 and fail
$test->{NAME
}, 'ascii:mandoc';
264 and fail
$test->{NAME
}, 'ascii:diff';
265 print "." unless $targets{verbose
};
267 my $m = "$test->{NAME}.in_man";
268 my $mo = "$test->{NAME}.mandoc_man";
269 if ($targets{man
} && !$skip_man{$test->{NAME
}} &&
270 $test->{NAME
} =~ /^$onlytest/) {
273 sysout
$m, @{$test->{MANDOC
}}, qw(-I os=OpenBSD -T man), $i
274 and fail
$test->{NAME
}, 'man:man';
275 sysout
$mo, @{$test->{MANDOC
}},
276 qw(-man -I os=OpenBSD -T ascii -O mdoc), $m
277 and fail
$test->{NAME
}, 'man:mandoc';
278 system @diff, $w, $mo
279 and fail
$test->{NAME
}, 'man:diff';
280 print "." unless $targets{verbose
};
282 if ($targets{clean
}) {
283 print "rm $o $m $mo\n" if $targets{verbose
};
284 $count_rm += unlink $o, $m, $mo;
287 if ($targets{ascii
} || $targets{man
}) {
288 print "Number of ascii and man tests:" if $targets{verbose
};
289 print " $count_ascii + $count_man tests run.\n";
293 if ($targets{utf8
}) {
294 print "Running utf8 tests ";
295 print "...\n" if $targets{verbose
};
297 for my $test (@utf8_tests) {
298 my $i = "$test->{NAME}.in";
299 my $o = "$test->{NAME}.mandoc_utf8";
300 my $w = "$test->{NAME}.out_utf8";
301 if ($targets{utf8
} && $test->{NAME
} =~ /^$onlytest/o) {
304 sysout
$o, @{$test->{MANDOC
}}, qw(-I os=OpenBSD -T utf8), $i
305 and fail
$test->{NAME
}, 'utf8:mandoc';
307 and fail
$test->{NAME
}, 'utf8:diff';
308 print "." unless $targets{verbose
};
310 if ($targets{clean
}) {
311 print "rm $o\n" if $targets{verbose
};
312 $count_rm += unlink $o;
315 if ($targets{utf8
}) {
316 print "Number of utf8 tests:" if $targets{verbose
};
317 print " $count_utf8 tests run.\n";
321 if ($targets{html
}) {
322 print "Running html tests ";
323 print "...\n" if $targets{verbose
};
325 for my $test (@html_tests) {
326 my $i = "$test->{NAME}.in";
327 my $o = "$test->{NAME}.mandoc_html";
328 my $w = "$test->{NAME}.out_html";
329 if ($targets{html
} && $test->{NAME
} =~ /^$onlytest/) {
332 syshtml
$o, @{$test->{MANDOC
}}, qw(-T html), $i
333 and fail
$test->{NAME
}, 'html:mandoc';
335 and fail
$test->{NAME
}, 'html:diff';
336 print "." unless $targets{verbose
};
338 if ($targets{clean
}) {
339 print "rm $o\n" if $targets{verbose
};
340 $count_rm += unlink $o;
343 if ($targets{html
}) {
344 print "Number of html tests:" if $targets{verbose
};
345 print " $count_html tests run.\n";
348 my $count_markdown = 0;
349 if ($targets{markdown
}) {
350 print "Running markdown tests ";
351 print "...\n" if $targets{verbose
};
353 for my $test (@regress_tests) {
354 my $i = "$test->{NAME}.in";
355 my $o = "$test->{NAME}.mandoc_markdown";
356 my $w = "$test->{NAME}.out_markdown";
357 if ($targets{markdown
} && !$skip_markdown{$test->{NAME
}} &&
358 $test->{NAME
} =~ /^$onlytest/) {
361 sysout
$o, @{$test->{MANDOC
}},
362 qw(-I os=OpenBSD -T markdown), $i
363 and fail
$test->{NAME
}, 'markdown:mandoc';
365 and fail
$test->{NAME
}, 'markdown:diff';
366 print "." unless $targets{verbose
};
368 if ($targets{clean
}) {
369 print "rm $o\n" if $targets{verbose
};
370 $count_rm += unlink $o;
373 if ($targets{markdown
}) {
374 print "Number of markdown tests:" if $targets{verbose
};
375 print " $count_markdown tests run.\n";
379 if ($targets{lint
}) {
380 print "Running lint tests ";
381 print "...\n" if $targets{verbose
};
383 for my $test (@lint_tests) {
384 my $i = "$test->{NAME}.in";
385 my $o = "$test->{NAME}.mandoc_lint";
386 my $w = "$test->{NAME}.out_lint";
387 if ($targets{lint
} && $test->{NAME
} =~ /^$onlytest/) {
390 syslint
$o, @{$test->{MANDOC
}},
391 qw(-I os=OpenBSD -T lint -W all), $i
392 and fail
$test->{NAME
}, 'lint:mandoc';
394 and fail
$test->{NAME
}, 'lint:diff';
395 print "." unless $targets{verbose
};
397 if ($targets{clean
}) {
398 print "rm $o\n" if $targets{verbose
};
399 $count_rm += unlink $o;
402 if ($targets{lint
}) {
403 print "Number of lint tests:" if $targets{verbose
};
404 print " $count_lint tests run.\n";
407 # --- final report -----------------------------------------------------
410 print "\nNUMBER OF FAILED TESTS: ", scalar @failures,
411 " (of $count_total tests run.)\n";
412 print "@$_\n" for @failures;
416 print "\n" if $targets{verbose
};
417 if ($count_total == 1) {
418 print "Test succeeded.\n";
419 } elsif ($count_total) {
420 print "All $count_total tests OK:";
421 print " $count_ascii ascii" if $count_ascii;
422 print " $count_man man" if $count_man;
423 print " $count_utf8 utf8" if $count_utf8;
424 print " $count_html html" if $count_html;
425 print " $count_markdown markdown" if $count_markdown;
426 print " $count_lint lint" if $count_lint;
429 print "No tests were run.\n";
431 if ($targets{clean
}) {
433 print "Deleted $count_rm test output files.\n";
434 print "The tree is now clean.\n";
436 print "No test output files were found.\n";
437 print "The tree was already clean.\n";