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