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