# Test script to test the failure modes of Test::HTML::Content use Test::More; use lib 't'; use testlib; BEGIN { eval { require Test::Builder::Tester; Test::Builder::Tester->import; }; if ($@) { plan skip_all => "Test::Builder::Tester required for testing error messages"; } }; sub run { # Test that each exported function fails as documented test_out("not ok 1 - Link failure (no links)"); test_fail(+8); if ($Test::HTML::Content::can_xpath eq 'XML::LibXML') { test_diag("Invalid HTML:",""); } else { test_diag("Expected to find at least one tag(s) matching", " href = http://www.perl.com", "Got none"); }; link_ok("","http://www.perl.com","Link failure (no links)"); test_test("Finding no link works"); test_out("not ok 1 - Link failure (two links that don't match)"); test_fail(+14); if ($Test::HTML::Content::can_xpath eq 'XML::LibXML') { test_diag("Expected to find at least one tag(s) matching", " href = http://www.perl.com", "Got", ' foo', ' Home'); } else { test_diag("Expected to find at least one tag(s) matching", " href = http://www.perl.com", "Got", " ", " "); }; link_ok("fooHome", "http://www.perl.com","Link failure (two links that don't match)"); test_test("Finding no link returns all other links"); test_out("not ok 1 - Link failure (two links shouldn't exist do)"); test_fail(+14); if ($Test::HTML::Content::can_xpath eq 'XML::LibXML') { test_diag("Expected to find no tag(s) matching", " href = (?-xism:.)", "Got", ' foo', ' Home'); } else { test_diag("Expected to find no tag(s) matching", " href = (?-xism:.)", "Got", " ", " "); }; no_link("fooHome", qr".","Link failure (two links shouldn't exist do)"); test_test("Finding a link where one should be returns all other links"); test_out("not ok 1 - Link failure (too few links)"); test_fail(+14); if ($Test::HTML::Content::can_xpath eq 'XML::LibXML') { test_diag("Expected to find exactly 3 tag(s) matching", " href = (?-xism:.)", "Got", ' foo', ' Home'); } else { test_diag("Expected to find exactly 3 tag(s) matching", " href = (?-xism:.)", "Got", " ", " "); }; link_count("fooHome",qr".",3,"Link failure (too few links)"); test_test("Diagnosing too few links works"); test_out("not ok 1 - Link failure (too many links)"); test_fail(+18); if ($Test::HTML::Content::can_xpath eq 'XML::LibXML') { test_diag("Expected to find exactly 3 tag(s) matching", " href = (?-xism:.)", "Got", ' bar', ' .', ' foo', ' Home'); } else { test_diag("Expected to find exactly 3 tag(s) matching", " href = (?-xism:.)", "Got", " ", " ", " ", " "); }; link_count("bar.fooHome",qr".",3,"Link failure (too many links)"); test_test("Diagnosing too many links works"); }; runtests( 5,\&run);