Subject: | 01-fallback-xpath.t failure |
# prove -b -v t/01-fallback-xpath.t
t/01-fallback-xpath....
1..4
ok 1 - use Test::HTML::Content;
ok 2 - Finding a link works without XML::LibXML
not ok 3 - Missing prerequisites don't let the tests fail
# Failed test 'Missing prerequisites don't let the tests fail'
# at t/01-fallback-xpath.t line 20.
# got: 'No such method textContent in
XML::XPath::Node::ElementImpl at /root/.cpan/build/Test-HTML-Content-0.08-
WAcuBY/blib/lib/Test/HTML/Content.pm line 278
# '
# expected: ''
not ok 4 - Skipped or passed when XML::LibXML is missing
# Failed test 'Skipped or passed when XML::LibXML is missing'
# at t/01-fallback-xpath.t line 21.
# Expected 'skip' or '1', but got ''
# Looks like you failed 2 tests of 4.
Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/4 subtests
Test Summary Report
-------------------
t/01-fallback-xpath (Wstat: 512 Tests: 4 Failed: 2)
Failed tests: 3-4
Non-zero exit status: 2
Files=1, Tests=4, 1 wallclock secs ( 0.09 usr 0.02 sys + 0.36 cusr
0.02 csys = 0.49 CPU)
Result: FAIL
falcon:root:Test-HTML-Content-0.08-WAcuBY:1070 #
Perl 5.8.8 on linux.
Test::HTML::Content failed to properly isolate a call to XML::libXML's
textContent function, so the test failed when it loaded XML::Xpath instead.
Once that was fixed, I discovered that the two routines were returning
different content, so I hunted through the POD until I found something that
worked for both.
With the attached patch applied, all tests pass.
Subject: | fallback.patch |
diff --git a/lib/Test/HTML/Content.pm b/lib/Test/HTML/Content.pm
index 3e4dfd7..d7abde1 100755
--- a/lib/Test/HTML/Content.pm
+++ b/lib/Test/HTML/Content.pm
@@ -69,6 +69,12 @@ sub __node_content {
if ($can_xpath eq 'XML::LibXML') { return $node->toString };
};
+sub __text_content {
+ my $node = shift;
+ if ($can_xpath eq 'XML::XPath') { return $node->string_value };
+ if ($can_xpath eq 'XML::LibXML') { return $node->textContent };
+}
+
sub __match_comment {
my ($text,$template) = @_;
$text =~ s/^<!--(.*?)-->$/$1/sm unless $HTML_PARSER_StripsTags;
@@ -276,7 +282,8 @@ sub __get_node_content {
my ($node,$name) = @_;
if ($name eq '_content') {
- return $node->textContent()
+ return __text_content( $node )
+# return $node->textContent()
} else {
return $node->getAttribute($name)
};