summaryrefslogtreecommitdiff
path: root/t/mercurial.t
blob: 4918fc76e9a0bb37adecc18ecbf47cc1eba1a795 (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) {
  10. eval q{
  11. use Test::More skip_all => "hg not available"
  12. }
  13. }
  14. if (! mkdir($dir)) {
  15. die $@;
  16. }
  17. }
  18. use Test::More tests => 11;
  19. BEGIN { use_ok("IkiWiki"); }
  20. %config=IkiWiki::defaultconfig();
  21. $config{rcs} = "mercurial";
  22. $config{srcdir} = "$dir/repo";
  23. IkiWiki::loadplugins();
  24. IkiWiki::checkconfig();
  25. use CGI::Session;
  26. my $session=CGI::Session->new;
  27. $session->param("name", "Joe User");
  28. system "hg init $config{srcdir}";
  29. # Web commit
  30. my $test1 = readfile("t/test1.mdwn");
  31. writefile('test1.mdwn', $config{srcdir}, $test1);
  32. IkiWiki::rcs_add("test1.mdwn");
  33. IkiWiki::rcs_commit(
  34. file => "test1.mdwn",
  35. message => "Added the first page",
  36. token => "moo",
  37. session => $session,
  38. );
  39. my @changes;
  40. @changes = IkiWiki::rcs_recentchanges(3);
  41. is($#changes, 0);
  42. is($changes[0]{message}[0]{"line"}, "Added the first page");
  43. is($changes[0]{pages}[0]{"page"}, "test1");
  44. is($changes[0]{user}, "Joe User");
  45. # Manual commit
  46. my $username = "Foo Bar";
  47. my $user = "$username <foo.bar\@example.com>";
  48. my $message = "Added the second page";
  49. my $test2 = readfile("t/test2.mdwn");
  50. writefile('test2.mdwn', $config{srcdir}, $test2);
  51. system "hg add -R $config{srcdir} $config{srcdir}/test2.mdwn";
  52. system "hg commit -R $config{srcdir} -u \"$user\" -m \"$message\" -d \"0 0\"";
  53. @changes = IkiWiki::rcs_recentchanges(3);
  54. is($#changes, 1);
  55. is($changes[0]{message}[0]{"line"}, $message);
  56. is($changes[0]{user}, $username);
  57. is($changes[0]{pages}[0]{"page"}, "test2");
  58. is($changes[1]{pages}[0]{"page"}, "test1");
  59. my $ctime = IkiWiki::rcs_getctime("test2.mdwn");
  60. is($ctime, 0);
  61. system "rm -rf $dir";