7 my %ideal_test_plan = (tests => 8);
10 sub _determine_test_plan {
11 my $cvs = `which cvs`; chomp $cvs;
12 my $cvsps = `which cvsps`; chomp $cvsps;
13 return (skip_all => 'cvs or cvsps not available')
14 unless -x $cvs && -x $cvsps;
16 foreach my $module (qw(File::ReadBackwards File::MimeInfo)) {
19 return (skip_all => "$module not available");
23 $dir = "/tmp/ikiwiki-test-cvs.$$";
24 return (skip_all => "can't create $dir: $!")
27 return %ideal_test_plan;
31 _generate_minimal_config();
39 sub _generate_minimal_config {
40 %config = IkiWiki::defaultconfig();
42 $config{srcdir} = "$dir/src";
43 $config{cvsrepo} = "$dir/repo";
44 $config{cvspath} = "ikiwiki";
45 IkiWiki::loadplugins();
46 IkiWiki::checkconfig();
49 sub _create_test_repo {
50 my $cvs = "cvs -d $config{cvsrepo}";
51 my $dn = ">/dev/null";
52 system "$cvs init $dn";
53 system "mkdir $dir/$config{cvspath} $dn";
54 system "cd $dir/$config{cvspath} && "
55 . "$cvs import -m import $config{cvspath} VENDOR RELEASE $dn";
56 system "rm -rf $dir/$config{cvspath} $dn";
57 system "$cvs co -d $config{srcdir} $config{cvspath} $dn";
60 sub test_web_add_and_commit {
61 my $message = "Added the first page";
62 writefile('test1.mdwn', $config{srcdir}, readfile("t/test1.mdwn"));
63 IkiWiki::rcs_add("test1.mdwn");
70 my @changes = IkiWiki::rcs_recentchanges(3);
77 $changes[0]{message}[0]{"line"},
79 q{first line of most recent commit message matches},
82 $changes[0]{pages}[0]{"page"},
84 q{first pagename from most recent commit matches},
88 sub test_manual_add_and_commit {
89 my $message = "Added the second page";
90 writefile('test2.mdwn', $config{srcdir}, readfile("t/test2.mdwn"));
91 system "cd $config{srcdir}"
92 . " && cvs add test2.mdwn >/dev/null 2>&1";
93 system "cd $config{srcdir}"
94 . " && cvs commit -m \"$message\" test2.mdwn >/dev/null";
96 my @changes = IkiWiki::rcs_recentchanges(3);
103 $changes[0]{message}[0]{"line"},
105 q{first line of most recent commit message matches},
108 $changes[0]{pages}[0]{"page"},
110 q{first pagename from most recent commit matches},
113 $changes[1]{pages}[0]{"page"},
115 q{first pagename from second-most-recent commit matches},
119 sub test_extra_path_slashes {
120 my $initial_cvspath = $config{cvspath};
121 $config{cvspath} = "/ikiwiki//";
122 IkiWiki::checkconfig();
126 q{rcs_recentchanges assumes checkconfig sanitizes cvspath},
130 plan(_determine_test_plan());
132 test_web_add_and_commit();
133 test_manual_add_and_commit();
134 test_extra_path_slashes();