Skip to content

Commit

Permalink
Item1125: added this->expect_failure() to TestCase to support expecte…
Browse files Browse the repository at this point in the history
…d failures on platforms that don't support tested features

git-svn-id: http://svn.foswiki.org/trunk@2624 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Feb 23, 2009
1 parent c956227 commit 67768bd
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
11 changes: 9 additions & 2 deletions UnitTestContrib/lib/Unit/TestCase.pm
Expand Up @@ -12,14 +12,16 @@ use vars qw( $differ );

sub new {
my $class = shift;
my $this = bless({}, $class);
@{$this->{annotations}} = ();
my $this = bless({
annotations => [],
expect_failure => 0 }, $class);
return $this;
}

sub set_up {
my $this = shift;
@{$this->{annotations}} = ();
$this->{expect_failure} = 0;
}

sub tear_down {
Expand Down Expand Up @@ -228,6 +230,11 @@ sub annotate {
push(@{$this->{annotations}}, $mess) if defined($mess);
}

sub expect_failure {
my ($this) = @_;
$this->{expect_failure} = 1;
}

# 1:1 HTML comparison. Correctly compares attributes in tags. Uses HTML::Parser
# which is tolerant of unbalanced tags, so the actual may have unbalanced
# tags which will _not_ be detected.
Expand Down
21 changes: 18 additions & 3 deletions UnitTestContrib/lib/Unit/TestRunner.pm
Expand Up @@ -51,20 +51,35 @@ sub start {
} catch Error::Simple with {
my $e = shift;
print "*** ",$e->stringify(),"\n";
if ($tester->{expect_failure}) {
$this->{expected_failures}++;
} else {
$this->{unexpected_failures}++;
}
push(@{$this->{failures}}, $test."\n".$e->stringify());
} otherwise {
if ($tester->{expect_failure}) {
$this->{unexpected_passes}++;
}
};
$tester->tear_down();
}
}
}

if (scalar(@{$this->{failures}})) {
print scalar(@{$this->{failures}})." failures\n";
if ($this->{unexpected_failures} || $this->{unexpected_passes}) {
print $this->{unexpected_failures}." failures\n"
if $this->{unexpected_failures};
print $this->{unexpected_passes}." unexpected passes\n"
if $this->{unexpected_passes};
print join("\n---------------------------\n",
@{$this->{failures}}),"\n";
print "$passes of ",$passes + scalar(@{$this->{failures}})," test cases passed\n";
print "$passes of ", $passes + $this->{unexpected_failures},
" test cases passed\n";
return scalar(@{$this->{failures}});
} else {
print $this->{expected_failures}." expected failures\n"
if $this->{expected_failures};
print "All tests passed ($passes)\n";
return 0;
}
Expand Down
13 changes: 12 additions & 1 deletion UnitTestContrib/test/unit/Fn_SEARCH.pm
Expand Up @@ -19,7 +19,7 @@ sub set_up {
my $this = shift;

$this->SUPER::set_up();
# Turn UseLocale off; otherwise the Ok-Topic Ok+Topic lexical sort
# Turn UseLocale off; otherwise the Ok+Topic Ok-Topic lexical sort
# order gets reversed
$Foswiki::cfg{UseLocale} = 0;
$this->{twiki}->{store}->saveTopic( $this->{twiki}->{user},
Expand Down Expand Up @@ -828,6 +828,11 @@ sub verify_formQuery3 {
sub verify_formQuery4 {
my $this = shift;

if ($Foswiki::cfg{OS} eq 'WINDOWS'
&& $Foswiki::cfg{DetailedOS} ne 'cygwin') {
$this->expect_failure();
$this->annotate("THIS IS WINDOWS; Test will fail because of Item1072");
}
$this->set_up_for_queries();
my $result =
$this->{twiki}
Expand All @@ -839,6 +844,12 @@ sub verify_formQuery4 {
sub verify_formQuery5 {
my $this = shift;

if ($Foswiki::cfg{OS} eq 'WINDOWS'
&& $Foswiki::cfg{DetailedOS} ne 'cygwin') {
$this->expect_failure();
$this->annotate("THIS IS WINDOWS; Test will fail because of Item1072");
}

$this->set_up_for_queries();
my $result =
$this->{twiki}
Expand Down
19 changes: 11 additions & 8 deletions UnitTestContrib/test/unit/PasswordTests.pm
Expand Up @@ -162,8 +162,8 @@ sub test_htpasswd_crypt_md5 {
my $this = shift;

if ($Foswiki::cfg{DetailedOS} eq 'darwin') {
print STDERR "*** CANNOT RUN crypt-md5 TESTS on OSX, they fail\n";
return;
$this->expect_failure();
$this->annotate("CANNOT RUN crypt-md5 TESTS on OSX");
}
$Foswiki::cfg{Htpasswd}{Encoding} = 'crypt-md5';
my $impl = new Foswiki::Users::HtPasswdUser($this->{twiki});
Expand All @@ -186,14 +186,16 @@ sub test_htpasswd_sha1 {
if( $@ ) {
my $mess = $@;
$mess =~ s/\(\@INC contains:.*$//s;
print STDERR "*** CANNOT RUN SHA1 TESTS: $mess\n";
$this->expect_failure();
$this->annotate("CANNOT RUN SHA1 TESTS: $mess");
return;
}
eval 'use Digest::SHA1';
if( $@ ) {
my $mess = $@;
$mess =~ s/\(\@INC contains:.*$//s;
print STDERR "*** CANNOT RUN TESTS: $mess\n";
$this->expect_failure();
$this->annotate("CANNOT RUN SHA1 TESTS: $mess");
return;
}

Expand All @@ -203,13 +205,14 @@ sub test_htpasswd_sha1 {
$this->doTests($impl,0);
}

sub detest_htpasswd_md5 {
sub test_htpasswd_md5 {
my $this = shift;
eval 'use Digest::MD5';
if( $@ ) {
my $mess = $@;
$mess =~ s/\(\@INC contains:.*$//s;
print STDERR "*** CANNOT RUN SHA1 TESTS: $mess\n";
$this->expect_failure();
$this->annotate("CANNOT RUN MD5 TESTS: $mess");
return;
}

Expand All @@ -233,8 +236,8 @@ sub test_htpasswd_apache {
if( $@ ) {
my $mess = $@;
$mess =~ s/\(\@INC contains:.*$//s;
print STDERR "*** CANNOT RUN APACHE HTPASSWD TESTS: $mess\n";
return;
$this->expect_failure();
$this->annotate("CANNOT RUN APACHE HTPASSWD TESTS: $mess");
}

my $impl = Foswiki::Users::ApacheHtpasswdUser->new($this->{twiki});
Expand Down

0 comments on commit 67768bd

Please sign in to comment.