thoughts
[ikiwiki.git] / t / svn.t
blobcce8452a66107dfb89c301200c22035087bf77de
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) {
12 eval q{
13 use Test::More skip_all => "svn or svnadmin not available"
16 if (! mkdir($dir)) {
17 die $@;
20 use Test::More tests => 12;
22 BEGIN { use_ok("IkiWiki"); }
24 %config=IkiWiki::defaultconfig();
25 $config{rcs} = "svn";
26 $config{srcdir} = "$dir/src";
27 $config{svnrepo} = "$dir/repo";
28 $config{svnpath} = "trunk";
29 IkiWiki::loadplugins();
30 IkiWiki::checkconfig();
32 my $svnrepo = "$dir/repo";
34 system "svnadmin create $svnrepo >/dev/null";
35 system "svn mkdir file://$svnrepo/trunk -m add >/dev/null";
36 system "svn co file://$svnrepo/trunk $config{srcdir} >/dev/null";
38 # Web commit
39 my $test1 = readfile("t/test1.mdwn");
40 writefile('test1.mdwn', $config{srcdir}, $test1);
41 IkiWiki::rcs_add("test1.mdwn");
42 IkiWiki::rcs_commit(
43 file => "test1.mdwn",
44 message => "Added the first page",
45 token => "moo",
48 my @changes;
49 @changes = IkiWiki::rcs_recentchanges(3);
51 is($#changes, 0);
52 is($changes[0]{message}[0]{"line"}, "Added the first page");
53 is($changes[0]{pages}[0]{"page"}, "test1");
55 # Manual commit
56 my $message = "Added the second page";
58 my $test2 = readfile("t/test2.mdwn");
59 writefile('test2.mdwn', $config{srcdir}, $test2);
60 system "svn add $config{srcdir}/test2.mdwn >/dev/null";
61 system "svn commit $config{srcdir}/test2.mdwn -m \"$message\" >/dev/null";
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");
67 is($changes[1]{pages}[0]{"page"}, "test1");
69 # extra slashes in the path shouldn't break things
70 $config{svnpath} = "/trunk//";
71 IkiWiki::checkconfig();
72 @changes = IkiWiki::rcs_recentchanges(3);
73 is($#changes, 1);
74 is($changes[0]{message}[0]{"line"}, $message);
75 is($changes[0]{pages}[0]{"page"}, "test2");
76 is($changes[1]{pages}[0]{"page"}, "test1");
78 system "rm -rf $dir";