response
[ikiwiki.git] / t / mercurial.t
blob4918fc76e9a0bb37adecc18ecbf47cc1eba1a795
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"
14 if (! mkdir($dir)) {
15 die $@;
18 use Test::More tests => 11;
20 BEGIN { use_ok("IkiWiki"); }
22 %config=IkiWiki::defaultconfig();
23 $config{rcs} = "mercurial";
24 $config{srcdir} = "$dir/repo";
25 IkiWiki::loadplugins();
26 IkiWiki::checkconfig();
28 use CGI::Session;
29 my $session=CGI::Session->new;
30 $session->param("name", "Joe User");
32 system "hg init $config{srcdir}";
34 # Web commit
35 my $test1 = readfile("t/test1.mdwn");
36 writefile('test1.mdwn', $config{srcdir}, $test1);
37 IkiWiki::rcs_add("test1.mdwn");
38 IkiWiki::rcs_commit(
39 file => "test1.mdwn",
40 message => "Added the first page",
41 token => "moo",
42 session => $session,
45 my @changes;
46 @changes = IkiWiki::rcs_recentchanges(3);
48 is($#changes, 0);
49 is($changes[0]{message}[0]{"line"}, "Added the first page");
50 is($changes[0]{pages}[0]{"page"}, "test1");
51 is($changes[0]{user}, "Joe User");
53 # Manual commit
54 my $username = "Foo Bar";
55 my $user = "$username <foo.bar\@example.com>";
56 my $message = "Added the second page";
58 my $test2 = readfile("t/test2.mdwn");
59 writefile('test2.mdwn', $config{srcdir}, $test2);
60 system "hg add -R $config{srcdir} $config{srcdir}/test2.mdwn";
61 system "hg commit -R $config{srcdir} -u \"$user\" -m \"$message\" -d \"0 0\"";
63 @changes = IkiWiki::rcs_recentchanges(3);
65 is($#changes, 1);
66 is($changes[0]{message}[0]{"line"}, $message);
67 is($changes[0]{user}, $username);
68 is($changes[0]{pages}[0]{"page"}, "test2");
70 is($changes[1]{pages}[0]{"page"}, "test1");
72 my $ctime = IkiWiki::rcs_getctime("test2.mdwn");
73 is($ctime, 0);
75 system "rm -rf $dir";