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