Please find attached a patch which fixes the test failures on windows. I tested this on both Cygwin and Strawberry Perl.
I also disabled the cron check for the test suite, I think the intention was to allow installing the distribution on platforms that don't have a crontab command, but the test suite doesn't actually call the crontab command as far as I an tell (except to check if it is there), and the actual effect is to disable the test suite in many places where it can usefully be run.
diff --git a/Crontab.pm b/Crontab.pm
index 3b2ed2d..24048f5 100644
--- a/Crontab.pm
+++ b/Crontab.pm
@@ -374,12 +374,29 @@ sub owner {
if( @_ ) {
my $owner = shift;
if( $owner ) {
- unless( defined( getpwnam($owner) ) ) {
- $self->error("Unknown user: $owner");
- if( $self->strict ) {
- croak $self->error;
+
+ if( $^O eq 'MSWin32' ) {
+
+ require Win32;
+ unless( Win32::LookupAccountName('', $owner, my $domain, my $sid, my $sidtype) ) {
+ $self->error("Unknown user: $owner");
+ if( $self->strict ) {
+ croak $self->error;
+ }
+ return;
+ }
+
+ }
+
+ else {
+
+ unless( defined( getpwnam($owner) ) ) {
+ $self->error("Unknown user: $owner");
+ if( $self->strict ) {
+ croak $self->error;
+ }
+ return;
}
- return;
}
if( $owner =~ $self->owner_re ) {
diff --git a/t/05_crontab.t b/t/05_crontab.t
index 6c6ac46..b607dfb 100644
--- a/t/05_crontab.t
+++ b/t/05_crontab.t
@@ -444,17 +444,18 @@ is( $blocks[2], undef, "undef" );
##
## try some owner tests
##
+my $admin = $^O =~ /^(cygwin|MSWin32)$/ ? 'Administrator' : 'root';
undef $ct;
$ct = new Config::Crontab;
-$ct->owner('root');
-is( $ct->owner, 'root', "owner" );
+$ct->owner($admin);
+is( $ct->owner, $admin, "owner" );
## stricter
$ct->strict(1);
eval { $ct->owner('somereallybogususername8838293') };
like( $@, qr(Unknown user)i, "unknown user" );
-eval { $ct->owner("root\0 2>/dev/null; cat /etc/passwd") };
+eval { $ct->owner("$admin\0 2>/dev/null; cat /etc/passwd") };
like( $@, qr(Illegal username)i, "illegal username" );
##
diff --git a/t/07_write.t b/t/07_write.t
index 50768bf..dc66961 100644
--- a/t/07_write.t
+++ b/t/07_write.t
@@ -1,5 +1,6 @@
#-*- mode: cperl -*-#
use Test::More;
+use Config;
use blib;
chdir 't' if -d 't';
@@ -123,27 +124,29 @@ ok( $ct->write, "write" );
undef $ct;
## test a pipe with 'new'
-$ct = new Config::Crontab( -file => "cat $crontabf|" );
+$ct = new Config::Crontab( -file => "$Config{cat} $crontabf|" );
$ct->read;
is( $ct->dump, $crontabd2, "dump clean" );
undef $ct;
+my $q = $^O eq 'MSWin32' ? '"' : "'";
+
## test a pipe with 'new'
-$ct = new Config::Crontab( -file => "perl -ne 'print' $crontabf|" );
+$ct = new Config::Crontab( -file => "perl -ne $q\print$q $crontabf|" );
$ct->read;
is( $ct->dump, $crontabd2, "dump clean" );
undef $ct;
## test a pipe with 'file'
$ct = new Config::Crontab;
-$ct->file("perl -ne 'print' $crontabf|");
+$ct->file("perl -ne $q\print$q $crontabf|");
$ct->read;
is( $ct->dump, $crontabd2, "dump clean" );
undef $ct;
## test a pipe with 'file'
$ct = new Config::Crontab;
-$ct->read( -file => "perl -ne 'print' $crontabf|" );
+$ct->read( -file => "perl -ne $q\print$q $crontabf|" );
is( $ct->dump, $crontabd2, "dump clean" );
undef $ct;
diff --git a/t/setup.pl b/t/setup.pl
index 492716f..d80180a 100644
--- a/t/setup.pl
+++ b/t/setup.pl
@@ -2,6 +2,7 @@ use strict;
use warnings;
sub have_crontab {
+ return 1;
eval 'system("crontab -l 2>/dev/null")';
return ($? >> 8 == 1);
}