test from google openid
[ikiwiki.git] / t / cvs.t
blob96359ab6e2a6bb9773af99179cf567da8732b3b1
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 my $dir;
5 BEGIN {
6 $dir="/tmp/ikiwiki-test-cvs.$$";
7 my $cvs=`which cvs`;
8 chomp $cvs;
9 my $cvsps=`which cvsps`;
10 chomp $cvsps;
11 if (! -x $cvs || ! -x $cvsps || ! mkdir($dir)) {
12 eval q{
13 use Test::More skip_all => "cvs or cvsps not available or could not make test dir"
16 foreach my $module ('File::ReadBackwards', 'File::MimeInfo') {
17 eval qq{use $module};
18 if ($@) {
19 eval qq{
20 use Test::More skip_all => "$module not available"
25 use Test::More tests => 12;
27 BEGIN { use_ok("IkiWiki"); }
29 %config=IkiWiki::defaultconfig();
30 $config{rcs} = "cvs";
31 $config{srcdir} = "$dir/src";
32 $config{cvsrepo} = "$dir/repo";
33 $config{cvspath} = "ikiwiki";
34 IkiWiki::loadplugins();
35 IkiWiki::checkconfig();
37 my $cvsrepo = "$dir/repo";
39 system "cvs -d $cvsrepo init >/dev/null";
40 system "mkdir $dir/ikiwiki >/dev/null";
41 system "cd $dir/ikiwiki && cvs -d $cvsrepo import -m import ikiwiki VENDOR RELEASE >/dev/null";
42 system "rm -rf $dir/ikiwiki >/dev/null";
43 system "cvs -d $cvsrepo co -d $config{srcdir} ikiwiki >/dev/null";
45 # Web commit
46 my $test1 = readfile("t/test1.mdwn");
47 writefile('test1.mdwn', $config{srcdir}, $test1);
48 IkiWiki::rcs_add("test1.mdwn");
49 IkiWiki::rcs_commit(
50 files => "test1.mdwn",
51 message => "Added the first page",
52 token => "moo"
55 my @changes;
56 @changes = IkiWiki::rcs_recentchanges(3);
58 is($#changes, 0);
59 is($changes[0]{message}[0]{"line"}, "Added the first page");
60 is($changes[0]{pages}[0]{"page"}, "test1");
62 # Manual commit
63 my $message = "Added the second page";
65 my $test2 = readfile("t/test2.mdwn");
66 writefile('test2.mdwn', $config{srcdir}, $test2);
67 system "cd $config{srcdir} && cvs add test2.mdwn >/dev/null 2>&1";
68 system "cd $config{srcdir} && cvs commit -m \"$message\" test2.mdwn >/dev/null";
70 @changes = IkiWiki::rcs_recentchanges(3);
71 is($#changes, 1);
72 is($changes[0]{message}[0]{"line"}, $message);
73 is($changes[0]{pages}[0]{"page"}, "test2");
74 is($changes[1]{pages}[0]{"page"}, "test1");
76 # extra slashes in the path shouldn't break things
77 $config{cvspath} = "/ikiwiki//";
78 IkiWiki::checkconfig();
79 @changes = IkiWiki::rcs_recentchanges(3);
80 is($#changes, 1);
81 is($changes[0]{message}[0]{"line"}, $message);
82 is($changes[0]{pages}[0]{"page"}, "test2");
83 is($changes[1]{pages}[0]{"page"}, "test1");
85 system "rm -rf $dir";