Uncomment the CVS keyword substitution mode tests, and make them pass:
authorAmitai Schlair <schmonz-web-ikiwiki@schmonz.com>
Thu, 26 Jan 2012 21:57:00 +0000 (16:57 -0500)
committerAmitai Schlair <schmonz-web-ikiwiki@schmonz.com>
Thu, 26 Jan 2012 21:57:00 +0000 (16:57 -0500)
Extract cvs_keyword_subst_args() and ensure it runs in $config{srcdir}.
Using Perl's -T operator appears to work equally well, perhaps switch?

IkiWiki/Plugin/cvs.pm
t/cvs.t

index dafaf13f576e6a5b524ec84ef40b665f254c1a4a..5ce3c5cbe98698049cab9d0dc76f0289d69de776 100644 (file)
@@ -202,15 +202,30 @@ sub rcs_commit_staged (@) {
        return undef # success
 }
 
+sub cvs_keyword_subst_args ($) {
+       my $file = shift;
+
+       local $CWD = $config{srcdir};
+
+       eval q{use File::MimeInfo};
+       error($@) if $@;
+       my $filemime = File::MimeInfo::default($file);
+       # if (-T $file) {
+
+       if (defined($filemime) && $filemime eq 'text/plain') {
+               return ($file);
+       }
+       else {
+               return ('-kb', $file);
+       }
+}
+
 sub rcs_add ($) {
        # filename is relative to the root of the srcdir
        my $file=shift;
        my $parent=IkiWiki::dirname($file);
        my @files_to_add = ($file);
 
-       eval q{use File::MimeInfo};
-       error($@) if $@;
-
        until ((length($parent) == 0) || cvs_is_controlling("$config{srcdir}/$parent")){
                push @files_to_add, $parent;
                $parent = IkiWiki::dirname($parent);
@@ -219,15 +234,8 @@ sub rcs_add ($) {
        while ($file = pop @files_to_add) {
                if (@files_to_add == 0) {
                        # file
-                       my $filemime = File::MimeInfo::default($file);
-                       if (defined($filemime) && $filemime eq 'text/plain') {
-                               cvs_runcvs('add', $file) ||
-                                       warn("cvs add $file failed\n");
-                       }
-                       else {
-                               cvs_runcvs('add', '-kb', $file) ||
-                                       warn("cvs add binary $file failed\n");
-                       }
+                       cvs_runcvs('add', cvs_keyword_subst_args($file)) ||
+                               warn("cvs add $file failed\n");
                }
                else {
                        # directory
diff --git a/t/cvs.t b/t/cvs.t
index f29e58a6a8baaeb3cc2cc2603cadcdd76bd7ed27..1c20d7741343dd4ae668ff879909b024f4eb4d6d 100755 (executable)
--- a/t/cvs.t
+++ b/t/cvs.t
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 use warnings;
 use strict;
-use Test::More; my $total_tests = 37;
+use Test::More; my $total_tests = 40;
 use IkiWiki;
 
 my $default_test_methods = '^test_*';
@@ -163,7 +163,7 @@ sub test_rcs_add {
                token => "moo",
        );
        is_newly_added("test0.mdwn");
-#      is_in_keyword_substitution_mode("test0.mdwn", undef);
+       is_in_keyword_substitution_mode("test0.mdwn", undef);
        my @changes = IkiWiki::rcs_recentchanges(3);
        is_total_number_of_changes(\@changes, 1);
        is_most_recent_change(\@changes, "test0", $message);
@@ -195,7 +195,7 @@ sub test_rcs_add {
                token => "omo",
        );
        is_newly_added("$dir2/test1.mdwn");
-#      is_in_keyword_substitution_mode("$dir2/test1.mdwn", undef);
+       is_in_keyword_substitution_mode("$dir2/test1.mdwn", undef);
        @changes = IkiWiki::rcs_recentchanges(3);
        is_total_number_of_changes(\@changes, 2);
        is_most_recent_change(\@changes, "$dir2/test1", $message);
@@ -233,7 +233,7 @@ 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($file1, undef);
        is_in_keyword_substitution_mode($file2, '-kb');
        @changes = IkiWiki::rcs_recentchanges(3);
        is_total_number_of_changes(\@changes, 3);
@@ -499,6 +499,7 @@ sub is_newly_added {
 
 sub is_in_keyword_substitution_mode {
        my ($file, $mode) = @_;
+       $mode = '(none)' unless defined $mode;
        is(
                IkiWiki::Plugin::cvs::cvs_info("Sticky Options", $file),
                $mode,