]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - t/trail.t
Merge branch 'master' of ssh://git.ikiwiki.info
[git.ikiwiki.info.git] / t / trail.t
index 0cf50ddc1cdb8aead5d655da59a4e70b077c9894..2e4b9278d1a324875684324b114b324431c55df7 100755 (executable)
--- a/t/trail.t
+++ b/t/trail.t
@@ -4,14 +4,42 @@ use strict;
 use Test::More 'no_plan';
 use IkiWiki;
 
 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;
+       my $blob=readfile("t/tmp/out/$file");
+       my ($trailline)=$blob=~/^trail=$trailname\s+(.*)$/m;
+       $trailline="" unless defined $trailline;
+       ok($trailline !~ /^trail=$trailname\s+/, "no $trailname in $file");
+}
+
 my $blob;
 
 ok(! system("rm -rf t/tmp"));
 ok(! system("mkdir t/tmp"));
 
 my $blob;
 
 ok(! system("rm -rf t/tmp"));
 ok(! system("mkdir t/tmp"));
 
+# Write files with a date in the past, so that when we refresh,
+# the update is detected.
+sub write_old_file {
+       my $name = shift;
+       my $content = shift;
+
+       writefile($name, "t/tmp/in", $content);
+       ok(utime(333333333, 333333333, "t/tmp/in/$name"));
+}
+
 # Use a rather stylized template to override the default rendering, to make
 # it easy to search for the desired results
 # Use a rather stylized template to override the default rendering, to make
 # it easy to search for the desired results
-writefile("templates/trails.tmpl", "t/tmp/in", <<EOF
+write_old_file("templates/trails.tmpl", <<EOF
 <TMPL_LOOP TRAILLOOP>
 <TMPL_IF __FIRST__><nav></TMPL_IF>
 <div>
 <TMPL_LOOP TRAILLOOP>
 <TMPL_IF __FIRST__><nav></TMPL_IF>
 <div>
@@ -30,46 +58,46 @@ trail=<TMPL_VAR TRAILPAGE> n=<TMPL_VAR NEXTPAGE> p=<TMPL_VAR PREVPAGE>
 </TMPL_LOOP>
 EOF
 );
 </TMPL_LOOP>
 EOF
 );
-writefile("badger.mdwn", "t/tmp/in", "[[!meta title=\"The Breezy Badger\"]]\ncontent of badger");
-writefile("mushroom.mdwn", "t/tmp/in", "content of mushroom");
-writefile("snake.mdwn", "t/tmp/in", "content of snake");
-writefile("ratty.mdwn", "t/tmp/in", "content of ratty");
-writefile("mr_toad.mdwn", "t/tmp/in", "content of mr toad");
-writefile("add.mdwn", "t/tmp/in", '[[!trailitems pagenames="add/a add/b add/c add/d add/e"]]');
-writefile("add/b.mdwn", "t/tmp/in", "b");
-writefile("add/d.mdwn", "t/tmp/in", "d");
-writefile("del.mdwn", "t/tmp/in", '[[!trailitems pages="del/*" sort=title]]');
-writefile("del/a.mdwn", "t/tmp/in", "a");
-writefile("del/b.mdwn", "t/tmp/in", "b");
-writefile("del/c.mdwn", "t/tmp/in", "c");
-writefile("del/d.mdwn", "t/tmp/in", "d");
-writefile("del/e.mdwn", "t/tmp/in", "e");
-writefile("self_referential.mdwn", "t/tmp/in", '[[!trailitems pagenames="self_referential" circular=yes]]');
-writefile("sorting/linked.mdwn", "t/tmp/in", "linked");
-writefile("sorting/a/b.mdwn", "t/tmp/in", "a/b");
-writefile("sorting/a/c.mdwn", "t/tmp/in", "a/c");
-writefile("sorting/z/a.mdwn", "t/tmp/in", "z/a");
-writefile("sorting/beginning.mdwn", "t/tmp/in", "beginning");
-writefile("sorting/middle.mdwn", "t/tmp/in", "middle");
-writefile("sorting/end.mdwn", "t/tmp/in", "end");
-writefile("sorting/new.mdwn", "t/tmp/in", "new");
-writefile("sorting/old.mdwn", "t/tmp/in", "old");
-writefile("sorting/ancient.mdwn", "t/tmp/in", "ancient");
+write_old_file("badger.mdwn", "[[!meta title=\"The Breezy Badger\"]]\ncontent of badger");
+write_old_file("mushroom.mdwn", "content of mushroom");
+write_old_file("snake.mdwn", "content of snake");
+write_old_file("ratty.mdwn", "content of ratty");
+write_old_file("mr_toad.mdwn", "content of mr toad");
+write_old_file("add.mdwn", '[[!trailitems pagenames="add/a add/b add/c add/d add/e"]]');
+write_old_file("add/b.mdwn", "b");
+write_old_file("add/d.mdwn", "d");
+write_old_file("del.mdwn", '[[!trailitems pages="del/*" sort=title]]');
+write_old_file("del/a.mdwn", "a");
+write_old_file("del/b.mdwn", "b");
+write_old_file("del/c.mdwn", "c");
+write_old_file("del/d.mdwn", "d");
+write_old_file("del/e.mdwn", "e");
+write_old_file("self_referential.mdwn", '[[!trailitems pagenames="self_referential" circular=yes]]');
+write_old_file("sorting/linked.mdwn", "linked");
+write_old_file("sorting/a/b.mdwn", "a/b");
+write_old_file("sorting/a/c.mdwn", "a/c");
+write_old_file("sorting/z/a.mdwn", "z/a");
+write_old_file("sorting/beginning.mdwn", "beginning");
+write_old_file("sorting/middle.mdwn", "middle");
+write_old_file("sorting/end.mdwn", "end");
+write_old_file("sorting/new.mdwn", "new");
+write_old_file("sorting/old.mdwn", "old");
+write_old_file("sorting/ancient.mdwn", "ancient");
 # These three need to be in the appropriate age order
 ok(utime(333333333, 333333333, "t/tmp/in/sorting/new.mdwn"));
 ok(utime(222222222, 222222222, "t/tmp/in/sorting/old.mdwn"));
 ok(utime(111111111, 111111111, "t/tmp/in/sorting/ancient.mdwn"));
 # These three need to be in the appropriate age order
 ok(utime(333333333, 333333333, "t/tmp/in/sorting/new.mdwn"));
 ok(utime(222222222, 222222222, "t/tmp/in/sorting/old.mdwn"));
 ok(utime(111111111, 111111111, "t/tmp/in/sorting/ancient.mdwn"));
