Fix longstanding bug (chdir to nonexistent dirs).
[ikiwiki] / t / cvs.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More; my $total_tests = 71;
5 use IkiWiki;
6
7 my $default_test_methods = '^test_*';
8 my @required_programs = qw(
9         cvs
10         cvsps
11 );
12 my @required_modules = qw(
13         File::chdir
14         File::MimeInfo
15         Date::Parse
16         File::Temp
17         File::ReadBackwards
18 );
19 my $dir = "/tmp/ikiwiki-test-cvs.$$";
20
21 # TESTS FOR GENERAL META-BEHAVIOR
22
23 sub test_web_comments {
24         # how much of the web-edit workflow are we actually testing?
25         # because we want to test comments:
26         # - when the first comment for page.mdwn is added, and page/ is
27         #   created to hold the comment, page/ isn't added to CVS control,
28         #   so the comment isn't either
29         #   - can't reproduce after chmod g+s ikiwiki.cgi (20120204)
30         # - side effect for moderated comments: after approval they
31         #   show up normally AND are still pending, too
32         # - comments.pm treats rcs_commit_staged() as returning conflicts?
33 }
34
35 sub test_chdir_magic {
36         # when are we bothering with "local $CWD" and when aren't we?
37 }
38
39 sub test_cvs_info {
40         # inspect "Repository revision" (used in code)
41         # inspect "Sticky Options" (used in tests to verify existence of "-kb")
42 }
43
44 sub test_cvs_run_cvs {
45         # extract the stdout-redirect thing
46         # - prove that it silences stdout
47         # - prove that stderr comes through just fine
48         # prove that when cvs exits nonzero (fail), function exits false
49         # prove that when cvs exits zero (success), function exits true
50         # always pass -f, just in case
51         # steal from git.pm: safe_git(), run_or_{die,cry,non}
52         # - open() instead of system()
53         # always call cvs_run_cvs(), don't ever run 'cvs' directly
54         # - for cvs_info(), make it respect wantarray
55 }
56
57 sub test_cvs_run_cvsps {
58         # parameterize command like run_cvs()
59         # expose config vars for e.g. "--cvs-direct -z 30"
60         # always pass -x (unless proven otherwise)
61         # - but diff doesn't! optimization alert
62         # always pass -b HEAD (configurable like gitmaster_branch?)
63 }
64
65 sub test_cvs_parse_cvsps {
66         # extract method from rcs_recentchanges
67         # document expected changeset format
68         # document expected changeset delimiter
69         # try: cvsps -q -x -p && ls | sort -rn | head -100
70         # - benchmark against current impl (that uses File::ReadBackwards)
71 }
72
73 sub test_cvs_parse_log_accum {
74         # add new, preferred method for rcs_recentchanges to use
75         # teach log_accum to record commits (into transient?)
76         # script cvsps to bootstrap (or replace?) commit history
77         # teach ikiwiki-makerepo to set up log_accum and commit_prep
78         # why are NetBSD commit mails unreliable?
79         # - is it working for CVS commits and failing for web commits?
80 }
81
82 sub test_cvs_is_controlling {
83         # with no args:
84         # - if srcdir is in CVS, return true
85         # - else, return false
86         # with a dir arg:
87         # - if dir is in CVS, return true
88         # - else, return false
89         # with a file arg:
90         # - is there anything that wants the answer? if so, answer
91         # - else, die
92 }
93
94
95 # TESTS FOR GENERAL PLUGIN API CALLS
96
97 sub test_checkconfig {
98         my $default_cvspath = 'ikiwiki';
99
100         undef $config{cvspath}; IkiWiki::checkconfig();
101         is(
102                 $config{cvspath}, $default_cvspath,
103                 q{can provide default cvspath},
104         );
105
106         $config{cvspath} = "/$default_cvspath/"; IkiWiki::checkconfig();
107         is(
108                 $config{cvspath}, $default_cvspath,
109                 q{can set typical cvspath and strip well-meaning slashes},
110         );
111
112         $config{cvspath} = "/$default_cvspath//subdir"; IkiWiki::checkconfig();
113         is(
114                 $config{cvspath}, "$default_cvspath/subdir",
115                 q{can really sanitize cvspath as assumed by rcs_recentchanges},
116         );
117
118         my $default_num_wrappers = @{$config{wrappers}};
119         undef $config{cvs_wrapper}; IkiWiki::checkconfig();
120         is(
121                 @{$config{wrappers}}, $default_num_wrappers,
122                 q{can start with no wrappers configured},
123         );
124
125         $config{cvs_wrapper} = $config{cvsrepo} . "/CVSROOT/post-commit";
126         IkiWiki::checkconfig();
127         is(
128                 @{$config{wrappers}}, ++$default_num_wrappers,
129                 q{can add cvs_wrapper},
130         );
131
132         undef $config{cvs_wrapper};
133         $config{cvspath} = $default_cvspath;
134         IkiWiki::checkconfig();
135 }
136
137 sub test_getsetup {
138         # anything worth testing?
139 }
140
141 sub test_genwrapper {
142         # testable directly? affects rcs_add, but are we exercising this?
143 }
144
145
146 # TESTS FOR VCS PLUGIN API CALLS
147
148 sub test_rcs_update {
149         # can it assume we're under CVS control? or must it check?
150         # anything else worth testing?
151 }
152
153 sub test_rcs_prepedit {
154         # can it assume we're under CVS control? or must it check?
155         # for existing file, returns latest revision in repo
156         # - what's this used for? should it return latest revision in checkout?
157         # for new file, returns empty string
158
159         # netbsd web log says "could not open lock file"
160         # XXX does this work right?
161         # how about with un-added dirs in the srcdir?
162         # how about with cvsps.core lying around?
163 }
164
165 sub test_rcs_commit {
166         # can it assume we're under CVS control? or must it check?
167         # if someone else changed the page since rcs_prepedit was called:
168         # - try to merge into our working copy
169         # - if merge succeeds, proceed to commit
170         # - else, return page content with the conflict markers in it
171         # commit:
172         # - if success, return undef
173         # - else, revert + return content with the conflict markers in it
174         # git.pm receives "session" param -- useful here?
175         # web commits start with "web commit {by,from} "
176
177         # XXX commit can fail due to "could not open lock file"
178 }
179
180 sub test_rcs_commit_staged {
181         # if commit succeeds, return undef
182         # else, warn and return error message (really? or just non-undef?)
183 }
184
185 sub test_rcs_add {
186         my @changes = IkiWiki::rcs_recentchanges(3);
187         is_total_number_of_changes(\@changes, 0);
188
189         my $message = "add a top-level ASCII (non-UTF-8) page via VCS API";
190         my $file = q{test0.mdwn};
191         add_and_commit($file, $message, qq{# \$Id\$\n* some plain ASCII text});
192         is_newly_added($file);
193         is_in_keyword_substitution_mode($file, q{-kkv});
194         like(
195                 readfile($config{srcdir} . "/$file"),
196                 qr/^# \$Id: $file,v 1\.1 .+\$$/m,
197                 q{can expand RCS Id keyword},
198         );
199         my $generated_file = $config{destdir} . q{/test0/index.html};
200         ok(-e $generated_file, q{post-commit hook generates content});
201         like(
202                 readfile($generated_file),
203                 qr/^<h1>\$Id: $file,v 1\.1 .+\$<\/h1>$/m,
204                 q{can htmlize mdwn, including RCS Id},
205         );
206         @changes = IkiWiki::rcs_recentchanges(3);
207         is_total_number_of_changes(\@changes, 1);
208         is_most_recent_change(\@changes, stripext($file), $message);
209
210         $message = "add a top-level dir via VCS API";
211         my $dir1 = q{test3};
212         can_mkdir($dir1);
213         IkiWiki::rcs_add($dir1);
214         # XXX test that the wrapper hangs here without our genwrapper()
215         # XXX test that the wrapper doesn't hang here with it
216         @changes = IkiWiki::rcs_recentchanges(3);
217         is_total_number_of_changes(\@changes, 1);       # despite the dir add
218         IkiWiki::rcs_commit(
219                 file => $dir1,
220                 message => $message,
221                 token => "oom",
222         );
223         @changes = IkiWiki::rcs_recentchanges(3);
224         is_total_number_of_changes(\@changes, 1);       # dirs aren't tracked
225
226         $message = "add a non-ASCII (UTF-8) text file in an un-added dir";
227         can_mkdir($_) for (qw(test4 test4/test5));
228         $file = q{test4/test5/test1.mdwn};
229         add_and_commit($file, $message, readfile("t/test1.mdwn"));
230         is_newly_added($file);
231         is_in_keyword_substitution_mode($file, q{-kkv});
232         @changes = IkiWiki::rcs_recentchanges(3);
233         is_total_number_of_changes(\@changes, 2);
234         is_most_recent_change(\@changes, stripext($file), $message);
235
236         $message = "add a binary file in an un-added dir, and commit_staged";
237         can_mkdir(q{test6});
238         $file = q{test6/test7.ico};
239         my $bindata_in = readfile("doc/favicon.ico", 1);
240         my $bindata_out = sub { readfile($config{srcdir} . "/$file", 1) };
241         writefile($file, $config{srcdir}, $bindata_in, 1);
242         is(&$bindata_out(), $bindata_in, q{binary files match before commit});
243         IkiWiki::rcs_add($file);
244         IkiWiki::rcs_commit_staged(message => $message);
245         is_newly_added($file);
246         is_in_keyword_substitution_mode($file, q{-kb});
247         is(&$bindata_out(), $bindata_in, q{binary files match after commit});
248         @changes = IkiWiki::rcs_recentchanges(3);
249         is_total_number_of_changes(\@changes, 3);
250         is_most_recent_change(\@changes, $file, $message);
251         ok(
252                 unlink($config{srcdir} . "/$file"),
253                 q{can remove file in order to re-fetch it from repo},
254         );
255         ok(! -e $config{srcdir} . "/$file", q{really removed file});
256         IkiWiki::rcs_update();
257         is(&$bindata_out(), $bindata_in, q{binary files match after re-fetch});
258
259         $message = "add a UTF-8 and a binary file in different dirs";
260         my $file1 = "test8/test9.mdwn";
261         my $file2 = "test10/test11.ico";
262         can_mkdir($_) for (qw(test8 test10));
263         writefile($file1, $config{srcdir}, readfile('t/test2.mdwn'));
264         writefile($file2, $config{srcdir}, $bindata_in, 1);
265         IkiWiki::rcs_add($_) for ($file1, $file2);
266         IkiWiki::rcs_commit_staged(message => $message);
267         is_newly_added($_) for ($file1, $file2);
268         is_in_keyword_substitution_mode($file1, q{-kkv});
269         is_in_keyword_substitution_mode($file2, q{-kb});
270         @changes = IkiWiki::rcs_recentchanges(3);
271         is_total_number_of_changes(\@changes, 3);
272         @changes = IkiWiki::rcs_recentchanges(4);
273         is_total_number_of_changes(\@changes, 4);
274         # XXX test for both files in the commit, and no other files
275         is_most_recent_change(\@changes, $file2, $message);
276
277         $message = "remove the UTF-8 and binary files we just added";
278         IkiWiki::rcs_remove($_) for ($file1, $file2);
279         IkiWiki::rcs_commit_staged(message => $message);
280         ok(! -d "$config{srcdir}/test8", q{empty dir pruned by post-commit});
281         ok(! -d "$config{srcdir}/test10", q{empty dir pruned by post-commit});
282         @changes = IkiWiki::rcs_recentchanges(11);
283         is_total_number_of_changes(\@changes, 5);
284         # XXX test for both files in the commit, and no other files
285         is_most_recent_change(\@changes, $file2, $message);
286
287         $message = "re-add UTF-8 and binary files with names swapped";
288         writefile($file2, $config{srcdir}, readfile('t/test2.mdwn'));
289         writefile($file1, $config{srcdir}, $bindata_in, 1);
290         IkiWiki::rcs_add($_) for ($file1, $file2);
291         IkiWiki::rcs_commit_staged(message => $message);
292         isnt_newly_added($_) for ($file1, $file2);
293         is_in_keyword_substitution_mode($file2, q{-kkv});
294         is_in_keyword_substitution_mode($file1, q{-kb});
295         @changes = IkiWiki::rcs_recentchanges(11);
296         is_total_number_of_changes(\@changes, 6);
297         # XXX test for both files in the commit, and no other files
298         is_most_recent_change(\@changes, $file2, $message);
299
300         # prevent web edits from attempting to create .../CVS/foo.mdwn
301         # on case-insensitive filesystems, also prevent .../cvs/foo.mdwn
302         # unless your "CVS" is something else and we've made it configurable
303         # also want a pre-commit hook for this?
304
305         # pre-commit hook:
306         # - lcase filenames
307         # - ?
308
309         # can it assume we're under CVS control? or must it check?
310 }
311
312 sub test_rcs_remove {
313         # can it assume we're under CVS control? or must it check?
314         # remove a top-level file
315         # - rcs_commit
316         # - inspect recentchanges: one new change, file removed
317         # remove two files (in different dirs)
318         # - rcs_commit_staged
319         # - inspect recentchanges: one new change, both files removed
320 }
321
322 sub test_rcs_rename {
323         # can it assume we're under CVS control? or must it check?
324         # rename a file in the same dir
325         # - rcs_commit_staged
326         # - inspect recentchanges: one new change, one file removed, one added
327         # rename a file into a different dir
328         # - rcs_commit_staged
329         # - inspect recentchanges: one new change, one file removed, one added
330         # rename a file into a not-yet-existing dir
331         # - rcs_commit_staged
332         # - inspect recentchanges: one new change, one file removed, one added
333         # is it safe to use "mv"? what if $dest is somehow outside the wiki?
334 }
335
336 sub test_rcs_recentchanges {
337         my @changes = IkiWiki::rcs_recentchanges(3);
338         is_total_number_of_changes(\@changes, 0);
339
340         my $message = "Add a page via CVS directly";
341         my $file = q{test2.mdwn};
342         writefile($file, $config{srcdir}, readfile(q{t/test2.mdwn}));
343         system "cd $config{srcdir}"
344                 . " && cvs add $file >/dev/null 2>&1";
345         system "cd $config{srcdir}"
346                 . " && cvs commit -m \"$message\" $file >/dev/null";
347
348         @changes = IkiWiki::rcs_recentchanges(3);
349         is_total_number_of_changes(\@changes, 1);
350         is_most_recent_change(\@changes, stripext($file), $message);
351
352         # CVS commits run ikiwiki once for every committed file (!)
353         # - commit_prep alone should fix this
354         # CVS multi-dir commits show only the first dir in recentchanges
355         # - commit_prep might also fix this?
356         # CVS post-commit hook is amped off to avoid locking against itself
357         # - commit_prep probably doesn't fix this... but maybe?
358         # can it assume we're under CVS control? or must it check?
359         # don't worry whether we're called with a number (we always are)
360         # other rcs tests already inspect much of the returned structure
361         # CVS commits say "cvs" and get the right committer
362         # web commits say "web" and get the right committer
363         # - and don't start with "web commit {by,from} "
364         # "nickname" -- can we ever meaningfully set this?
365
366         # prefer log_accum, then cvsps, else die
367         # run the high-level recentchanges tests 2x (once for each method)
368         # - including in other test subs that check recentchanges?
369 }
370
371 sub test_rcs_diff {
372         my @changes = IkiWiki::rcs_recentchanges(3);
373         is_total_number_of_changes(\@changes, 0);
374
375         my $message = "add a UTF-8 and an ASCII file in different dirs";
376         my $file1 = "rcsdiff1/utf8.mdwn";
377         my $file2 = "rcsdiff2/ascii.mdwn";
378         my $contents2 = ''; $contents2 .= "$_. foo\n" for (1..11);
379         can_mkdir($_) for (qw(rcsdiff1 rcsdiff2));
380         writefile($file1, $config{srcdir}, readfile('t/test2.mdwn'));
381         writefile($file2, $config{srcdir}, $contents2);
382         IkiWiki::rcs_add($_) for ($file1, $file2);
383         IkiWiki::rcs_commit_staged(message => $message);
384
385         # XXX we rely on rcs_recentchanges() to be called first!
386         # XXX or else for no cvsps cache to exist yet...
387         # XXX because rcs_diff() doesn't pass -x (as an optimization)
388         @changes = IkiWiki::rcs_recentchanges(3);
389         is_total_number_of_changes(\@changes, 1);
390
391         my $changeset = 1;
392
393         my $maxlines = undef;
394         my $scalar_diffs = IkiWiki::rcs_diff($changeset, $maxlines);
395         like(
396                 $scalar_diffs,
397                 qr/^\+11\. foo$/m,
398                 q{unbounded scalar diffs go all the way to 11},
399         );
400         my @array_diffs = IkiWiki::rcs_diff($changeset, $maxlines);
401         is(
402                 $array_diffs[$#array_diffs],
403                 "+11. foo\n",
404                 q{unbounded array diffs go all the way to 11},
405         );
406
407         $maxlines = 8;
408         $scalar_diffs = IkiWiki::rcs_diff($changeset, $maxlines);
409         unlike(
410                 $scalar_diffs,
411                 qr/^\+11\. foo$/m,
412                 q{bounded scalar diffs don't go all the way to 11},
413         );
414         @array_diffs = IkiWiki::rcs_diff($changeset, $maxlines);
415         isnt(
416                 $array_diffs[$#array_diffs],
417                 "+11. foo\n",
418                 q{bounded array diffs don't go all the way to 11},
419         );
420         is(
421                 scalar @array_diffs,
422                 $maxlines,
423                 q{bounded array diffs contain expected maximum number of lines},
424         );
425
426         # can it assume we're under CVS control? or must it check?
427 }
428
429 sub test_rcs_getctime {
430         # can it assume we're under CVS control? or must it check?
431         # given a file, find its creation time, else return 0
432         # first implement in the obvious way
433         # then cache
434 }
435
436 sub test_rcs_getmtime {
437         # can it assume we're under CVS control? or must it check?
438         # given a file, find its modification time, else return 0
439         # first implement in the obvious way
440         # then cache
441 }
442
443 sub test_rcs_receive {
444         my $description = q{rcs_receive doesn't make sense for CVS};
445         exists $IkiWiki::hooks{rcs}{rcs_receive}
446                 ? fail($description)
447                 : pass($description);
448 }
449
450 sub test_rcs_preprevert {
451         # can it assume we're under CVS control? or must it check?
452         # given a patchset number, return structure describing what'd happen:
453         # - see doc/plugins/write.mdwn:rcs_receive()
454         # don't forget about attachments
455 }
456
457 sub test_rcs_revert {
458         # test rcs_recentchanges() real darn well
459         # extract read-backwards patchset parser from rcs_recentchanges()
460         # recentchanges: given max, return list of changeset/files/etc.
461         # revert: given changeset ID, return list of file/rev/action
462         #
463         # can it assume we're under CVS control? or must it check?
464         # given a patchset number, stage the revert for rcs_commit_staged()
465         # if commit succeeds, return undef
466         # else, warn and return error message (really? or just non-undef?)
467 }
468
469 sub main {
470         my $test_methods = defined $ENV{TEST_METHOD} 
471                          ? $ENV{TEST_METHOD}
472                          : $default_test_methods;
473
474         _startup($test_methods eq $default_test_methods);
475         _runtests(_get_matching_test_subs($test_methods));
476         _shutdown($test_methods eq $default_test_methods);
477 }
478
479 main();
480
481
482 # INTERNAL SUPPORT ROUTINES
483
484 sub _plan_for_test_more {
485         my $can_plan = shift;
486
487         foreach my $program (@required_programs) {
488                 my $program_path = `which $program`;
489                 chomp $program_path;
490                 return plan(skip_all => "$program not available")
491                         unless -x $program_path;
492         }
493
494         foreach my $module (@required_modules) {
495                 eval qq{use $module};
496                 return plan(skip_all => "$module not available")
497                         if $@;
498         }
499
500         return plan(skip_all => "can't create $dir: $!")
501                 unless mkdir($dir);
502         return plan(skip_all => "can't remove $dir: $!")
503                 unless rmdir($dir);
504
505         return unless $can_plan;
506
507         return plan(tests => $total_tests);
508 }
509
510 # http://stackoverflow.com/questions/607282/whats-the-best-way-to-discover-all-subroutines-a-perl-module-has
511
512 use B qw/svref_2object/;
513
514 sub in_package {
515         my ($coderef, $package) = @_;
516         my $cv = svref_2object($coderef);
517         return if not $cv->isa('B::CV') or $cv->GV->isa('B::SPECIAL');
518         return $cv->GV->STASH->NAME eq $package;
519 }
520
521 sub list_module {
522         my $module = shift;
523         no strict 'refs';
524         return grep {
525                 defined &{"$module\::$_"} and in_package(\&{*$_}, $module)
526         } keys %{"$module\::"};
527 }
528
529
530 # support for xUnit-style testing, a la Test::Class
531
532 sub _startup {
533         my $can_plan = shift;
534         _plan_for_test_more($can_plan);
535         hook(type => "genwrapper", id => "cvstest", call => \&_wrapper_paths);
536         _generate_test_config();
537 }
538
539 sub _shutdown {
540         my $had_plan = shift;
541         done_testing() unless $had_plan;
542 }
543
544 sub _setup {
545         _generate_test_repo();
546 }
547
548 sub _teardown {
549         system "rm -rf $dir";
550 }
551
552 sub _runtests {
553         my @coderefs = (@_);
554         for (@coderefs) {
555                 _setup();
556                 $_->();
557                 _teardown();
558         }
559 }
560
561 sub _get_matching_test_subs {
562         my $re = shift;
563         no strict 'refs';
564         return map { \&{*$_} } grep { /$re/ } sort(list_module('main'));
565 }
566
567 sub _generate_test_config {
568         %config = IkiWiki::defaultconfig();
569         $config{rcs} = "cvs";
570         $config{srcdir} = "$dir/src";
571         $config{allow_symlinks_before_srcdir} = 1;
572         $config{destdir} = "$dir/dest";
573         $config{cvsrepo} = "$dir/repo";
574         $config{cvspath} = "ikiwiki";
575         use Cwd; $config{templatedir} = getcwd() . '/templates';
576         IkiWiki::loadplugins();
577         IkiWiki::checkconfig();
578 }
579
580 sub _generate_test_repo {
581         die "can't create $dir: $!"
582                 unless mkdir($dir);
583
584         my $cvs = "cvs -d $config{cvsrepo}";
585         my $dn = ">/dev/null";
586
587         system "$cvs init $dn";
588         system "mkdir $dir/$config{cvspath} $dn";
589         system "cd $dir/$config{cvspath} && "
590                 . "$cvs import -m import $config{cvspath} VENDOR RELEASE $dn";
591         system "rm -rf $dir/$config{cvspath} $dn";
592         system "$cvs co -d $config{srcdir} $config{cvspath} $dn";
593
594         _generate_and_configure_post_commit_hook();
595 }
596
597 sub _generate_and_configure_post_commit_hook {
598         $config{cvs_wrapper} = $config{cvsrepo} . "/CVSROOT/test-post";
599         $config{wrapper} = $config{cvs_wrapper};
600
601         require IkiWiki::Wrapper;
602         {
603                 no warnings 'once';
604                 $IkiWiki::program_to_wrap = 'ikiwiki.out';
605                 # XXX substitute its interpreter to Makefile's $(PERL)
606                 # XXX best solution: do this to all scripts during build
607         }
608         IkiWiki::gen_wrapper();
609
610         my $cvs = "cvs -d $config{cvsrepo}";
611         my $dn = ">/dev/null";
612
613         system "mkdir $config{destdir} $dn";
614         system "cd $dir && $cvs co CVSROOT $dn && cd CVSROOT && " .
615                 "echo 'DEFAULT $config{cvsrepo}/CVSROOT/test-post %{sVv} &' "
616                 . " >> loginfo && "
617                 . "$cvs commit -m 'test repo setup' $dn && "
618                 . "cd .. && rm -rf CVSROOT";
619 }
620
621 sub add_and_commit {
622         my ($file, $message, $contents) = @_;
623         writefile($file, $config{srcdir}, $contents);
624         IkiWiki::rcs_add($file);
625         IkiWiki::rcs_commit(
626                 file => $file,
627                 message => $message,
628                 token => "moo",
629         );
630 }
631
632 sub can_mkdir {
633         my $dir = shift;
634         ok(
635                 mkdir($config{srcdir} . "/$dir"),
636                 qq{can mkdir $dir},
637         );
638 }
639
640 sub is_newly_added { _newly_added_or_not(shift, 1) }
641 sub isnt_newly_added { _newly_added_or_not(shift, 0) }
642 sub _newly_added_or_not {
643         my ($file, $expected_new) = @_;
644         my ($func, $word);
645         if ($expected_new) {
646                 $func = \&Test::More::is;
647                 $word = q{is};
648         }
649         else {
650                 $func = \&Test::More::isnt;
651                 $word = q{isn't};
652         }
653         $func->(
654                 IkiWiki::Plugin::cvs::cvs_info("Repository revision", $file),
655                 '1.1',
656                 qq{$file $word newly added to CVS},
657         );
658 }
659
660 sub is_in_keyword_substitution_mode {
661         my ($file, $mode) = @_;
662         is(
663                 IkiWiki::Plugin::cvs::cvs_info("Sticky Options", $file),
664                 $mode,
665                 qq{$file is in CVS with expected keyword substitution mode},
666         );
667 }
668
669 sub is_total_number_of_changes {
670         my ($changes, $expected_total) = @_;
671         is(
672                 $#{$changes},
673                 $expected_total - 1,
674                 qq{total commits == $expected_total},
675         );
676 }
677
678 sub is_most_recent_change {
679         my ($changes, $page, $message) = @_;
680         is(
681                 $changes->[0]{message}[0]{"line"},
682                 $message,
683                 q{most recent commit's first message line matches},
684         );
685         is(
686                 $changes->[0]{pages}[0]{"page"},
687                 $page,
688                 q{most recent commit's first pagename matches},
689         );
690 }
691
692 sub stripext {
693         my ($file, $extension) = @_;
694         $extension = '\..+?' unless defined $extension;
695         $file =~ s|$extension$||g;
696         return $file;
697 }
698
699 sub _wrapper_paths {
700         return qq{newenviron[i++]="PERL5LIB=$ENV{PERL5LIB}";};
701 }