summaryrefslogtreecommitdiff
path: root/t/mercurial.t
blob: 954b17526bd31c987fa21a0c77fa64e98b4d3139 (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::loadplugins();
  21. IkiWiki::checkconfig();
  22. system "hg 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 "hg add -R $config{srcdir} $config{srcdir}/test2.mdwn";
  41. system "hg commit -R $config{srcdir} -u \"$user\" -m \"$message\" -d \"0 0\"";
  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. is($ctime, 0);
  50. system "rm -rf $dir";