X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/c7bc11f26fc4aa8e2a9c7e1bec60076944181b52..690cc823aeb234fb0ef4cf099302ad78fdd364f1:/t/trail.t diff --git a/t/trail.t b/t/trail.t index b24a81e41..dce3b3c7e 100755 --- a/t/trail.t +++ b/t/trail.t @@ -4,6 +4,24 @@ use strict; use Test::More 'no_plan'; use IkiWiki; +sub check_trail { + my $file=shift; + my $expected=shift; + my $trailname=shift || qr/\w+/; + my $blob=readfile("t/tmp/out/$file"); + my ($trailline)=$blob=~/^trail=$trailname\s+(.*)$/m; + is($trailline, $expected, "expected $expected in $file"); +} + +sub check_no_trail { + my $file=shift; + my $trailname=shift || qr/\w+/; + my $blob=readfile("t/tmp/out/$file"); + my ($trailline)=$blob=~/^trail=$trailname\s+(.*)$/m; + $trailline="" unless defined $trailline; + ok($trailline !~ /^trail=$trailname\s+/, "no trail $trailname in $file"); +} + my $blob; ok(! system("rm -rf t/tmp")); @@ -75,9 +93,21 @@ write_old_file("sorting/linked2.mdwn", "linked2"); write_old_file("sorting.mdwn", '[[!traillink linked]] ' . '[[!trailitems pages="sorting/z/a or sorting/a/b or sorting/a/c"]] ' . - '[[!trailitems pagenames="beginning middle end"]] ' . + '[[!trailitems pagenames="sorting/beginning sorting/middle sorting/end"]] ' . '[[!inline pages="sorting/old or sorting/ancient or sorting/new" trail="yes"]] ' . '[[!traillink linked2]]'); +write_old_file("limited/a.mdwn", "a"); +write_old_file("limited/b.mdwn", "b"); +write_old_file("limited/c.mdwn", "c"); +write_old_file("limited/d.mdwn", "d"); +write_old_file("limited.mdwn", + '[[!inline pages="limited/*" trail="yes" show=2 sort=title]]'); +write_old_file("untrail/a.mdwn", "a"); +write_old_file("untrail/b.mdwn", "b"); +write_old_file("untrail.mdwn", "[[!traillink a]] [[!traillink b]]"); +write_old_file("retitled/a.mdwn", "a"); +write_old_file("retitled.mdwn", + '[[!meta title="the old title"]][[!traillink a]]'); write_old_file("meme.mdwn", <badger<\/a>/m); ok($blob =~ /This is a link to badger, with a title<\/a>/m); ok($blob =~ /That is the badger<\/a>/m); -$blob = readfile("t/tmp/out/badger.html"); -ok($blob =~ /^trail=meme n=mushroom p=$/m); -ok($blob =~ /^trail=wind_in_the_willows n=mr_toad p=ratty$/m); +check_trail("badger.html", "n=mushroom p=", "meme"); +check_trail("badger.html", "n=mr_toad p=ratty", "wind_in_the_willows"); ok(! -f "t/tmp/out/moley.html"); -$blob = readfile("t/tmp/out/mr_toad.html"); -ok($blob !~ /^trail=meme/m); -ok($blob =~ /^trail=wind_in_the_willows n=ratty p=badger$/m); +check_trail("mr_toad.html", "n=ratty p=badger", "wind_in_the_willows"); +check_no_trail("mr_toad.html", "meme"); # meta title is respected for pages that have one +$blob = readfile("t/tmp/out/mr_toad.html"); ok($blob =~ /">< The Breezy Badger<\/a>/m); # pagetitle for pages that don't ok($blob =~ /">ratty ><\/a>/m); -$blob = readfile("t/tmp/out/ratty.html"); -ok($blob !~ /^trail=meme/m); -ok($blob =~ /^trail=wind_in_the_willows n=badger p=mr_toad$/m); +check_no_trail("ratty.html", "meme"); +check_trail("ratty.html", "n=badger p=mr_toad", "wind_in_the_willows"); -$blob = readfile("t/tmp/out/mushroom.html"); -ok($blob =~ /^trail=meme n=snake p=badger$/m); -ok($blob !~ /^trail=wind_in_the_willows/m); +check_trail("mushroom.html", "n=snake p=badger", "meme"); +check_no_trail("mushroom.html", "wind_in_the_willows"); -$blob = readfile("t/tmp/out/snake.html"); -ok($blob =~ /^trail=meme n= p=mushroom$/m); -ok($blob !~ /^trail=wind_in_the_willows/m); +check_trail("snake.html", "n= p=mushroom", "meme"); +check_no_trail("snake.html", "wind_in_the_willows"); -$blob = readfile("t/tmp/out/self_referential.html"); -ok($blob =~ /^trail=self_referential n= p=$/m); +check_trail("self_referential.html", "n= p=", "self_referential"); -$blob = readfile("t/tmp/out/add/b.html"); -ok($blob =~ /^trail=add n=add\/d p=$/m); -$blob = readfile("t/tmp/out/add/d.html"); -ok($blob =~ /^trail=add n= p=add\/b$/m); +check_trail("add/b.html", "n=add/d p=", "add"); +check_trail("add/d.html", "n= p=add/b", "add"); ok(! -f "t/tmp/out/add/a.html"); ok(! -f "t/tmp/out/add/c.html"); ok(! -f "t/tmp/out/add/e.html"); -$blob = readfile("t/tmp/out/del/a.html"); -ok($blob =~ /^trail=del n=del\/b p=$/m); -$blob = readfile("t/tmp/out/del/b.html"); -ok($blob =~ /^trail=del n=del\/c p=del\/a$/m); -$blob = readfile("t/tmp/out/del/c.html"); -ok($blob =~ /^trail=del n=del\/d p=del\/b$/m); -$blob = readfile("t/tmp/out/del/d.html"); -ok($blob =~ /^trail=del n=del\/e p=del\/c$/m); -$blob = readfile("t/tmp/out/del/e.html"); -ok($blob =~ /^trail=del n= p=del\/d$/m); - -$blob = readfile("t/tmp/out/sorting/linked.html"); -ok($blob =~ m{^trail=sorting n=sorting/a/b p=$}m); -$blob = readfile("t/tmp/out/sorting/a/b.html"); -ok($blob =~ m{^trail=sorting n=sorting/a/c p=sorting/linked$}m); -$blob = readfile("t/tmp/out/sorting/a/c.html"); -ok($blob =~ m{^trail=sorting n=sorting/z/a p=sorting/a/b$}m); -$blob = readfile("t/tmp/out/sorting/z/a.html"); -ok($blob =~ m{^trail=sorting n=sorting/beginning p=sorting/a/c$}m); -$blob = readfile("t/tmp/out/sorting/beginning.html"); -ok($blob =~ m{^trail=sorting n=sorting/middle p=sorting/z/a$}m); -$blob = readfile("t/tmp/out/sorting/middle.html"); -ok($blob =~ m{^trail=sorting n=sorting/end p=sorting/beginning$}m); -$blob = readfile("t/tmp/out/sorting/end.html"); -ok($blob =~ m{^trail=sorting n=sorting/new p=sorting/middle$}m); -$blob = readfile("t/tmp/out/sorting/new.html"); -ok($blob =~ m{^trail=sorting n=sorting/old p=sorting/end$}m); -$blob = readfile("t/tmp/out/sorting/old.html"); -ok($blob =~ m{^trail=sorting n=sorting/ancient p=sorting/new$}m); -$blob = readfile("t/tmp/out/sorting/ancient.html"); -ok($blob =~ m{^trail=sorting n=sorting/linked2 p=sorting/old$}m); -$blob = readfile("t/tmp/out/sorting/linked2.html"); -ok($blob =~ m{^trail=sorting n= p=sorting/ancient$}m); +check_trail("del/a.html", "n=del/b p="); +check_trail("del/b.html", "n=del/c p=del/a"); +check_trail("del/c.html", "n=del/d p=del/b"); +check_trail("del/d.html", "n=del/e p=del/c"); +check_trail("del/e.html", "n= p=del/d"); + +check_trail("sorting/linked.html", "n=sorting/a/b p="); +check_trail("sorting/a/b.html", "n=sorting/a/c p=sorting/linked"); +check_trail("sorting/a/c.html", "n=sorting/z/a p=sorting/a/b"); +check_trail("sorting/z/a.html", "n=sorting/beginning p=sorting/a/c"); +check_trail("sorting/beginning.html", "n=sorting/middle p=sorting/z/a"); +check_trail("sorting/middle.html", "n=sorting/end p=sorting/beginning"); +check_trail("sorting/end.html", "n=sorting/new p=sorting/middle"); +check_trail("sorting/new.html", "n=sorting/old p=sorting/end"); +check_trail("sorting/old.html", "n=sorting/ancient p=sorting/new"); +check_trail("sorting/ancient.html", "n=sorting/linked2 p=sorting/old"); +check_trail("sorting/linked2.html", "n= p=sorting/ancient"); + +# If the inline has a limited number of pages, the trail still contains +# everything. +$blob = readfile("t/tmp/out/limited.html"); +ok($blob =~ /a<\/a>/m); +ok($blob =~ /b<\/a>/m); +ok($blob !~ //m); +ok($blob !~ //m); +check_trail("limited/a.html", "n=limited/b p="); +check_trail("limited/b.html", "n=limited/c p=limited/a"); +check_trail("limited/c.html", "n=limited/d p=limited/b"); +check_trail("limited/d.html", "n= p=limited/c"); + +check_trail("untrail/a.html", "n=untrail/b p="); +check_trail("untrail/b.html", "n= p=untrail/a"); + +$blob = readfile("t/tmp/out/retitled/a.html"); +ok($blob =~ /\^ the old title \^/m); # Make some changes and refresh. These writefile calls don't set an # old mtime, so they're strictly newer than the "old" files. @@ -197,48 +222,71 @@ writefile("sorting.mdwn", "t/tmp/in", readfile("t/tmp/in/sorting.mdwn") . '[[!trailoptions sort="title" reverse="yes"]]'); +writefile("retitled.mdwn", "t/tmp/in", + '[[!meta title="the new title"]][[!traillink a]]'); + +# If the inline has a limited number of pages, the trail still depends on +# everything. +writefile("limited.html", "t/tmp/out", "[this gets rebuilt]"); +writefile("limited/c.mdwn", "t/tmp/in", '[[!meta title="New C page"]]c'); + +writefile("untrail.mdwn", "t/tmp/in", "no longer a trail"); + ok(! system("$command -refresh")); -$blob = readfile("t/tmp/out/add/a.html"); -ok($blob =~ /^trail=add n=add\/b p=$/m); -$blob = readfile("t/tmp/out/add/b.html"); -ok($blob =~ /^trail=add n=add\/c p=add\/a$/m); -$blob = readfile("t/tmp/out/add/c.html"); -ok($blob =~ /^trail=add n=add\/d p=add\/b$/m); -$blob = readfile("t/tmp/out/add/d.html"); -ok($blob =~ /^trail=add n=add\/e p=add\/c$/m); -$blob = readfile("t/tmp/out/add/e.html"); -ok($blob =~ /^trail=add n= p=add\/d$/m); - -$blob = readfile("t/tmp/out/del/b.html"); -ok($blob =~ /^trail=del n=del\/d p=$/m); -$blob = readfile("t/tmp/out/del/d.html"); -ok($blob =~ /^trail=del n= p=del\/b$/m); +check_trail("add/a.html", "n=add/b p="); +check_trail("add/b.html", "n=add/c p=add/a"); +check_trail("add/c.html", "n=add/d p=add/b"); +check_trail("add/d.html", "n=add/e p=add/c"); +check_trail("add/e.html", "n= p=add/d"); + +check_trail("del/b.html", "n=del/d p="); +check_trail("del/d.html", "n= p=del/b"); ok(! -f "t/tmp/out/del/a.html"); ok(! -f "t/tmp/out/del/c.html"); ok(! -f "t/tmp/out/del/e.html"); -$blob = readfile("t/tmp/out/sorting/old.html"); -ok($blob =~ m{^trail=sorting n=sorting/new p=$}m); -$blob = readfile("t/tmp/out/sorting/new.html"); -ok($blob =~ m{^trail=sorting n=sorting/middle p=sorting/old$}m); -$blob = readfile("t/tmp/out/sorting/middle.html"); -ok($blob =~ m{^trail=sorting n=sorting/linked2 p=sorting/new$}m); -$blob = readfile("t/tmp/out/sorting/linked2.html"); -ok($blob =~ m{^trail=sorting n=sorting/linked p=sorting/middle$}m); -$blob = readfile("t/tmp/out/sorting/linked.html"); -ok($blob =~ m{^trail=sorting n=sorting/end p=sorting/linked2$}m); -$blob = readfile("t/tmp/out/sorting/end.html"); -ok($blob =~ m{^trail=sorting n=sorting/a/c p=sorting/linked$}m); -$blob = readfile("t/tmp/out/sorting/a/c.html"); -ok($blob =~ m{^trail=sorting n=sorting/beginning p=sorting/end$}m); -$blob = readfile("t/tmp/out/sorting/beginning.html"); -ok($blob =~ m{^trail=sorting n=sorting/a/b p=sorting/a/c$}m); -$blob = readfile("t/tmp/out/sorting/a/b.html"); -ok($blob =~ m{^trail=sorting n=sorting/ancient p=sorting/beginning$}m); -$blob = readfile("t/tmp/out/sorting/ancient.html"); -ok($blob =~ m{^trail=sorting n=sorting/z/a p=sorting/a/b$}m); -$blob = readfile("t/tmp/out/sorting/z/a.html"); -ok($blob =~ m{^trail=sorting n= p=sorting/ancient$}m); +check_trail("sorting/old.html", "n=sorting/new p="); +check_trail("sorting/new.html", "n=sorting/middle p=sorting/old"); +check_trail("sorting/middle.html", "n=sorting/linked2 p=sorting/new"); +check_trail("sorting/linked2.html", "n=sorting/linked p=sorting/middle"); +check_trail("sorting/linked.html", "n=sorting/end p=sorting/linked2"); +check_trail("sorting/end.html", "n=sorting/a/c p=sorting/linked"); +check_trail("sorting/a/c.html", "n=sorting/beginning p=sorting/end"); +check_trail("sorting/beginning.html", "n=sorting/a/b p=sorting/a/c"); +check_trail("sorting/a/b.html", "n=sorting/ancient p=sorting/beginning"); +check_trail("sorting/ancient.html", "n=sorting/z/a p=sorting/a/b"); +check_trail("sorting/z/a.html", "n= p=sorting/ancient"); + +# If the inline has a limited number of pages, the trail still depends on +# everything, so it gets rebuilt even though it doesn't strictly need it. +# This means we could use it as a way to recompute the order of members +# and the contents of their trail navbars, allowing us to fix the regression +# described in [[bugs/trail excess dependencies]] without a full content +# dependency. +$blob = readfile("t/tmp/out/limited.html"); +ok($blob =~ /a<\/a>/m); +ok($blob =~ /b<\/a>/m); +ok($blob !~ //m); +ok($blob !~ //m); +check_trail("limited/a.html", "n=limited/b p="); +check_trail("limited/b.html", "n=limited/c p=limited/a"); +check_trail("limited/c.html", "n=limited/d p=limited/b"); +check_trail("limited/d.html", "n= p=limited/c"); +# Also, b and d should pick up the change to c. This regressed with the +# change to using a presence dependency. +$blob = readfile("t/tmp/out/limited/b.html"); +ok($blob =~ /New C page >/m); +$blob = readfile("t/tmp/out/limited/d.html"); +ok($blob =~ /< New C page/m); + +# Members of a retitled trail should pick up that change. +# This regressed with the change to using a presence dependency. +$blob = readfile("t/tmp/out/retitled/a.html"); +ok($blob =~ /\^ the new title \^/m); + +# untrail is no longer a trail, so these are no longer in it. +check_no_trail("untrail/a.html"); +check_no_trail("untrail/b.html"); ok(! system("rm -rf t/tmp"));