From de04fd539805cc38e747ea684ada03d65903e34f Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Sun, 8 Jan 2012 13:33:04 -0500 Subject: [PATCH 1/9] add TODO notes --- TODO.cvs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 TODO.cvs diff --git a/TODO.cvs b/TODO.cvs new file mode 100644 index 000000000..bf92a00ce --- /dev/null +++ b/TODO.cvs @@ -0,0 +1,20 @@ +* write test cases: + * web edits can create CVS/foo.mdwn (and think of case-insensitive "cvs/") + * binary file detection + * `cvsps` output format + * `findtimes()` +* `File::MimeInfo::default()` wrongly marks some text files `-kb` + * stop doing it + * find and fix existing +* instead of reading backwards, write one changeset per file and + `ls | sort -nr | head -100` + * obviates need for File::ReadBackwards +* parameterize `cvsps` command +* when is `-x` overkill? ever? +* `-b HEAD`, always? +* use `open()` instead of `system()` +* implement the time optimizations +* use `cvs_runcvs` everywhere `cvs` is run +* set up `log_accum` and `commit_prep` in `ikiwiki-makerepo` + * obviates need for `cvsps` +* historyurl overzealously escapes path slashes? From 700d39d765e59f45d15d5b6dd81c187947bd308d Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Sun, 8 Jan 2012 13:33:04 -0500 Subject: [PATCH 2/9] add TODO notes --- TODO.cvs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 TODO.cvs diff --git a/TODO.cvs b/TODO.cvs new file mode 100644 index 000000000..bf92a00ce --- /dev/null +++ b/TODO.cvs @@ -0,0 +1,20 @@ +* write test cases: + * web edits can create CVS/foo.mdwn (and think of case-insensitive "cvs/") + * binary file detection + * `cvsps` output format + * `findtimes()` +* `File::MimeInfo::default()` wrongly marks some text files `-kb` + * stop doing it + * find and fix existing +* instead of reading backwards, write one changeset per file and + `ls | sort -nr | head -100` + * obviates need for File::ReadBackwards +* parameterize `cvsps` command +* when is `-x` overkill? ever? +* `-b HEAD`, always? +* use `open()` instead of `system()` +* implement the time optimizations +* use `cvs_runcvs` everywhere `cvs` is run +* set up `log_accum` and `commit_prep` in `ikiwiki-makerepo` + * obviates need for `cvsps` +* historyurl overzealously escapes path slashes? From 94c1f3bd337f53119d8e28fead322e85f000253e Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Sat, 21 Jan 2012 14:37:24 -0500 Subject: [PATCH 3/9] Extract subs: startup/shutdown, and tests for web and manual commits. No functional change intended. --- t/cvs.t | 111 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 64 insertions(+), 47 deletions(-) diff --git a/t/cvs.t b/t/cvs.t index 5ed377ed5..2937ac2ed 100755 --- a/t/cvs.t +++ b/t/cvs.t @@ -29,60 +29,77 @@ use Test::More tests => 12; BEGIN { use_ok("IkiWiki"); } -%config=IkiWiki::defaultconfig(); -$config{rcs} = "cvs"; -$config{srcdir} = "$dir/src"; -$config{cvsrepo} = "$dir/repo"; -$config{cvspath} = "ikiwiki"; -IkiWiki::loadplugins(); -IkiWiki::checkconfig(); +sub _startup { + _generate_minimal_config(); + _create_test_repo(); +} -my $cvsrepo = "$dir/repo"; +sub _shutdown { + system "rm -rf $dir"; +} -system "cvs -d $cvsrepo init >/dev/null"; -system "mkdir $dir/ikiwiki >/dev/null"; -system "cd $dir/ikiwiki && cvs -d $cvsrepo import -m import ikiwiki VENDOR RELEASE >/dev/null"; -system "rm -rf $dir/ikiwiki >/dev/null"; -system "cvs -d $cvsrepo co -d $config{srcdir} ikiwiki >/dev/null"; +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(); +} -# Web commit -my $test1 = readfile("t/test1.mdwn"); -writefile('test1.mdwn', $config{srcdir}, $test1); -IkiWiki::rcs_add("test1.mdwn"); -IkiWiki::rcs_commit( - files => "test1.mdwn", - message => "Added the first page", - token => "moo" -); +sub _create_test_repo { + my $cvsrepo = "$dir/repo"; -my @changes; -@changes = IkiWiki::rcs_recentchanges(3); + system "cvs -d $cvsrepo init >/dev/null"; + system "mkdir $dir/ikiwiki >/dev/null"; + system "cd $dir/ikiwiki && cvs -d $cvsrepo import -m import ikiwiki VENDOR RELEASE >/dev/null"; + system "rm -rf $dir/ikiwiki >/dev/null"; + system "cvs -d $cvsrepo co -d $config{srcdir} ikiwiki >/dev/null"; +} -is($#changes, 0); -is($changes[0]{message}[0]{"line"}, "Added the first page"); -is($changes[0]{pages}[0]{"page"}, "test1"); +sub test_web_commit { + my $test1 = readfile("t/test1.mdwn"); + writefile('test1.mdwn', $config{srcdir}, $test1); + IkiWiki::rcs_add("test1.mdwn"); + IkiWiki::rcs_commit( + files => "test1.mdwn", + message => "Added the first page", + token => "moo" + ); -# Manual commit -my $message = "Added the second page"; + my @changes = IkiWiki::rcs_recentchanges(3); -my $test2 = readfile("t/test2.mdwn"); -writefile('test2.mdwn', $config{srcdir}, $test2); -system "cd $config{srcdir} && cvs add test2.mdwn >/dev/null 2>&1"; -system "cd $config{srcdir} && cvs commit -m \"$message\" test2.mdwn >/dev/null"; + is($#changes, 0); + is($changes[0]{message}[0]{"line"}, "Added the first page"); + is($changes[0]{pages}[0]{"page"}, "test1"); +} -@changes = IkiWiki::rcs_recentchanges(3); -is($#changes, 1); -is($changes[0]{message}[0]{"line"}, $message); -is($changes[0]{pages}[0]{"page"}, "test2"); -is($changes[1]{pages}[0]{"page"}, "test1"); +sub test_manual_commit { + my $message = "Added the second page"; -# extra slashes in the path shouldn't break things -$config{cvspath} = "/ikiwiki//"; -IkiWiki::checkconfig(); -@changes = IkiWiki::rcs_recentchanges(3); -is($#changes, 1); -is($changes[0]{message}[0]{"line"}, $message); -is($changes[0]{pages}[0]{"page"}, "test2"); -is($changes[1]{pages}[0]{"page"}, "test1"); + my $test2 = readfile("t/test2.mdwn"); + writefile('test2.mdwn', $config{srcdir}, $test2); + system "cd $config{srcdir} && cvs add test2.mdwn >/dev/null 2>&1"; + system "cd $config{srcdir} && cvs commit -m \"$message\" test2.mdwn >/dev/null"; -system "rm -rf $dir"; + my @changes = IkiWiki::rcs_recentchanges(3); + is($#changes, 1); + is($changes[0]{message}[0]{"line"}, $message); + is($changes[0]{pages}[0]{"page"}, "test2"); + is($changes[1]{pages}[0]{"page"}, "test1"); + + # extra slashes in the path shouldn't break things + $config{cvspath} = "/ikiwiki//"; + IkiWiki::checkconfig(); + @changes = IkiWiki::rcs_recentchanges(3); + is($#changes, 1); + is($changes[0]{message}[0]{"line"}, $message); + is($changes[0]{pages}[0]{"page"}, "test2"); + is($changes[1]{pages}[0]{"page"}, "test1"); +} + +_startup(); +test_web_commit(); +test_manual_commit(); +_shutdown(); From bcb69f8fed4dbdb9e0ec10955319e17b663eb538 Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Sat, 21 Jan 2012 15:00:52 -0500 Subject: [PATCH 4/9] Simplify startup: use Test::More unconditionally, then determine the test plan at runtime. Use IkiWiki unconditionally too (as that's not what I'm testing here) to avoid the TAP error of printing a test result before having printed the plan. --- t/cvs.t | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/t/cvs.t b/t/cvs.t index 2937ac2ed..fdd26dbc8 100755 --- a/t/cvs.t +++ b/t/cvs.t @@ -1,35 +1,30 @@ #!/usr/bin/perl use warnings; use strict; +use Test::More; +use IkiWiki; + my $dir; -BEGIN { - $dir="/tmp/ikiwiki-test-cvs.$$"; - my $cvs=`which cvs`; - chomp $cvs; - my $cvsps=`which cvsps`; - chomp $cvsps; - if (! -x $cvs || ! -x $cvsps) { - eval q{ - use Test::More skip_all => "cvs or cvsps not available" - } - } - if (! mkdir($dir)) { - die $@; - } + +sub _determine_test_plan { + + my $cvs=`which cvs`; chomp $cvs; + my $cvsps=`which cvsps`; chomp $cvsps; + return (skip_all => 'cvs or cvsps not available') + unless -x $cvs && -x $cvsps; + foreach my $module ('File::ReadBackwards', 'File::MimeInfo') { eval qq{use $module}; if ($@) { - eval qq{ - use Test::More skip_all => "$module not available" - } + return (skip_all => "$module not available"); } } -} -use Test::More tests => 12; -BEGIN { use_ok("IkiWiki"); } + return (tests => 11); +} sub _startup { + _mktempdir(); _generate_minimal_config(); _create_test_repo(); } @@ -38,6 +33,13 @@ sub _shutdown { system "rm -rf $dir"; } +sub _mktempdir { + $dir="/tmp/ikiwiki-test-cvs.$$"; + if (! mkdir($dir)) { + die $@; + } +} + sub _generate_minimal_config { %config=IkiWiki::defaultconfig(); $config{rcs} = "cvs"; @@ -99,6 +101,7 @@ sub test_manual_commit { is($changes[1]{pages}[0]{"page"}, "test1"); } +plan(_determine_test_plan()); _startup(); test_web_commit(); test_manual_commit(); From 2586346231eda2c4f04f2d063ed0f569d46ccf0f Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Sat, 21 Jan 2012 15:25:57 -0500 Subject: [PATCH 5/9] Fix a typo in the web commit test. --- t/cvs.t | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/t/cvs.t b/t/cvs.t index fdd26dbc8..c4e9eb276 100755 --- a/t/cvs.t +++ b/t/cvs.t @@ -7,7 +7,6 @@ use IkiWiki; my $dir; sub _determine_test_plan { - my $cvs=`which cvs`; chomp $cvs; my $cvsps=`which cvsps`; chomp $cvsps; return (skip_all => 'cvs or cvsps not available') @@ -65,9 +64,9 @@ sub test_web_commit { writefile('test1.mdwn', $config{srcdir}, $test1); IkiWiki::rcs_add("test1.mdwn"); IkiWiki::rcs_commit( - files => "test1.mdwn", + file => "test1.mdwn", message => "Added the first page", - token => "moo" + token => "moo", ); my @changes = IkiWiki::rcs_recentchanges(3); From 9e5ee1475aad8397f52ce330624e0038efd93d20 Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Sat, 21 Jan 2012 20:17:52 -0500 Subject: [PATCH 6/9] * Define expected number of tests near the top. * Call readfile() directly from writefile(). * Parameterize commit message for the web-commit case. * Describe intent of test cases. * Rename test subs to match what they actually do. * To prove extra path slashes don't cause trouble, instead of running the same tests a second time, just assert that checkconfig() strips the slashes. --- t/cvs.t | 81 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/t/cvs.t b/t/cvs.t index c4e9eb276..af1786c65 100755 --- a/t/cvs.t +++ b/t/cvs.t @@ -4,6 +4,7 @@ use strict; use Test::More; use IkiWiki; +my %ideal_test_plan = (tests => 8); my $dir; sub _determine_test_plan { @@ -19,7 +20,7 @@ sub _determine_test_plan { } } - return (tests => 11); + return %ideal_test_plan; } sub _startup { @@ -59,49 +60,77 @@ sub _create_test_repo { system "cvs -d $cvsrepo co -d $config{srcdir} ikiwiki >/dev/null"; } -sub test_web_commit { - my $test1 = readfile("t/test1.mdwn"); - writefile('test1.mdwn', $config{srcdir}, $test1); +sub test_web_add_and_commit { + writefile('test1.mdwn', $config{srcdir}, readfile("t/test1.mdwn")); IkiWiki::rcs_add("test1.mdwn"); + my $message = "Added the first page"; IkiWiki::rcs_commit( file => "test1.mdwn", - message => "Added the first page", + message => $message, token => "moo", ); my @changes = IkiWiki::rcs_recentchanges(3); - - is($#changes, 0); - is($changes[0]{message}[0]{"line"}, "Added the first page"); - is($changes[0]{pages}[0]{"page"}, "test1"); + is( + $#changes, + 0, + q{1 total commit}, + ); + is( + $changes[0]{message}[0]{"line"}, + $message, + q{first line of most recent commit message matches}, + ); + is( + $changes[0]{pages}[0]{"page"}, + "test1", + q{first pagename from most recent commit matches}, + ); } -sub test_manual_commit { - my $message = "Added the second page"; - - my $test2 = readfile("t/test2.mdwn"); - writefile('test2.mdwn', $config{srcdir}, $test2); +sub test_manual_add_and_commit { + writefile('test2.mdwn', $config{srcdir}, readfile("t/test2.mdwn")); system "cd $config{srcdir} && cvs add test2.mdwn >/dev/null 2>&1"; + my $message = "Added the second page"; system "cd $config{srcdir} && cvs commit -m \"$message\" test2.mdwn >/dev/null"; my @changes = IkiWiki::rcs_recentchanges(3); - is($#changes, 1); - is($changes[0]{message}[0]{"line"}, $message); - is($changes[0]{pages}[0]{"page"}, "test2"); - is($changes[1]{pages}[0]{"page"}, "test1"); + is( + $#changes, + 1, + q{2 total commits}, + ); + is( + $changes[0]{message}[0]{"line"}, + $message, + q{first line of most recent commit message matches}, + ); + is( + $changes[0]{pages}[0]{"page"}, + "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}, + ); +} - # extra slashes in the path shouldn't break things +sub test_extra_path_slashes { + my $initial_cvspath = $config{cvspath}; $config{cvspath} = "/ikiwiki//"; IkiWiki::checkconfig(); - @changes = IkiWiki::rcs_recentchanges(3); - is($#changes, 1); - is($changes[0]{message}[0]{"line"}, $message); - is($changes[0]{pages}[0]{"page"}, "test2"); - is($changes[1]{pages}[0]{"page"}, "test1"); + is( + $config{cvspath}, + $initial_cvspath, + q{rcs_recentchanges assumes checkconfig sanitizes cvspath}, + ); } plan(_determine_test_plan()); _startup(); -test_web_commit(); -test_manual_commit(); +test_web_add_and_commit(); +test_manual_add_and_commit(); +test_extra_path_slashes(); _shutdown(); From 302643fb4e4b79b7d92cc6b1279b47b209926dc5 Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Sat, 21 Jan 2012 20:40:20 -0500 Subject: [PATCH 7/9] Use config parameters directly and shorten long lines. --- t/cvs.t | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/t/cvs.t b/t/cvs.t index af1786c65..8b5bbb568 100755 --- a/t/cvs.t +++ b/t/cvs.t @@ -51,13 +51,14 @@ sub _generate_minimal_config { } sub _create_test_repo { - my $cvsrepo = "$dir/repo"; - - system "cvs -d $cvsrepo init >/dev/null"; - system "mkdir $dir/ikiwiki >/dev/null"; - system "cd $dir/ikiwiki && cvs -d $cvsrepo import -m import ikiwiki VENDOR RELEASE >/dev/null"; - system "rm -rf $dir/ikiwiki >/dev/null"; - system "cvs -d $cvsrepo co -d $config{srcdir} ikiwiki >/dev/null"; + 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"; } sub test_web_add_and_commit { From fe1c7ea12625b2640fe54e4dfb037e9ae498911d Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Sat, 21 Jan 2012 20:54:26 -0500 Subject: [PATCH 8/9] Fix regression: failing to make the temp dir should nix the test plan. While here, nitpick style and wrap long lines. --- t/cvs.t | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/t/cvs.t b/t/cvs.t index 8b5bbb568..b216a88d6 100755 --- a/t/cvs.t +++ b/t/cvs.t @@ -8,23 +8,26 @@ my %ideal_test_plan = (tests => 8); my $dir; sub _determine_test_plan { - my $cvs=`which cvs`; chomp $cvs; - my $cvsps=`which cvsps`; chomp $cvsps; + my $cvs = `which cvs`; chomp $cvs; + my $cvsps = `which cvsps`; chomp $cvsps; return (skip_all => 'cvs or cvsps not available') unless -x $cvs && -x $cvsps; - foreach my $module ('File::ReadBackwards', 'File::MimeInfo') { + foreach my $module (qw(File::ReadBackwards File::MimeInfo)) { eval qq{use $module}; if ($@) { return (skip_all => "$module not available"); } } + $dir = "/tmp/ikiwiki-test-cvs.$$"; + return (skip_all => "can't create $dir: $!") + unless mkdir($dir); + return %ideal_test_plan; } sub _startup { - _mktempdir(); _generate_minimal_config(); _create_test_repo(); } @@ -33,15 +36,8 @@ sub _shutdown { system "rm -rf $dir"; } -sub _mktempdir { - $dir="/tmp/ikiwiki-test-cvs.$$"; - if (! mkdir($dir)) { - die $@; - } -} - sub _generate_minimal_config { - %config=IkiWiki::defaultconfig(); + %config = IkiWiki::defaultconfig(); $config{rcs} = "cvs"; $config{srcdir} = "$dir/src"; $config{cvsrepo} = "$dir/repo"; @@ -62,9 +58,9 @@ sub _create_test_repo { } sub test_web_add_and_commit { + my $message = "Added the first page"; writefile('test1.mdwn', $config{srcdir}, readfile("t/test1.mdwn")); IkiWiki::rcs_add("test1.mdwn"); - my $message = "Added the first page"; IkiWiki::rcs_commit( file => "test1.mdwn", message => $message, @@ -90,10 +86,12 @@ sub test_web_add_and_commit { } sub test_manual_add_and_commit { - writefile('test2.mdwn', $config{srcdir}, readfile("t/test2.mdwn")); - system "cd $config{srcdir} && cvs add test2.mdwn >/dev/null 2>&1"; my $message = "Added the second page"; - system "cd $config{srcdir} && cvs commit -m \"$message\" test2.mdwn >/dev/null"; + writefile('test2.mdwn', $config{srcdir}, readfile("t/test2.mdwn")); + system "cd $config{srcdir}" + . " && cvs add test2.mdwn >/dev/null 2>&1"; + system "cd $config{srcdir}" + . " && cvs commit -m \"$message\" test2.mdwn >/dev/null"; my @changes = IkiWiki::rcs_recentchanges(3); is( From 97016a00618138bf9571f2c4c3a66d5f2f51e1a7 Mon Sep 17 00:00:00 2001 From: Amitai Schlair Date: Sun, 22 Jan 2012 02:30:48 -0500 Subject: [PATCH 9/9] Describe the needed test cases, and implement a couple Test::Class features. * Run all subs matching /^test_*/ (for which we can plan)... * Unless TEST_METHOD is set, in which case run matching subs (sans plan). * Define total number of tests very near 'use Test::More', where expected. * Define test tempdir where it's declared, no longer any reason why not. * Move most comments from TODO.cvs into t/cvs.t. * Add a whole bunch more comments describing the needed test cases. XXX existing tests are order-dependent, but currently happen to pass --- TODO.cvs | 26 ++--- t/cvs.t | 314 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 303 insertions(+), 37 deletions(-) diff --git a/TODO.cvs b/TODO.cvs index bf92a00ce..e1ae4570a 100644 --- a/TODO.cvs +++ b/TODO.cvs @@ -1,20 +1,6 @@ -* write test cases: - * web edits can create CVS/foo.mdwn (and think of case-insensitive "cvs/") - * binary file detection - * `cvsps` output format - * `findtimes()` -* `File::MimeInfo::default()` wrongly marks some text files `-kb` - * stop doing it - * find and fix existing -* instead of reading backwards, write one changeset per file and - `ls | sort -nr | head -100` - * obviates need for File::ReadBackwards -* parameterize `cvsps` command -* when is `-x` overkill? ever? -* `-b HEAD`, always? -* use `open()` instead of `system()` -* implement the time optimizations -* use `cvs_runcvs` everywhere `cvs` is run -* set up `log_accum` and `commit_prep` in `ikiwiki-makerepo` - * obviates need for `cvsps` -* historyurl overzealously escapes path slashes? +DON'T PUSH BEFORE PULLING AND REBASING! + +* make old tests run in any order +* merge old tests into new test subs + +* more copyright years? diff --git a/t/cvs.t b/t/cvs.t index b216a88d6..a8f1254ef 100755 --- a/t/cvs.t +++ b/t/cvs.t @@ -1,39 +1,47 @@ #!/usr/bin/perl use warnings; use strict; -use Test::More; +use Test::More; my $total_tests = 10; use IkiWiki; -my %ideal_test_plan = (tests => 8); -my $dir; +my $dir = "/tmp/ikiwiki-test-cvs.$$"; + +sub _plan { + my $can_plan = shift; -sub _determine_test_plan { my $cvs = `which cvs`; chomp $cvs; my $cvsps = `which cvsps`; chomp $cvsps; - return (skip_all => 'cvs or cvsps not available') + 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 (skip_all => "$module not available"); + return plan(skip_all => "$module not available"); } } - $dir = "/tmp/ikiwiki-test-cvs.$$"; - return (skip_all => "can't create $dir: $!") + return plan(skip_all => "can't create $dir: $!") unless mkdir($dir); - return %ideal_test_plan; + 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 { @@ -83,6 +91,18 @@ sub test_web_add_and_commit { "test1", q{first pagename from most recent commit matches}, ); + + # 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 + # how much of the web-edit workflow are we actually testing? + # because we want to test comments: + # - when the first comment for page.mdwn is added, and page/ is + # created to hold the comment, page/ isn't added to CVS control, + # so the comment isn't either + # - side effect for moderated comments: after approval they + # show up normally AND are still pending, too + # - comments.pm treats rcs_commit_staged() as returning conflicts? } sub test_manual_add_and_commit { @@ -114,22 +134,282 @@ sub test_manual_add_and_commit { "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 + # CVS multi-dir commits show only the first dir in recentchanges + # - commit_prep might also fix this? + # CVS post-commit hook is amped off to avoid locking against itself + # - commit_prep probably doesn't fix this... but maybe? } -sub test_extra_path_slashes { +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? +} + +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 sanitizes cvspath}, + q{rcs_recentchanges assumes checkconfig has sanitized cvspath}, ); } -plan(_determine_test_plan()); -_startup(); -test_web_add_and_commit(); -test_manual_add_and_commit(); -test_extra_path_slashes(); -_shutdown(); +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") +} + +sub test_cvs_run_cvs { + # extract the stdout-redirect thing + # - prove that it silences stdout + # - prove that stderr comes through just fine + # prove that when cvs exits nonzero (fail), function exits false + # prove that when cvs exits zero (success), function exits true + # always pass -f, just in case + # 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 +} + +sub test_cvs_run_cvsps { + # parameterize command like run_cvs() + # expose config vars for e.g. "--cvs-direct -z 30" + # always pass -x (unless proven otherwise) + # always pass -b HEAD (configurable like gitmaster_branch?) +} + +sub test_cvs_parse_cvsps { + # extract method from rcs_recentchanges + # document expected changeset format + # document expected changeset delimiter + # try: cvsps -q -x -p && ls | sort -rn | head -100 + # - benchmark against current impl (that uses File::ReadBackwards) +} + +sub test_cvs_parse_log_accum { + # add new, preferred method for rcs_recentchanges to use + # teach log_accum to record commits (into transient?) + # script cvsps to bootstrap (or replace?) commit history + # teach ikiwiki-makerepo to set up log_accum and commit_prep + # why are NetBSD commit mails unreliable? + # - is it working for CVS commits and failing for web commits? +} + +sub test_cvs_is_controlling { + # with no args: + # - if srcdir is in CVS, return true + # - else, return false + # with a dir arg: + # - if dir is in CVS, return true + # - else, return false + # with a file arg: + # - is there anything that wants the answer? if so, answer + # - else, die +} + +sub test_rcs_update { + # can it assume we're under CVS control? or must it check? + # anything else worth testing? +} + +sub test_rcs_prepedit { + # can it assume we're under CVS control? or must it check? + # for existing file, returns latest revision in repo + # - what's this used for? should it return latest revision in checkout? + # for new file, returns empty string +} + +sub test_rcs_commit { + # can it assume we're under CVS control? or must it check? + # if someone else changed the page since rcs_prepedit was called: + # - try to merge into our working copy + # - if merge succeeds, proceed to commit + # - else, return page content with the conflict markers in it + # commit: + # - if success, return undef + # - 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? +} + +sub test_rcs_commit_staged { + # if commit succeeds, return undef + # else, warn and return error message (really? or just non-undef?) +} + +sub test_rcs_add { + my $dir1 = "test3"; + my $dir2 = "test4/test5"; + ok( + mkdir($config{srcdir} . "/$dir1"), + qq{can make $dir1}, + ); + IkiWiki::rcs_add($dir1); + IkiWiki::rcs_commit( + file => $dir1, + message => "shouldn't happen", + token => "oom", + ); + + # can it assume we're under CVS control? or must it check? + # add a top-level text file + # - rcs_commit it + # - inspect recentchanges: new change, no -kb + # add a top-level dir + # - test mustn't hang (does it hang if we comment out genwrapper?) + # - inspect recentchanges: no new change + # - rcs_commit it + # - reinspect recentchanges: still no new change + # add a text file in that dir + # - rcs_commit_staged + # - inspect recentchanges: new change, no -kb + # add a top-level dir + add a binary file in it + # - rcs_commit_staged + # - inspect recentchanges: new change, yes -kb + # add a top-level dir + subdir + add one text and one binary file in it + # - rcs_commit_staged + # - inspect recentchanges: one new change, two files, one -kb, one not + + # 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? +} + +sub test_rcs_remove { + # can it assume we're under CVS control? or must it check? + # remove a top-level file + # - rcs_commit + # - inspect recentchanges: one new change, file removed + # remove two files (in different dirs) + # - rcs_commit_staged + # - inspect recentchanges: one new change, both files removed +} + +sub test_rcs_rename { + # can it assume we're under CVS control? or must it check? + # rename a file in the same dir + # - rcs_commit_staged + # - inspect recentchanges: one new change, one file removed, one added + # rename a file into a different dir + # - rcs_commit_staged + # - inspect recentchanges: one new change, one file removed, one added + # rename a file into a not-yet-existing dir + # - rcs_commit_staged + # - inspect recentchanges: one new change, one file removed, one added + # is it safe to use "mv"? what if $dest is somehow outside the wiki? +} + +sub test_rcs_recentchanges { + # can it assume we're under CVS control? or must it check? + # don't worry whether we're called with a number (we always are) + # other rcs tests already inspect much of the returned structure + # CVS commits say "cvs" and get the right committer + # web commits say "web" and get the right committer + # - and don't start with "web commit {by,from} " + # "nickname" -- can we ever meaningfully set this? + + # prefer log_accum, then cvsps, else die + # run the high-level recentchanges tests 2x (once for each method) + # - including in other test subs that check recentchanges? +} + +sub test_rcs_diff { + # can it assume we're under CVS control? or must it check? + # in list context, return all lines (with \n), up to $maxlines if set + # in scalar context, return the whole diff, up to $maxlines if set +} + +sub test_rcs_getctime { + # can it assume we're under CVS control? or must it check? + # given a file, find its creation time, else return 0 + # first implement in the obvious way + # then cache +} + +sub test_rcs_getmtime { + # can it assume we're under CVS control? or must it check? + # given a file, find its modification time, else return 0 + # first implement in the obvious way + # then cache +} + +sub test_rcs_receive { + pass(q{rcs_receive doesn't make sense for CVS}); +} + +sub test_rcs_preprevert { + # can it assume we're under CVS control? or must it check? + # given a patchset number, return structure describing what'd happen: + # - see doc/plugins/write.mdwn:rcs_receive() + # don't forget about attachments +} + +sub test_rcs_revert { + # can it assume we're under CVS control? or must it check? + # given a patchset number, stage the revert for rcs_commit_staged() + # if commit succeeds, return undef + # else, warn and return error message (really? or just non-undef?) +} + +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); + _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'); +} + +# http://stackoverflow.com/questions/607282/whats-the-best-way-to-discover-all-subroutines-a-perl-module-has + +use B qw/svref_2object/; + +sub in_package { + my ($coderef, $package) = @_; + my $cv = svref_2object($coderef); + return if not $cv->isa('B::CV') or $cv->GV->isa('B::SPECIAL'); + return $cv->GV->STASH->NAME eq $package; +} + +sub list_module { + my $module = shift; + no strict 'refs'; + return grep { + defined &{"$module\::$_"} and in_package(\&{*$_}, $module) + } keys %{"$module\::"}; +}