-writefile("sorting/linked2.mdwn", "t/tmp/in", "linked2");
-# This initially uses the default sort order: age for trailinline, and path
-# for trail. We change it later.
-writefile("sorting.mdwn", "t/tmp/in",
+write_old_file("sorting/linked2.mdwn", "linked2");
+# This initially uses the default sort order: age for the inline, and path
+# for trailitems. We change it later.
+write_old_file("sorting.mdwn",
        '[[!traillink linked]] ' .
        '[[!trailitems pages="sorting/z/a or sorting/a/b or sorting/a/c"]] ' .
        '[[!traillink linked]] ' .
        '[[!trailitems pages="sorting/z/a or sorting/a/b or sorting/a/c"]] ' .
-       '[[!trailitems pagenames="beginning middle end"]] ' .
-       '[[!trailinline pages="sorting/old or sorting/ancient or sorting/new"]] ' .
+       '[[!trailitems pagenames="sorting/beginning sorting/middle sorting/end"]] ' .
+       '[[!inline pages="sorting/old or sorting/ancient or sorting/new" trail="yes"]] ' .
        '[[!traillink linked2]]');
 
        '[[!traillink linked2]]');
 
-writefile("meme.mdwn", "t/tmp/in", <<EOF
+write_old_file("meme.mdwn", <<EOF
 [[!trail]]
 * [[!traillink badger]]
 * [[!traillink badger text="This is a link to badger, with a title"]]
 [[!trail]]
 * [[!traillink badger]]
 * [[!traillink badger text="This is a link to badger, with a title"]]
@@ -82,7 +110,7 @@ writefile("meme.mdwn", "t/tmp/in", <<EOF
 EOF
 );
 
 EOF
 );
 
-writefile("wind_in_the_willows.mdwn", "t/tmp/in", <<EOF
+write_old_file("wind_in_the_willows.mdwn", <<EOF
 [[!trailoptions circular=yes sort=title]]
 [[!trailitems pages="ratty or badger or mr_toad"]]
 [[!trailitem moley]]
 [[!trailoptions circular=yes sort=title]]
 [[!trailitems pages="ratty or badger or mr_toad"]]
 [[!trailitem moley]]
@@ -102,78 +130,56 @@ ok($blob =~ /<a href="(\.\/)?badger.html">badger<\/a>/m);
 ok($blob =~ /<a href="(\.\/)?badger.html">This is a link to badger, with a title<\/a>/m);
 ok($blob =~ /<a href="(\.\/)?badger.html">That is the badger<\/a>/m);
 
 ok($blob =~ /<a href="(\.\/)?badger.html">This is a link to badger, with a title<\/a>/m);
 ok($blob =~ /<a href="(\.\/)?badger.html">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");
 
 
 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
 # meta title is respected for pages that have one
+$blob = readfile("t/tmp/out/mr_toad.html");
 ok($blob =~ /">&lt; The Breezy Badger<\/a>/m);
 # pagetitle for pages that don't
 ok($blob =~ /">ratty &gt;<\/a>/m);
 
 ok($blob =~ /">&lt; The Breezy Badger<\/a>/m);
 # pagetitle for pages that don't
 ok($blob =~ /">ratty &gt;<\/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");
 
 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);
-
-# Make some changes and refresh
+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");
+
+# Make some changes and refresh. These writefile calls don't set an
+# old mtime, so they're strictly newer than the "old" files.
 
 writefile("add/a.mdwn", "t/tmp/in", "a");
 writefile("add/c.mdwn", "t/tmp/in", "c");
 
 writefile("add/a.mdwn", "t/tmp/in", "a");
 writefile("add/c.mdwn", "t/tmp/in", "c");
@@ -188,46 +194,28 @@ writefile("sorting.mdwn", "t/tmp/in",
 
 ok(! system("$command -refresh"));
 
 
 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");
 
 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");
 
 ok(! system("rm -rf t/tmp"));
 
 ok(! system("rm -rf t/tmp"));