+sub test_web_comments {
+ # how much of the web-edit workflow are we actually testing?
+ # because we want to test 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?
+}
+
+sub test_chdir_magic {
+ # when are we bothering with "local $CWD" and when aren't we?
+}
+
+sub test_cvs_info {
+ # inspect "Repository revision" (used in code)
+ # inspect "Sticky Options" (used in tests to verify existence of "-kb")
+}
+
+sub test_cvs_run_cvs {
+ # extract the stdout-redirect thing
+ # - prove that it silences stdout
+ # - prove that stderr comes through just fine
+ # prove that when cvs exits nonzero (fail), function exits false
+ # prove that when cvs exits zero (success), function exits true
+ # always pass -f, just in case
+ # steal from git.pm: safe_git(), run_or_{die,cry,non}
+ # - open() instead of system()
+ # always call cvs_run_cvs(), don't ever run 'cvs' directly
+ # - for cvs_info(), make it respect wantarray
+}
+
+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?)
+}
+
+sub test_cvs_parse_cvsps {
+ # extract method from rcs_recentchanges
+ # document expected changeset format
+ # document expected changeset delimiter
+ # try: cvsps -q -x -p && ls | sort -rn | head -100
+ # - benchmark against current impl (that uses File::ReadBackwards)
+}
+
+sub test_cvs_parse_log_accum {
+ # add new, preferred method for rcs_recentchanges to use
+ # teach log_accum to record commits (into transient?)
+ # script cvsps to bootstrap (or replace?) commit history
+ # teach ikiwiki-makerepo to set up log_accum and commit_prep
+ # why are NetBSD commit mails unreliable?
+ # - is it working for CVS commits and failing for web commits?
+}
+
+sub test_cvs_is_controlling {
+ # with no args:
+ # - if srcdir is in CVS, return true
+ # - else, return false
+ # with a dir arg:
+ # - if dir is in CVS, return true
+ # - else, return false
+ # with a file arg:
+ # - is there anything that wants the answer? if so, answer
+ # - else, die
+}
+
+
+# TESTS FOR GENERAL PLUGIN API CALLS
+
+sub test_checkconfig {
+ 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{wrappers}}, ++$default_num_wrappers,
+ q{can add cvs_wrapper},
+ );
+
+ undef $config{cvs_wrapper};
+ $config{cvspath} = $default_cvspath;
+ IkiWiki::checkconfig();
+}
+
+sub test_getsetup {
+ # anything worth testing?
+}
+
+sub test_genwrapper {
+ # testable directly? affects rcs_add, but are we exercising this?
+}
+
+
+# TESTS FOR VCS PLUGIN API CALLS
+
+sub test_rcs_update {
+ # can it assume we're under CVS control? or must it check?
+ # anything else worth testing?
+}
+
+sub test_rcs_prepedit {
+ # can it assume we're under CVS control? or must it check?
+ # 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 {
+ # can it assume we're under CVS control? or must it check?
+ # if someone else changed the page since rcs_prepedit was called:
+ # - try to merge into our working copy
+ # - if merge succeeds, proceed to commit
+ # - else, return page content with the conflict markers in it
+ # commit:
+ # - if success, return undef
+ # - else, revert + return content with the conflict markers in it
+ # git.pm receives "session" param -- useful here?
+ # web commits start with "web commit {by,from} "
+
+ # XXX commit can fail due to "could not open lock file"
+}
+
+sub test_rcs_commit_staged {
+ # if commit succeeds, return undef
+ # else, warn and return error message (really? or just non-undef?)
+}
+
+sub test_rcs_add {
+ 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, qq{# \$Id\$\n* some plain ASCII text});
+ is_newly_added($file);
+ is_in_keyword_substitution_mode($file, q{-kkv});
+ like(
+ readfile($config{srcdir} . "/$file"),
+ qr/^# \$Id: $file,v 1\.1 .+\$$/m,
+ q{can expand RCS Id keyword},
+ );
+ my $generated_file = $config{destdir} . q{/test0/index.html};
+ ok(-e $generated_file, q{post-commit hook generates content});
+ like(
+ readfile($generated_file),
+ qr/^<h1>\$Id: $file,v 1\.1 .+\$<\/h1>$/m,
+ q{can htmlize mdwn, including RCS Id},
+ );
+ @changes = IkiWiki::rcs_recentchanges(3);
+ is_total_number_of_changes(\@changes, 1);
+ is_most_recent_change(\@changes, stripext($file), $message);
+
+ $message = "add a top-level dir via VCS API";
+ my $dir1 = q{test3};
+ can_mkdir($dir1);
+ IkiWiki::rcs_add($dir1);
+ # XXX test that the wrapper hangs here without our genwrapper()
+ # XXX test that the wrapper doesn't hang here with it
+ @changes = IkiWiki::rcs_recentchanges(3);
+ is_total_number_of_changes(\@changes, 1); # despite the dir add
+ IkiWiki::rcs_commit(
+ file => $dir1,
+ message => $message,
+ token => "oom",
+ );
+ @changes = IkiWiki::rcs_recentchanges(3);
+ 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";
+ 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, q{-kkv});
+ @changes = IkiWiki::rcs_recentchanges(3);
+ is_total_number_of_changes(\@changes, 2);
+ is_most_recent_change(\@changes, stripext($file), $message);
+
+ $message = "add a binary file in an un-added dir, and commit_staged";
+ 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);
+ is(&$bindata_out(), $bindata_in, q{binary files match before commit});
+ IkiWiki::rcs_add($file);
+ IkiWiki::rcs_commit_staged(message => $message);
+ is_newly_added($file);
+ is_in_keyword_substitution_mode($file, q{-kb});
+ is(&$bindata_out(), $bindata_in, q{binary files match after commit});
+ @changes = IkiWiki::rcs_recentchanges(3);
+ is_total_number_of_changes(\@changes, 3);
+ is_most_recent_change(\@changes, $file, $message);
+ ok(
+ unlink($config{srcdir} . "/$file"),
+ q{can remove file in order to re-fetch it from repo},
+ );
+ ok(! -e $config{srcdir} . "/$file", q{really removed file});
+ IkiWiki::rcs_update();
+ is(&$bindata_out(), $bindata_in, q{binary files match after re-fetch});
+
+ $message = "add a UTF-8 and a binary file in different dirs";
+ my $file1 = "test8/test9.mdwn";
+ my $file2 = "test10/test11.ico";
+ 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);
+ IkiWiki::rcs_commit_staged(message => $message);
+ is_newly_added($_) for ($file1, $file2);
+ is_in_keyword_substitution_mode($file1, q{-kkv});
+ is_in_keyword_substitution_mode($file2, q{-kb});
+ @changes = IkiWiki::rcs_recentchanges(3);
+ is_total_number_of_changes(\@changes, 3);
+ @changes = IkiWiki::rcs_recentchanges(4);
+ is_total_number_of_changes(\@changes, 4);
+ # XXX test for both files in the commit, and no other files
+ is_most_recent_change(\@changes, $file2, $message);
+
+ $message = "remove the UTF-8 and binary files we just added";
+ IkiWiki::rcs_remove($_) for ($file1, $file2);
+ IkiWiki::rcs_commit_staged(message => $message);
+ ok(! -d "$config{srcdir}/test8", q{empty dir pruned by post-commit});
+ ok(! -d "$config{srcdir}/test10", q{empty dir pruned by post-commit});
+ @changes = IkiWiki::rcs_recentchanges(11);
+ is_total_number_of_changes(\@changes, 5);
+ # XXX test for both files in the commit, and no other files
+ is_most_recent_change(\@changes, $file2, $message);
+
+ $message = "re-add UTF-8 and binary files with names swapped";
+ writefile($file2, $config{srcdir}, readfile('t/test2.mdwn'));
+ writefile($file1, $config{srcdir}, $bindata_in, 1);
+ IkiWiki::rcs_add($_) for ($file1, $file2);
+ IkiWiki::rcs_commit_staged(message => $message);
+ isnt_newly_added($_) for ($file1, $file2);
+ is_in_keyword_substitution_mode($file2, q{-kkv});
+ is_in_keyword_substitution_mode($file1, q{-kb});
+ @changes = IkiWiki::rcs_recentchanges(11);
+ is_total_number_of_changes(\@changes, 6);
+ # XXX test for both files in the commit, and no other files
+ is_most_recent_change(\@changes, $file2, $message);
+
+ # prevent web edits from attempting to create .../CVS/foo.mdwn
+ # on case-insensitive filesystems, also prevent .../cvs/foo.mdwn
+ # unless your "CVS" is something else and we've made it configurable
+ # also want a pre-commit hook for this?
+
+ # pre-commit hook:
+ # - lcase filenames
+ # - ?
+
+ # can it assume we're under CVS control? or must it check?
+}
+
+sub test_rcs_remove {
+ # can it assume we're under CVS control? or must it check?
+ # remove a top-level file
+ # - rcs_commit
+ # - inspect recentchanges: one new change, file removed
+ # remove two files (in different dirs)
+ # - rcs_commit_staged
+ # - inspect recentchanges: one new change, both files removed
+}
+
+sub test_rcs_rename {
+ # can it assume we're under CVS control? or must it check?
+ # rename a file in the same dir
+ # - rcs_commit_staged
+ # - inspect recentchanges: one new change, one file removed, one added
+ # rename a file into a different dir
+ # - rcs_commit_staged
+ # - inspect recentchanges: one new change, one file removed, one added
+ # rename a file into a not-yet-existing dir
+ # - rcs_commit_staged
+ # - inspect recentchanges: one new change, one file removed, one added
+ # is it safe to use "mv"? what if $dest is somehow outside the wiki?
+}
+
+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";
+ my $file = q{test2.mdwn};
+ writefile($file, $config{srcdir}, readfile(q{t/test2.mdwn}));
+ system "cd $config{srcdir}"
+ . " && cvs add $file >/dev/null 2>&1";
+ system "cd $config{srcdir}"
+ . " && cvs commit -m \"$message\" $file >/dev/null";
+
+ @changes = IkiWiki::rcs_recentchanges(3);
+ is_total_number_of_changes(\@changes, 1);
+ is_most_recent_change(\@changes, stripext($file), $message);