File: 07-errors.link.t

package info (click to toggle)
libtest-html-content-perl 0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 328 kB
  • sloc: perl: 1,393; makefile: 2
file content (114 lines) | stat: -rwxr-xr-x 4,406 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# 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";
  }
};

# perldelta 5.14
# Accept both old and new-style stringification
my $modifiers = (qr/foobar/ =~ /\Q(?^/) ? "^" : "-xism";

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 <a> 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 <a> tag(s) matching",
              "  href = http://www.perl.com",
              "Got",
              '  <a href="http://www.foo.com">foo</a>',
              '  <a href="index.html">Home</a>');
  } else {
    test_diag("Expected to find at least one <a> tag(s) matching",
              "  href = http://www.perl.com",
              "Got",
              "  <a href='http://www.foo.com'>",
              "  <a href='index.html'>");
  };
  link_ok("<a href='http://www.foo.com'>foo</a><a href='index.html'>Home</a>",
          "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 <a> tag(s) matching",
              "  href = (?$modifiers:.)",
              "Got",
              '  <a href="http://www.foo.com">foo</a>',
              '  <a href="index.html">Home</a>');
  } else {
    test_diag("Expected to find no <a> tag(s) matching",
              "  href = (?$modifiers:.)",
              "Got",
              "  <a href='http://www.foo.com'>",
              "  <a href='index.html'>");
  };
  no_link("<a href='http://www.foo.com'>foo</a><a href='index.html'>Home</a>",
          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 <a> tag(s) matching",
              "  href = (?$modifiers:.)",
              "Got",
              '  <a href="http://www.foo.com">foo</a>',
              '  <a href="index.html">Home</a>');
  } else {
    test_diag("Expected to find exactly 3 <a> tag(s) matching",
              "  href = (?$modifiers:.)",
              "Got",
              "  <a href='http://www.foo.com'>",
              "  <a href='index.html'>");
  };
  link_count("<a href='http://www.foo.com'>foo</a><a href='index.html'>Home</a>",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 <a> tag(s) matching",
              "  href = (?$modifiers:.)",
              "Got",
              '  <a href="http://www.bar.com">bar</a>',
              '  <a href="http://www.dot.com">.</a>',
              '  <a href="http://www.foo.com">foo</a>',
              '  <a href="index.html">Home</a>');
  } else {
    test_diag("Expected to find exactly 3 <a> tag(s) matching",
              "  href = (?$modifiers:.)",
              "Got",
              "  <a href='http://www.bar.com'>",
              "  <a href='http://www.dot.com'>",
              "  <a href='http://www.foo.com'>",
              "  <a href='index.html'>");
  };
  link_count("<a href='http://www.bar.com'>bar</a><a href='http://www.dot.com'>.</a><a href='http://www.foo.com'>foo</a><a href='index.html'>Home</a>",qr".",3,"Link failure (too many links)");
  test_test("Diagnosing too many links works");
};

runtests( 5,\&run);