]> sipb.mit.edu Git - ikiwiki.git/blob - t/index.t
Add a regression test for autoindex_commit => 1
[ikiwiki.git] / t / index.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use IkiWiki;
5
6 package IkiWiki; # use internal variables
7 use Test::More tests => 31;
8
9 $config{wikistatedir}="/tmp/ikiwiki-test.$$";
10 system "rm -rf $config{wikistatedir}";
11
12 ok(! loadindex(), "loading nonexistent index file");
13
14 # Load standard plugins.
15 ok(loadplugin("meta"), "meta plugin loaded");
16 ok(loadplugin("mdwn"), "mdwn plugin loaded");
17
18 # Set up a default state.
19 $pagesources{"Foo"}="Foo.mdwn";
20 $pagesources{"bar"}="bar.mdwn";
21 $pagesources{"bar.png"}="bar.png";
22 my $now=time();
23 $pagemtime{"Foo"}=$now;
24 $pagemtime{"bar"}=$now-1000;
25 $pagemtime{"bar.png"}=$now;
26 $pagectime{"Foo"}=$now;
27 $pagectime{"bar"}=$now-100000;
28 $pagectime{"bar.png"}=$now-100000;
29 $renderedfiles{"Foo"}=["Foo.html"];
30 $renderedfiles{"bar"}=["bar.html", "bar.rss", "sparkline-foo.gif"];
31 $renderedfiles{"bar.png"}=["bar.png"];
32 $links{"Foo"}=["bar.png"];
33 $links{"bar"}=["Foo", "new-page"];
34 $typedlinks{"bar"}={tag => {"Foo" => 1}};
35 $links{"bar.png"}=[];
36 $depends{"Foo"}={};
37 $depends{"bar"}={"foo*" => 1};
38 $depends{"bar.png"}={};
39 $pagestate{"bar"}{meta}{title}="a page about bar";
40 $pagestate{"bar"}{meta}{moo}="mooooo";
41
42 ok(saveindex(), "save index");
43 ok(-s "$config{wikistatedir}/indexdb", "index file created");
44
45 # Clear state.
46 %oldrenderedfiles=%pagectime=();
47 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
48 %destsources=%renderedfiles=%pagecase=%pagestate=();
49
50 ok(loadindex(), "load index");
51 is_deeply(\%pagesources, {
52         Foo => "Foo.mdwn",
53         bar => "bar.mdwn",
54         "bar.png" => "bar.png",
55 }, "%pagesources loaded correctly");
56 is_deeply(\%pagemtime, {
57         Foo => $now,
58         bar => $now-1000,
59         "bar.png" => $now,
60 }, "%pagemtime loaded correctly");
61 is_deeply(\%pagectime, {
62         Foo => $now,
63         bar => $now-100000,
64         "bar.png" => $now-100000,
65 }, "%pagemtime loaded correctly");
66 is_deeply(\%renderedfiles, {
67         Foo => ["Foo.html"],
68         bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
69         "bar.png" => ["bar.png"],
70 }, "%renderedfiles loaded correctly");
71 is_deeply(\%oldrenderedfiles, {
72         Foo => ["Foo.html"],
73         bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
74         "bar.png" => ["bar.png"],
75 }, "%oldrenderedfiles loaded correctly");
76 is_deeply(\%links, {
77         Foo => ["bar.png"],
78         bar => ["Foo", "new-page"],
79         "bar.png" => [],
80 }, "%links loaded correctly");
81 is_deeply(\%depends, {
82         Foo => {},
83         bar => {"foo*" => 1},
84         "bar.png" => {},
85 }, "%depends loaded correctly");
86 is_deeply(\%pagestate, {
87         bar => {
88                 meta => {
89                         title => "a page about bar",
90                         moo => "mooooo",
91                 },
92         },
93 }, "%pagestate loaded correctly");
94 is_deeply(\%pagecase, {
95         foo => "Foo",
96         bar => "bar",
97         "bar.png" => "bar.png"
98 }, "%pagecase generated correctly");
99 is_deeply(\%destsources, {
100         "Foo.html" => "Foo",
101         "bar.html" => "bar",
102         "bar.rss" => "bar",
103         "sparkline-foo.gif" => "bar",
104         "bar.png" => "bar.png",
105 }, "%destsources generated correctly");
106 is_deeply(\%typedlinks, {
107         bar => {tag => {"Foo" => 1}},
108 }, "%typedlinks loaded correctly");
109 is_deeply(\%oldtypedlinks, {
110         bar => {tag => {"Foo" => 1}},
111 }, "%oldtypedlinks loaded correctly");
112
113 # Clear state.
114 %oldrenderedfiles=%pagectime=();
115 %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
116 %destsources=%renderedfiles=%pagecase=%pagestate=();
117
118 # When state is loaded for a wiki rebuild, only ctime, oldrenderedfiles,
119 # and pagesources are retained.
120 $config{rebuild}=1;
121 ok(loadindex(), "load index");
122 is_deeply(\%pagesources, {
123         Foo => "Foo.mdwn",
124         bar => "bar.mdwn",
125         "bar.png" => "bar.png",
126 }, "%pagesources loaded correctly");
127 is_deeply(\%pagemtime, {
128 }, "%pagemtime loaded correctly");
129 is_deeply(\%pagectime, {
130         Foo => $now,
131         bar => $now-100000,
132         "bar.png" => $now-100000,
133 }, "%pagemtime loaded correctly");
134 is_deeply(\%renderedfiles, {
135 }, "%renderedfiles loaded correctly");
136 is_deeply(\%oldrenderedfiles, {
137         Foo => ["Foo.html"],
138         bar => ["bar.html", "bar.rss", "sparkline-foo.gif"],
139         "bar.png" => ["bar.png"],
140 }, "%oldrenderedfiles loaded correctly");
141 is_deeply(\%links, {
142 }, "%links loaded correctly");
143 is_deeply(\%depends, {
144 }, "%depends loaded correctly");
145 is_deeply(\%pagestate, {
146 }, "%pagestate loaded correctly");
147 is_deeply(\%pagecase, { # generated implicitly since pagesources is loaded
148         foo => "Foo",
149         bar => "bar",
150         "bar.png" => "bar.png"
151 }, "%pagecase generated correctly");
152 is_deeply(\%destsources, {
153 }, "%destsources generated correctly");
154 is_deeply(\%typedlinks, {
155 }, "%typedlinks cleared correctly");
156 is_deeply(\%oldtypedlinks, {
157 }, "%oldtypedlinks cleared correctly");
158
159 system "rm -rf $config{wikistatedir}";