summaryrefslogtreecommitdiff
path: root/t/bazaar.t
blob: f064814fe15cbdf5d6ee9a41a5f22df766ab8ab8 (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 => 11;
  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 $config{srcdir}/test2.mdwn";
  40. system "bzr commit --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. system "rm -rf $dir";