and, to test this:use constant WEEKDAY => 1; use constant WEEKEND => 0; ... sub is_weekday { my ($self, $date) = @_; my $dow = (localtime ($date || time))[6]; return substr $self->{weekdays}, $dow, 1 ? WEEKDAY : WEEKEND; }
This works perfectly on my development system. This also works perfectly on the first-line testing system which I installed the code on myself. However, the client installed this himself to a third system and is getting the following test failures:my %params = ( ... weekdays => '0011111', # Note that this sets Sun/Mon = weekend, Tue-Sat = weekd +ay ... ); ... is_deeply($obj, \%params, 'account type created with params'); is($obj->is_weekday(UnixDate(ParseDate('last sunday'), "%s")), 0, 'Sunday is weekend'); is($obj->is_weekday(UnixDate(ParseDate('last tuesday'), "%s")), 1, 'Tuesday is weekday');
(There are additional failed tests, but they are direct results of confusing weekends for weekdays and vice-versa. They do not appear likely to be due to separate bugs.)root@system:/some/path# prove account_type.t account_type....NOK 27 # Failed test 'Sunday is weekend' # in account_type.t at line 69. # got: '1' # expected: '0' account_type....NOK 28 # Failed test 'Tuesday is weekday' # in account_type.t at line 71. # got: '0' # expected: '1'
The immediately preceding is_deeply should verify that the content of $obj->{weekdays} is '0011111', yet is_weekday is apparently interpreting the string's first character as true and the third character as false. Any ideas as to what I'm missing or why this might run correctly on the two machines I've touched while failing on a third? (I'm trying to get access to the machine where it's failing so that I can investigate more directly, but have not yet been able to arrange it.)
Edit: Added comment clarifying that the test is using a nonstandard concept of what's a weekday and what isn't, since that's caused a little confusion for those trying to help. Sorry about that.
In reply to Inscrutable test failure by dsheroh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |