Skip to content

Commit

Permalink
Incorporate improved Windows fragility workaround from qtest
Browse files Browse the repository at this point in the history
  • Loading branch information
jberkenbilt committed Feb 2, 2019
1 parent d491ed8 commit 8acf636
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 60 deletions.
7 changes: 0 additions & 7 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ Soon

* Set up OSS-Fuzz (Google). See starred email in qpdf label.

* Get to the bottom of Windows test fragility. The symptom is that
sometimes the output of a command is truncated even though the
command ran successfully. I strongly suspect it has to do with
TestDriver->winrun and/or use of temporary files in qtest for
Windows. If found, remove workarounds. Search for sleep to find
them.

Next ABI
========

Expand Down
25 changes: 2 additions & 23 deletions examples/qtest/create.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,9 @@ cleanup();

my $td = new TestDriver('create');

# This test is fragile on Windows for unknown reasons. Sometimes the
# output of the command is truncated even though it works and exits
# normally.

for (my $i = 0; $i < 5; ++$i)
{
unlink "tmp.out";
if ((system("pdf-create a.pdf > tmp.out") == 0) &&
open(F, "<check.tmpout"))
{
local $/ = undef;
my $text = <F>;
close(F);
if ($text =~ m/passed/)
{
last;
}
}
sleep 1;
}

$td->runtest("create a simple PDF",
{$td->FILE => "tmp.out"},
{$td->FILE => "create.out"},
{$td->COMMAND => "pdf-create a.pdf"},
{$td->FILE => "create.out", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);

cleanup();
Expand Down
32 changes: 3 additions & 29 deletions qpdf/qtest/qpdf.test
Original file line number Diff line number Diff line change
Expand Up @@ -3724,36 +3724,10 @@ foreach my $file (@files)
{$td->STRING => "",
$td->EXIT_STATUS => 0});

# This test is fragile on Windows for unknown reasons.
# Sometimes the output of qpdf --check is truncated yet
# qpdf --check still exits normally. As a workaround, try
# writing the output of qpdf --check to a file and test
# for truncation. If we get a non-truncated output, use
# that output as the test input. If this loop fails to
# produce a non-truncated output, the truncated or
# otherwise incorrect output will still be used as the
# test input, so the test will fail as it should. We lose
# a check of qpdf --check's output, but it's not important
# for this test to verify that.
unlink "check.tmpout";
for (my $i = 0; $i < 5; ++$i)
{
if ((system("qpdf --check a.pdf > check.tmpout") == 0) &&
open(F, "<check.tmpout"))
{
local $/ = undef;
my $text = <F>;
close(F);
if ($text =~ m/No syntax or stream/)
{
last;
}
}
sleep 1;
}
$td->runtest("check status",
{$td->FILE => "check.tmpout"},
{$td->FILE => "$base.$n$osuf.check"},
{$td->COMMAND => "qpdf --check a.pdf"},
{$td->FILE => "$base.$n$osuf.check",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);

$td->runtest("check with C API",
Expand Down
6 changes: 5 additions & 1 deletion qtest/module/TestDriver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ my $color_emph = "";
# MSWin32 support
my $in_windows = 0;
my $winbin = undef;
if ($^O eq 'MSWin32')
if (($^O eq 'MSWin32') || ($^O eq 'msys'))
{
$in_windows = 1;
}
Expand Down Expand Up @@ -784,6 +784,10 @@ sub runtest
binmode F;
while (<$in>)
{
if ($flags & $rep->NORMALIZE_NEWLINES)
{
s/\r$//;
}
print F;
}
$in->close();
Expand Down

0 comments on commit 8acf636

Please sign in to comment.