Skip Menu |

This queue is for tickets about the Config-Crontab CPAN distribution.

Report information
The Basics
Id: 59578
Status: open
Worked: 2 hours (120 min)
Priority: 0/
Queue: Config-Crontab

People
Owner: Nobody in particular
Requestors: CHORNY [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.30
Fixed in: (no value)



Subject: Tests fail under Windows
Tests fail under Windows. See cpantesters reports for Windows: http://matrix.cpantesters.org/?dist=Config-Crontab%201.30;reports=1;os=MSWin32 -- Alexandr Ciornii, http://chorny.net
version 1.31 now checks for a crontab program on the system and skips all tests if not found. I don't have a Windows machine to verify this fixes the issue. Let me know otherwise.
On 2011-04-11 18:36:48, SCOTTW wrote: Show quoted text
> version 1.31 now checks for a crontab program on the system and skips > all tests if not found. I > don't have a Windows machine to verify this fixes the issue. Let me > know otherwise.
There are at least two further issues: * 05_crontab.t is using getpwnam, which is unimplemented under Windows * 07_write.t fails some tests because Windows usually does not have the "cat" command available Here's an overview of the Windows test reports: http://matrix.cpantesters.org/?dist=Config-Crontab%201.33;os=mswin32;reports=1 Regards, Slaven
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.
Subject: windows.diff
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); }