X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=tests%2FWgetTest.pm.in;h=c4c0d4d94dad44ccf3d4756fd5da59faeb397c93;hp=b20b5d8fb752fef11381695b369a3bd13866bcfa;hb=b014f8fae9291e7504c0cca2dd8b9a0035466c03;hpb=829f83bf5bce33e856971b55a8e00c3560da7b4b diff --git a/tests/WgetTest.pm.in b/tests/WgetTest.pm.in index b20b5d8f..c4c0d4d9 100644 --- a/tests/WgetTest.pm.in +++ b/tests/WgetTest.pm.in @@ -1,14 +1,17 @@ -#!/usr/bin/perl -w +# WARNING! +# WgetTest.pm is a generated file! Do not edit! Edit WgetTest.pm.in +# instead. package WgetTest; $VERSION = 0.01; use strict; +use warnings; use Cwd; use File::Path; -our $WGETPATH = "@top_srcdir@/src/wget"; +our $WGETPATH = "@abs_top_builddir@/src/wget"; my @unexpected_downloads = (); @@ -22,14 +25,14 @@ my @unexpected_downloads = (); _name => "", _output => {}, ); - + sub _default_for { my ($self, $attr) = @_; $_attr_data{$attr}; } - sub _standard_keys + sub _standard_keys { keys %_attr_data; } @@ -66,27 +69,30 @@ sub new { sub run { my $self = shift; my $result_message = "Test successful.\n"; - + printf "Running test $self->{_name}\n"; - - # Setup + + # Setup $self->_setup(); chdir ("$self->{_workdir}/$self->{_name}/input"); - + # Launch server my $pid = $self->_fork_and_launch_server(); - + # Call wget chdir ("$self->{_workdir}/$self->{_name}/output"); - # print "Calling $self->{_cmdline}\n"; - my $errcode = - ($self->{_cmdline} =~ m{^/.*}) - ? system ($self->{_cmdline}) - : system ("$self->{_workdir}/../src/$self->{_cmdline}"); + my $cmdline = $self->{_cmdline}; + $cmdline = $self->_substitute_port($cmdline); + print "Calling $cmdline\n"; + my $errcode = + ($cmdline =~ m{^/.*}) + ? system ($cmdline) + : system ("$self->{_workdir}/../src/$cmdline"); + $errcode >>= 8; # XXX: should handle abnormal error codes. # Shutdown server - # if we didn't explicitely kill the server, we would have to call - # waitpid ($pid, 0) here in order to wait for the child process to + # if we didn't explicitely kill the server, we would have to call + # waitpid ($pid, 0) here in order to wait for the child process to # terminate kill ('TERM', $pid); @@ -118,19 +124,25 @@ sub _setup { chdir ($self->{_name}); mkdir ("input"); mkdir ("output"); - + # Setup existing files chdir ("output"); foreach my $filename (keys %{$self->{_existing}}) { - open (FILE, ">$filename") + open (FILE, ">$filename") or return "Test failed: cannot open pre-existing file $filename\n"; - - print FILE $self->{_existing}->{$filename}->{content} + + my $file = $self->{_existing}->{$filename}; + print FILE $file->{content} or return "Test failed: cannot write pre-existing file $filename\n"; - + close (FILE); - } - + + if (exists($file->{timestamp})) { + utime $file->{timestamp}, $file->{timestamp}, $filename + or return "Test failed: cannot set timestamp on pre-existing file $filename\n"; + } + } + chdir ("../input"); $self->_setup_server(); @@ -142,7 +154,7 @@ sub _cleanup { my $self = shift; chdir ($self->{_workdir}); - File::Path::rmtree ($self->{_name}); + File::Path::rmtree ($self->{_name}) unless $ENV{WGET_TEST_NO_CLEANUP}; } @@ -150,37 +162,39 @@ sub _verify_download { my $self = shift; chdir ("$self->{_workdir}/$self->{_name}/output"); - + # use slurp mode to read file content my $old_input_record_separator = $/; undef $/; - + while (my ($filename, $filedata) = each %{$self->{_output}}) { - open (FILE, $filename) + open (FILE, $filename) or return "Test failed: file $filename not downloaded\n"; - + my $content = ; - $content eq $filedata->{'content'} + 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"; if (exists($filedata->{'timestamp'})) { my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat FILE; - $mtime == $filedata->{'timestamp'} + $mtime == $filedata->{'timestamp'} or return "Test failed: wrong timestamp for file $filename\n"; } - + close (FILE); - } - - $/ = $old_input_record_separator; + } + + $/ = $old_input_record_separator; # make sure no unexpected files were downloaded chdir ("$self->{_workdir}/$self->{_name}/output"); __dir_walk('.', sub { push @unexpected_downloads, $_[0] unless (exists $self->{_output}{$_[0]}) }, sub { shift; return @_ } ); - if (@unexpected_downloads) { + if (@unexpected_downloads) { return "Test failed: unexpected downloaded files [" . join(', ', @unexpected_downloads) . "]\n"; } @@ -214,7 +228,7 @@ sub __dir_walk { } -sub _fork_and_launch_server +sub _fork_and_launch_server { my $self = shift; @@ -225,7 +239,7 @@ sub _fork_and_launch_server if ($pid < 0) { die "Cannot fork"; } elsif ($pid == 0) { - # child + # child close FROM_CHILD; $self->_launch_server(sub { print TO_PARENT "SYNC\n"; close TO_PARENT }); } else {