]> sjero.net Git - wget/commitdiff
[svn] Merging fix for b20431: automated testing via "make test".
authormicah <devnull@localhost>
Thu, 12 Jul 2007 06:10:48 +0000 (23:10 -0700)
committermicah <devnull@localhost>
Thu, 12 Jul 2007 06:10:48 +0000 (23:10 -0700)
29 files changed:
Makefile.in
configure.in
tests/FTPTest.pm
tests/HTTPTest.pm
tests/Makefile.in
tests/Test--spider-fail.px [changed mode: 0644->0755]
tests/Test--spider-r.px [changed mode: 0644->0755]
tests/Test--spider.px [changed mode: 0644->0755]
tests/Test-E-k-K.px [changed mode: 0644->0755]
tests/Test-E-k.px [changed mode: 0644->0755]
tests/Test-HTTP-Content-Disposition-1.px [changed mode: 0644->0755]
tests/Test-HTTP-Content-Disposition-2.px [changed mode: 0644->0755]
tests/Test-HTTP-Content-Disposition.px [changed mode: 0644->0755]
tests/Test-N-current.px [changed mode: 0644->0755]
tests/Test-N-old.px [changed mode: 0644->0755]
tests/Test-N.px [changed mode: 0644->0755]
tests/Test-O-nonexisting.px [changed mode: 0644->0755]
tests/Test-O.px [changed mode: 0644->0755]
tests/Test-Restrict-Lowercase.px [changed mode: 0644->0755]
tests/Test-Restrict-Uppercase.px [changed mode: 0644->0755]
tests/Test-c-full.px [changed mode: 0644->0755]
tests/Test-c-partial.px [changed mode: 0644->0755]
tests/Test-c.px [changed mode: 0644->0755]
tests/Test-ftp.px [changed mode: 0644->0755]
tests/Test-nonexisting-quiet.px [changed mode: 0644->0755]
tests/Test-noop.px [changed mode: 0644->0755]
tests/Test-np.px [changed mode: 0644->0755]
tests/Test.pm [deleted file]
tests/WgetTest.pm.in [new file with mode: 0644]

index 8d7f9de817c47a0f0551a28f324885447ed955e6..b76228c0bbc1b44b51abc8922e1cd6d709d3c015 100644 (file)
@@ -86,7 +86,7 @@ SUBDIRS = src doc po tests util windows
 # default target
 all: src/config.h Makefile $(SUBDIRS)
 
-unittest: src/config.h Makefile 
+test: src/config.h Makefile 
        cd tests && $(MAKE) $(MAKEDEFS) $@
        
 check: all
