summaryrefslogtreecommitdiff
path: root/t/mercurial.t
blob: b64ea8e563a0a0f6a683fa095374712c194a2c38 (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. use CGI::Session;
  23. my $session=CGI::Session->new;
  24. $session->param("name", "Joe User");
  25. system "hg init $config{srcdir}";
  26. # Web commit
  27. my $test1 = readfile("t/test1.mdwn");
  28. writefile('test1.mdwn', $config{srcdir}, $test1);
  29. IkiWiki::rcs_add("test1.mdwn");
  30. IkiWiki::rcs_commit(
  31. file => "test1.mdwn",
  32. message => "Added the first page",
  33. token => "moo",
  34. session => $session,
  35. );
  36. my @changes;
  37. @changes = IkiWiki::rcs_recentchanges(3);
  38. is($#changes, 0);
  39. is($changes[0]{message}[0]{"line"}, "Added the first page");
  40. is($changes[0]{pages}[0]{"page"}, "test1");
  41. is($changes[0]{user}, "Joe User");
  42. # Manual commit
  43. my $username = "Foo Bar";
  44. my $user = "$username <foo.bar\@example.com>";
  45. my $message = "Added the second page";
  46. my $test2 = readfile("t/test2.mdwn");
  47. writefile('test2.mdwn', $config{srcdir}, $test2);
  48. system "hg add -R $config{srcdir} $config{srcdir}/test2.mdwn";
  49. system "hg commit -R $config{srcdir} -u \"$user\" -m \"$message\" -d \"0 0\"";
  50. @changes = IkiWiki::rcs_recentchanges(3);
  51. is($#changes, 1);
  52. is($changes[0]{message}[0]{"line"}, $message);
  53. is($changes[0]{user}, $username);
  54. is($changes[0]{pages}[0]{"page"}, "test2");
  55. is($changes[1]{pages}[0]{"page"}, "test1");
  56. my $ctime = IkiWiki::rcs_getctime("test2.mdwn");
  57. is($ctime, 0);
  58. system "rm -rf $dir";