From 36c605cadace789d14354a1c835457f5f23ee1c2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Oct 2009 23:27:00 -0400 Subject: add test suite for add_depends and found a bug in my bitmath.. --- t/add_depends.t | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 t/add_depends.t (limited to 't/add_depends.t') diff --git a/t/add_depends.t b/t/add_depends.t new file mode 100644 index 000000000..935a57944 --- /dev/null +++ b/t/add_depends.t @@ -0,0 +1,68 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 50; + +BEGIN { use_ok("IkiWiki"); } +%config=IkiWiki::defaultconfig(); +$config{srcdir}=$config{destdir}="/dev/null"; +IkiWiki::checkconfig(); + +# avoids adding an unparseable pagespec +ok(! add_depends("foo", "foo and (bar")); +ok(! add_depends("foo", "foo another")); + +# simple and not-so-simple dependencies split +ok(add_depends("foo", "*")); +ok(add_depends("foo", "bar")); +ok(add_depends("foo", "BAZ")); +ok(exists $IkiWiki::depends_simple{foo}{"bar"}); +ok(exists $IkiWiki::depends_simple{foo}{"baz"}); # lowercase +ok(! exists $IkiWiki::depends_simple{foo}{"*"}); +ok(! exists $IkiWiki::depends{foo}{"bar"}); +ok(! exists $IkiWiki::depends{foo}{"baz"}); + +# default dependencies are content dependencies +ok($IkiWiki::depends{foo}{"*"} & $IkiWiki::DEPEND_CONTENT); +ok(! ($IkiWiki::depends{foo}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); +ok($IkiWiki::depends_simple{foo}{"bar"} & $IkiWiki::DEPEND_CONTENT); +ok(! ($IkiWiki::depends_simple{foo}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); + +# adding other dep types standalone +ok(add_depends("foo2", "*", presence => 1)); +ok(add_depends("foo2", "bar", links => 1)); +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", links => 1, presence => 1)); +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 a pagespec that requires page metadata should cause a fallback to +# a content dependency +foreach my $spec ("* and ! link(bar)", "* or link(bar)", "unknownspec()", + "title(hi)", + "* or backlink(yo)", # this one could actually be acceptably be + # detected to not need a content dep .. in + # theory! + ) { + ok(add_depends("foo3", $spec, presence => 1)); + ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_CONTENT); + ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); +} + +# 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", presence => 1)); # 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("foo", "bar", links => 1)); # had only content before +ok($IkiWiki::depends{foo}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)); +ok(! ($IkiWiki::depends{foo}{"*"} & $IkiWiki::DEPEND_PRESENCE)); -- cgit v1.2.3 From 62cc2afcaa7d09f73cb00a7efb15502406743178 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 6 Oct 2009 18:44:34 -0400 Subject: update to test backlinks() pagespecs --- t/add_depends.t | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) mode change 100644 => 100755 t/add_depends.t (limited to 't/add_depends.t') diff --git a/t/add_depends.t b/t/add_depends.t old mode 100644 new mode 100755 index 935a57944..68429b24a --- a/t/add_depends.t +++ b/t/add_depends.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 50; +use Test::More tests => 85; BEGIN { use_ok("IkiWiki"); } %config=IkiWiki::defaultconfig(); @@ -42,19 +42,6 @@ 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 a pagespec that requires page metadata should cause a fallback to -# a content dependency -foreach my $spec ("* and ! link(bar)", "* or link(bar)", "unknownspec()", - "title(hi)", - "* or backlink(yo)", # this one could actually be acceptably be - # detected to not need a content dep .. in - # theory! - ) { - ok(add_depends("foo3", $spec, presence => 1)); - ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_CONTENT); - ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); -} - # adding dep types to existing dependencies should merge the flags ok(add_depends("foo2", "baz")); ok($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_LINKS); @@ -66,3 +53,35 @@ ok(! ($IkiWiki::depends_simple{foo2}{"bar"} & $IkiWiki::DEPEND_CONTENT)); ok(add_depends("foo", "bar", links => 1)); # had only content before ok($IkiWiki::depends{foo}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)); ok(! ($IkiWiki::depends{foo}{"*"} & $IkiWiki::DEPEND_PRESENCE)); + +# adding a pagespec that requires page metadata should cause a fallback to +# a content dependency +foreach my $spec ("* and ! link(bar)", "* or link(bar)", "unknownspec()", + "title(hi)", + "* or unknown(yo)", # this one could actually be acceptably be + # detected to not need a content dep .. in + # theory! + ) { + ok(add_depends("foo3", $spec, presence => 1)); + ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_CONTENT); + ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); + ok(add_depends("foo4", $spec, links => 1)); + ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_CONTENT); + ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); +} + +# a pagespec with backlinks() in it is acceptable for a links dependency, +# but not a presence dependency +foreach my $spec ("index or (backlink(index) and !*.png)", "backlink(foo)") { + ok(add_depends("foo5", $spec, presence => 1)); + ok($IkiWiki::depends{foo5}{$spec} & $IkiWiki::DEPEND_CONTENT); + ok(! ($IkiWiki::depends{foo5}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); + ok(add_depends("foo6", $spec, links => 1)); + ok($IkiWiki::depends{foo6}{$spec} & $IkiWiki::DEPEND_LINKS); + ok(! ($IkiWiki::depends{foo6}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT))); + # combining both ends up with a content+links dependency + ok(add_depends("foo7", $spec, presence => 1, links => 1)); + ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_LINKS); + ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE)); +} -- cgit v1.2.3 From 7a8b492bcce45123cef45ebe6f97cd70b38b9db7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 6 Oct 2009 19:07:52 -0400 Subject: add_depends should default to content dependencies if unknown type specified --- IkiWiki.pm | 4 +--- t/add_depends.t | 7 ++++++- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 't/add_depends.t') diff --git a/IkiWiki.pm b/IkiWiki.pm index 7348ea2f7..7b1d24c6a 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1810,9 +1810,7 @@ sub add_depends ($$;@) { } } } - else { - $deptype=$DEPEND_CONTENT; - } + $deptype=$DEPEND_CONTENT unless $deptype; if ($simple) { $depends_simple{$page}{lc $pagespec} |= $deptype; diff --git a/t/add_depends.t b/t/add_depends.t index 68429b24a..2d686a17d 100755 --- a/t/add_depends.t +++ b/t/add_depends.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 85; +use Test::More tests => 88; BEGIN { use_ok("IkiWiki"); } %config=IkiWiki::defaultconfig(); @@ -85,3 +85,8 @@ foreach my $spec ("index or (backlink(index) and !*.png)", "backlink(foo)") { ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_LINKS); ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE)); } + +# content is the default if unknown types are entered +ok(add_depends("foo8", "*", presenCe => 1)); +ok($IkiWiki::depends{foo8}{"*"} & $IkiWiki::DEPEND_CONTENT); +ok(! ($IkiWiki::depends{foo8}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); -- cgit v1.2.3 From bb389a5ae25461ed20e2d28b18ea8b08f5f36473 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 7 Oct 2009 21:13:10 -0400 Subject: convert add_depends to use influences No more horrible special-case pagespec parsing. OTOH, matching over all pages to determine influences is a lot of work. --- IkiWiki.pm | 52 +++++++++++----------------------- t/add_depends.t | 86 ++++++++++++++++++++++++++++++--------------------------- 2 files changed, 62 insertions(+), 76 deletions(-) (limited to 't/add_depends.t') diff --git a/IkiWiki.pm b/IkiWiki.pm index 9c386e154..7adc63139 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1772,52 +1772,32 @@ sub add_depends ($$;@) { my $page=shift; my $pagespec=shift; - # Is the pagespec a simple page name? - my $simple=$pagespec =~ /$config{wiki_file_regexp}/ && - $pagespec !~ /[\s*?()!]/; - my $deptype=0; if (@_) { my %params=@_; - if ($params{presence}) { - # Is the pagespec limited to terms that will continue - # to match pages as long as those pages exist? - my $presence_limited=1; - while ($presence_limited && $pagespec=~m/(\w+)\([^\)]*\)/g) { - $presence_limited = $1 =~ /^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after)$/; - } - if ($presence_limited) { - $deptype=$deptype | $DEPEND_PRESENCE; - } - else { - $deptype=$deptype | $DEPEND_CONTENT; - } - } - if ($params{links}) { - # Is the pagespec limited to terms that will continue - # to match pages as long as those pages exist and - # link to the same places? - my $links_limited=1; - while ($links_limited && $pagespec=~m/(\w+)\([^\)]*\)/g) { - $links_limited = $1 =~ /^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after|backlink)$/; - } - if ($links_limited) { - $deptype=$deptype | $DEPEND_LINKS; - } - else { - $deptype=$deptype | $DEPEND_CONTENT; - } - } + $deptype=$deptype | $DEPEND_PRESENCE if $params{presence}; + $deptype=$deptype | $DEPEND_LINKS if $params{links}; } $deptype=$DEPEND_CONTENT unless $deptype; - if ($simple) { + # Is the pagespec a simple page name? + if ($pagespec =~ /$config{wiki_file_regexp}/ && + $pagespec !~ /[\s*?()!]/) { $depends_simple{$page}{lc $pagespec} |= $deptype; return 1; } - return unless pagespec_valid($pagespec); + # Analyse the pagespec, and match it against all pages + # to get a list of influences, and add explicit + # content dependencies for those. + my $sub=pagespec_translate($pagespec); + return if $@; + foreach my $p (keys %pagesources) { + my $r=$sub->($p, location => $page ); + map { $depends_simple{$page}{lc $_} |= $DEPEND_CONTENT } $r->influences + if $r; + } $depends{$page}{$pagespec} |= $deptype; return 1; @@ -2099,7 +2079,7 @@ sub match_link ($$;@) { my $from=exists $params{location} ? $params{location} : ''; my $links = $IkiWiki::links{$page}; - return IkiWiki::FailReason->new("$page has no links", $link) unless $links && @{$links}; + return IkiWiki::FailReason->new("$page has no links", $page) unless $links && @{$links}; my $bestlink = IkiWiki::bestlink($from, $link); foreach my $p (@{$links}) { if (length $bestlink) { diff --git a/t/add_depends.t b/t/add_depends.t index 2d686a17d..d49aa74ce 100755 --- a/t/add_depends.t +++ b/t/add_depends.t @@ -8,25 +8,27 @@ BEGIN { use_ok("IkiWiki"); } $config{srcdir}=$config{destdir}="/dev/null"; IkiWiki::checkconfig(); +$pagesources{"foo$_"}="foo$_.mdwn" for 0..9; + # avoids adding an unparseable pagespec -ok(! add_depends("foo", "foo and (bar")); -ok(! add_depends("foo", "foo another")); +ok(! add_depends("foo0", "foo and (bar")); +ok(! add_depends("foo0", "foo another")); # simple and not-so-simple dependencies split -ok(add_depends("foo", "*")); -ok(add_depends("foo", "bar")); -ok(add_depends("foo", "BAZ")); -ok(exists $IkiWiki::depends_simple{foo}{"bar"}); -ok(exists $IkiWiki::depends_simple{foo}{"baz"}); # lowercase -ok(! exists $IkiWiki::depends_simple{foo}{"*"}); -ok(! exists $IkiWiki::depends{foo}{"bar"}); -ok(! exists $IkiWiki::depends{foo}{"baz"}); +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{foo}{"*"} & $IkiWiki::DEPEND_CONTENT); -ok(! ($IkiWiki::depends{foo}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); -ok($IkiWiki::depends_simple{foo}{"bar"} & $IkiWiki::DEPEND_CONTENT); -ok(! ($IkiWiki::depends_simple{foo}{"bar"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); +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", "*", presence => 1)); @@ -50,43 +52,47 @@ ok(($IkiWiki::depends_simple{foo2}{"baz"} & $IkiWiki::DEPEND_CONTENT)); ok(add_depends("foo2", "bar", presence => 1)); # 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("foo", "bar", links => 1)); # had only content before -ok($IkiWiki::depends{foo}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)); -ok(! ($IkiWiki::depends{foo}{"*"} & $IkiWiki::DEPEND_PRESENCE)); +ok(add_depends("foo0", "bar", links => 1)); # had only content before +ok($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS)); +ok(! ($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_PRESENCE)); -# adding a pagespec that requires page metadata should cause a fallback to -# a content dependency -foreach my $spec ("* and ! link(bar)", "* or link(bar)", "unknownspec()", - "title(hi)", - "* or unknown(yo)", # this one could actually be acceptably be - # detected to not need a content dep .. in - # theory! - ) { +# Adding a pagespec that requires page metadata should add the influence +# as an explicit content dependency. +$links{foo0}=$links{foo9}=[qw{bar baz}]; +foreach my $spec ("* and ! link(bar)", "* or link(bar)") { ok(add_depends("foo3", $spec, presence => 1)); - ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_CONTENT); - ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); + ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_PRESENCE); + ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); + ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_CONTENT); ok(add_depends("foo4", $spec, links => 1)); - ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_CONTENT); - ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); + ok($IkiWiki::depends{foo4}{$spec} & $IkiWiki::DEPEND_LINKS); + ok(! ($IkiWiki::depends{foo4}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE))); + ok($IkiWiki::depends_simple{foo4}{foo4} == $IkiWiki::DEPEND_CONTENT); } -# a pagespec with backlinks() in it is acceptable for a links dependency, -# but not a presence dependency -foreach my $spec ("index or (backlink(index) and !*.png)", "backlink(foo)") { +# a pagespec with backlinks() will add as an influence the page with the links +$links{foo0}=[qw{foo5 foo7}]; +foreach my $spec ("bugs or (backlink(foo0) and !*.png)", "backlink(foo)") { ok(add_depends("foo5", $spec, presence => 1)); - ok($IkiWiki::depends{foo5}{$spec} & $IkiWiki::DEPEND_CONTENT); - ok(! ($IkiWiki::depends{foo5}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); + ok($IkiWiki::depends{foo5}{$spec} & $IkiWiki::DEPEND_PRESENCE); + ok(! ($IkiWiki::depends{foo5}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); + ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_CONTENT); ok(add_depends("foo6", $spec, links => 1)); ok($IkiWiki::depends{foo6}{$spec} & $IkiWiki::DEPEND_LINKS); ok(! ($IkiWiki::depends{foo6}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT))); - # combining both ends up with a content+links dependency + ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_CONTENT); ok(add_depends("foo7", $spec, presence => 1, links => 1)); - ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE); ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_LINKS); - ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE)); + ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT)); + ok($IkiWiki::depends_simple{foo7}{foo0} == $IkiWiki::DEPEND_CONTENT); + ok(add_depends("foo8", $spec)); + ok($IkiWiki::depends{foo8}{$spec} & $IkiWiki::DEPEND_CONTENT); + ok(! ($IkiWiki::depends{foo8}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); + ok($IkiWiki::depends_simple{foo8}{foo0} == $IkiWiki::DEPEND_CONTENT); } # content is the default if unknown types are entered -ok(add_depends("foo8", "*", presenCe => 1)); -ok($IkiWiki::depends{foo8}{"*"} & $IkiWiki::DEPEND_CONTENT); -ok(! ($IkiWiki::depends{foo8}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); +ok(add_depends("foo9", "*", presenCe => 1)); +ok($IkiWiki::depends{foo9}{"*"} & $IkiWiki::DEPEND_CONTENT); +ok(! ($IkiWiki::depends{foo9}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); -- cgit v1.2.3 From 5f9860e65c65aa769f11e550e63cc164b1519710 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 7 Oct 2009 21:48:03 -0400 Subject: add type info to influence information --- IkiWiki.pm | 49 ++++++++++++++++++++++++++++++------------------- IkiWiki/Plugin/meta.pm | 6 +++--- doc/plugins/write.mdwn | 6 +++--- docwiki.setup | 2 +- t/add_depends.t | 14 +++++++------- t/pagespec_match.t | 32 ++++++++++++++++---------------- 6 files changed, 60 insertions(+), 49 deletions(-) (limited to 't/add_depends.t') diff --git a/IkiWiki.pm b/IkiWiki.pm index 7adc63139..39a43ddbe 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -1795,8 +1795,10 @@ sub add_depends ($$;@) { return if $@; foreach my $p (keys %pagesources) { my $r=$sub->($p, location => $page ); - map { $depends_simple{$page}{lc $_} |= $DEPEND_CONTENT } $r->influences - if $r; + my %i=$r->influences; + foreach my $i (keys %i) { + $depends_simple{$page}{lc $i} |= $i{$i}; + } } $depends{$page}{$pagespec} |= $deptype; @@ -1998,8 +2000,8 @@ use overload ( '""' => sub { $_[0][0] }, '0+' => sub { 0 }, '!' => sub { bless $_[0], 'IkiWiki::SuccessReason'}, - '&' => sub { $_[0][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[0] }, - '|' => sub { $_[1][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[1] }, + '&' => sub { $_[0]->merge_influences($_[1]); $_[0] }, + '|' => sub { $_[1]->merge_influences($_[0]); $_[1] }, fallback => 1, ); @@ -2011,19 +2013,27 @@ use overload ( '""' => sub { $_[0][0] }, '0+' => sub { 1 }, '!' => sub { bless $_[0], 'IkiWiki::FailReason'}, - '&' => sub { $_[1][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[1] }, - '|' => sub { $_[0][1]={%{$_[0][1]}, %{$_[1][1]}}; $_[0] }, + '&' => sub { $_[1]->merge_influences($_[0]); $_[1] }, + '|' => sub { $_[0]->merge_influences($_[1]); $_[0] }, fallback => 1, ); sub new { my $class = shift; my $value = shift; - return bless [$value, {map { $_ => 1 } @_}], $class; + return bless [$value, {@_}], $class; } sub influences { - return keys %{$_[0][1]}; + return %{$_[0][1]}; +} + +sub merge_influences { + my $this=shift; + my $other=shift; + foreach my $influence (keys %{$other->[1]}) { + $this->[1]{$influence} |= $other->[1]{$influence}; + } } package IkiWiki::ErrorReason; @@ -2079,23 +2089,24 @@ sub match_link ($$;@) { my $from=exists $params{location} ? $params{location} : ''; my $links = $IkiWiki::links{$page}; - return IkiWiki::FailReason->new("$page has no links", $page) unless $links && @{$links}; + return IkiWiki::FailReason->new("$page has no links", $page => $IkiWiki::DEPEND_LINKS) + unless $links && @{$links}; my $bestlink = IkiWiki::bestlink($from, $link); foreach my $p (@{$links}) { if (length $bestlink) { - return IkiWiki::SuccessReason->new("$page links to $link", $page) + return IkiWiki::SuccessReason->new("$page links to $link", $page => $IkiWiki::DEPEND_LINKS) if $bestlink eq IkiWiki::bestlink($page, $p); } else { - return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page) + return IkiWiki::SuccessReason->new("$page links to page $p matching $link", $page => $IkiWiki::DEPEND_LINKS) if match_glob($p, $link, %params); my ($p_rel)=$p=~/^\/?(.*)/; $link=~s/^\///; - return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page) + return IkiWiki::SuccessReason->new("$page links to page $p_rel matching $link", $page => $IkiWiki::DEPEND_LINKS) if match_glob($p_rel, $link, %params); } } - return IkiWiki::FailReason->new("$page does not link to $link", $page); + return IkiWiki::FailReason->new("$page does not link to $link", $page => $IkiWiki::DEPEND_LINKS); } sub match_backlink ($$;@) { @@ -2111,14 +2122,14 @@ sub match_created_before ($$;@) { if (exists $IkiWiki::pagectime{$testpage}) { if ($IkiWiki::pagectime{$page} < $IkiWiki::pagectime{$testpage}) { - return IkiWiki::SuccessReason->new("$page created before $testpage", $testpage); + return IkiWiki::SuccessReason->new("$page created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE); } else { - return IkiWiki::FailReason->new("$page not created before $testpage", $testpage); + return IkiWiki::FailReason->new("$page not created before $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE); } } else { - return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage); + return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE); } } @@ -2131,14 +2142,14 @@ sub match_created_after ($$;@) { if (exists $IkiWiki::pagectime{$testpage}) { if ($IkiWiki::pagectime{$page} > $IkiWiki::pagectime{$testpage}) { - return IkiWiki::SuccessReason->new("$page created after $testpage", $testpage); + return IkiWiki::SuccessReason->new("$page created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE); } else { - return IkiWiki::FailReason->new("$page not created after $testpage", $testpage); + return IkiWiki::FailReason->new("$page not created after $testpage", $testpage => $IkiWiki::DEPEND_PRESENCE); } } else { - return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage); + return IkiWiki::ErrorReason->new("$testpage does not exist", $testpage => $IkiWiki::DEPEND_PRESENCE); } } diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index a8ee5bc85..c160e7eba 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -291,14 +291,14 @@ sub match { if (defined $val) { if ($val=~/^$re$/i) { - return IkiWiki::SuccessReason->new("$re matches $field of $page", $page); + return IkiWiki::SuccessReason->new("$re matches $field of $page", $page => $IkiWiki::DEPEND_CONTENT); } else { - return IkiWiki::FailReason->new("$re does not match $field of $page", $page); + return IkiWiki::FailReason->new("$re does not match $field of $page", $page => $IkiWiki::DEPEND_CONTENT); } } else { - return IkiWiki::FailReason->new("$page does not have a $field", $page); + return IkiWiki::FailReason->new("$page does not have a $field", $page => $IkiWiki::DEPEND_CONTENT); } } diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 6b47033e5..232430079 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -982,9 +982,9 @@ an IkiWiki::FailReason object if the match fails. If the match cannot be attempted at all, for any page, it can instead return an IkiWiki::ErrorReason object explaining why. -When constructing these objects, you should also include a list of any -pages whose contents or other metadata influenced the result of the match. -For example, "backlink(foo)" is influenced by the contents of page foo; +When constructing these objects, you should also include information about +of any pages whose contents or other metadata influenced the result of the +match. For example, "backlink(foo)" is influenced by the contents of page foo; "link(foo)" and "title(bar)" are influenced by the contents of any page they match; "created_before(foo)" is influenced by the metadata of foo; while "glob(*)" is not influenced by the contents of any page. diff --git a/docwiki.setup b/docwiki.setup index 52421e501..41c07f024 100644 --- a/docwiki.setup +++ b/docwiki.setup @@ -16,5 +16,5 @@ use IkiWiki::Setup::Standard { userdir => "users", usedirs => 0, prefix_directives => 1, - add_plugins => [qw{goodstuff version haiku polygen fortune}], + add_plugins => [qw{linkmap goodstuff version haiku polygen fortune}], } diff --git a/t/add_depends.t b/t/add_depends.t index d49aa74ce..9f426187b 100755 --- a/t/add_depends.t +++ b/t/add_depends.t @@ -57,17 +57,17 @@ ok($IkiWiki::depends{foo0}{"*"} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_L ok(! ($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_PRESENCE)); # Adding a pagespec that requires page metadata should add the influence -# as an explicit content dependency. +# as an explicit dependency. In the case of a link, a links dependency. $links{foo0}=$links{foo9}=[qw{bar baz}]; foreach my $spec ("* and ! link(bar)", "* or link(bar)") { ok(add_depends("foo3", $spec, presence => 1)); ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_PRESENCE); ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); - ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_LINKS); ok(add_depends("foo4", $spec, links => 1)); ok($IkiWiki::depends{foo4}{$spec} & $IkiWiki::DEPEND_LINKS); ok(! ($IkiWiki::depends{foo4}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE))); - ok($IkiWiki::depends_simple{foo4}{foo4} == $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends_simple{foo4}{foo4} == $IkiWiki::DEPEND_LINKS); } # a pagespec with backlinks() will add as an influence the page with the links @@ -76,20 +76,20 @@ foreach my $spec ("bugs or (backlink(foo0) and !*.png)", "backlink(foo)") { ok(add_depends("foo5", $spec, presence => 1)); ok($IkiWiki::depends{foo5}{$spec} & $IkiWiki::DEPEND_PRESENCE); ok(! ($IkiWiki::depends{foo5}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); - ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS); ok(add_depends("foo6", $spec, links => 1)); ok($IkiWiki::depends{foo6}{$spec} & $IkiWiki::DEPEND_LINKS); ok(! ($IkiWiki::depends{foo6}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT))); - ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS); ok(add_depends("foo7", $spec, presence => 1, links => 1)); ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE); ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_LINKS); ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT)); - ok($IkiWiki::depends_simple{foo7}{foo0} == $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends_simple{foo7}{foo0} == $IkiWiki::DEPEND_LINKS); ok(add_depends("foo8", $spec)); ok($IkiWiki::depends{foo8}{$spec} & $IkiWiki::DEPEND_CONTENT); ok(! ($IkiWiki::depends{foo8}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); - ok($IkiWiki::depends_simple{foo8}{foo0} == $IkiWiki::DEPEND_CONTENT); + ok($IkiWiki::depends_simple{foo8}{foo0} == $IkiWiki::DEPEND_LINKS); } # content is the default if unknown types are entered diff --git a/t/pagespec_match.t b/t/pagespec_match.t index 1a0db1cef..36fa04370 100755 --- a/t/pagespec_match.t +++ b/t/pagespec_match.t @@ -93,19 +93,19 @@ $ret=pagespec_match("foo", "bar or foo"); ok($ret, "simple match"); is($ret, "foo matches foo", "stringified return"); -$ret=pagespec_match("foo", "link(bar)"); -is(join(",", $ret->influences), 'foo', "link is influenced by the page with the link"); -$ret=pagespec_match("bar", "backlink(foo)"); -is(join(",", $ret->influences), 'foo', "backlink is influenced by the page with the link"); -$ret=pagespec_match("bar", "backlink(foo)"); -is(join(",", $ret->influences), 'foo', "backlink is influenced by the page with the link"); -$ret=pagespec_match("bar", "created_before(foo)"); -is(join(",", $ret->influences), 'foo', "created_before is influenced by the comparison page"); -$ret=pagespec_match("bar", "created_after(foo)"); -is(join(",", $ret->influences), 'foo', "created_after is influenced by the comparison page"); -$ret=pagespec_match("bar", "link(quux) and created_after(foo)"); -is(join(",", sort $ret->influences), 'foo,quux', "influences add up over AND"); -$ret=pagespec_match("bar", "link(quux) and created_after(foo)"); -is(join(",", sort $ret->influences), 'foo,quux', "influences add up over OR"); -$ret=pagespec_match("bar", "!link(quux) and !created_after(foo)"); -is(join(",", sort $ret->influences), 'foo,quux', "influences unaffected by negation"); +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("bar", "link(quux) and created_after(foo)")->influences; +is(join(",", sort keys %i), 'bar,foo', "influences add up over AND"); +%i=pagespec_match("bar", "link(quux) and created_after(foo)")->influences; +is(join(",", sort keys %i), 'bar,foo', "influences add up over OR"); +%i=pagespec_match("bar", "!link(quux) and !created_after(foo)")->influences; +is(join(",", sort keys %i), 'bar,foo', "influences unaffected by negation"); -- cgit v1.2.3 From 34b213235529300c8be19290cefb1e5a01e2da3a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Oct 2009 00:06:58 -0400 Subject: fix test to use new calling convention This test still fails several cases, since add_depends influence testing is currently commented out. --- t/add_depends.t | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 't/add_depends.t') diff --git a/t/add_depends.t b/t/add_depends.t index 9f426187b..fce7a76c6 100755 --- a/t/add_depends.t +++ b/t/add_depends.t @@ -31,15 +31,15 @@ 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", "*", presence => 1)); -ok(add_depends("foo2", "bar", links => 1)); +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", links => 1, presence => 1)); +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)); @@ -49,10 +49,10 @@ 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", presence => 1)); # had only links before +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", links => 1)); # had only content before +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)); @@ -60,11 +60,11 @@ ok(! ($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_PRESENCE)); # as an explicit dependency. In the case of a link, a links dependency. $links{foo0}=$links{foo9}=[qw{bar baz}]; foreach my $spec ("* and ! link(bar)", "* or link(bar)") { - ok(add_depends("foo3", $spec, presence => 1)); + ok(add_depends("foo3", $spec, deptype("presence"))); ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_PRESENCE); ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_LINKS); - ok(add_depends("foo4", $spec, links => 1)); + ok(add_depends("foo4", $spec, deptype("links"))); ok($IkiWiki::depends{foo4}{$spec} & $IkiWiki::DEPEND_LINKS); ok(! ($IkiWiki::depends{foo4}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE))); ok($IkiWiki::depends_simple{foo4}{foo4} == $IkiWiki::DEPEND_LINKS); @@ -73,15 +73,15 @@ foreach my $spec ("* and ! link(bar)", "* or link(bar)") { # a pagespec with backlinks() will add as an influence the page with the links $links{foo0}=[qw{foo5 foo7}]; foreach my $spec ("bugs or (backlink(foo0) and !*.png)", "backlink(foo)") { - ok(add_depends("foo5", $spec, presence => 1)); + ok(add_depends("foo5", $spec, deptype("presence"))); ok($IkiWiki::depends{foo5}{$spec} & $IkiWiki::DEPEND_PRESENCE); ok(! ($IkiWiki::depends{foo5}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS); - ok(add_depends("foo6", $spec, links => 1)); + ok(add_depends("foo6", $spec, deptype("links"))); ok($IkiWiki::depends{foo6}{$spec} & $IkiWiki::DEPEND_LINKS); ok(! ($IkiWiki::depends{foo6}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT))); ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS); - ok(add_depends("foo7", $spec, presence => 1, links => 1)); + ok(add_depends("foo7", $spec, deptype("presence", "links"))); ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE); ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_LINKS); ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT)); @@ -93,6 +93,6 @@ foreach my $spec ("bugs or (backlink(foo0) and !*.png)", "backlink(foo)") { } # content is the default if unknown types are entered -ok(add_depends("foo9", "*", presenCe => 1)); +ok(add_depends("foo9", "*", deptype("monkey"))); ok($IkiWiki::depends{foo9}{"*"} & $IkiWiki::DEPEND_CONTENT); ok(! ($IkiWiki::depends{foo9}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); -- cgit v1.2.3 From 9eb229bfc73066e5d12d5a199c77f63d5881dfb7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Oct 2009 14:05:22 -0400 Subject: move influence tests to pagespec_match_list.t --- t/add_depends.t | 36 ------------------------------ t/pagespec_match_list.t | 58 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 38 deletions(-) (limited to 't/add_depends.t') diff --git a/t/add_depends.t b/t/add_depends.t index fce7a76c6..e3f0b6603 100755 --- a/t/add_depends.t +++ b/t/add_depends.t @@ -56,42 +56,6 @@ 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)); -# Adding a pagespec that requires page metadata should add the influence -# as an explicit dependency. In the case of a link, a links dependency. -$links{foo0}=$links{foo9}=[qw{bar baz}]; -foreach my $spec ("* and ! link(bar)", "* or link(bar)") { - ok(add_depends("foo3", $spec, deptype("presence"))); - ok($IkiWiki::depends{foo3}{$spec} & $IkiWiki::DEPEND_PRESENCE); - ok(! ($IkiWiki::depends{foo3}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); - ok($IkiWiki::depends_simple{foo3}{foo3} == $IkiWiki::DEPEND_LINKS); - ok(add_depends("foo4", $spec, deptype("links"))); - ok($IkiWiki::depends{foo4}{$spec} & $IkiWiki::DEPEND_LINKS); - ok(! ($IkiWiki::depends{foo4}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_PRESENCE))); - ok($IkiWiki::depends_simple{foo4}{foo4} == $IkiWiki::DEPEND_LINKS); -} - -# a pagespec with backlinks() will add as an influence the page with the links -$links{foo0}=[qw{foo5 foo7}]; -foreach my $spec ("bugs or (backlink(foo0) and !*.png)", "backlink(foo)") { - ok(add_depends("foo5", $spec, deptype("presence"))); - ok($IkiWiki::depends{foo5}{$spec} & $IkiWiki::DEPEND_PRESENCE); - ok(! ($IkiWiki::depends{foo5}{$spec} & ($IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_LINKS))); - ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS); - ok(add_depends("foo6", $spec, deptype("links"))); - ok($IkiWiki::depends{foo6}{$spec} & $IkiWiki::DEPEND_LINKS); - ok(! ($IkiWiki::depends{foo6}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_CONTENT))); - ok($IkiWiki::depends_simple{foo5}{foo0} == $IkiWiki::DEPEND_LINKS); - ok(add_depends("foo7", $spec, deptype("presence", "links"))); - ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_PRESENCE); - ok($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_LINKS); - ok(! ($IkiWiki::depends{foo7}{$spec} & $IkiWiki::DEPEND_CONTENT)); - ok($IkiWiki::depends_simple{foo7}{foo0} == $IkiWiki::DEPEND_LINKS); - ok(add_depends("foo8", $spec)); - ok($IkiWiki::depends{foo8}{$spec} & $IkiWiki::DEPEND_CONTENT); - ok(! ($IkiWiki::depends{foo8}{$spec} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); - ok($IkiWiki::depends_simple{foo8}{foo0} == $IkiWiki::DEPEND_LINKS); -} - # content is the default if unknown types are entered ok(add_depends("foo9", "*", deptype("monkey"))); ok($IkiWiki::depends{foo9}{"*"} & $IkiWiki::DEPEND_CONTENT); diff --git a/t/pagespec_match_list.t b/t/pagespec_match_list.t index 85a30b542..301197cc1 100755 --- a/t/pagespec_match_list.t +++ b/t/pagespec_match_list.t @@ -1,19 +1,29 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 10; +use Test::More tests => 49; 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"]); @@ -22,10 +32,54 @@ is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 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", - limit => sub { $_[0] !~ /3/}) ], + 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); +} -- cgit v1.2.3 From 04d0a72c09528a4117b2ba641f5fdedbbe2a2171 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 19:05:37 -0400 Subject: typo --- t/add_depends.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't/add_depends.t') diff --git a/t/add_depends.t b/t/add_depends.t index e3f0b6603..9b074818c 100755 --- a/t/add_depends.t +++ b/t/add_depends.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 88; +use Test::More tests => 38; BEGIN { use_ok("IkiWiki"); } %config=IkiWiki::defaultconfig(); @@ -39,7 +39,7 @@ 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(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)); -- cgit v1.2.3 From ef34ea7c05189db8952b08d78aad718ccb64475a Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 22 Apr 2010 00:07:25 -0400 Subject: fix test cases for dynamic influence calculation --- t/add_depends.t | 10 +++++++++- t/pagespec_match_list.t | 25 ++++++++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) (limited to 't/add_depends.t') diff --git a/t/add_depends.t b/t/add_depends.t index 9b074818c..aa58fb0ff 100755 --- a/t/add_depends.t +++ b/t/add_depends.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 38; +use Test::More tests => 40; BEGIN { use_ok("IkiWiki"); } %config=IkiWiki::defaultconfig(); @@ -60,3 +60,11 @@ ok(! ($IkiWiki::depends{foo0}{"*"} & $IkiWiki::DEPEND_PRESENCE)); ok(add_depends("foo9", "*", deptype("monkey"))); ok($IkiWiki::depends{foo9}{"*"} & $IkiWiki::DEPEND_CONTENT); ok(! ($IkiWiki::depends{foo9}{"*"} & ($IkiWiki::DEPEND_PRESENCE | $IkiWiki::DEPEND_LINKS))); + +# Influences are added for dependencies involving links. +$pagesources{"foo"}="foo.mdwn"; +$links{foo}=[qw{bar}]; +$pagesources{"bar"}="bar.mdwn"; +$links{bar}=[qw{}]; +ok(add_depends("foo", "link(bar) and backlink(meep)")); +ok($IkiWiki::depends_simple{foo}{foo} == $IkiWiki::DEPEND_LINKS); diff --git a/t/pagespec_match_list.t b/t/pagespec_match_list.t index 27546e6ca..244ad9159 100755 --- a/t/pagespec_match_list.t +++ b/t/pagespec_match_list.t @@ -1,7 +1,7 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More tests => 115; +use Test::More tests => 126; BEGIN { use_ok("IkiWiki"); } @@ -71,19 +71,27 @@ foreach my $spec ("* and link(bar)", "* or link(bar)") { 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); - ok($IkiWiki::depends_simple{foo2}{foo} != $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); - ok($IkiWiki::depends_simple{foo3}{foo} != $IkiWiki::DEPEND_LINKS); %IkiWiki::depends_simple=(); %IkiWiki::depends=(); } -# Above we tested that a link pagespec is influenced -# by the pages that currently contain the link. + +# A link pagespec is influenced by the pages that currently contain the link. +# It is not influced by pages that do not currently contain the link, +# because if those pages were changed to contain it, regular dependency +# handling would be triggered. +foreach my $spec ("* and link(bar)", "link(bar)", "no_such_page or link(bar)") { + pagespec_match_list("foo2", $spec); + ok($IkiWiki::depends_simple{foo2}{foo2} == $IkiWiki::DEPEND_LINKS); + ok(! exists $IkiWiki::depends_simple{foo2}{foo}, $spec); + %IkiWiki::depends_simple=(); + %IkiWiki::depends=(); +} # Oppositely, a pagespec that tests for pages that do not have a link # is not influenced by pages that currently contain the link, but @@ -91,8 +99,8 @@ foreach my $spec ("* and link(bar)", "* or link(bar)") { # could be changed to have it). foreach my $spec ("* and !link(bar)", "* and !(!(!link(bar)))") { pagespec_match_list("foo2", $spec); - ok($IkiWiki::depends_simple{foo2}{foo2} != $IkiWiki::DEPEND_LINKS); - ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS); + ok(! exists $IkiWiki::depends_simple{foo2}{foo2}); + ok($IkiWiki::depends_simple{foo2}{foo} == $IkiWiki::DEPEND_LINKS, $spec); %IkiWiki::depends_simple=(); %IkiWiki::depends=(); } @@ -103,12 +111,14 @@ foreach my $spec ("bar or (backlink(foo) and !*.png)", "backlink(foo)", "!backli 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); + ok(! exists $IkiWiki::depends_simple{foo2}{foo2}); %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); + ok(! exists $IkiWiki::depends_simple{foo2}{foo2}); %IkiWiki::depends_simple=(); %IkiWiki::depends=(); pagespec_match_list("foo2", $spec, deptype => deptype("presence", "links")); @@ -116,6 +126,7 @@ foreach my $spec ("bar or (backlink(foo) and !*.png)", "backlink(foo)", "!backli 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); + ok(! exists $IkiWiki::depends_simple{foo2}{foo2}); %IkiWiki::depends_simple=(); %IkiWiki::depends=(); pagespec_match_list("foo2", $spec); -- cgit v1.2.3