* Define expected number of tests near the top.

* Call readfile() directly from writefile().
* Parameterize commit message for the web-commit case.
* Describe intent of test cases.
* Rename test subs to match what they actually do.
* To prove extra path slashes don't cause trouble, instead of running
  the same tests a second time, just assert that checkconfig()
  strips the slashes.
master
Amitai Schlair 2012-01-21 20:17:52 -05:00
parent b77da0bb3b
commit d760df3821
1 changed files with 55 additions and 26 deletions

81
t/cvs.t
View File

@ -4,6 +4,7 @@ use strict;
use Test::More; use Test::More;
use IkiWiki; use IkiWiki;
my %ideal_test_plan = (tests => 8);
my $dir; my $dir;
sub _determine_test_plan { sub _determine_test_plan {
@ -19,7 +20,7 @@ sub _determine_test_plan {
} }
} }
return (tests => 11); return %ideal_test_plan;
} }
sub _startup { sub _startup {
@ -59,49 +60,77 @@ sub _create_test_repo {
system "cvs -d $cvsrepo co -d $config{srcdir} ikiwiki >/dev/null"; system "cvs -d $cvsrepo co -d $config{srcdir} ikiwiki >/dev/null";
} }
sub test_web_commit { sub test_web_add_and_commit {
my $test1 = readfile("t/test1.mdwn"); writefile('test1.mdwn', $config{srcdir}, readfile("t/test1.mdwn"));
writefile('test1.mdwn', $config{srcdir}, $test1);
IkiWiki::rcs_add("test1.mdwn"); IkiWiki::rcs_add("test1.mdwn");
my $message = "Added the first page";
IkiWiki::rcs_commit( IkiWiki::rcs_commit(
file => "test1.mdwn", file => "test1.mdwn",
message => "Added the first page", message => $message,
token => "moo", token => "moo",
); );
my @changes = IkiWiki::rcs_recentchanges(3); my @changes = IkiWiki::rcs_recentchanges(3);
is(
is($#changes, 0); $#changes,
is($changes[0]{message}[0]{"line"}, "Added the first page"); 0,
is($changes[0]{pages}[0]{"page"}, "test1"); q{1 total commit},
);
is(
$changes[0]{message}[0]{"line"},
$message,
q{first line of most recent commit message matches},
);
is(
$changes[0]{pages}[0]{"page"},
"test1",
q{first pagename from most recent commit matches},
);
} }
sub test_manual_commit { sub test_manual_add_and_commit {
my $message = "Added the second page"; writefile('test2.mdwn', $config{srcdir}, readfile("t/test2.mdwn"));
my $test2 = readfile("t/test2.mdwn");
writefile('test2.mdwn', $config{srcdir}, $test2);
system "cd $config{srcdir} && cvs add test2.mdwn >/dev/null 2>&1"; system "cd $config{srcdir} && cvs add test2.mdwn >/dev/null 2>&1";
my $message = "Added the second page";
system "cd $config{srcdir} && cvs commit -m \"$message\" test2.mdwn >/dev/null"; system "cd $config{srcdir} && cvs commit -m \"$message\" test2.mdwn >/dev/null";
my @changes = IkiWiki::rcs_recentchanges(3); my @changes = IkiWiki::rcs_recentchanges(3);
is($#changes, 1); is(
is($changes[0]{message}[0]{"line"}, $message); $#changes,
is($changes[0]{pages}[0]{"page"}, "test2"); 1,
is($changes[1]{pages}[0]{"page"}, "test1"); q{2 total commits},
);
is(
$changes[0]{message}[0]{"line"},
$message,
q{first line of most recent commit message matches},
);
is(
$changes[0]{pages}[0]{"page"},
"test2",
q{first pagename from most recent commit matches},
);
is(
$changes[1]{pages}[0]{"page"},
"test1",
q{first pagename from second-most-recent commit matches},
);
}
# extra slashes in the path shouldn't break things sub test_extra_path_slashes {
my $initial_cvspath = $config{cvspath};
$config{cvspath} = "/ikiwiki//"; $config{cvspath} = "/ikiwiki//";
IkiWiki::checkconfig(); IkiWiki::checkconfig();
@changes = IkiWiki::rcs_recentchanges(3); is(
is($#changes, 1); $config{cvspath},
is($changes[0]{message}[0]{"line"}, $message); $initial_cvspath,
is($changes[0]{pages}[0]{"page"}, "test2"); q{rcs_recentchanges assumes checkconfig sanitizes cvspath},
is($changes[1]{pages}[0]{"page"}, "test1"); );
} }
plan(_determine_test_plan()); plan(_determine_test_plan());
_startup(); _startup();
test_web_commit(); test_web_add_and_commit();
test_manual_commit(); test_manual_add_and_commit();
test_extra_path_slashes();
_shutdown(); _shutdown();