summaryrefslogtreecommitdiff
path: root/t/bazaar.t
blob: 0bdd883d51e754d587d4a92e37d34c67b97621bf (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 => 17;
  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. my $mtime = IkiWiki::rcs_getmtime("test2.mdwn");
  51. ok($mtime >= time() - 20);
  52. writefile('test3.mdwn', $config{srcdir}, $test1);
  53. IkiWiki::rcs_add("test3.mdwn");
  54. IkiWiki::rcs_rename("test3.mdwn", "test4.mdwn");
  55. IkiWiki::rcs_commit_staged("Added the 4th page", "moo", "Joe User");
  56. @changes = IkiWiki::rcs_recentchanges(4);
  57. is($#changes, 2);
  58. is($changes[0]{pages}[0]{"page"}, "test4");
  59. ok(mkdir($config{srcdir}."/newdir"));
  60. IkiWiki::rcs_rename("test4.mdwn", "newdir/test5.mdwn");
  61. IkiWiki::rcs_commit_staged("Added the 5th page", "moo", "Joe User");
  62. @changes = IkiWiki::rcs_recentchanges(4);
  63. is($#changes, 3);
  64. is($changes[0]{pages}[0]{"page"}, "newdir/test5");
  65. IkiWiki::rcs_remove("newdir/test5.mdwn");
  66. IkiWiki::rcs_commit_staged("Remove the 5th page", "moo", "Joe User");
  67. system "rm -rf $dir";