X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/414ccfb1e298a722d2afa8b8540ca84dc1ccc6f2..8d4342183b1c3a96797def6fff96feebacb90db6:/t/cvs.t?ds=sidebyside diff --git a/t/cvs.t b/t/cvs.t index 12afc6687..6acafd701 100755 --- a/t/cvs.t +++ b/t/cvs.t @@ -1,9 +1,11 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More; my $total_tests = 57; +use Test::More; my $total_tests = 72; use IkiWiki; +my $installed = $ENV{INSTALLED_TESTS}; + my $default_test_methods = '^test_*'; my @required_programs = qw( cvs @@ -33,12 +35,7 @@ sub test_web_comments { } sub test_chdir_magic { - # cvs.pm operations are always occurring inside $config{srcdir} - # other ikiwiki operations are occurring wherever, and are unaffected # when are we bothering with "local $CWD" and when aren't we? - # after commit, presumably only with post-commit hook enabled: - #> Use of chdir('') or chdir(undef) as chdir() is deprecated at - #> /usr/pkg/lib/perl5/vendor_perl/5.14.0/File/chdir.pm line 45. } sub test_cvs_info { @@ -56,6 +53,7 @@ sub test_cvs_run_cvs { # 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 { @@ -177,7 +175,6 @@ sub test_rcs_commit { # - 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} " - # seeing File::chdir errors on commit? # XXX commit can fail due to "could not open lock file" } @@ -195,12 +192,19 @@ sub test_rcs_add { 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, undef); + is_in_keyword_substitution_mode($file, q{-kkv}); like( readfile($config{srcdir} . "/$file"), - qr/^# \$Id: $file,v 1.1 .+\$$/m, + 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/^

\$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); @@ -226,7 +230,7 @@ sub test_rcs_add { $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, undef); + 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); @@ -263,8 +267,8 @@ sub test_rcs_add { IkiWiki::rcs_add($_) for ($file1, $file2); IkiWiki::rcs_commit_staged(message => $message); is_newly_added($_) for ($file1, $file2); - is_in_keyword_substitution_mode($file1, undef); - is_in_keyword_substitution_mode($file2, '-kb'); + 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); @@ -272,15 +276,39 @@ sub test_rcs_add { # 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? - # can it assume we're under CVS control? or must it check? + # pre-commit hook: + # - lcase filenames + # - ? - # extract method: filetype-guessing - # add a binary file, remove it, add a text file by same name, no -kb? - # add a text file, remove it, add a binary file by same name, -kb? + # can it assume we're under CVS control? or must it check? } sub test_rcs_remove { @@ -362,6 +390,12 @@ sub test_rcs_diff { @changes = IkiWiki::rcs_recentchanges(3); is_total_number_of_changes(\@changes, 1); + unlike( + $changes[0]->{pages}->[0]->{diffurl}, + qr/%2F/m, + q{path separators are preserved when UTF-8scaping filename}, + ); + my $changeset = 1; my $maxlines = undef; @@ -506,6 +540,7 @@ sub list_module { sub _startup { my $can_plan = shift; _plan_for_test_more($can_plan); + hook(type => "genwrapper", id => "cvstest", call => \&_wrapper_paths); _generate_test_config(); } @@ -519,7 +554,6 @@ sub _setup { } sub _teardown { - # XXX does srcdir persist between test subs? system "rm -rf $dir"; } @@ -542,8 +576,12 @@ sub _generate_test_config { %config = IkiWiki::defaultconfig(); $config{rcs} = "cvs"; $config{srcdir} = "$dir/src"; + $config{allow_symlinks_before_srcdir} = 1; + $config{destdir} = "$dir/dest"; $config{cvsrepo} = "$dir/repo"; $config{cvspath} = "ikiwiki"; + use Cwd; $config{templatedir} = getcwd() . '/templates'; + $config{diffurl} = "/nonexistent/cvsweb/[[file]]"; IkiWiki::loadplugins(); IkiWiki::checkconfig(); } @@ -554,12 +592,41 @@ sub _generate_test_repo { my $cvs = "cvs -d $config{cvsrepo}"; my $dn = ">/dev/null"; + system "$cvs init $dn"; system "mkdir $dir/$config{cvspath} $dn"; system "cd $dir/$config{cvspath} && " . "$cvs import -m import $config{cvspath} VENDOR RELEASE $dn"; system "rm -rf $dir/$config{cvspath} $dn"; system "$cvs co -d $config{srcdir} $config{cvspath} $dn"; + + _generate_and_configure_post_commit_hook(); +} + +sub _generate_and_configure_post_commit_hook { + $config{cvs_wrapper} = $config{cvsrepo} . "/CVSROOT/test-post"; + $config{wrapper} = $config{cvs_wrapper}; + + require IkiWiki::Wrapper; + if ($installed) { + $IkiWiki::program_to_wrap = `which ikiwiki`; + } + else { + $IkiWiki::program_to_wrap = './ikiwiki.out'; + } + # XXX substitute its interpreter to Makefile's $(PERL) + # XXX best solution: do this to all scripts during build + IkiWiki::gen_wrapper(); + + my $cvs = "cvs -d $config{cvsrepo}"; + my $dn = ">/dev/null"; + + system "mkdir $config{destdir} $dn"; + system "cd $dir && $cvs co CVSROOT $dn && cd CVSROOT && " . + "echo 'DEFAULT $config{cvsrepo}/CVSROOT/test-post %{sVv} &' " + . " >> loginfo && " + . "$cvs commit -m 'test repo setup' $dn && " + . "cd .. && rm -rf CVSROOT"; } sub add_and_commit { @@ -581,18 +648,28 @@ sub can_mkdir { ); } -sub is_newly_added { - my $file = shift; - is( +sub is_newly_added { _newly_added_or_not(shift, 1) } +sub isnt_newly_added { _newly_added_or_not(shift, 0) } +sub _newly_added_or_not { + my ($file, $expected_new) = @_; + my ($func, $word); + if ($expected_new) { + $func = \&Test::More::is; + $word = q{is}; + } + else { + $func = \&Test::More::isnt; + $word = q{isn't}; + } + $func->( IkiWiki::Plugin::cvs::cvs_info("Repository revision", $file), '1.1', - qq{$file is newly added to CVS}, + qq{$file $word newly added to CVS}, ); } sub is_in_keyword_substitution_mode { my ($file, $mode) = @_; - $mode = '(none)' unless defined $mode; is( IkiWiki::Plugin::cvs::cvs_info("Sticky Options", $file), $mode, @@ -629,3 +706,7 @@ sub stripext { $file =~ s|$extension$||g; return $file; } + +sub _wrapper_paths { + return qq{addenv("PERL5LIB", "$ENV{PERL5LIB}");}; +}