diff --git a/test.pl b/test.pl index cbac267..163ac9c 100755 --- a/test.pl +++ b/test.pl @@ -2,6 +2,8 @@ use strict; +use File::stat; + 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'); @@ -20,6 +22,8 @@ run_for_input_with_error("test/unterminated-verb.tex"); run_for_input_with_error("test/unterminated-verb-eol.tex"); +fuzz(); + print "Tests ok\n"; sub assert_produces_correct_output { @@ -60,6 +64,22 @@ sub run_for_input_with_error { die "exit code $res" if ($res != 1); } +sub fuzz { + chdir 'test'; + my $input = 'in.tex'; + my $sb = stat($input); + for (my $i=0; $i<25; ++$i) { + my $bytes = int(rand($sb->size)); + printf("Fuzz: bytes %5d/%5d of %s. ", $bytes, $sb->size, $input); + system("head -c $bytes $input > /tmp/trunc.tex"); + my $res = system(get_cmd("../delatex /tmp/trunc.tex > /tmp/trunc.log")) >> 8; + print "Exit code $res\n"; + if ($res != 0 && $res != 1) { + die; + } + } +} + sub execute_cmd { my ($cmd) = @_; my $res = system(get_cmd($cmd));