]> sipb.mit.edu Git - ikiwiki.git/commitdiff
Merge branch 'master' into cvs
authorAmitai Schlair <schmonz-web-ikiwiki@schmonz.com>
Tue, 7 Feb 2012 13:33:32 +0000 (08:33 -0500)
committerAmitai Schlair <schmonz-web-ikiwiki@schmonz.com>
Tue, 7 Feb 2012 13:33:32 +0000 (08:33 -0500)
IkiWiki/Plugin/cvs.pm
t/cvs.t

index 0a6cbfaf6358f7a53014260f71c69ae5820641dc..8e0e2a4dab54473902e8b383ff99072a0198d403 100644 (file)
@@ -394,11 +394,15 @@ sub rcs_diff ($;$) {
        my @cvsps = `env TZ=UTC cvsps -q --cvs-direct -z 30 -g -s $rev`;
        my $blank_lines_seen = 0;
 
+       # skip log, get to the diff
        while (my $line = shift @cvsps) {
                $blank_lines_seen++ if ($line =~ /^$/);
                last if $blank_lines_seen == 2;
        }
 
+       @cvsps = @cvsps[0..$maxlines-1]
+               if defined $maxlines && @cvsps > $maxlines;
+
        if (wantarray) {
                return @cvsps;
        }
diff --git a/t/cvs.t b/t/cvs.t
index 9afd5a7e9061767f8cc0f1f5ad08d97dcc335c98..12afc6687ab40abf9baa9612703fd1a379511c37 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 = 42;
+use Test::More; my $total_tests = 57;
 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 {
@@ -58,6 +62,7 @@ sub test_cvs_run_cvsps {
        # parameterize command like run_cvs()
        # expose config vars for e.g. "--cvs-direct -z 30"
        # always pass -x (unless proven otherwise)
+       # - but diff doesn't! optimization alert
        # always pass -b HEAD (configurable like gitmaster_branch?)
 }
 
@@ -94,21 +99,43 @@ sub test_cvs_is_controlling {
 # TESTS FOR GENERAL PLUGIN API CALLS
 
 sub test_checkconfig {
-       # undef cvspath, expect "ikiwiki"
-       # define cvspath normally, get it back
-       # define cvspath in a subdir, get it back?
-       # define cvspath with extra slashes, get sanitized version back
-       # - yoink test_extra_path_slashes
-       # undef cvs_wrapper, expect $config{wrappers} same size as before
-
-       my $initial_cvspath = $config{cvspath};
-       $config{cvspath} = "/ikiwiki//";
+       my $default_cvspath = 'ikiwiki';
+
+       undef $config{cvspath}; IkiWiki::checkconfig();
+       is(
+               $config{cvspath}, $default_cvspath,
+               q{can provide default cvspath},
+       );
+
+       $config{cvspath} = "/$default_cvspath/"; IkiWiki::checkconfig();
+       is(
+               $config{cvspath}, $default_cvspath,
+               q{can set typical cvspath and strip well-meaning slashes},
+       );
+
+       $config{cvspath} = "/$default_cvspath//subdir"; IkiWiki::checkconfig();
+       is(
+               $config{cvspath}, "$default_cvspath/subdir",
+               q{can really sanitize cvspath as assumed by rcs_recentchanges},
+       );
+
+       my $default_num_wrappers = @{$config{wrappers}};
+       undef $config{cvs_wrapper}; IkiWiki::checkconfig();
+       is(
+               @{$config{wrappers}}, $default_num_wrappers,
+               q{can start with no wrappers configured},
+       );
+
+       $config{cvs_wrapper} = $config{cvsrepo} . "/CVSROOT/post-commit";
        IkiWiki::checkconfig();
        is(
-               $config{cvspath},
-               $initial_cvspath,
-               q{rcs_recentchanges assumes checkconfig has sanitized cvspath},
+               @{$config{wrappers}}, ++$default_num_wrappers,
+               q{can add cvs_wrapper},
        );
+
+       undef $config{cvs_wrapper};
+       $config{cvspath} = $default_cvspath;
+       IkiWiki::checkconfig();
 }
 
 sub test_getsetup {
@@ -132,6 +159,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 +178,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 {
@@ -159,9 +193,14 @@ sub test_rcs_add {
 
        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});
+       add_and_commit($file, $message, qq{# \$Id\$\n* some plain ASCII text});
        is_newly_added($file);
        is_in_keyword_substitution_mode($file, undef);
+       like(
+               readfile($config{srcdir} . "/$file"),
+               qr/^# \$Id: $file,v 1.1 .+\$$/m,
+               q{can expand RCS Id keyword},
+       );
        @changes = IkiWiki::rcs_recentchanges(3);
        is_total_number_of_changes(\@changes, 1);
        is_most_recent_change(\@changes, stripext($file), $message);
@@ -218,7 +257,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);
@@ -304,9 +343,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 {
@@ -428,6 +519,7 @@ sub _setup {
 }
 
 sub _teardown {
+       # XXX does srcdir persist between test subs?
        system "rm -rf $dir";
 }