]> sipb.mit.edu Git - ikiwiki.git/blob - t/cvs.t
style.css: Add compatability definitions for more block-level html5 elements. Closes...
[ikiwiki.git] / t / cvs.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More; my $total_tests = 72;
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         unlike(
392                 $changes[0]->{pages}->[0]->{diffurl},
393                 qr/%2F/m,
394                 q{path separators are preserved when UTF-8scaping filename},
395         );
396
397         my $changeset = 1;
398
399         my $maxlines = undef;
400         my $scalar_diffs = IkiWiki::rcs_diff($changeset, $maxlines);
401         like(
402                 $scalar_diffs,
403                 qr/^\+11\. foo$/m,
404                 q{unbounded scalar diffs go all the way to 11},
405         );
406         my @array_diffs = IkiWiki::rcs_diff($changeset, $maxlines);
407         is(
408                 $array_diffs[$#array_diffs],
409                 "+11. foo\n",
410                 q{unbounded array diffs go all the way to 11},
411         );
412
413         $maxlines = 8;
414         $scalar_diffs = IkiWiki::rcs_diff($changeset, $maxlines);
415         unlike(
416                 $scalar_diffs,
417                 qr/^\+11\. foo$/m,
418                 q{bounded scalar diffs don't go all the way to 11},
419         );
420         @array_diffs = IkiWiki::rcs_diff($changeset, $maxlines);
421         isnt(
422                 $array_diffs[$#array_diffs],
423                 "+11. foo\n",
424                 q{bounded array diffs don't go all the way to 11},
425         );
426         is(
427                 scalar @array_diffs,
428                 $maxlines,
429                 q{bounded array diffs contain expected maximum number of lines},
430         );
431
432         # can it assume we're under CVS control? or must it check?
433 }
434
435 sub test_rcs_getctime {
436         # can it assume we're under CVS control? or must it check?
437         # given a file, find its creation time, else return 0
438         # first implement in the obvious way
439         # then cache
440 }
441
442 sub test_rcs_getmtime {
443         # can it assume we're under CVS control? or must it check?
444         # given a file, find its modification time, else return 0
445         # first implement in the obvious way
446         # then cache
447 }
448
449 sub test_rcs_receive {
450         my $description = q{rcs_receive doesn't make sense for CVS};
451         exists $IkiWiki::hooks{rcs}{rcs_receive}
452                 ? fail($description)
453                 : pass($description);
454 }
455
456 sub test_rcs_preprevert {
457         # can it assume we're under CVS control? or must it check?
458         # given a patchset number, return structure describing what'd happen:
459         # - see doc/plugins/write.mdwn:rcs_receive()
460         # don't forget about attachments
461 }
462
463 sub test_rcs_revert {
464         # test rcs_recentchanges() real darn well
465         # extract read-backwards patchset parser from rcs_recentchanges()
466         # recentchanges: given max, return list of changeset/files/etc.
467         # revert: given changeset ID, return list of file/rev/action
468         #
469         # can it assume we're under CVS control? or must it check?
470         # given a patchset number, stage the revert for rcs_commit_staged()
471         # if commit succeeds, return undef
472         # else, warn and return error message (really? or just non-undef?)
473 }
474
475 sub main {
476         my $test_methods = defined $ENV{TEST_METHOD} 
477                          ? $ENV{TEST_METHOD}
478                          : $default_test_methods;
479
480         _startup($test_methods eq $default_test_methods);
481         _runtests(_get_matching_test_subs($test_methods));
482         _shutdown($test_methods eq $default_test_methods);
483 }
484
485 main();
486
487
488 # INTERNAL SUPPORT ROUTINES
489
490 sub _plan_for_test_more {
491         my $can_plan = shift;
492
493         foreach my $program (@required_programs) {
494                 my $program_path = `which $program`;
495                 chomp $program_path;
496                 return plan(skip_all => "$program not available")
497                         unless -x $program_path;
498         }
499
500         foreach my $module (@required_modules) {
501                 eval qq{use $module};
502                 return plan(skip_all => "$module not available")
503                         if $@;
504         }
505
506         return plan(skip_all => "can't create $dir: $!")
507                 unless mkdir($dir);
508         return plan(skip_all => "can't remove $dir: $!")
509                 unless rmdir($dir);
510
511         return unless $can_plan;
512
513         return plan(tests => $total_tests);
514 }
515
516 # http://stackoverflow.com/questions/607282/whats-the-best-way-to-discover-all-subroutines-a-perl-module-has
517
518 use B qw/svref_2object/;
519
520 sub in_package {
521         my ($coderef, $package) = @_;
522         my $cv = svref_2object($coderef);
523         return if not $cv->isa('B::CV') or $cv->GV->isa('B::SPECIAL');
524         return $cv->GV->STASH->NAME eq $package;
525 }
526
527 sub list_module {
528         my $module = shift;
529         no strict 'refs';
530         return grep {
531                 defined &{"$module\::$_"} and in_package(\&{*$_}, $module)
532         } keys %{"$module\::"};
533 }
534
535
536 # support for xUnit-style testing, a la Test::Class
537
538 sub _startup {
539         my $can_plan = shift;
540         _plan_for_test_more($can_plan);
541         hook(type => "genwrapper", id => "cvstest", call => \&_wrapper_paths);
542         _generate_test_config();
543 }
544
545 sub _shutdown {
546         my $had_plan = shift;
547         done_testing() unless $had_plan;
548 }
549
550 sub _setup {
551         _generate_test_repo();
552 }
553
554 sub _teardown {
555         system "rm -rf $dir";
556 }
557
558 sub _runtests {
559         my @coderefs = (@_);
560         for (@coderefs) {
561                 _setup();
562                 $_->();
563                 _teardown();
564         }
565 }
566
567 sub _get_matching_test_subs {
568         my $re = shift;
569         no strict 'refs';
570         return map { \&{*$_} } grep { /$re/ } sort(list_module('main'));
571 }
572
573 sub _generate_test_config {
574         %config = IkiWiki::defaultconfig();
575         $config{rcs} = "cvs";
576         $config{srcdir} = "$dir/src";
577         $config{allow_symlinks_before_srcdir} = 1;
578         $config{destdir} = "$dir/dest";
579         $config{cvsrepo} = "$dir/repo";
580         $config{cvspath} = "ikiwiki";
581         use Cwd; $config{templatedir} = getcwd() . '/templates';
582         $config{diffurl} = "/nonexistent/cvsweb/[[file]]";
583         IkiWiki::loadplugins();
584         IkiWiki::checkconfig();
585 }
586
587 sub _generate_test_repo {
588         die "can't create $dir: $!"
589                 unless mkdir($dir);
590
591         my $cvs = "cvs -d $config{cvsrepo}";
592         my $dn = ">/dev/null";
593
594         system "$cvs init $dn";
595         system "mkdir $dir/$config{cvspath} $dn";
596         system "cd $dir/$config{cvspath} && "
597                 . "$cvs import -m import $config{cvspath} VENDOR RELEASE $dn";
598         system "rm -rf $dir/$config{cvspath} $dn";
599         system "$cvs co -d $config{srcdir} $config{cvspath} $dn";
600
601         _generate_and_configure_post_commit_hook();
602 }
603
604 sub _generate_and_configure_post_commit_hook {
605         $config{cvs_wrapper} = $config{cvsrepo} . "/CVSROOT/test-post";
606         $config{wrapper} = $config{cvs_wrapper};
607
608         require IkiWiki::Wrapper;
609         {
610                 no warnings 'once';
611                 $IkiWiki::program_to_wrap = 'ikiwiki.out';
612                 # XXX substitute its interpreter to Makefile's $(PERL)
613                 # XXX best solution: do this to all scripts during build
614         }
615         IkiWiki::gen_wrapper();
616
617         my $cvs = "cvs -d $config{cvsrepo}";
618         my $dn = ">/dev/null";
619
620         system "mkdir $config{destdir} $dn";
621         system "cd $dir && $cvs co CVSROOT $dn && cd CVSROOT && " .
622                 "echo 'DEFAULT $config{cvsrepo}/CVSROOT/test-post %{sVv} &' "
623                 . " >> loginfo && "
624                 . "$cvs commit -m 'test repo setup' $dn && "
625                 . "cd .. && rm -rf CVSROOT";
626 }
627
628 sub add_and_commit {
629         my ($file, $message, $contents) = @_;
630         writefile($file, $config{srcdir}, $contents);
631         IkiWiki::rcs_add($file);
632         IkiWiki::rcs_commit(
633                 file => $file,
634                 message => $message,
635                 token => "moo",
636         );
637 }
638
639 sub can_mkdir {
640         my $dir = shift;
641         ok(
642                 mkdir($config{srcdir} . "/$dir"),
643                 qq{can mkdir $dir},
644         );
645 }
646
647 sub is_newly_added { _newly_added_or_not(shift, 1) }
648 sub isnt_newly_added { _newly_added_or_not(shift, 0) }
649 sub _newly_added_or_not {
650         my ($file, $expected_new) = @_;
651         my ($func, $word);
652         if ($expected_new) {
653                 $func = \&Test::More::is;
654                 $word = q{is};
655         }
656         else {
657                 $func = \&Test::More::isnt;
658                 $word = q{isn't};
659         }
660         $func->(
661                 IkiWiki::Plugin::cvs::cvs_info("Repository revision", $file),
662                 '1.1',
663                 qq{$file $word newly added to CVS},
664         );
665 }
666
667 sub is_in_keyword_substitution_mode {
668         my ($file, $mode) = @_;
669         is(
670                 IkiWiki::Plugin::cvs::cvs_info("Sticky Options", $file),
671                 $mode,
672                 qq{$file is in CVS with expected keyword substitution mode},
673         );
674 }
675
676 sub is_total_number_of_changes {
677         my ($changes, $expected_total) = @_;
678         is(
679                 $#{$changes},
680                 $expected_total - 1,
681                 qq{total commits == $expected_total},
682         );
683 }
684
685 sub is_most_recent_change {
686         my ($changes, $page, $message) = @_;
687         is(
688                 $changes->[0]{message}[0]{"line"},
689                 $message,
690                 q{most recent commit's first message line matches},
691         );
692         is(
693                 $changes->[0]{pages}[0]{"page"},
694                 $page,
695                 q{most recent commit's first pagename matches},
696         );
697 }
698
699 sub stripext {
700         my ($file, $extension) = @_;
701         $extension = '\..+?' unless defined $extension;
702         $file =~ s|$extension$||g;
703         return $file;
704 }
705
706 sub _wrapper_paths {
707         return qq{newenviron[i++]="PERL5LIB=$ENV{PERL5LIB}";};
708 }