Skip to content

Commit

Permalink
Use TAP for the test driver.
Browse files Browse the repository at this point in the history
Autotools comes with support for TAP-based test suites, and the test
suite was nearly there, so I adapted it to fit.
  • Loading branch information
DWesl committed Jun 18, 2019
1 parent 34e7c11 commit 5cf1ddc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ TEST_EXTENSIONS = .pl
PL_LOG_COMPILER = $(PERL)
AM_PL_LOG_FLAGS = -w

PL_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
$(top_srcdir)/aux_files/tap-driver.sh

dist_check_DATA = test/correct.txt test/in.tex test/noinclude.tex \
test/noinclude-correct.txt test/nouns.tex \
test/nouns-correct.txt test/part.tex test/unterminated.txt \
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ AC_CONFIG_SRCDIR([detex.h])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([aux_files])
AC_CONFIG_MACRO_DIR([m4])
AC_REQUIRE_AUX_FILE([tap-driver.sh])

AM_INIT_AUTOMAKE([foreign dist-bzip2])

Expand Down
19 changes: 13 additions & 6 deletions test.pl.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/perl -w

print "1..10\n";
my $current_test = 1;
my $exit_status = 0;
assert_produces_correct_output('in.tex', 'correct.txt');
assert_produces_correct_output('in.tex', 'correct.txt', '-l');
assert_produces_correct_output('noinclude.tex', 'noinclude-correct.txt', '-n');
Expand All @@ -12,40 +15,44 @@ run_for_wrong_input("non-existent-file.tex");
run_for_wrong_input("non-existent-file.txt");
run_for_wrong_input("test/unterminated.txt");

print "Tests ok\n";
exit $exit_status;

sub assert_produces_correct_output {
my ($input, $correct, $options) = @_;
$options ||= '';
my $options_desc = $options ? " ($options)" : '';
print "Checking correct output is produced for $input->$correct$options_desc\n";
execute_cmd("./detex $options @top_srcdir@/test/$input > /tmp/testDelatex.txt");
print "Correct output is produced for $input->$correct$options_desc\n";

my $compared = "@top_srcdir@/test/$correct /tmp/testDelatex.txt";
my $diffResult = `diff $compared 2>&1`;

if ($diffResult ne '') {
print "Test failed:\n":
if (`which kdiff3`) {
system("kdiff3 $compared");
} elsif (!$ENV{CI} && `which vimdiff`) {
system("vimdiff $compared");
} else {
system("diff -u $compared");
}
exit(11);
}
}

sub run_for_wrong_input {
my ($input) = @_;
print "Checking response for $input...\n";
execute_cmd("./detex @top_srcdir@/$input");
print "Response for $input...\n";
}

sub execute_cmd {
my ($cmd) = @_;
system(get_cmd($cmd)) or die;
if (system(get_cmd($cmd)) == 0) {
print "ok ${current_test} - ";
} else {
print "not ok ${current test} - ";
$exit_status = 11;
}
$current_test = $current_test + 1
}

sub get_cmd {
Expand Down

0 comments on commit 5cf1ddc

Please sign in to comment.