From 986cfac8d5e2dddf00615bcc11ef6d8ed7a15a55 Mon Sep 17 00:00:00 2001 From: Steven Schubiger Date: Sat, 5 Sep 2009 22:54:05 +0200 Subject: [PATCH] Enhance tests to include feature checking. --- tests/ChangeLog | 23 +++++++++++++++++++ tests/Makefile.am | 1 + tests/Test-ftp-iri-disabled.px | 1 + tests/Test-ftp-iri-fallback.px | 1 + tests/Test-ftp-iri-recursive.px | 1 + tests/Test-ftp-iri.px | 1 + tests/Test-idn-cmd.px | 1 + tests/Test-idn-headers.px | 1 + tests/Test-idn-meta.px | 1 + tests/Test-idn-robots.px | 1 + tests/Test-iri-forced-remote.px | 1 + tests/Test-iri-list.px | 1 + tests/Test-iri-percent.px | 1 + tests/Test-iri.px | 1 + tests/Test-proxied-https-auth.px | 10 +-------- tests/WgetFeature.cfg | 6 +++++ tests/WgetFeature.pm | 29 ++++++++++++++++++++++++ tests/run-px | 38 +++++++++++++++++++++++--------- 18 files changed, 99 insertions(+), 20 deletions(-) create mode 100644 tests/WgetFeature.cfg create mode 100644 tests/WgetFeature.pm diff --git a/tests/ChangeLog b/tests/ChangeLog index 702c9d73..f6327b2e 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,26 @@ +2009-09-05 Steven Schubiger + + * run-px: Introduce two new diagnostics: Skip and Unknown. + + * WgetFeature.pm (import): Parse the version output of Wget + and assert the availability of a feature. + + * WgetFeature.cfg: Messages to be printed in absence of a + required feature. + + * Test-ftp-iri-disabled.px, Test-ftp-iri-fallback.px, + Test-ftp-iri-recursive.px, Test-ftp-iri.px, Test-idn-cmd.px, + Test-idn-headers.px, Test-idn-meta.px, Test-idn-robots.px, + Test-iri-forced-remote.px, Test-iri-list.px, + Test-iri-percent.px, Test-iri.px: Use WgetFeature.pm to + check for the presence of the IDN/IRI feature. + + * Test-proxied-https-auth.px: Replace grepping for a feature + with loading WgetFeature.pm at compile-time. + + * Makefile.am: Add WgetFeature.pm and WgetFeature.cfg + to EXTRA_DIST. + 2009-09-02 Micah Cowan * Makefile.am (unit-tests): explicit dependency is diff --git a/tests/Makefile.am b/tests/Makefile.am index e4d0e96b..ec68d6d5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -60,6 +60,7 @@ run-px-tests: WgetTest.pm ../src/wget$(EXEEXT) $(srcdir)/run-px $(top_srcdir) EXTRA_DIST = FTPServer.pm FTPTest.pm HTTPServer.pm HTTPTest.pm \ + WgetFeature.pm WgetFeature.cfg \ Test-auth-basic.px \ Test-auth-no-challenge.px \ Test-auth-no-challenge-url.px \ diff --git a/tests/Test-ftp-iri-disabled.px b/tests/Test-ftp-iri-disabled.px index 17bb85c8..4ded28ff 100755 --- a/tests/Test-ftp-iri-disabled.px +++ b/tests/Test-ftp-iri-disabled.px @@ -3,6 +3,7 @@ use strict; use warnings; +use WgetFeature qw(iri); use FTPTest; diff --git a/tests/Test-ftp-iri-fallback.px b/tests/Test-ftp-iri-fallback.px index f4857213..c3f97385 100755 --- a/tests/Test-ftp-iri-fallback.px +++ b/tests/Test-ftp-iri-fallback.px @@ -3,6 +3,7 @@ use strict; use warnings; +use WgetFeature qw(iri); use FTPTest; diff --git a/tests/Test-ftp-iri-recursive.px b/tests/Test-ftp-iri-recursive.px index 5bbc8808..1a664e95 100755 --- a/tests/Test-ftp-iri-recursive.px +++ b/tests/Test-ftp-iri-recursive.px @@ -3,6 +3,7 @@ use strict; use warnings; +use WgetFeature qw(iri); use FTPTest; diff --git a/tests/Test-ftp-iri.px b/tests/Test-ftp-iri.px index 7bedb891..7594a80c 100755 --- a/tests/Test-ftp-iri.px +++ b/tests/Test-ftp-iri.px @@ -3,6 +3,7 @@ use strict; use warnings; +use WgetFeature qw(iri); use FTPTest; diff --git a/tests/Test-idn-cmd.px b/tests/Test-idn-cmd.px index 822803ae..4f92ea0c 100755 --- a/tests/Test-idn-cmd.px +++ b/tests/Test-idn-cmd.px @@ -3,6 +3,7 @@ use strict; use warnings; +use WgetFeature qw(iri); use HTTPTest; # " Kon'nichiwa Japan diff --git a/tests/Test-idn-headers.px b/tests/Test-idn-headers.px index b94c1cde..f5858137 100755 --- a/tests/Test-idn-headers.px +++ b/tests/Test-idn-headers.px @@ -3,6 +3,7 @@ use strict; use warnings; +use WgetFeature qw(iri); use HTTPTest; # " Kon'nichiwa Japan diff --git a/tests/Test-idn-meta.px b/tests/Test-idn-meta.px index 2734e1ea..199eabe2 100755 --- a/tests/Test-idn-meta.px +++ b/tests/Test-idn-meta.px @@ -3,6 +3,7 @@ use strict; use warnings; +use WgetFeature qw(iri); use HTTPTest; # " Kon'nichiwa Japan diff --git a/tests/Test-idn-robots.px b/tests/Test-idn-robots.px index ff5033f0..3f0f8dde 100755 --- a/tests/Test-idn-robots.px +++ b/tests/Test-idn-robots.px @@ -3,6 +3,7 @@ use strict; use warnings; +use WgetFeature qw(iri); use HTTPTest; # " Kon'nichiwa Japan diff --git a/tests/Test-iri-forced-remote.px b/tests/Test-iri-forced-remote.px index 8341d516..9c3d5b6b 100755 --- a/tests/Test-iri-forced-remote.px +++ b/tests/Test-iri-forced-remote.px @@ -3,6 +3,7 @@ use strict; use warnings; +use WgetFeature qw(iri); use HTTPTest; # cf. http://en.wikipedia.org/wiki/Latin1 diff --git a/tests/Test-iri-list.px b/tests/Test-iri-list.px index 87cc33c8..8110358a 100755 --- a/tests/Test-iri-list.px +++ b/tests/Test-iri-list.px @@ -3,6 +3,7 @@ use strict; use warnings; +use WgetFeature qw(iri); use HTTPTest; # cf. http://en.wikipedia.org/wiki/Latin1 diff --git a/tests/Test-iri-percent.px b/tests/Test-iri-percent.px index 158392df..2184b4d8 100755 --- a/tests/Test-iri-percent.px +++ b/tests/Test-iri-percent.px @@ -3,6 +3,7 @@ use strict; use warnings; +use WgetFeature qw(iri); use HTTPTest; # Just a sanity check to verify that %-encoded values are always left diff --git a/tests/Test-iri.px b/tests/Test-iri.px index 01e1c50a..f81ef38f 100755 --- a/tests/Test-iri.px +++ b/tests/Test-iri.px @@ -3,6 +3,7 @@ use strict; use warnings; +use WgetFeature qw(iri); use HTTPTest; # cf. http://en.wikipedia.org/wiki/Latin1 diff --git a/tests/Test-proxied-https-auth.px b/tests/Test-proxied-https-auth.px index 2b37f32b..71d43b16 100755 --- a/tests/Test-proxied-https-auth.px +++ b/tests/Test-proxied-https-auth.px @@ -3,6 +3,7 @@ use strict; use warnings; +use WgetFeature qw(https); use WgetTest; # For $WGETPATH. my $cert_path; @@ -14,15 +15,6 @@ if (@ARGV) { $cert_path = "$top_srcdir/tests/certs/server-cert.pem"; } -# Have we even built an HTTPS-supporting Wget? -{ - my @version_lines = `${WgetTest::WGETPATH} --version`; - unless (grep /\+(openssl|gnutls)/, @version_lines) { - print "Not running test: Wget under test doesn't support HTTPS.\n"; - exit 0; - } -} - use HTTP::Daemon; use HTTP::Request; use IO::Socket::SSL; diff --git a/tests/WgetFeature.cfg b/tests/WgetFeature.cfg new file mode 100644 index 00000000..a1176e03 --- /dev/null +++ b/tests/WgetFeature.cfg @@ -0,0 +1,6 @@ +%skip_messages = ( + https => "Not running test: Wget under test doesn't support HTTPS.", + iri => "Not running test: Wget under test doesn't support IDN/IRI.", +); + +1; diff --git a/tests/WgetFeature.pm b/tests/WgetFeature.pm new file mode 100644 index 00000000..f58b9983 --- /dev/null +++ b/tests/WgetFeature.pm @@ -0,0 +1,29 @@ +package WgetFeature; + +use strict; +use warnings; + +use WgetTest; + +our %skip_messages; +require 'WgetFeature.cfg'; + +sub import +{ + my ($class, $feature) = @_; + + my $output = `$WgetTest::WGETPATH --version`; + my ($list) = $output =~ /^([\+\-]\S+(?:\s+[\+\-]\S+)+)/m; + my %have_features = map { + my $feature = $_; + $feature =~ s/^.//; + ($feature, /^\+/ ? 1 : 0); + } split /\s+/, $list; + + unless ($have_features{$feature}) { + print $skip_messages{$feature}, "\n"; + exit 2; # skip + } +} + +1; diff --git a/tests/run-px b/tests/run-px index 5dade1bd..29765c95 100755 --- a/tests/run-px +++ b/tests/run-px @@ -4,8 +4,7 @@ use 5.006; use strict; use warnings; -use Term::ANSIColor ':constants'; -$Term::ANSIColor::AUTORESET = 1; +use Term::ANSIColor; die "Please specify the top source directory.\n" if (!@ARGV); my $top_srcdir = shift @ARGV; @@ -82,26 +81,42 @@ my @tested; foreach my $test (@tests) { print "Running $test\n\n"; system("$^X -I$top_srcdir/tests $top_srcdir/tests/$test $top_srcdir"); - push @tested, { name => $test, result => $? }; + push @tested, { name => $test, result => $? >> 8 }; } foreach my $var (qw(SYSTEM_WGETRC WGETRC)) { delete $ENV{$var}; } +my %exit = ( + pass => 0, + fail => 1, + skip => 2, + unknown => 3, # or greater +); + +my %colors = ( + $exit{pass} => colored('pass:', 'green' ), + $exit{fail} => colored('FAIL:', 'red' ), + $exit{skip} => colored('Skip:', 'yellow' ), + $exit{unknown} => colored('Unknown:', 'magenta'), +); + print "\n"; foreach my $test (@tested) { - ($test->{result} == 0) - ? print GREEN 'pass: ' - : print RED 'FAIL: '; - print $test->{name}, "\n"; + my $colored = exists $colors{$test->{result}} + ? $colors{$test->{result}} + : $colors{$exit{unknown}}; + print "$colored $test->{name}\n"; } my $count = sub { return { - pass => sub { scalar grep $_->{result} == 0, @tested }, - fail => sub { scalar grep $_->{result} != 0, @tested }, + pass => sub { scalar grep $_->{result} == $exit{pass}, @tested }, + fail => sub { scalar grep $_->{result} == $exit{fail}, @tested }, + skip => sub { scalar grep $_->{result} == $exit{skip}, @tested }, + unknown => sub { scalar grep $_->{result} >= $exit{unknown}, @tested }, }->{$_[0]}->(); }; @@ -110,6 +125,7 @@ my $summary = sub my @lines = ( "${\scalar @tested} tests were run", "${\$count->('pass')} PASS, ${\$count->('fail')} FAIL", + "${\$count->('skip')} SKIP, ${\$count->('unknown')} UNKNOWN", ); my $len_longest = sub { @@ -129,8 +145,8 @@ my $summary = sub print "\n"; print $count->('fail') - ? RED $summary - : GREEN $summary; + ? colored($summary, 'red') + : colored($summary, 'green'); print "\n"; exit $count->('fail');