aboutsummaryrefslogtreecommitdiff
path: root/t/conflicts.t
blob: 07c392cd3a70ae59992f422124814cd21fdd5b32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/perl
# Tests for bugs relating to conflicting files in the srcdir
use warnings;
use strict;
use Test::More tests => 106;

my $installed = $ENV{INSTALLED_TESTS};

my @command;
if ($installed) {
	ok(1, "running installed");
	@command = qw(ikiwiki);
}
else {
	ok(! system("make -s ikiwiki.out"));
	@command = qw(perl -I. ./ikiwiki.out
		--underlaydir=underlays/basewiki
		--set underlaydirbase=underlays
		--templatedir=templates);
}

# setup
my $srcdir="t/tmp/src";
my $destdir="t/tmp/dest";

# runs ikiwiki to build test site
sub runiki {
	my $testdesc=shift;
	ok((! system(@command, qw(--plugin txt --plugin rawhtml),
				$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");

# 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");

# 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"));
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");
# 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"));
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"));
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"));