]> sipb.mit.edu Git - ikiwiki.git/blobdiff - t/cvs.t
Notes from an evening's debugging.
[ikiwiki.git] / t / cvs.t
diff --git a/t/cvs.t b/t/cvs.t
index 1c20d7741343dd4ae668ff879909b024f4eb4d6d..cae3f8dc393c0008c50e268bb8dc44e54844afae 100755 (executable)
--- a/t/cvs.t
+++ b/t/cvs.t
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 use warnings;
 use strict;
-use Test::More; my $total_tests = 40;
+use Test::More; my $total_tests = 52;
 use IkiWiki;
 
 my $default_test_methods = '^test_*';
@@ -26,6 +26,7 @@ sub test_web_comments {
        # - when the first comment for page.mdwn is added, and page/ is
        #   created to hold the comment, page/ isn't added to CVS control,
        #   so the comment isn't either
+       #   - can't reproduce after chmod g+s ikiwiki.cgi (20120204)
        # - side effect for moderated comments: after approval they
        #   show up normally AND are still pending, too
        # - comments.pm treats rcs_commit_staged() as returning conflicts?
@@ -35,6 +36,9 @@ sub test_chdir_magic {
        # cvs.pm operations are always occurring inside $config{srcdir}
        # other ikiwiki operations are occurring wherever, and are unaffected
        # when are we bothering with "local $CWD" and when aren't we?
+       # after commit, presumably only with post-commit hook enabled:
+       #> Use of chdir('') or chdir(undef) as chdir() is deprecated at
+       #> /usr/pkg/lib/perl5/vendor_perl/5.14.0/File/chdir.pm line 45.
 }
 
 sub test_cvs_info {
@@ -132,6 +136,11 @@ sub test_rcs_prepedit {
        # for existing file, returns latest revision in repo
        # - what's this used for? should it return latest revision in checkout?
        # for new file, returns empty string
+
+       # netbsd web log says "could not open lock file"
+       # XXX does this work right?
+       # how about with un-added dirs in the srcdir?
+       # how about with cvsps.core lying around?
 }
 
 sub test_rcs_commit {
@@ -146,6 +155,8 @@ sub test_rcs_commit {
        # git.pm receives "session" param -- useful here?
        # web commits start with "web commit {by,from} "
        # seeing File::chdir errors on commit?
+
+       # XXX commit can fail due to "could not open lock file"
 }
 
 sub test_rcs_commit_staged {
@@ -154,22 +165,20 @@ sub test_rcs_commit_staged {
 }
 
 sub test_rcs_add {
-       my $message = "add a top-level ASCII (non-UTF-8) page via VCS API";
-       writefile('test0.mdwn', $config{srcdir}, "* some plain ASCII text");
-       IkiWiki::rcs_add("test0.mdwn");
-       IkiWiki::rcs_commit(
-               file => "test0.mdwn",
-               message => $message,
-               token => "moo",
-       );
-       is_newly_added("test0.mdwn");
-       is_in_keyword_substitution_mode("test0.mdwn", undef);
        my @changes = IkiWiki::rcs_recentchanges(3);
+       is_total_number_of_changes(\@changes, 0);
+
+       my $message = "add a top-level ASCII (non-UTF-8) page via VCS API";
+       my $file = q{test0.mdwn};
+       add_and_commit($file, $message, q{* some plain ASCII text});
+       is_newly_added($file);
+       is_in_keyword_substitution_mode($file, undef);
+       @changes = IkiWiki::rcs_recentchanges(3);
        is_total_number_of_changes(\@changes, 1);
-       is_most_recent_change(\@changes, "test0", $message);
+       is_most_recent_change(\@changes, stripext($file), $message);
 
        $message = "add a top-level dir via VCS API";
-       my $dir1 = "test3";
+       my $dir1 = q{test3};
        can_mkdir($dir1);
        IkiWiki::rcs_add($dir1);
        # XXX test that the wrapper hangs here without our genwrapper()
@@ -185,25 +194,18 @@ sub test_rcs_add {
        is_total_number_of_changes(\@changes, 1);       # dirs aren't tracked
 
        $message = "add a non-ASCII (UTF-8) text file in an un-added dir";
-       my $dir2 = "test4/test5";
-       can_mkdir($_) for ('test4', $dir2);
-       writefile("$dir2/test1.mdwn", $config{srcdir},readfile("t/test1.mdwn"));
-       IkiWiki::rcs_add("$dir2/test1.mdwn");
-       IkiWiki::rcs_commit(
-               file => "$dir2/test1.mdwn",
-               message => $message,
-               token => "omo",
-       );
-       is_newly_added("$dir2/test1.mdwn");
-       is_in_keyword_substitution_mode("$dir2/test1.mdwn", undef);
+       can_mkdir($_) for (qw(test4 test4/test5));
+       $file = q{test4/test5/test1.mdwn};
+       add_and_commit($file, $message, readfile("t/test1.mdwn"));
+       is_newly_added($file);
+       is_in_keyword_substitution_mode($file, undef);
        @changes = IkiWiki::rcs_recentchanges(3);
        is_total_number_of_changes(\@changes, 2);
-       is_most_recent_change(\@changes, "$dir2/test1", $message);
+       is_most_recent_change(\@changes, stripext($file), $message);
 
        $message = "add a binary file in an un-added dir, and commit_staged";
-       my $dir3 = "test6";
-       my $file = "$dir3/test7.ico";
-       can_mkdir($dir3);
+       can_mkdir(q{test6});
+       $file = q{test6/test7.ico};
        my $bindata_in = readfile("doc/favicon.ico", 1);
        my $bindata_out = sub { readfile($config{srcdir} . "/$file", 1) };
        writefile($file, $config{srcdir}, $bindata_in, 1);
@@ -227,7 +229,7 @@ sub test_rcs_add {
        $message = "add a UTF-8 and a binary file in different dirs";
        my $file1 = "test8/test9.mdwn";
        my $file2 = "test10/test11.ico";
-       can_mkdir(qw(test8 test10));
+       can_mkdir($_) for (qw(test8 test10));
        writefile($file1, $config{srcdir}, readfile('t/test2.mdwn'));
        writefile($file2, $config{srcdir}, $bindata_in, 1);
        IkiWiki::rcs_add($_) for ($file1, $file2);
@@ -278,29 +280,20 @@ sub test_rcs_rename {
 }
 
 sub test_rcs_recentchanges {
+       my @changes = IkiWiki::rcs_recentchanges(3);
+       is_total_number_of_changes(\@changes, 0);
+
        my $message = "Add a page via CVS directly";
-       writefile('test2.mdwn', $config{srcdir}, readfile("t/test2.mdwn"));
+       my $file = q{test2.mdwn};
+       writefile($file, $config{srcdir}, readfile(q{t/test2.mdwn}));
        system "cd $config{srcdir}"
-               . " && cvs add test2.mdwn >/dev/null 2>&1";
+               . " && cvs add $file >/dev/null 2>&1";
        system "cd $config{srcdir}"
-               . " && cvs commit -m \"$message\" test2.mdwn >/dev/null";
+               . " && cvs commit -m \"$message\" $file >/dev/null";
 
-       my @changes = IkiWiki::rcs_recentchanges(3);
-       is(
-               $#changes,
-               0,
-               q{total commits: 1},
-       );
-       is(
-               $changes[0]{message}[0]{"line"},
-               $message,
-               q{most recent commit's first message line matches},
-       );
-       is(
-               $changes[0]{pages}[0]{"page"},
-               "test2",
-               q{most recent commit's first pagename matches},
-       );
+       @changes = IkiWiki::rcs_recentchanges(3);
+       is_total_number_of_changes(\@changes, 1);
+       is_most_recent_change(\@changes, stripext($file), $message);
 
        # CVS commits run ikiwiki once for every committed file (!)
        # - commit_prep alone should fix this
@@ -322,9 +315,61 @@ sub test_rcs_recentchanges {
 }
 
 sub test_rcs_diff {
+       my @changes = IkiWiki::rcs_recentchanges(3);
+       is_total_number_of_changes(\@changes, 0);
+
+       my $message = "add a UTF-8 and an ASCII file in different dirs";
+       my $file1 = "rcsdiff1/utf8.mdwn";
+       my $file2 = "rcsdiff2/ascii.mdwn";
+       my $contents2 = ''; $contents2 .= "$_. foo\n" for (1..11);
+       can_mkdir($_) for (qw(rcsdiff1 rcsdiff2));
+       writefile($file1, $config{srcdir}, readfile('t/test2.mdwn'));
+       writefile($file2, $config{srcdir}, $contents2);
+       IkiWiki::rcs_add($_) for ($file1, $file2);
+       IkiWiki::rcs_commit_staged(message => $message);
+
+       # XXX we rely on rcs_recentchanges() to be called first!
+       # XXX or else for no cvsps cache to exist yet...
+       # XXX because rcs_diff() doesn't pass -x (as an optimization)
+       @changes = IkiWiki::rcs_recentchanges(3);
+       is_total_number_of_changes(\@changes, 1);
+
+       my $changeset = 1;
+
+       my $maxlines = undef;
+       my $scalar_diffs = IkiWiki::rcs_diff($changeset, $maxlines);
+       like(
+               $scalar_diffs,
+               qr/^\+11\. foo$/m,
+               q{unbounded scalar diffs go all the way to 11},
+       );
+       my @array_diffs = IkiWiki::rcs_diff($changeset, $maxlines);
+       is(
+               $array_diffs[$#array_diffs],
+               "+11. foo\n",
+               q{unbounded array diffs go all the way to 11},
+       );
+
+       $maxlines = 8;
+       $scalar_diffs = IkiWiki::rcs_diff($changeset, $maxlines);
+       unlike(
+               $scalar_diffs,
+               qr/^\+11\. foo$/m,
+               q{bounded scalar diffs don't go all the way to 11},
+       );
+       @array_diffs = IkiWiki::rcs_diff($changeset, $maxlines);
+       isnt(
+               $array_diffs[$#array_diffs],
+               "+11. foo\n",
+               q{bounded array diffs don't go all the way to 11},
+       );
+       is(
+               scalar @array_diffs,
+               $maxlines,
+               q{bounded array diffs contain expected maximum number of lines},
+       );
+
        # can it assume we're under CVS control? or must it check?
-       # in list context, return all lines (with \n), up to $maxlines if set
-       # in scalar context, return the whole diff, up to $maxlines if set
 }
 
 sub test_rcs_getctime {
@@ -342,7 +387,10 @@ sub test_rcs_getmtime {
 }
 
 sub test_rcs_receive {
-       pass(q{rcs_receive doesn't make sense for CVS});
+       my $description = q{rcs_receive doesn't make sense for CVS};
+       exists $IkiWiki::hooks{rcs}{rcs_receive}
+               ? fail($description)
+               : pass($description);
 }
 
 sub test_rcs_preprevert {
@@ -353,6 +401,11 @@ sub test_rcs_preprevert {
 }
 
 sub test_rcs_revert {
+       # test rcs_recentchanges() real darn well
+       # extract read-backwards patchset parser from rcs_recentchanges()
+       # recentchanges: given max, return list of changeset/files/etc.
+       # revert: given changeset ID, return list of file/rev/action
+       #
        # can it assume we're under CVS control? or must it check?
        # given a patchset number, stage the revert for rcs_commit_staged()
        # if commit succeeds, return undef
@@ -438,6 +491,7 @@ sub _setup {
 }
 
 sub _teardown {
+       # XXX does srcdir persist between test subs?
        system "rm -rf $dir";
 }
 
@@ -480,6 +534,17 @@ sub _generate_test_repo {
        system "$cvs co -d $config{srcdir} $config{cvspath} $dn";
 }
 
+sub add_and_commit {
+       my ($file, $message, $contents) = @_;
+       writefile($file, $config{srcdir}, $contents);
+       IkiWiki::rcs_add($file);
+       IkiWiki::rcs_commit(
+               file => $file,
+               message => $message,
+               token => "moo",
+       );
+}
+
 sub can_mkdir {
        my $dir = shift;
        ok(
@@ -529,3 +594,10 @@ sub is_most_recent_change {
                q{most recent commit's first pagename matches},
        );
 }
+
+sub stripext {
+       my ($file, $extension) = @_;
+       $extension = '\..+?' unless defined $extension;
+       $file =~ s|$extension$||g;
+       return $file;
+}