web commit by http://alcopop.org/me/openid/
[ikiwiki.git] / t / svn.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 my $dir;
5 BEGIN {
6         $dir="/tmp/ikiwiki-test-svn.$$";
7         my $svn=`which svn`;
8         chomp $svn;
9         my $svnadmin=`which svnadmin`;
10         chomp $svnadmin;
11         if (! -x $svn || ! -x $svnadmin || ! mkdir($dir)) {
12                 eval q{
13                         use Test::More skip_all => "svn not available or could not make test dir"
14                 }
15         }
16 }
17 use Test::More tests => 12;
18
19 BEGIN { use_ok("IkiWiki"); }
20
21 %config=IkiWiki::defaultconfig();
22 $config{rcs} = "svn";
23 $config{srcdir} = "$dir/src";
24 $config{svnpath} = "trunk";
25 IkiWiki::checkconfig();
26
27 my $svnrepo = "$dir/repo";
28
29 system "svnadmin create $svnrepo >/dev/null";
30 system "svn mkdir file://$svnrepo/trunk -m add >/dev/null";
31 system "svn co file://$svnrepo/trunk $config{srcdir} >/dev/null";
32
33 # Web commit
34 my $test1 = readfile("t/test1.mdwn");
35 writefile('test1.mdwn', $config{srcdir}, $test1);
36 IkiWiki::rcs_add("test1.mdwn");
37 IkiWiki::rcs_commit("test1.mdwn", "Added the first page", "moo");
38
39 my @changes;
40 @changes = IkiWiki::rcs_recentchanges(3);
41
42 is($#changes, 0);
43 is($changes[0]{message}[0]{"line"}, "Added the first page");
44 is($changes[0]{pages}[0]{"page"}, "test1.mdwn");
45         
46 # Manual commit
47 my $message = "Added the second page";
48
49 my $test2 = readfile("t/test2.mdwn");
50 writefile('test2.mdwn', $config{srcdir}, $test2);
51 system "svn add $config{srcdir}/test2.mdwn >/dev/null";
52 system "svn commit $config{srcdir}/test2.mdwn -m \"$message\" >/dev/null";
53
54 @changes = IkiWiki::rcs_recentchanges(3);
55 is($#changes, 1);
56 is($changes[0]{message}[0]{"line"}, $message);
57 is($changes[0]{pages}[0]{"page"}, "test2.mdwn");
58 is($changes[1]{pages}[0]{"page"}, "test1.mdwn");
59
60 # extra slashes in the path shouldn't break things
61 $config{svnpath} = "/trunk//";
62 IkiWiki::checkconfig();
63 @changes = IkiWiki::rcs_recentchanges(3);
64 is($#changes, 1);
65 is($changes[0]{message}[0]{"line"}, $message);
66 is($changes[0]{pages}[0]{"page"}, "test2.mdwn");
67 is($changes[1]{pages}[0]{"page"}, "test1.mdwn");
68
69 system "rm -rf $dir";