File: 09-errors.xpath.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 (86 lines) | stat: -rwxr-xr-x 2,262 bytes parent folder | download
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
# Test script to test the failure modes of Test::HTML::Content
use Test::More;
BEGIN{
  eval {
    require Test::Builder::Tester;
    Test::Builder::Tester->import;
  };

  if ($@) {
    plan skip_all => "Test::Builder::Tester required for testing error messages";
  }
};

BEGIN {
  plan tests => 7;
  use_ok('Test::HTML::Content');
};

SKIP: {

if (! $Test::HTML::Content::can_xpath) {
  skip "Need XPath functionality to test it", 6;
  exit;
};

my $HTML = q{<html><head><title>Test</title></head>
<body>
<p foo="bar"></p>
<p foo="foo">1</p>
<p foo="baz">2</p>
</body>
</html>
};

test_out("not ok 1 - no XPath results found");
test_fail(+5);
test_diag(q{Got},
          q{  <p foo="bar"/>},
          q{  <p foo="foo">1</p>},
          q{  <p foo="baz">2</p>});
xpath_ok($HTML,'//p[@boo]','//p',"no XPath results found");
test_test("Finding no xpath results where some should be outputs the fallback");

test_out("not ok 1 - no XPath results found");
test_fail(+2);
test_diag(q{Got none});
xpath_ok($HTML,'//p[@boo]',"no XPath results found");
test_test("Finding no xpath results (implicit)");

test_out("not ok 1 - no XPath results found");
test_fail(+5);
test_diag(q{Got},
          q{  <p foo="bar"/>},
          q{  <p foo="foo">1</p>},
          q{  <p foo="baz">2</p>});
no_xpath($HTML,'//p[@foo]','//p',"no XPath results found");
test_test("Finding xpath results where none should be outputs the fallback");

test_out("not ok 1 - no XPath results found");
test_fail(+5);
test_diag(q{Got},
          q{  <p foo="bar"/>},
          q{  <p foo="foo">1</p>},
          q{  <p foo="baz">2</p>});
no_xpath($HTML,'//p',"no XPath results found");
test_test("Finding xpath results (implicit fallback)");

test_out("not ok 1 - no XPath results found");
test_fail(+5);
test_diag(q{Got},
          q{  <p foo="bar"/>},
          q{  <p foo="foo">1</p>},
          q{  <p foo="baz">2</p>});
xpath_count($HTML,'//p',4,"no XPath results found");
test_test("Too few hits get reported");

test_out("not ok 1 - no XPath results found");
test_fail(+5);
test_diag(q{Got},
          q{  <p foo="bar"/>},
          q{  <p foo="foo">1</p>},
          q{  <p foo="baz">2</p>});
xpath_count($HTML,'//p',2,"no XPath results found");
test_test("Too many hits get reported");

};