From cd50595319c7eaf76fbd4e92fc55e1b3e179bae8 Mon Sep 17 00:00:00 2001 From: mtortonesi Date: Fri, 10 Nov 2006 03:06:24 -0800 Subject: [PATCH] [svn] Added testing for -np option. --- tests/ChangeLog | 6 ++ tests/HTTPServer.pm | 5 +- tests/Test-np.px | 148 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 158 insertions(+), 1 deletion(-) create mode 100755 tests/Test-np.px diff --git a/tests/ChangeLog b/tests/ChangeLog index daaa10fc..618e6563 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2006-11-10 Mauro Tortonesi + + * Test-np.px: Added test for -np. + + * HTTPTest.pm: Ignore initial '/' character in requested URLs. + 2006-10-12 Mauro Tortonesi * Test1.px: Renamed to Test-noop.px. diff --git a/tests/HTTPServer.pm b/tests/HTTPServer.pm index 88224f4f..2d56160a 100755 --- a/tests/HTTPServer.pm +++ b/tests/HTTPServer.pm @@ -29,9 +29,12 @@ sub run { print STDERR "Accepted a new connection\n" if $log; while (my $req = $con->get_request) { my $url_path = $req->url->path; - if ($url_path =~ m{/$}) { + if ($url_path =~ m{/$}) { # append 'index.html' $url_path .= 'index.html'; } + if ($url_path =~ m{^/}) { # remove trailing '/' + $url_path = substr ($url_path, 1); + } if ($log) { print STDERR "Method: ", $req->method, "\n"; print STDERR "Path: ", $url_path, "\n"; diff --git a/tests/Test-np.px b/tests/Test-np.px new file mode 100755 index 00000000..09b77da4 --- /dev/null +++ b/tests/Test-np.px @@ -0,0 +1,148 @@ +#!/usr/bin/perl -w + +use strict; + +use HTTPTest; + + +############################################################################### + +my $mainpage = < + + Main Page + + +

+ Some text and a link to a second page. +

+ + +EOF + +my $secondpage = < + + Second Page + + +

+ Some text and a link to a third page. +

+ + +EOF + +my $thirdpage = < + + Third Page + + +

+ Some text and a link to a higher level page. +

+ + +EOF + +my $fourthpage = < + + Fourth Page + + +

+ This page is only linked by the higher level page. Therefore, it should not + be downloaded. +

+ + +EOF + +my $higherlevelpage = < + + Higher Level Page + + +

+ This page is on a higher level in the URL path hierarchy. Therefore, it + should not be downloaded. Wget should not visit the following link to a + fourth page. +

+ + +EOF + +# code, msg, headers, content +my %urls = ( + 'firstlevel/index.html' => { + code => "200", + msg => "Dontcare", + headers => { + "Content-type" => "text/html", + }, + content => $mainpage, + }, + 'firstlevel/secondpage.html' => { + code => "200", + msg => "Dontcare", + headers => { + "Content-type" => "text/html", + }, + content => $secondpage, + }, + 'firstlevel/lowerlevel/thirdpage.html' => { + code => "200", + msg => "Dontcare", + headers => { + "Content-type" => "text/html", + }, + content => $thirdpage, + }, + 'firstlevel/fourthpage.html' => { + code => "200", + msg => "Dontcare", + headers => { + "Content-type" => "text/plain", + }, + content => $fourthpage, + }, + 'higherlevelpage.html' => { + code => "200", + msg => "Dontcare", + headers => { + "Content-type" => "text/plain", + }, + content => $higherlevelpage, + }, +); + +my $cmdline = "wget -np -nH -r http://localhost:8080/firstlevel/"; + +my $expected_error_code = 0; + +my %expected_downloaded_files = ( + 'firstlevel/index.html' => { + content => $mainpage, + }, + 'firstlevel/secondpage.html' => { + content => $secondpage, + }, + 'firstlevel/lowerlevel/thirdpage.html' => { + content => $thirdpage, + }, +); + +############################################################################### + +my $the_test = HTTPTest->new (name => "Test-np", + input => \%urls, + cmdline => $cmdline, + errcode => $expected_error_code, + output => \%expected_downloaded_files); +$the_test->run(); + +# vim: et ts=4 sw=4 +