X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/1ea4949257c52b799c37888d05c52acf20663229..16572fb0b40bd09ff235991bd0ee03113a488fa3:/t/cvs.t diff --git a/t/cvs.t b/t/cvs.t index a8f1254ef..bb6e3e90a 100755 --- a/t/cvs.t +++ b/t/cvs.t @@ -1,72 +1,27 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More; my $total_tests = 10; +use Test::More; my $total_tests = 9; use IkiWiki; +my $default_test_methods = '^test_*'; +my @required_programs = qw( + cvs + cvsps +); +my @required_modules = qw( + File::chdir + File::MimeInfo + Date::Parse + File::Temp + File::ReadBackwards +); my $dir = "/tmp/ikiwiki-test-cvs.$$"; -sub _plan { - my $can_plan = shift; - - my $cvs = `which cvs`; chomp $cvs; - my $cvsps = `which cvsps`; chomp $cvsps; - return plan(skip_all => 'cvs or cvsps not available') - unless -x $cvs && -x $cvsps; - - foreach my $module (qw(File::ReadBackwards File::MimeInfo)) { - eval qq{use $module}; - if ($@) { - return plan(skip_all => "$module not available"); - } - } - - return plan(skip_all => "can't create $dir: $!") - unless mkdir($dir); - - return unless $can_plan; - - return plan(tests => $total_tests); -} - -sub _startup { - my $can_plan = shift; - - _plan($can_plan); - _generate_minimal_config(); - _create_test_repo(); -} - -sub _shutdown { - my $had_plan = shift; - - system "rm -rf $dir"; - done_testing() unless $had_plan; -} - -sub _generate_minimal_config { - %config = IkiWiki::defaultconfig(); - $config{rcs} = "cvs"; - $config{srcdir} = "$dir/src"; - $config{cvsrepo} = "$dir/repo"; - $config{cvspath} = "ikiwiki"; - IkiWiki::loadplugins(); - IkiWiki::checkconfig(); -} - -sub _create_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"; -} +# TESTS FOR GENERAL META-BEHAVIOR sub test_web_add_and_commit { - my $message = "Added the first page"; + my $message = "Add a page via VCS API"; writefile('test1.mdwn', $config{srcdir}, readfile("t/test1.mdwn")); IkiWiki::rcs_add("test1.mdwn"); IkiWiki::rcs_commit( @@ -106,7 +61,7 @@ sub test_web_add_and_commit { } sub test_manual_add_and_commit { - my $message = "Added the second page"; + my $message = "Add a page via CVS directly"; writefile('test2.mdwn', $config{srcdir}, readfile("t/test2.mdwn")); system "cd $config{srcdir}" . " && cvs add test2.mdwn >/dev/null 2>&1"; @@ -116,8 +71,8 @@ sub test_manual_add_and_commit { my @changes = IkiWiki::rcs_recentchanges(3); is( $#changes, - 1, - q{2 total commits}, + 0, + q{1 total commit}, ); is( $changes[0]{message}[0]{"line"}, @@ -129,11 +84,6 @@ sub test_manual_add_and_commit { "test2", q{first pagename from most recent commit matches}, ); - is( - $changes[1]{pages}[0]{"page"}, - "test1", - q{first pagename from second-most-recent commit matches}, - ); # CVS commits run ikiwiki once for every committed file (!) # - commit_prep alone should fix this @@ -149,32 +99,6 @@ sub test_chdir_magic { # when are we bothering with "local $CWD" and when aren't we? } -sub test_genwrapper { - # testable directly? affects rcs_add, but are we exercising this? -} - -sub test_checkconfig { - # undef cvspath, expect "ikiwiki" - # define cvspath normally, get it back - # define cvspath in a subdir, get it back? - # define cvspath with extra slashes, get sanitized version back - # - yoink test_extra_path_slashes - # undef cvs_wrapper, expect $config{wrappers} same size as before - - my $initial_cvspath = $config{cvspath}; - $config{cvspath} = "/ikiwiki//"; - IkiWiki::checkconfig(); - is( - $config{cvspath}, - $initial_cvspath, - q{rcs_recentchanges assumes checkconfig has sanitized cvspath}, - ); -} - -sub test_getsetup { - # anything worth testing? -} - sub test_cvs_info { # inspect "Repository revision" (used in code) # inspect "Sticky Options" (used in tests to verify existence of "-kb") @@ -228,6 +152,38 @@ sub test_cvs_is_controlling { # - else, die } + +# TESTS FOR GENERAL PLUGIN API CALLS + +sub test_checkconfig { + # undef cvspath, expect "ikiwiki" + # define cvspath normally, get it back + # define cvspath in a subdir, get it back? + # define cvspath with extra slashes, get sanitized version back + # - yoink test_extra_path_slashes + # undef cvs_wrapper, expect $config{wrappers} same size as before + + my $initial_cvspath = $config{cvspath}; + $config{cvspath} = "/ikiwiki//"; + IkiWiki::checkconfig(); + is( + $config{cvspath}, + $initial_cvspath, + q{rcs_recentchanges assumes checkconfig has sanitized cvspath}, + ); +} + +sub test_getsetup { + # anything worth testing? +} + +sub test_genwrapper { + # testable directly? affects rcs_add, but are we exercising this? +} + + +# TESTS FOR VCS PLUGIN API CALLS + sub test_rcs_update { # can it assume we're under CVS control? or must it check? # anything else worth testing? @@ -374,25 +330,44 @@ sub test_rcs_revert { } sub main { - my $default_test_methods = '^test_*'; my $test_methods = defined $ENV{TEST_METHOD} ? $ENV{TEST_METHOD} : $default_test_methods; _startup($test_methods eq $default_test_methods); - $_->() foreach get_test_subs($test_methods); + _runtests(_get_matching_test_subs($test_methods)); _shutdown($test_methods eq $default_test_methods); } main(); -################################################################################ -# don't want a dependency on Test::Class; do want a couple of its features -sub get_test_subs { - my $re = shift; - no strict 'refs'; - return map { \&{*$_} } grep { /$re/ } list_module('main'); +# INTERNAL SUPPORT ROUTINES + +sub _plan_for_test_more { + my $can_plan = shift; + + foreach my $program (@required_programs) { + my $program_path = `which $program`; + chomp $program_path; + return plan(skip_all => "$program not available") + unless -x $program_path; + } + + foreach my $module (@required_modules) { + eval qq{use $module}; + return plan(skip_all => "$module not available") + if $@; + } + + return plan(skip_all => "can't create $dir: $!") + unless mkdir($dir); + return plan(skip_all => "can't remove $dir: $!") + unless rmdir($dir); + + return unless $can_plan; + + return plan(tests => $total_tests); } # http://stackoverflow.com/questions/607282/whats-the-best-way-to-discover-all-subroutines-a-perl-module-has @@ -413,3 +388,64 @@ sub list_module { defined &{"$module\::$_"} and in_package(\&{*$_}, $module) } keys %{"$module\::"}; } + + +# support for xUnit-style testing, a la Test::Class + +sub _startup { + my $can_plan = shift; + _plan_for_test_more($can_plan); + _generate_test_config(); +} + +sub _shutdown { + my $had_plan = shift; + done_testing() unless $had_plan; +} + +sub _setup { + _generate_test_repo(); +} + +sub _teardown { + system "rm -rf $dir"; +} + +sub _runtests { + my @coderefs = (@_); + for (@coderefs) { + _setup(); + $_->(); + _teardown(); + } +} + +sub _get_matching_test_subs { + my $re = shift; + no strict 'refs'; + return map { \&{*$_} } grep { /$re/ } sort(list_module('main')); +} + +sub _generate_test_config { + %config = IkiWiki::defaultconfig(); + $config{rcs} = "cvs"; + $config{srcdir} = "$dir/src"; + $config{cvsrepo} = "$dir/repo"; + $config{cvspath} = "ikiwiki"; + IkiWiki::loadplugins(); + IkiWiki::checkconfig(); +} + +sub _generate_test_repo { + die "can't create $dir: $!" + unless mkdir($dir); + + 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"; +}