_input => {},
_name => "",
_output => {},
+ _server_behavior => {},
);
sub _default_for
sub run {
my $self = shift;
my $result_message = "Test successful.\n";
+ my $errcode;
printf "Running test $self->{_name}\n";
# Setup
- $self->_setup();
+ my $new_result = $self->_setup();
chdir ("$self->{_workdir}/$self->{_name}/input");
+ if (defined $new_result) {
+ $result_message = $new_result;
+ $errcode = 1;
+ goto cleanup;
+ }
# Launch server
my $pid = $self->_fork_and_launch_server();
my $cmdline = $self->{_cmdline};
$cmdline = $self->_substitute_port($cmdline);
print "Calling $cmdline\n";
- my $errcode =
+ $errcode =
($cmdline =~ m{^/.*})
? system ($cmdline)
: system ("$self->{_workdir}/../src/$cmdline");
# Verify download
unless ($errcode == $self->{_errcode}) {
$result_message = "Test failed: wrong code returned (was: $errcode, expected: $self->{_errcode})\n";
+ goto cleanup;
}
my $error_str;
if ($error_str = $self->_verify_download()) {
$result_message = $error_str;
}
- # Cleanup
+ cleanup:
$self->_cleanup();
print $result_message;
$self->_setup_server();
chdir ($self->{_workdir});
+ return;
}
File::Path::rmtree ($self->{_name}) unless $ENV{WGET_TEST_NO_CLEANUP};
}
+# not a method
+sub quotechar {
+ my $c = ord( shift );
+ if ($c >= 0x7 && $c <= 0xD) {
+ return '\\' . qw(a b t n v f r)[$c - 0x7];
+ } else {
+ return sprintf('\\x%02x', $c);
+ }
+}
+
+# not a method
+sub _show_diff {
+ my $SNIPPET_SIZE = 10;
+
+ my ($expected, $actual) = @_;
+
+ my $str = '';
+ my $explen = length $expected;
+ my $actlen = length $actual;
+
+ if ($explen != $actlen) {
+ $str .= "Sizes don't match: expected = $explen, actual = $actlen\n";
+ }
+
+ my $min = $explen <= $actlen? $explen : $actlen;
+ my $line = 1;
+ my $col = 1;
+ my $i;
+ for ($i=0; $i != $min; ++$i) {
+ last if substr($expected, $i, 1) ne substr($actual, $i, 1);
+ if (substr($expected, $i, 1) eq '\n') {
+ $line++;
+ $col = 0;
+ } else {
+ $col++;
+ }
+ }
+ my $snip_start = $i - ($SNIPPET_SIZE / 2);
+ if ($snip_start < 0) {
+ $SNIPPET_SIZE += $snip_start; # Take it from the end.
+ $snip_start = 0;
+ }
+ my $exp_snip = substr($expected, $snip_start, $SNIPPET_SIZE);
+ my $act_snip = substr($actual, $snip_start, $SNIPPET_SIZE);
+ $exp_snip =~s/[^[:print:]]/ quotechar($&) /ge;
+ $act_snip =~s/[^[:print:]]/ quotechar($&) /ge;
+ $str .= "Mismatch at line $line, col $col:\n";
+ $str .= " $exp_snip\n";
+ $str .= " $act_snip\n";
+
+ return $str;
+}
sub _verify_download {
my $self = shift;
my $content = <FILE>;
my $expected_content = $filedata->{'content'};
$expected_content = $self->_substitute_port($expected_content);
- $content eq $expected_content
- or return "Test failed: wrong content for file $filename\n";
+ unless ($content eq $expected_content) {
+ return "Test failed: wrong content for file $filename\n"
+ . _show_diff($expected_content, $content);
+ }
if (exists($filedata->{'timestamp'})) {
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,