index c502a7e4ebf0ba50f13d83d30bc06b5dfbb2d650..ae07c6aa998cf3feef30e5a3e236783d48cba80a 100644 (file)
@@ -476,7 +476,8 @@ dnl
 dnl Create output
 dnl
 AC_CONFIG_FILES([Makefile src/Makefile doc/Makefile util/Makefile
-                 po/Makefile.in tests/Makefile windows/Makefile])
+                 po/Makefile.in tests/Makefile tests/WgetTest.pm
+                 windows/Makefile])
 AC_CONFIG_HEADERS([src/config.h])
 AH_BOTTOM([
 #include "config-post.h"
index 01c738d48a59a3515ff7467579f70dbd57293f4e..0e9e0715508948517473a96d0d90eadf44281045 100644 (file)
@@ -5,9 +5,9 @@ package FTPTest;
 use strict;
 
 use FTPServer;
-use Test;
+use WgetTest;
 
-our @ISA = qw(Test);
+our @ISA = qw(WgetTest);
 my $VERSION = 0.01;
 
 
index 885850d0304fe8026737ff0ed4f64c5687dc0387..cd4fb2e2e777b8318009f840d2c3fcc4e82bf44b 100644 (file)
@@ -5,9 +5,9 @@ package HTTPTest;
 use strict;
 
 use HTTPServer;
-use Test;
+use WgetTest;
 
-our @ISA = qw(Test);
+our @ISA = qw(WgetTest);
 my $VERSION = 0.01;
 
 
index 49548a5d172686f70c25c41593ba4ec8fbf13e17..b038664070bb40ee69ff1a1f6a5778925ac98b17 100644 (file)
@@ -74,7 +74,38 @@ GETOPT_OBJ = @GETOPT_OBJ@
 
 all:
 
-unittest: test$(exeext)
+.PHONY: test
+
+test: run-unit-tests run-px-tests
+
+run-unit-tests: unit-tests$(exeext)
+       ./unit-tests$(exeext)
+
+run-px-tests: WgetTest.pm
+       ./Test-c-full.px && echo && echo
+       ./Test-c-partial.px && echo && echo
+       ./Test-c.px && echo && echo
+#      ./Test-E-k-K.px && echo && echo
+#      ./Test-E-k.px && echo && echo
+       ./Test-ftp.px && echo && echo
+#      ./Test-HTTP-Content-Disposition.px && echo && echo
+#      ./Test-HTTP-Content-Disposition-1.px && echo && echo
+#      ./Test-HTTP-Content-Disposition-2.px && echo && echo
+       ./Test-N-current.px && echo && echo
+#      ./Test-nonexisting-quiet.px && echo && echo
+#      ./Test-noop.px && echo && echo
+#      ./Test-np.px && echo && echo
+#      ./Test-N.px && echo && echo
+       ./Test-O-nonexisting.px && echo && echo
+       ./Test-O.px && echo && echo
+#      ./Test-Restrict-Lowercase.px && echo && echo
+#      ./Test-Restrict-Uppercase.px && echo && echo
+       ./Test--spider-fail.px && echo && echo
+       ./Test--spider.px && echo && echo
+       ./Test--spider-r.px && echo && echo
+
+WgetTest.pm: WgetTest.pm.in @top_srcdir@/config.status
+       cd @top_srcdir@ && ./config.status
 
 #
 # Dependencies for test binary
@@ -227,7 +258,7 @@ xmalloc.o: ../src/xmalloc.c $(HEADERS)
        $(COMPILE) -DTESTING -c $<
 
        
-test$(exeext): $(TESTOBJ)
+unit-tests$(exeext): $(TESTOBJ)
        $(LINK) $(TESTOBJ) $(LIBS)
 
 #
@@ -235,7 +266,7 @@ test$(exeext): $(TESTOBJ)
 #
 
 clean:
-       $(RM) *.o test$(exeext) *~ *.bak core core.[0-9]*
+       $(RM) *.o unit-tests$(exeext) *~ *.bak core core.[0-9]*
 
 distclean: clean
        $(RM) Makefile
old mode 100644 (file)
new mode 100755 (executable)
index 9682681..c5a299d
@@ -32,7 +32,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget --spider http://localhost:8080/nonexistent";
+my $cmdline = $WgetTest::WGETPATH . " --spider http://localhost:8080/nonexistent";
 
 my $expected_error_code = 256;
 
@@ -46,7 +46,7 @@ my $the_test = HTTPTest->new (name => "Test--spider-fail",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 94ca2c7..7b8d460
@@ -89,7 +89,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget --spider -r http://localhost:8080/";
+my $cmdline = $WgetTest::WGETPATH . " --spider -r http://localhost:8080/";
 
 my $expected_error_code = 0;
 
@@ -103,7 +103,7 @@ my $the_test = HTTPTest->new (name => "Test--spider-r",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 2c58ceb..c2c1263
@@ -32,7 +32,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget --spider http://localhost:8080/index.html";
+my $cmdline = $WgetTest::WGETPATH . " --spider http://localhost:8080/index.html";
 
 my $expected_error_code = 256;
 
@@ -46,7 +46,7 @@ my $the_test = HTTPTest->new (name => "Test--spider",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 854d47a..71d51ea
@@ -60,7 +60,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget -d -r -nd -E -k -K http://localhost:8080/index.php";
+my $cmdline = $WgetTest::WGETPATH . " -d -r -nd -E -k -K http://localhost:8080/index.php";
 
 my $expected_error_code = 0;
 
@@ -83,7 +83,7 @@ my $the_test = HTTPTest->new (name => "Test-E-k-K",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 86e2dcf..3bf441d
@@ -60,7 +60,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget -r -nd -E -k http://localhost:8080/index.php";
+my $cmdline = $WgetTest::WGETPATH . " -r -nd -E -k http://localhost:8080/index.php";
 
 my $expected_error_code = 0;
 
@@ -80,7 +80,7 @@ my $the_test = HTTPTest->new (name => "Test-E-k",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index da27e3e..6d29523
@@ -37,7 +37,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget http://localhost:8080/dummy.html";
+my $cmdline = $WgetTest::WGETPATH . " http://localhost:8080/dummy.html";
 
 my $expected_error_code = 0;
 
@@ -70,7 +70,7 @@ my $the_test = HTTPTest->new (name => "Test-HTTP-Content-Disposition-1",
                               errcode => $expected_error_code, 
                               existing => \%existing_files,
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 589329f..03eb2be
@@ -37,7 +37,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget --no-content-disposition http://localhost:8080/dummy.html";
+my $cmdline = $WgetTest::WGETPATH . " --no-content-disposition http://localhost:8080/dummy.html";
 
 my $expected_error_code = 0;
 
@@ -70,7 +70,7 @@ my $the_test = HTTPTest->new (name => "Test-HTTP-Content-Disposition-2",
                               errcode => $expected_error_code, 
                               existing => \%existing_files,
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 465c43f..2a8fd39
@@ -33,7 +33,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget http://localhost:8080/dummy.html";
+my $cmdline = $WgetTest::WGETPATH . " http://localhost:8080/dummy.html";
 
 my $expected_error_code = 0;
 
@@ -50,7 +50,7 @@ my $the_test = HTTPTest->new (name => "Test-HTTP-Content-Disposition",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 9343d17..bb5b0d9
@@ -27,7 +27,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget -c http://localhost:8080/somefile.txt";
+my $cmdline = $WgetTest::WGETPATH . " -c http://localhost:8080/somefile.txt";
 
 my $expected_error_code = 0;
 
@@ -51,7 +51,7 @@ my $the_test = HTTPTest->new (name => "Test-N-current",
                               errcode => $expected_error_code, 
                               existing => \%existing_files,
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 7cdc3a0..05383db
@@ -33,7 +33,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget -N http://localhost:8080/somefile.txt";
+my $cmdline = $WgetTest::WGETPATH . " -N http://localhost:8080/somefile.txt";
 
 my $expected_error_code = 0;
 
@@ -59,7 +59,7 @@ my $the_test = HTTPTest->new (name => "Test-N-old",
                               errcode => $expected_error_code, 
                               existing => \%existing_files,
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index d70171d..6106987
@@ -24,7 +24,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget -N http://localhost:8080/dummy.txt";
+my $cmdline = $WgetTest::WGETPATH . " -N http://localhost:8080/dummy.txt";
 
 my $expected_error_code = 0;
 
@@ -42,7 +42,7 @@ my $the_test = HTTPTest->new (name => "Test-N",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index b341b7f..347dc38
@@ -23,7 +23,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget --quiet -O out http://localhost:8080/nonexistent";
+my $cmdline = $WgetTest::WGETPATH . " --quiet -O out http://localhost:8080/nonexistent";
 
 my $expected_error_code = 256;
 
@@ -40,7 +40,7 @@ my $the_test = HTTPTest->new (name => "Test-O-nonexisting",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 722ff39..e584d06
@@ -23,7 +23,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget -O out http://localhost:8080/dummy.txt";
+my $cmdline = $WgetTest::WGETPATH . " -O out http://localhost:8080/dummy.txt";
 
 my $expected_error_code = 0;
 
@@ -40,7 +40,7 @@ my $the_test = HTTPTest->new (name => "Test-O",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 035b47a..fab08d4
@@ -32,7 +32,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget --restrict-file-names=lowercase http://localhost:8080/SomePage.html";
+my $cmdline = $WgetTest::WGETPATH . " --restrict-file-names=lowercase http://localhost:8080/SomePage.html";
 
 my $expected_error_code = 0;
 
@@ -49,7 +49,7 @@ my $the_test = HTTPTest->new (name => "Test-Restrict-Lowercase",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 05e5bcd..cefa172
@@ -32,7 +32,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget --restrict-file-names=uppercase http://localhost:8080/SomePage.html";
+my $cmdline = $WgetTest::WGETPATH . " --restrict-file-names=uppercase http://localhost:8080/SomePage.html";
 
 my $expected_error_code = 0;
 
@@ -49,7 +49,7 @@ my $the_test = HTTPTest->new (name => "Test-Restrict-Uppercase",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index c57182e..bb9304b
@@ -27,7 +27,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget -c http://localhost:8080/somefile.txt";
+my $cmdline = $WgetTest::WGETPATH . " -c http://localhost:8080/somefile.txt";
 
 my $expected_error_code = 0;
 
@@ -51,7 +51,7 @@ my $the_test = HTTPTest->new (name => "Test-c-full",
                               errcode => $expected_error_code, 
                               existing => \%existing_files,
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 8661cfa..ee48cbf
@@ -32,7 +32,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget -c http://localhost:8080/somefile.txt";
+my $cmdline = $WgetTest::WGETPATH . " -c http://localhost:8080/somefile.txt";
 
 my $expected_error_code = 0;
 
@@ -56,7 +56,7 @@ my $the_test = HTTPTest->new (name => "Test-c-partial",
                               errcode => $expected_error_code, 
                               existing => \%existing_files,
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 4306cab..58b45f7
@@ -27,7 +27,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget -c http://localhost:8080/somefile.txt";
+my $cmdline = $WgetTest::WGETPATH . " -c http://localhost:8080/somefile.txt";
 
 my $expected_error_code = 0;
 
@@ -48,7 +48,7 @@ my $the_test = HTTPTest->new (name => "Test-c",
                               errcode => $expected_error_code, 
                               existing => \%existing_files,
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index c756ac6..5925e38
@@ -21,7 +21,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget -S ftp://localhost:8021/afile.txt";
+my $cmdline = $WgetTest::WGETPATH . " -S ftp://localhost:8021/afile.txt";
 
 my $expected_error_code = 0;
 
@@ -38,7 +38,7 @@ my $the_test = FTPTest->new (name => "Test-ftp",
                              cmdline => $cmdline, 
                              errcode => $expected_error_code, 
                              output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 97ee275..45f2439
@@ -23,7 +23,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget --quiet http://localhost:8080/nonexistent";
+my $cmdline = $WgetTest::WGETPATH . " --quiet http://localhost:8080/nonexistent";
 
 my $expected_error_code = 256;
 
@@ -37,7 +37,7 @@ my $the_test = HTTPTest->new (name => "Test-nonexisting-quiet",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index 296e845..e45c8af
@@ -33,7 +33,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget http://localhost:8080/";
+my $cmdline = $WgetTest::WGETPATH . " http://localhost:8080/";
 
 my $expected_error_code = 0;
 
@@ -50,7 +50,7 @@ my $the_test = HTTPTest->new (name => "Test-noop",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
old mode 100644 (file)
new mode 100755 (executable)
index dcb165f..8a14b32
@@ -119,7 +119,7 @@ my %urls = (
     },
 );
 
-my $cmdline = "wget -np -nH -r http://localhost:8080/firstlevel/";
+my $cmdline = $WgetTest::WGETPATH . " -np -nH -r http://localhost:8080/firstlevel/";
 
 my $expected_error_code = 0;
 
@@ -142,7 +142,7 @@ my $the_test = HTTPTest->new (name => "Test-np",
                               cmdline => $cmdline, 
                               errcode => $expected_error_code, 
                               output => \%expected_downloaded_files);
-$the_test->run();
+exit $the_test->run();
 
 # vim: et ts=4 sw=4
 
diff --git a/tests/Test.pm b/tests/Test.pm
deleted file mode 100644 (file)
index c5449d5..0000000
+++ /dev/null
@@ -1,240 +0,0 @@
-#!/usr/bin/perl -w
-
-package Test;
-$VERSION = 0.01;
-
-use strict;
-
-use Cwd;
-use File::Path;
-
-my @unexpected_downloads = ();
-
-{
-    my %_attr_data = ( # DEFAULT
-        _cmdline      => "",
-        _workdir      => Cwd::getcwd(),
-        _errcode      => 0,
-        _existing     => {},
-        _input        => {},
-        _name         => "",
-        _output       => {},
-    );
-    
-    sub _default_for
-    {
-        my ($self, $attr) = @_;
-        $_attr_data{$attr};
-    }
-
-    sub _standard_keys 
-    {
-        keys %_attr_data;
-    }
-}
-
-
-sub new {
-    my ($caller, %args) = @_;
-    my $caller_is_obj = ref($caller);
-    my $class = $caller_is_obj || $caller;
-    #print STDERR "class = ", $class, "\n";
-    #print STDERR "_attr_data {workdir} = ", $Test::_attr_data{_workdir}, "\n";
-    my $self = bless {}, $class;
-    foreach my $attrname ($self->_standard_keys()) {
-        #print STDERR "attrname = ", $attrname, " value = ";
-        my ($argname) = ($attrname =~ /^_(.*)/);
-        if (exists $args{$argname}) {
-            #printf STDERR "Setting up $attrname\n";
-            $self->{$attrname} = $args{$argname};
-        } elsif ($caller_is_obj) {
-            #printf STDERR "Copying $attrname\n";
-            $self->{$attrname} = $caller->{$attrname};
-        } else {
-            #printf STDERR "Using default for $attrname\n";
-            $self->{$attrname} = $self->_default_for($attrname);
-        }
-        #print STDERR $attrname, '=', $self->{$attrname}, "\n";
-    }
-    #printf STDERR "_workdir default = ", $self->_default_for("_workdir");
-    return $self;
-}
-
-
-sub run {
-    my $self = shift;
-    my $result_message = "Test successful.\n";
-   
-    printf "Running test $self->{_name}\n";
-    
-    # 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}");
-
-    # 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 
-    # terminate
-    kill ('TERM', $pid);
-
-    # Verify download
-    unless ($errcode == $self->{_errcode}) {
-        $result_message = "Test failed: wrong code returned (was: $errcode, expected: $self->{_errcode})\n";
-    }
-    if (my $error_str = $self->_verify_download()) {
-        $result_message = $error_str;
-    }
-
-    # Cleanup
-    $self->_cleanup();
-
-    print $result_message;
-}
-
-
-sub _setup {
-    my $self = shift;
-
-    #print $self->{_name}, "\n";
-    chdir ($self->{_workdir});
-
-    # Create temporary directory
-    mkdir ($self->{_name});
-    chdir ($self->{_name});
-    mkdir ("input");
-    mkdir ("output");
-    
-    # Setup existing files
-    chdir ("output");
-    foreach my $filename (keys %{$self->{_existing}}) {
-        open (FILE, ">$filename") 
-            or return "Test failed: cannot open pre-existing file $filename\n";
-        
-        print FILE $self->{_existing}->{$filename}->{content}
-            or return "Test failed: cannot write pre-existing file $filename\n";
-        
-        close (FILE);
-    } 
-    
-    chdir ("../input");
-    $self->_setup_server();
-
-    chdir ($self->{_workdir});
-}
-
-
-sub _cleanup {
-    my $self = shift;
-
-    chdir ($self->{_workdir});
-    File::Path::rmtree ($self->{_name});
-}
-
-
-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) 
-            or return "Test failed: file $filename not downloaded\n";
-        
-        my $content = <FILE>;
-        $content eq $filedata->{'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'} 
-                or return "Test failed: wrong timestamp for file $filename\n";
-        }
-        
-        close (FILE);
-    } 
-    
-    $/ = $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) { 
-        return "Test failed: unexpected downloaded files [" . join(', ', @unexpected_downloads) . "]\n";
-    }
-
-    return "";
-}
-
-
-sub __dir_walk {
-    my ($top, $filefunc, $dirfunc) = @_;
-
-    my $DIR;
-
-    if (-d $top) {
-        my $file;
-        unless (opendir $DIR, $top) {
-            warn "Couldn't open directory $DIR: $!; skipping.\n";
-            return;
-        }
-
-        my @results;
-        while ($file = readdir $DIR) {
-            next if $file eq '.' || $file eq '..';
-            my $nextdir = $top eq '.' ? $file : "$top/$file";
-            push @results, __dir_walk($nextdir, $filefunc, $dirfunc);
-        }
-
-        return $dirfunc ? $dirfunc->($top, @results) : () ;
-    } else {
-        return $filefunc ? $filefunc->($top) : () ;
-    }
-}
-
-
-sub _fork_and_launch_server 
-{
-    my $self = shift;
-
-    pipe(FROM_CHILD, TO_PARENT) or die "Cannot create pipe!";
-    select((select(TO_PARENT), $| = 1)[0]);
-
-    my $pid = fork();
-    if ($pid < 0) {
-        die "Cannot fork";
-    } elsif ($pid == 0) {
-        # child 
-        close FROM_CHILD;
-        $self->_launch_server(sub { print TO_PARENT "SYNC\n"; close TO_PARENT });
-    } else {
-        # father
-        close TO_PARENT;
-        chomp(my $line = <FROM_CHILD>);
-        close FROM_CHILD;
-    }
-
-    return $pid;
-}
-
-1;
-
-# vim: et ts=4 sw=4
-
diff --git a/tests/WgetTest.pm.in b/tests/WgetTest.pm.in
new file mode 100644 (file)
index 0000000..b20b5d8
--- /dev/null
@@ -0,0 +1,244 @@
+#!/usr/bin/perl -w
+
+package WgetTest;
+$VERSION = 0.01;
+
+use strict;
+
+use Cwd;
+use File::Path;
+
+our $WGETPATH = "@top_srcdir@/src/wget";
+
+my @unexpected_downloads = ();
+
+{
+    my %_attr_data = ( # DEFAULT
+        _cmdline      => "",
+        _workdir      => Cwd::getcwd(),
+        _errcode      => 0,
+        _existing     => {},
+        _input        => {},
+        _name         => "",
+        _output       => {},
+    );
+    
+    sub _default_for
+    {
+        my ($self, $attr) = @_;
+        $_attr_data{$attr};
+    }
+
+    sub _standard_keys 
+    {
+        keys %_attr_data;
+    }
+}
+
+
+sub new {
+    my ($caller, %args) = @_;
+    my $caller_is_obj = ref($caller);
+    my $class = $caller_is_obj || $caller;
+    #print STDERR "class = ", $class, "\n";
+    #print STDERR "_attr_data {workdir} = ", $WgetTest::_attr_data{_workdir}, "\n";
+    my $self = bless {}, $class;
+    foreach my $attrname ($self->_standard_keys()) {
+        #print STDERR "attrname = ", $attrname, " value = ";
+        my ($argname) = ($attrname =~ /^_(.*)/);
+        if (exists $args{$argname}) {
+            #printf STDERR "Setting up $attrname\n";
+            $self->{$attrname} = $args{$argname};
+        } elsif ($caller_is_obj) {
+            #printf STDERR "Copying $attrname\n";
+            $self->{$attrname} = $caller->{$attrname};
+        } else {
+            #printf STDERR "Using default for $attrname\n";
+            $self->{$attrname} = $self->_default_for($attrname);
+        }
+        #print STDERR $attrname, '=', $self->{$attrname}, "\n";
+    }
+    #printf STDERR "_workdir default = ", $self->_default_for("_workdir");
+    return $self;
+}
+
+
+sub run {
+    my $self = shift;
+    my $result_message = "Test successful.\n";
+   
+    printf "Running test $self->{_name}\n";
+    
+    # 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}");
+
+    # 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 
+    # terminate
+    kill ('TERM', $pid);
+
+    # Verify download
+    unless ($errcode == $self->{_errcode}) {
+        $result_message = "Test failed: wrong code returned (was: $errcode, expected: $self->{_errcode})\n";
+    }
+    my $error_str;
+    if ($error_str = $self->_verify_download()) {
+        $result_message = $error_str;
+    }
+
+    # Cleanup
+    $self->_cleanup();
+
+    print $result_message;
+    return $errcode != $self->{_errcode} || ($error_str ? 1 : 0);
+}
+
+
+sub _setup {
+    my $self = shift;
+
+    #print $self->{_name}, "\n";
+    chdir ($self->{_workdir});
+
+    # Create temporary directory
+    mkdir ($self->{_name});
+    chdir ($self->{_name});
+    mkdir ("input");
+    mkdir ("output");
+    
+    # Setup existing files
+    chdir ("output");
+    foreach my $filename (keys %{$self->{_existing}}) {
+        open (FILE, ">$filename") 
+            or return "Test failed: cannot open pre-existing file $filename\n";
+        
+        print FILE $self->{_existing}->{$filename}->{content}
+            or return "Test failed: cannot write pre-existing file $filename\n";
+        
+        close (FILE);
+    } 
+    
+    chdir ("../input");
+    $self->_setup_server();
+
+    chdir ($self->{_workdir});
+}
+
+
+sub _cleanup {
+    my $self = shift;
+
+    chdir ($self->{_workdir});
+    File::Path::rmtree ($self->{_name});
+}
+
+
+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) 
+            or return "Test failed: file $filename not downloaded\n";
+        
+        my $content = <FILE>;
+        $content eq $filedata->{'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'} 
+                or return "Test failed: wrong timestamp for file $filename\n";
+        }
+        
+        close (FILE);
+    } 
+    
+    $/ = $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) { 
+        return "Test failed: unexpected downloaded files [" . join(', ', @unexpected_downloads) . "]\n";
+    }
+
+    return "";
+}
+
+
+sub __dir_walk {
+    my ($top, $filefunc, $dirfunc) = @_;
+
+    my $DIR;
+
+    if (-d $top) {
+        my $file;
+        unless (opendir $DIR, $top) {
+            warn "Couldn't open directory $DIR: $!; skipping.\n";
+            return;
+        }
+
+        my @results;
+        while ($file = readdir $DIR) {
+            next if $file eq '.' || $file eq '..';
+            my $nextdir = $top eq '.' ? $file : "$top/$file";
+            push @results, __dir_walk($nextdir, $filefunc, $dirfunc);
+        }
+
+        return $dirfunc ? $dirfunc->($top, @results) : () ;
+    } else {
+        return $filefunc ? $filefunc->($top) : () ;
+    }
+}
+
+
+sub _fork_and_launch_server 
+{
+    my $self = shift;
+
+    pipe(FROM_CHILD, TO_PARENT) or die "Cannot create pipe!";
+    select((select(TO_PARENT), $| = 1)[0]);
+
+    my $pid = fork();
+    if ($pid < 0) {
+        die "Cannot fork";
+    } elsif ($pid == 0) {
+        # child 
+        close FROM_CHILD;
+        $self->_launch_server(sub { print TO_PARENT "SYNC\n"; close TO_PARENT });
+    } else {
+        # father
+        close TO_PARENT;
+        chomp(my $line = <FROM_CHILD>);
+        close FROM_CHILD;
+    }
+
+    return $pid;
+}
+
+1;
+
+# vim: et ts=4 sw=4
+