summaryrefslogtreecommitdiff
path: root/t/mercurial.t
blob: 7d6c2eacc3a1daf378ec3b31225629ebb5617c21 (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. my $dir;
  5. BEGIN {
  6. $dir = "/tmp/ikiwiki-test-hg.$$";
  7. my $hg=`which hg`;
  8. chomp $hg;
  9. if (! -x $hg || ! mkdir($dir)) {
  10. eval q{
  11. use Test::More skip_all => "hg 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} = "mercurial";
  19. $config{srcdir} = "$dir/repo";
  20. IkiWiki::checkconfig();
  21. system "hg 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 "hg add -R $config{srcdir} $config{srcdir}/test2.mdwn";
  40. system "hg commit -R $config{srcdir} -u \"$user\" -m \"$message\" -d \"0 0\"";
  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. TODO: {
  48. local $TODO = "hg behavior change seems to have broken this";
  49. my $ctime = IkiWiki::rcs_getctime("test2.mdwn");
  50. is($ctime, 0);
  51. }
  52. system "rm -rf $dir";