Fix POD markup error
[libwww-perl-eserte.git] / t / robot / rules-dbm.t
blob2335b944ca6d5d35e840455e953a1f5bedb45246
2 print "1..13\n";
5 use WWW::RobotRules::AnyDBM_File;
7 $file = "test-$$";
9 $r = new WWW::RobotRules::AnyDBM_File "myrobot/2.0", $file;
11 $r->parse("http://www.aas.no/robots.txt", "");
13 $r->visit("www.aas.no:80");
15 print "not " if $r->no_visits("www.aas.no:80") != 1;
16 print "ok 1\n";
19 $r->push_rules("www.sn.no:80", "/aas", "/per");
20 $r->push_rules("www.sn.no:80", "/god", "/old");
22 @r = $r->rules("www.sn.no:80");
23 print "Rules: @r\n";
25 print "not " if "@r" ne "/aas /per /god /old";
26 print "ok 2\n";
28 $r->clear_rules("per");
29 $r->clear_rules("www.sn.no:80");
31 @r = $r->rules("www.sn.no:80");
32 print "Rules: @r\n";
34 print "not " if "@r" ne "";
35 print "ok 3\n";
37 $r->visit("www.aas.no:80", time+10);
38 $r->visit("www.sn.no:80");
40 print "No visits: ", $r->no_visits("www.aas.no:80"), "\n";
41 print "Last visit: ", $r->last_visit("www.aas.no:80"), "\n";
42 print "Fresh until: ", $r->fresh_until("www.aas.no:80"), "\n";
44 print "not " if $r->no_visits("www.aas.no:80") != 2;
45 print "ok 4\n";
47 print "not " if abs($r->last_visit("www.sn.no:80") - time) > 2;
48 print "ok 5\n";
50 $r = undef;
52 # Try to reopen the database without a name specified
53 $r = new WWW::RobotRules::AnyDBM_File undef, $file;
54 $r->visit("www.aas.no:80");
56 print "not " if $r->no_visits("www.aas.no:80") != 3;
57 print "ok 6\n";
59 print "Agent-Name: ", $r->agent, "\n";
60 print "not " if $r->agent ne "myrobot";
61 print "ok 7\n";
63 $r = undef;
65 print "*** Dump of database ***\n";
66 tie(%cat, AnyDBM_File, $file, 0, 0644) or die "Can't tie: $!";
67 while (($key,$val) = each(%cat)) {
68     print "$key\t$val\n";
70 print "******\n";
72 untie %cat;
74 # Try to open database with a different agent name
75 $r = new WWW::RobotRules::AnyDBM_File "MOMSpider/2.0", $file;
77 print "not " if $r->no_visits("www.sn.no:80");
78 print "ok 8\n";
80 # Try parsing
81 $r->parse("http://www.sn.no:8080/robots.txt", <<EOT, (time + 3));
83 User-Agent: *
84 Disallow: /
86 User-Agent: Momspider
87 Disallow: /foo
88 Disallow: /bar
90 EOT
92 @r = $r->rules("www.sn.no:8080");
93 print "not " if "@r" ne "/foo /bar";
94 print "ok 9\n";
96 print "not " if $r->allowed("http://www.sn.no") >= 0;
97 print "ok 10\n";
99 print "not " if $r->allowed("http://www.sn.no:8080/foo/gisle");
100 print "ok 11\n";
102 sleep(5);  # wait until file has expired
103 print "not " if $r->allowed("http://www.sn.no:8080/foo/gisle") >= 0;
104 print "ok 12\n";
107 $r = undef;
109 print "*** Dump of database ***\n";
110 tie(%cat, AnyDBM_File, $file, 0, 0644) or die "Can't tie: $!";
111 while (($key,$val) = each(%cat)) {
112     print "$key\t$val\n";
114 print "******\n";
116 untie %cat;                     # Otherwise the next line fails on DOSish
118 while (unlink("$file", "$file.pag", "$file.dir", "$file.db")) {}
120 # Try open a an emty database without specifying a name
121 eval { 
122    $r = new WWW::RobotRules::AnyDBM_File undef, $file;
124 print $@;
125 print "not " unless $@;  # should fail
126 print "ok 13\n";
128 unlink "$file", "$file.pag", "$file.dir", "$file.db";