summaryrefslogtreecommitdiff
path: root/t/bazaar.t
blob: 6e58f48f1c4e6183ea6a03d8c194317e5b2f2759 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. my $dir;
  5. BEGIN {
  6. $dir = "/tmp/ikiwiki-test-bzr.$$";
  7. my $bzr=`which bzr`;
  8. chomp $bzr;
  9. if (! -x $bzr) {
  10. eval q{
  11. use Test::More skip_all => "bzr not available"
  12. }
  13. }
  14. if (! mkdir($dir)) {
  15. die $@;
  16. }
  17. }
  18. use Test::More tests => 17;
  19. BEGIN { use_ok("IkiWiki"); }
  20. %config=IkiWiki::defaultconfig();
  21. $config{rcs} = "bzr";
  22. $config{srcdir} = "$dir/repo";
  23. IkiWiki::loadplugins();
  24. IkiWiki::checkconfig();
  25. # XXX
  26. # This is a workaround for bzr's new requirement that bzr whoami be run
  27. # before committing. This makes the test suite work with an unconfigured
  28. # bzr, but ignores the need to have a properly configured bzr before
  29. # using ikiwiki with bzr.
  30. $ENV{HOME}=$dir;
  31. system 'bzr whoami test@example.com';
  32. system "bzr init $config{srcdir}";
  33. use CGI::Session;
  34. my $session=CGI::Session->new;
  35. $session->param("name", "Joe User");
  36. # Web commit
  37. my $test1 = readfile("t/test1.mdwn");
  38. writefile('test1.mdwn', $config{srcdir}, $test1);
  39. IkiWiki::rcs_add("test1.mdwn");
  40. IkiWiki::rcs_commit(
  41. file => "test1.mdwn",
  42. message => "Added the first page",
  43. token => "moo",
  44. session => $session);
  45. my @changes;
  46. @changes = IkiWiki::rcs_recentchanges(3);
  47. is($#changes, 0);
  48. is($changes[0]{message}[0]{"line"}, "Added the first page");
  49. is($changes[0]{pages}[0]{"page"}, "test1");
  50. is($changes[0]{user}, "Joe User");
  51. # Manual commit
  52. my $username = "Foo Bar";
  53. my $user = "$username <foo.bar\@example.com>";
  54. my $message = "Added the second page";
  55. my $test2 = readfile("t/test2.mdwn");
  56. writefile('test2.mdwn', $config{srcdir}, $test2);
  57. system "bzr add --quiet $config{srcdir}/test2.mdwn";
  58. system "bzr commit --quiet --author \"$user\" -m \"$message\" $config{srcdir}";
  59. @changes = IkiWiki::rcs_recentchanges(3);
  60. is($#changes, 1);
  61. is($changes[0]{message}[0]{"line"}, $message);
  62. is($changes[0]{user}, $username);
  63. is($changes[0]{pages}[0]{"page"}, "test2");
  64. is($changes[1]{pages}[0]{"page"}, "test1");
  65. my $ctime = IkiWiki::rcs_getctime("test2.mdwn");
  66. ok($ctime >= time() - 20);
  67. my $mtime = IkiWiki::rcs_getmtime("test2.mdwn");
  68. ok($mtime >= time() - 20);
  69. writefile('test3.mdwn', $config{srcdir}, $test1);
  70. IkiWiki::rcs_add("test3.mdwn");
  71. IkiWiki::rcs_rename("test3.mdwn", "test4.mdwn");
  72. IkiWiki::rcs_commit_staged(
  73. message => "Added the 4th page",
  74. session => $session,
  75. );
  76. @changes = IkiWiki::rcs_recentchanges(4);
  77. is($#changes, 2);
  78. is($changes[0]{pages}[0]{"page"}, "test4");
  79. ok(mkdir($config{srcdir}."/newdir"));
  80. IkiWiki::rcs_rename("test4.mdwn", "newdir/test5.mdwn");
  81. IkiWiki::rcs_commit_staged(
  82. message => "Added the 5th page",
  83. session => $session,
  84. );
  85. @changes = IkiWiki::rcs_recentchanges(4);
  86. is($#changes, 3);
  87. is($changes[0]{pages}[0]{"page"}, "newdir/test5");
  88. IkiWiki::rcs_remove("newdir/test5.mdwn");
  89. IkiWiki::rcs_commit_staged(
  90. message => "Remove the 5th page",
  91. session => $session,
  92. );
  93. system "rm -rf $dir";