Merge branch 'master' of ssh://git.ikiwiki.info/srv/git/ikiwiki.info
[ikiwiki.git] / t / conflicts.t
blobd7e04d3ae39a66b1bdcd711aa0aa0ee12f0584ec
1 #!/usr/bin/perl
2 # Tests for bugs relating to conflicting files in the srcdir
3 use warnings;
4 use strict;
5 use Test::More tests => 106;
7 # setup
8 my $srcdir="t/tmp/src";
9 my $destdir="t/tmp/dest";
10 ok(! system("make -s ikiwiki.out"));
12 # runs ikiwiki to build test site
13 sub runiki {
14 my $testdesc=shift;
15 ok((! system("perl -I. ./ikiwiki.out -plugin txt -plugin rawhtml -underlaydir=underlays/basewiki -set underlaydirbase=underlays -templatedir=templates $srcdir $destdir @_")),
16 $testdesc);
18 sub refreshiki {
19 runiki(shift);
21 sub setupiki {
22 ok(! system("rm -rf $srcdir/.ikiwiki $destdir"));
23 runiki(shift, "--rebuild");
25 sub newsrcdir {
26 ok(! system("rm -rf $srcdir $destdir"));
27 ok(! system("mkdir -p $srcdir"));
30 # At one point, changing the extension of the source file of a page caused
31 # ikiwiki to fail.
32 newsrcdir();
33 ok(! system("touch $srcdir/foo.mdwn"));
34 setupiki("initial setup");
35 ok(! system("mv $srcdir/foo.mdwn $srcdir/foo.txt"));
36 refreshiki("changed extension of source file of page");
37 ok(! system("mv $srcdir/foo.txt $srcdir/foo.mdwn"));
38 refreshiki("changed extension of source file of page 2");
40 # Conflicting page sources is sorta undefined behavior,
41 # but should not crash ikiwiki.
42 # Added when refreshing
43 ok(! system("touch $srcdir/foo.txt"));
44 refreshiki("conflicting page sources in refresh");
45 # Present during setup
46 newsrcdir();
47 ok(! system("touch $srcdir/foo.mdwn"));
48 ok(! system("touch $srcdir/foo.txt"));
49 setupiki("conflicting page sources in setup");
51 # Page and non-page file with same pagename.
52 newsrcdir();
53 ok(! system("touch $srcdir/foo.mdwn"));
54 ok(! system("touch $srcdir/foo"));
55 setupiki("conflicting page and non-page in setup");
56 newsrcdir();
57 ok(! system("touch $srcdir/foo.mdwn"));
58 setupiki("initial setup");
59 ok(! system("touch $srcdir/foo"));
60 refreshiki("conflicting page added (non-page already existing) in refresh");
61 newsrcdir();
62 ok(! system("touch $srcdir/foo"));
63 setupiki("initial setup");
64 ok(! system("touch $srcdir/foo.mdwn"));
65 refreshiki("conflicting non-page added (page already existing) in refresh");
67 # Page that renders to a file that is also a subdirectory holding another
68 # file.
69 newsrcdir();
70 ok(! system("touch $srcdir/foo.mdwn"));
71 ok(! system("mkdir -p $srcdir/foo/index.html"));
72 ok(! system("touch $srcdir/foo/index.html/bar.mdwn"));
73 setupiki("conflicting page file and subdirectory");
74 newsrcdir();
75 ok(! system("touch $srcdir/foo.mdwn"));
76 ok(! system("mkdir -p $srcdir/foo/index.html"));
77 ok(! system("touch $srcdir/foo/index.html/bar"));
78 setupiki("conflicting page file and subdirectory 2");
80 # Changing a page file into a non-page could also cause ikiwiki to fail.
81 newsrcdir();
82 ok(! system("touch $srcdir/foo.mdwn"));
83 setupiki("initial setup");
84 ok(! system("mv $srcdir/foo.mdwn $srcdir/foo"));
85 refreshiki("page file turned into non-page");
87 # Changing a non-page file into a page could also cause ikiwiki to fail.
88 newsrcdir();
89 ok(! system("touch $srcdir/foo"));
90 setupiki("initial setup");
91 ok(! system("mv $srcdir/foo $srcdir/foo.mdwn"));
92 refreshiki("non-page file turned into page");
94 # What if a page renders to the same html file that a rawhtml file provides?
95 # Added when refreshing
96 newsrcdir();
97 ok(! system("touch $srcdir/foo.mdwn"));
98 setupiki("initial setup");
99 ok(! system("mkdir -p $srcdir/foo"));
100 ok(! system("touch $srcdir/foo/index.html"));
101 refreshiki("rawhtml file rendered same as existing page in refresh");
102 # Moved when refreshing
103 newsrcdir();
104 ok(! system("touch $srcdir/foo.mdwn"));
105 setupiki("initial setup");
106 ok(! system("mkdir -p $srcdir/foo"));
107 ok(! system("mv $srcdir/foo.mdwn $srcdir/foo/index.html"));
108 refreshiki("existing page moved to rawhtml file in refresh");
109 # Inverse added when refreshing
110 newsrcdir();
111 ok(! system("mkdir -p $srcdir/foo"));
112 ok(! system("touch $srcdir/foo/index.html"));
113 setupiki("initial setup");
114 ok(! system("touch $srcdir/foo.mdwn"));
115 refreshiki("page rendered same as existing rawhtml file in refresh");
116 # Inverse moved when refreshing
117 newsrcdir();
118 ok(! system("mkdir -p $srcdir/foo"));
119 ok(! system("touch $srcdir/foo/index.html"));
120 setupiki("initial setup");
121 ok(! system("mv $srcdir/foo/index.html $srcdir/foo.mdwn"));
122 refreshiki("rawhtml file moved to page in refresh");
123 # Present during setup
124 newsrcdir();
125 ok(! system("touch $srcdir/foo.mdwn"));
126 ok(! system("mkdir -p $srcdir/foo"));
127 ok(! system("touch $srcdir/foo/index.html"));
128 setupiki("rawhtml file rendered same as existing page in setup");
130 # cleanup
131 ok(! system("rm -rf t/tmp"));