summaryrefslogtreecommitdiff
path: root/t/bazaar.t
blob: 2ca44a65e084ce1395855ae177f4fa8632ba3e5c (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 || ! mkdir($dir)) {
  10. eval q{
  11. use Test::More skip_all => "bzr not available or could not make test dir"
  12. }
  13. }
  14. }
  15. use Test::More tests => 16;
  16. BEGIN { use_ok("IkiWiki"); }
  17. %config=IkiWiki::defaultconfig();
  18. $config{rcs} = "bzr";
  19. $config{srcdir} = "$dir/repo";
  20. IkiWiki::loadplugins();
  21. IkiWiki::checkconfig();
  22. system "bzr init $config{srcdir}";
  23. # Web commit
  24. my $test1 = readfile("t/test1.mdwn");
  25. writefile('test1.mdwn', $config{srcdir}, $test1);
  26. IkiWiki::rcs_add("test1.mdwn");
  27. IkiWiki::rcs_commit("test1.mdwn", "Added the first page", "moo", "Joe User");
  28. my @changes;
  29. @changes = IkiWiki::rcs_recentchanges(3);
  30. is($#changes, 0);
  31. is($changes[0]{message}[0]{"line"}, "Added the first page");
  32. is($changes[0]{pages}[0]{"page"}, "test1");
  33. is($changes[0]{user}, "Joe User");
  34. # Manual commit
  35. my $username = "Foo Bar";
  36. my $user = "$username <foo.bar\@example.com>";
  37. my $message = "Added the second page";
  38. my $test2 = readfile("t/test2.mdwn");
  39. writefile('test2.mdwn', $config{srcdir}, $test2);
  40. system "bzr add --quiet $config{srcdir}/test2.mdwn";
  41. system "bzr commit --quiet --author \"$user\" -m \"$message\" $config{srcdir}";
  42. @changes = IkiWiki::rcs_recentchanges(3);
  43. is($#changes, 1);
  44. is($changes[0]{message}[0]{"line"}, $message);
  45. is($changes[0]{user}, $username);
  46. is($changes[0]{pages}[0]{"page"}, "test2");
  47. is($changes[1]{pages}[0]{"page"}, "test1");
  48. my $ctime = IkiWiki::rcs_getctime("test2.mdwn");
  49. ok($ctime >= time() - 20);
  50. writefile('test3.mdwn', $config{srcdir}, $test1);
  51. IkiWiki::rcs_add("test3.mdwn");
  52. IkiWiki::rcs_rename("test3.mdwn", "test4.mdwn");
  53. IkiWiki::rcs_commit_staged("Added the 4th page", "moo", "Joe User");
  54. @changes = IkiWiki::rcs_recentchanges(4);
  55. is($#changes, 2);
  56. is($changes[0]{pages}[0]{"page"}, "test4");
  57. ok(mkdir($config{srcdir}."/newdir"));
  58. IkiWiki::rcs_rename("test4.mdwn", "newdir/test5.mdwn");
  59. IkiWiki::rcs_commit_staged("Added the 5th page", "moo", "Joe User");
  60. @changes = IkiWiki::rcs_recentchanges(4);
  61. is($#changes, 3);
  62. is($changes[0]{pages}[0]{"page"}, "newdir/test5");
  63. IkiWiki::rcs_remove("newdir/test5.mdwn");
  64. IkiWiki::rcs_commit_staged("Remove the 5th page", "moo", "Joe User");
  65. system "rm -rf $dir";