summaryrefslogtreecommitdiff
path: root/Build/tests/checkdvi.pl
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-02-25 19:22:25 +0000
committerKarl Berry <karl@freefriends.org>2021-02-25 19:22:25 +0000
commitad547a6b5986815fda458221149728d9d9ab1d87 (patch)
tree16296910eb3eca724371474ea9aea3994dc69614 /Build/tests/checkdvi.pl
parent947b43de3dd21d58ccc2ffadefc4441ea1c2a813 (diff)
restore Build,TODO from r57911
git-svn-id: svn://tug.org/texlive/trunk@57915 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/tests/checkdvi.pl')
-rwxr-xr-xBuild/tests/checkdvi.pl123
1 files changed, 123 insertions, 0 deletions
diff --git a/Build/tests/checkdvi.pl b/Build/tests/checkdvi.pl
new file mode 100755
index 00000000000..9c6eff2172d
--- /dev/null
+++ b/Build/tests/checkdvi.pl
@@ -0,0 +1,123 @@
+#!/usr/local/bin/perl
+# dvicheck -- DVI autotest helper.
+# $Id: //depot/Master/support/tests/checkdvi.pl#1 $
+#
+# Public domain.
+# Originally written as a shell script by Patrice Dumas.
+# Revised version written in Perl by Karl Berry.
+#
+# (Although it's much simpler and more functional in sh, Perl makes it
+# possible to run on Windows, for TeX Live, etc. I hope someone cares
+# some day.)
+
+exit (&main ());
+
+sub main
+{
+ if (@ARGV != 2) {
+ print <<END_USAGE;
+Usage: $0 DVITYPE_KNOWN_GOOD DVI_TO_CHECK
+
+Run dvitype on DVI_TO_CHECK, and compare against DVITYPE_KNOWN_GOOD,
+ignoring the DVI comment. DVI_TO_CHECK is assumed to be the straight
+output from dvitype (full output), including the banner line.
+
+For autotesting.
+END_USAGE
+ return 1;
+ }
+
+ my $good_type = $ARGV[0];
+ my $check_dvi = $ARGV[1];
+
+ die "No DVI file $check_dvi" if ! -s $check_dvi;
+ die "No good dvitype file $good_type" if ! -s $good_type;
+
+ # run dvitype on the file to test.
+ my $check = &snarf_output ("dvitype", $check_dvi);
+
+ # remove extraneous comments from the known good dvitype output.
+ my $good = &clean_file ($good_type);
+
+ # they should be exactly the same.
+ my $ret = $check ne $good;
+ if ($ret) {
+ warn "$0: ${check_dvi}type different from $good_type.\n";
+ warn "check=$check\n";
+ warn "good=$good\n";
+ &save_file ("${check_dvi}type", $check);
+ system ("diff", "${check_dvi}type", $good_type);
+ }
+
+ return $ret;
+}
+
+
+#
+# Run PROGRAM on ARGS, running output with clean_dvitype and returning as
+# a string.
+#
+sub snarf_output
+{
+ my ($program,@args) = @_;
+
+ # use safe (more or less) form of open.
+ local *PROG;
+ open (PROG, "-|", $program, @args) ||die "open($program @args |) failed: $!";
+ my @lines = <PROG>;
+#warn "read lines from $program @args:\n@lines";
+ close (PROG) || warn "close($program @args |) failed: $!";
+
+ return &clean_dvitype (@lines);
+}
+
+
+#
+# Read file, run through clean_dvitype, and return as a string.
+#
+sub clean_file
+{
+ my ($file) = @_;
+
+ local *FILE;
+ open (FILE, $file) || die "open($file) failed: $!";
+ # read whole file.
+ my @lines = <FILE>;
+ close (FILE) || warn "close($file) failed: $!";
+
+ return &clean_dvitype (@lines);
+}
+
+
+#
+# Clean dvitype output. Make the first element of LINES be the empty
+# string (this contains the version number), and excise the first '...'
+# string (this is the DVI comment, which typically contains the date).
+# Return resulting string.
+#
+sub clean_dvitype
+{
+ my (@lines) = @_;
+
+ $lines[0] = "";
+ for my $line (@lines) {
+ last if $line =~ s/^'.*'//;
+ }
+
+ my $clean = join ("", @lines);
+#warn "cleaned lines:\n@lines\ninto:$clean";
+ return $clean;
+}
+
+
+#
+# Save STRING into FILE. This will be the cleaned version, but that's ok.
+#
+sub save_file
+{
+ my ($file,$string) = @_;
+ local *FILE;
+ open (FILE, ">$file") || die "open(>$FILE) failed: $!";
+ print FILE $string;
+ close (FILE) || warn "close(>$FILE) failed: $!";
+}