diff options
Diffstat (limited to 't')
-rwxr-xr-x | t/add_depends.t | 62 | ||||
-rwxr-xr-x | t/basewiki_brokenlinks.t | 2 | ||||
-rwxr-xr-x | t/cvs.t | 8 | ||||
-rwxr-xr-x | t/pagespec_match.t | 23 | ||||
-rwxr-xr-x | t/pagespec_match_list.t | 112 | ||||
-rwxr-xr-x | t/pagespec_match_result.t | 84 | ||||
-rwxr-xr-x | t/yesno.t | 4 |
7 files changed, 292 insertions, 3 deletions
diff --git a/t/add_depends.t b/t/add_depends.t new file mode 100755 index 000000000..9b074818c --- /dev/null +++ b/t/add_depends.t @@ -0,0 +1,62 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 38; + +BEGIN { use_ok("IkiWiki"); } +%config=IkiWiki::defaultconfig(); +$config{srcdir}=$config{destdir}="/dev/null"; +IkiWiki::checkconfig(); + +$pagesources{"foo$_"}="foo$_.mdwn" for 0..9; + +# avoids adding an unparseable pagespec +ok(! add_depends("foo0", "foo and (bar")); +ok(! add_depends("foo0", "foo another")); + +# simple and not-so-simple dependencies split +ok(add_depends("foo0", "*")); +ok(add_depends("foo0", "bar")); +ok(add_depends("foo0", "BAZ")); +ok(exists $IkiWiki::depends_simple{foo0}{"bar"}); +ok(exists $IkiWiki::depends_simple{foo0}{"baz"}); # lowercase +ok(! exists $IkiWiki::depends_simple{foo0}{"*"}); +ok(! exists $IkiWiki::depends{foo0}{"bar"}); +ok(! exists $IkiWiki::depends{foo0}{"baz"}); + +# default dependencies are content dependencies +ok($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_CONTENT); +ok(! ($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); +ok($IkiWiki::depends_simple{foo0}{"bar"} & $IkiWiki::DEPEND_CONTENT); +ok(! ($IkiWiki::depends_simple{foo0}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); + +# adding other dep types standalone +ok(add_depends("foo2", "*", deptype("presence"))); +ok(add_depends("foo2", "bar", deptype("links"))); +ok($IkiWiki::depends{foo2}{"*"} & $IkiWiki::DEPEND_PRESENCE); +ok(! ($IkiWiki::depends{foo2}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); +ok($IkiWiki::depends_simple{foo2}{"bar"} & $IkiWiki::DEPEND_LINKS); +ok(! ($IkiWiki::depends_simple{foo2}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT))); + +# adding combined dep types +ok(add_depends("foo2", "baz", deptype("links", "presence"))); +ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_LINKS); +ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_PRESENCE); +ok(! ($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_CONTENT)); + +# adding dep types to existing dependencies should merge the flags +ok(add_depends("foo2", "baz")); +ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_LINKS); +ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_PRESENCE); +ok(($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_CONTENT)); +ok(add_depends("foo2", "bar", deptype("presence"))); # had only links before +ok($IkiWiki::depends_simple{foo2}{"bar"} & ($IkiWiki::DEPEND_LINKS | $IkiWiki::DEPEND_PRESENCE)); +ok(! ($IkiWiki::depends_simple{foo2}{"bar"} & $IkiWiki::DEPEND_CONTENT)); +ok(add_depends("foo0", "bar", deptype("links"))); # had only content before +ok($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)); +ok(! ($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_PRESENCE)); + +# content is the default if unknown types are entered +ok(add_depends("foo9", "*", deptype("monkey"))); +ok($IkiWiki::depends{foo9}{"*"} & $IkiWiki::DEPEND_CONTENT); +ok(! ($IkiWiki::depends{foo9}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); diff --git a/t/basewiki_brokenlinks.t b/t/basewiki_brokenlinks.t index d74f64e36..2dd950832 100755 --- a/t/basewiki_brokenlinks.t +++ b/t/basewiki_brokenlinks.t @@ -8,7 +8,7 @@ ok(! system("make -s ikiwiki.out")); ok(! system("make underlay_install DESTDIR=`pwd`/t/tmp/install PREFIX=/usr >/dev/null")); foreach my $plugin ("", "listdirectives") { - ok(! system("perl -I. ./ikiwiki.out -rebuild -plugin brokenlinks ". + ok(! system("LANG=C perl -I. ./ikiwiki.out -rebuild -plugin brokenlinks ". # always enabled because pages link to it conditionally, # which brokenlinks cannot handle properly "-plugin smiley ". @@ -13,6 +13,14 @@ BEGIN { use Test::More skip_all => "cvs or cvsps not available or could not make test dir" } } + foreach my $module ('File::ReadBackwards', 'File::MimeInfo') { + eval qq{use $module}; + if ($@) { + eval qq{ + use Test::More skip_all => "$module not available" + } + } + } } use Test::More tests => 12; diff --git a/t/pagespec_match.t b/t/pagespec_match.t index 64408f489..d529106f7 100755 --- a/t/pagespec_match.t +++ b/t/pagespec_match.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 54; +use Test::More tests => 64; BEGIN { use_ok("IkiWiki"); } @@ -88,3 +88,24 @@ ok(! pagespec_match("foo", "no_such_function(foo)"), "foo"); my $ret=pagespec_match("foo", "(invalid"); ok(! $ret, "syntax error"); ok($ret =~ /syntax error/, "error message"); + +$ret=pagespec_match("foo", "bar or foo"); +ok($ret, "simple match"); +is($ret, "foo matches foo", "stringified return"); + +my $i=pagespec_match("foo", "link(bar)")->influences; +is(join(",", keys %$i), 'foo', "link is influenced by the page with the link"); +$i=pagespec_match("bar", "backlink(foo)")->influences; +is(join(",", keys %$i), 'foo', "backlink is influenced by the page with the link"); +$i=pagespec_match("bar", "backlink(foo)")->influences; +is(join(",", keys %$i), 'foo', "backlink is influenced by the page with the link"); +$i=pagespec_match("bar", "created_before(foo)")->influences; +is(join(",", keys %$i), 'foo', "created_before is influenced by the comparison page"); +$i=pagespec_match("bar", "created_after(foo)")->influences; +is(join(",", keys %$i), 'foo', "created_after is influenced by the comparison page"); +$i=pagespec_match("foo", "link(baz) and created_after(bar)")->influences; +is(join(",", sort keys %$i), 'bar,foo', "influences add up over AND"); +$i=pagespec_match("foo", "link(baz) and created_after(bar)")->influences; +is(join(",", sort keys %$i), 'bar,foo', "influences add up over OR"); +$i=pagespec_match("foo", "!link(baz) and !created_after(bar)")->influences; +is(join(",", sort keys %$i), 'bar,foo', "influences unaffected by negation"); diff --git a/t/pagespec_match_list.t b/t/pagespec_match_list.t new file mode 100755 index 000000000..dd5dcc5b0 --- /dev/null +++ b/t/pagespec_match_list.t @@ -0,0 +1,112 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 88; + +BEGIN { use_ok("IkiWiki"); } + +%config=IkiWiki::defaultconfig(); +$config{srcdir}=$config{destdir}="/dev/null"; +IkiWiki::checkconfig(); + +%pagesources=( + foo => "foo.mdwn", + foo2 => "foo2.mdwn", + foo3 => "foo3.mdwn", + bar => "bar.mdwn", + "post/1" => "post/1.mdwn", + "post/2" => "post/2.mdwn", + "post/3" => "post/3.mdwn", +); +$links{foo}=[qw{post/1 post/2}]; +$links{foo2}=[qw{bar}]; +$links{foo3}=[qw{bar}]; + +is_deeply([pagespec_match_list("foo", "bar")], ["bar"]); +is_deeply([sort(pagespec_match_list("foo", "* and !post/*"))], ["bar", "foo", "foo2", "foo3"]); +is_deeply([sort(pagespec_match_list("foo", "post/*"))], ["post/1", "post/2", "post/3"]); +is_deeply([pagespec_match_list("foo", "post/*", sort => "title", reverse => 1)], + ["post/3", "post/2", "post/1"]); +is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 2)], + ["post/1", "post/2"]); +is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 50)], + ["post/1", "post/2", "post/3"]); +is_deeply([pagespec_match_list("foo", "post/*", sort => "title", + filter => sub { $_[0] =~ /3/}) ], + ["post/1", "post/2"]); +my $r=eval { pagespec_match_list("foo", "beep") }; +ok(eval { pagespec_match_list("foo", "beep") } == 0); +ok(! $@, "does not fail with error when unable to match anything"); +eval { pagespec_match_list("foo", "this is not a legal pagespec!") }; +ok($@, "fails with error when pagespec bad"); + +# A pagespec that requires page metadata should add influences +# as an explicit dependency. In the case of a link, a links dependency. +foreach my $spec ("* and link(bar)", "* or link(bar)") { + pagespec_match_list("foo2", $spec, deptype => deptype("presence")); + ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE); + ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); + ok($IkiWiki::depends_simple{foo2}{foo2} == $IkiWiki::DEPEND_LINKS); + %IkiWiki::depends_simple=(); + %IkiWiki::depends=(); + pagespec_match_list("foo3", $spec, deptype => deptype("links")); + ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_LINKS); + ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE))); + ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_LINKS); + %IkiWiki::depends_simple=(); + %IkiWiki::depends=(); +} + +# a pagespec with backlinks() will add as an influence the page with the links +foreach my $spec ("bar or (backlink(foo) and !*.png)", "backlink(foo)") { + pagespec_match_list("foo2", $spec, deptype => deptype("presence")); + ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE); + ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); + ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS); + %IkiWiki::depends_simple=(); + %IkiWiki::depends=(); + pagespec_match_list("foo2", $spec, deptype => deptype("links")); + ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_LINKS); + ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT))); + ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS); + %IkiWiki::depends_simple=(); + %IkiWiki::depends=(); + pagespec_match_list("foo2", $spec, deptype => deptype("presence", "links")); + ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE); + ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_LINKS); + ok(! ($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_CONTENT)); + ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS); + %IkiWiki::depends_simple=(); + %IkiWiki::depends=(); + pagespec_match_list("foo2", $spec); + ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_CONTENT); + ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); + ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS); + %IkiWiki::depends_simple=(); + %IkiWiki::depends=(); +} + +# Hard fails due to a glob, etc, will block influences of other anded terms. +foreach my $spec ("nosuchpage and link(bar)", "link(bar) and nosuchpage", + "link(bar) and */Discussion", "*/Discussion and link(bar)", + "!foo2 and link(bar)", "link(bar) and !foo2") { + pagespec_match_list("foo2", $spec, deptype => deptype("presence")); + ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE); + ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); + ok(! exists $IkiWiki::depends_simple{foo2}{foo2}, "no influence from $spec"); + %IkiWiki::depends_simple=(); + %IkiWiki::depends=(); +} + +# A hard fail will not block influences of other ored terms. +foreach my $spec ("nosuchpage or link(bar)", "link(bar) or nosuchpage", + "link(bar) or */Discussion", "*/Discussion or link(bar)", + "!foo2 or link(bar)", "link(bar) or !foo2", + "link(bar) or (!foo2 and !foo1)") { + pagespec_match_list("foo2", $spec, deptype => deptype("presence")); + ok($IkiWiki::depends{foo2}{$spec} & $IkiWiki::DEPEND_PRESENCE); + ok(! ($IkiWiki::depends{foo2}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); + ok($IkiWiki::depends_simple{foo2}{foo2} == $IkiWiki::DEPEND_LINKS); + %IkiWiki::depends_simple=(); + %IkiWiki::depends=(); +} diff --git a/t/pagespec_match_result.t b/t/pagespec_match_result.t new file mode 100755 index 000000000..13fcdcad0 --- /dev/null +++ b/t/pagespec_match_result.t @@ -0,0 +1,84 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 138; + +BEGIN { use_ok("IkiWiki"); } + +# Note that new objects have to be constructed freshly for each test, since +# object states are mutated as they are combined. +sub S { IkiWiki::SuccessReason->new("match", @_) } +sub F { IkiWiki::FailReason->new("no match", @_) } +sub E { IkiWiki::ErrorReason->new("error in matching", @_) } + +ok(S() eq "match"); +ok(F() eq "no match"); +ok(E() eq "error in matching"); + +ok(S()); +ok(! F()); +ok(! E()); + +ok(!(! S())); +ok(!(!(! F))); +ok(!(!(! E))); + +ok(S() | F()); +ok(F() | S()); +ok(!(F() | E())); +ok(!(!S() | F() | E())); + +ok(S() & S() & S()); +ok(!(S() & E())); +ok(!(S() & F())); +ok(!(S() & F() & E())); +ok(S() & (F() | F() | S())); + +# influence merging tests +foreach my $test ( + ['$s | $f' => 1], # OR merges + ['! $s | ! $f' => 1], # OR merges with negated terms too + ['!(!(!$s)) | $f' => 1],# OR merges with multiple negation too + ['$s | $f | E()' => 1], # OR merges, even though E() has no influences + ['$s | E() | $f' => 1], # ditto + ['E() | $s | $f' => 1], # ditto + ['!$s | !$f | E()' => 1],# negated terms also do not block merges + ['!$s | E() | $f' => 1],# ditto + ['E() | $s | !$f' => 1],# ditto + ['$s & $f' => 1], # AND merges if both items have influences + ['!$s & $f' => 1], # AND merges negated terms too + ['$s & !$f' => 1], # AND merges negated terms too + ['$s & $f & E()' => 0], # AND fails to merge since E() has no influences + ['$s & E() & $f' => 0], # ditto + ['E() & $s & $f' => 0], # ditto + ) { + my $op=$test->[0]; + my $influence=$test->[1]; + + my $s=S(foo => 1, bar => 1); + is($s->influences->{foo}, 1); + is($s->influences->{bar}, 1); + my $f=F(bar => 2, baz => 1); + is($f->influences->{bar}, 2); + is($f->influences->{baz}, 1); + my $c = eval $op; + ok(ref $c); + if ($influence) { + is($c->influences->{foo}, 1, "foo ($op)"); + is($c->influences->{bar}, (1 | 2), "bar ($op)"); + is($c->influences->{baz}, 1, "baz ($op)"); + } + else { + ok(! %{$c->influences}, "no influence for ($op)"); + } +} + +my $s=S(foo => 0, bar => 1); +$s->influences(baz => 1); +ok(! $s->influences->{foo}, "removed 0 influence"); +ok(! $s->influences->{bar}, "removed 1 influence"); +ok($s->influences->{baz}, "set influence"); +ok($s->influences_static); +$s=S(foo => 0, bar => 1); +$s->influences(baz => 1, "" => 1); +ok(! $s->influences_static); @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 10; +use Test::More tests => 11; BEGIN { use_ok("IkiWiki"); } @@ -19,3 +19,5 @@ ok(IkiWiki::yesno("NO") == 0); ok(IkiWiki::yesno("1") == 1); ok(IkiWiki::yesno("0") == 0); ok(IkiWiki::yesno("mooooooooooo") == 0); + +ok(IkiWiki::yesno(undef) == 0); |