From 41423084295f4b694cdb0ec208ea0a1807dc8a62 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 17 Jul 2010 13:24:40 -0400 Subject: turning into complete source file conflict test suite --- t/conflicts.t | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 t/conflicts.t (limited to 't/conflicts.t') diff --git a/t/conflicts.t b/t/conflicts.t new file mode 100755 index 000000000..7748c105f --- /dev/null +++ b/t/conflicts.t @@ -0,0 +1,81 @@ +#!/usr/bin/perl +# Tests for bugs relating to conflicting files in the srcdir +use warnings; +use strict; +use Test::More 'no_plan'; + +# setup +my $srcdir="t/tmp/src"; +my $destdir="t/tmp/dest"; +ok(! system("make -s ikiwiki.out")); + +# runs ikiwiki to build test site +sub runiki { + my $testdesc=shift; + ok((! system("perl -I. ./ikiwiki.out -plugin txt -plugin rawhtml -underlaydir=underlays/basewiki -set underlaydirbase=underlays -templatedir=templates $srcdir $destdir @_")), + $testdesc); +} +sub refreshiki { + runiki(shift); +} +sub setupiki { + ok(! system("rm -rf $srcdir/.ikiwiki $destdir")); + runiki(shift, "--rebuild"); +} +sub newsrcdir { + ok(! system("rm -rf $srcdir $destdir")); + ok(! system("mkdir -p $srcdir")); +} + +# At one point, changing the extension of the source file of a page caused +# ikiwiki to fail. +newsrcdir(); +ok(! system("touch $srcdir/foo.mdwn")); +setupiki("initial setup"); +ok(! system("mv $srcdir/foo.mdwn $srcdir/foo.txt")); +refreshiki("changed extension of source file of page"); +ok(! system("mv $srcdir/foo.txt $srcdir/foo.mdwn")); +refreshiki("changed extension of source file of page 2"); + +# Conflicting page sources is sorta undefined behavior, +# but should not crash ikiwiki. +# Added when refreshing +ok(! system("touch $srcdir/foo.txt")); +refreshiki("conflicting page sources in refresh"); +# Present during setup +newsrcdir(); +ok(! system("touch $srcdir/foo.mdwn")); +ok(! system("touch $srcdir/foo.txt")); +setupiki("conflicting page sources in setup"); + +# Changing a page file into a non-page could also cause ikiwiki to fail. +newsrcdir(); +ok(! system("touch $srcdir/foo.mdwn")); +setupiki("initial setup"); +ok(! system("mv $srcdir/foo.mdwn $srcdir/foo")); +refreshiki("page file turned into non-page"); + +# Changing a non-page file into a page could also cause ikiwiki to fail. +newsrcdir(); +ok(! system("touch $srcdir/foo")); +setupiki("initial setup"); +ok(! system("mv $srcdir/foo $srcdir/foo.mdwn")); +refreshiki("non-page file turned into page"); + +# What if a page renders to the same html file that a rawhtml file provides? +# Added when refreshing +newsrcdir(); +ok(! system("touch $srcdir/foo.mdwn")); +setupiki("initial setup"); +ok(! system("mkdir -p $srcdir/foo")); +ok(! system("touch $srcdir/foo/index.html")); +refreshiki("rawhtml file rendered same as existing page in refresh"); +# Present during setup +newsrcdir(); +ok(! system("touch $srcdir/foo.mdwn")); +ok(! system("mkdir -p $srcdir/foo")); +ok(! system("touch $srcdir/foo/index.html")); +setupiki("rawhtml file rendered same as existing page in setup"); + +# cleanup +ok(! system("rm -rf t/tmp")); -- cgit v1.2.3 From bfa4660df78aaae5f7c2b41caeccf6732ed4d74e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 17 Jul 2010 13:30:08 -0400 Subject: update --- t/conflicts.t | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 't/conflicts.t') diff --git a/t/conflicts.t b/t/conflicts.t index 7748c105f..ac5f93b03 100755 --- a/t/conflicts.t +++ b/t/conflicts.t @@ -2,7 +2,7 @@ # Tests for bugs relating to conflicting files in the srcdir use warnings; use strict; -use Test::More 'no_plan'; +use Test::More tests => 48; # setup my $srcdir="t/tmp/src"; @@ -70,6 +70,13 @@ setupiki("initial setup"); ok(! system("mkdir -p $srcdir/foo")); ok(! system("touch $srcdir/foo/index.html")); refreshiki("rawhtml file rendered same as existing page in refresh"); +# Inverse added when refreshing +newsrcdir(); +ok(! system("mkdir -p $srcdir/foo")); +ok(! system("touch $srcdir/foo/index.html")); +setupiki("initial setup"); +ok(! system("touch $srcdir/foo.mdwn")); +refreshiki("page rendered same as existing rawhtml file in refresh"); # Present during setup newsrcdir(); ok(! system("touch $srcdir/foo.mdwn")); -- cgit v1.2.3 From a291f24be6af3f08573efa72f8809868120cfab4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 18 Jul 2010 13:50:06 -0400 Subject: some other (similar) failure cases --- t/conflicts.t | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 't/conflicts.t') diff --git a/t/conflicts.t b/t/conflicts.t index ac5f93b03..ac270e806 100755 --- a/t/conflicts.t +++ b/t/conflicts.t @@ -48,6 +48,22 @@ ok(! system("touch $srcdir/foo.mdwn")); ok(! system("touch $srcdir/foo.txt")); setupiki("conflicting page sources in setup"); +# Page and non-page file with same pagename. +newsrcdir(); +ok(! system("touch $srcdir/foo.mdwn")); +ok(! system("touch $srcdir/foo")); +setupiki("conflicting page and non-page in setup"); +newsrcdir(); +ok(! system("touch $srcdir/foo.mdwn")); +setupiki("initial setup"); +ok(! system("touch $srcdir/foo")); +refreshiki("conflicting page added (non-page already existing) in refresh"); +newsrcdir(); +ok(! system("touch $srcdir/foo")); +setupiki("initial setup"); +ok(! system("touch $srcdir/foo.mdwn")); +refreshiki("conflicting non-page added (page already existing) in refresh"); + # Changing a page file into a non-page could also cause ikiwiki to fail. newsrcdir(); ok(! system("touch $srcdir/foo.mdwn")); -- cgit v1.2.3 From 773db5a35e5b81fee3f1f8bf48dffc1dd4f3e2fe Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 18 Jul 2010 16:28:39 -0400 Subject: avoid error if two source files render the same destination file There are two sub-caces. If both source files still exist, the winner that renders the destination file is undefined. If one source file is deleted and the other added, in a refresh, the new file will take over the destination file. --- IkiWiki.pm | 14 +++++++++++++- t/conflicts.t | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 't/conflicts.t') diff --git a/IkiWiki.pm b/IkiWiki.pm index 701f7137d..4acc5508a 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -879,7 +879,19 @@ sub will_render ($$;$) { # Important security check. if (-e "$config{destdir}/$dest" && ! $config{rebuild} && ! grep { $_ eq $dest } (@{$renderedfiles{$page}}, @{$oldrenderedfiles{$page}}, @{$wikistate{editpage}{previews}})) { - error("$config{destdir}/$dest independently created, not overwriting with version from $page"); + my $from_other_page=0; + foreach my $p (keys %renderedfiles) { + if (grep { + $_ eq $dest || + dirname($_) eq $dest + } @{$renderedfiles{$p}}) { + $from_other_page=1; + last; + } + } + + error("$config{destdir}/$dest independently created, not overwriting with version from $page") + unless $from_other_page; } if (! $clear || $cleared{$page}) { diff --git a/t/conflicts.t b/t/conflicts.t index ac270e806..81b2c12cb 100755 --- a/t/conflicts.t +++ b/t/conflicts.t @@ -2,7 +2,7 @@ # Tests for bugs relating to conflicting files in the srcdir use warnings; use strict; -use Test::More tests => 48; +use Test::More tests => 76; # setup my $srcdir="t/tmp/src"; -- cgit v1.2.3 From d6cb4436bd93d0c49f629f46eb0f0ada0fa0ef3d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 18 Jul 2010 16:45:44 -0400 Subject: 2 more cases --- t/conflicts.t | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 't/conflicts.t') diff --git a/t/conflicts.t b/t/conflicts.t index 81b2c12cb..4664e1b6e 100755 --- a/t/conflicts.t +++ b/t/conflicts.t @@ -2,7 +2,7 @@ # Tests for bugs relating to conflicting files in the srcdir use warnings; use strict; -use Test::More tests => 76; +use Test::More tests => 92; # setup my $srcdir="t/tmp/src"; @@ -86,6 +86,13 @@ setupiki("initial setup"); ok(! system("mkdir -p $srcdir/foo")); ok(! system("touch $srcdir/foo/index.html")); refreshiki("rawhtml file rendered same as existing page in refresh"); +# Moved when refreshing +newsrcdir(); +ok(! system("touch $srcdir/foo.mdwn")); +setupiki("initial setup"); +ok(! system("mkdir -p $srcdir/foo")); +ok(! system("mv $srcdir/foo.mdwn $srcdir/foo/index.html")); +refreshiki("existing page moved to rawhtml file in refresh"); # Inverse added when refreshing newsrcdir(); ok(! system("mkdir -p $srcdir/foo")); @@ -93,6 +100,13 @@ ok(! system("touch $srcdir/foo/index.html")); setupiki("initial setup"); ok(! system("touch $srcdir/foo.mdwn")); refreshiki("page rendered same as existing rawhtml file in refresh"); +# Inverse moved when refreshing +newsrcdir(); +ok(! system("mkdir -p $srcdir/foo")); +ok(! system("touch $srcdir/foo/index.html")); +setupiki("initial setup"); +ok(! system("mv $srcdir/foo/index.html $srcdir/foo.mdwn")); +refreshiki("rawhtml file moved to page in refresh"); # Present during setup newsrcdir(); ok(! system("touch $srcdir/foo.mdwn")); -- cgit v1.2.3 From 1dbb2632ef5f7eaa1f5745d587b1373b45b09e56 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 18 Jul 2010 17:16:39 -0400 Subject: another class of conflicts: subdir/file conflicts --- t/conflicts.t | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 't/conflicts.t') diff --git a/t/conflicts.t b/t/conflicts.t index 4664e1b6e..d7e04d3ae 100755 --- a/t/conflicts.t +++ b/t/conflicts.t @@ -2,7 +2,7 @@ # Tests for bugs relating to conflicting files in the srcdir use warnings; use strict; -use Test::More tests => 92; +use Test::More tests => 106; # setup my $srcdir="t/tmp/src"; @@ -64,6 +64,19 @@ setupiki("initial setup"); ok(! system("touch $srcdir/foo.mdwn")); refreshiki("conflicting non-page added (page already existing) in refresh"); +# Page that renders to a file that is also a subdirectory holding another +# file. +newsrcdir(); +ok(! system("touch $srcdir/foo.mdwn")); +ok(! system("mkdir -p $srcdir/foo/index.html")); +ok(! system("touch $srcdir/foo/index.html/bar.mdwn")); +setupiki("conflicting page file and subdirectory"); +newsrcdir(); +ok(! system("touch $srcdir/foo.mdwn")); +ok(! system("mkdir -p $srcdir/foo/index.html")); +ok(! system("touch $srcdir/foo/index.html/bar")); +setupiki("conflicting page file and subdirectory 2"); + # Changing a page file into a non-page could also cause ikiwiki to fail. newsrcdir(); ok(! system("touch $srcdir/foo.mdwn")); -- cgit v1.2.3