Skip Menu |

This queue is for tickets about the Test-Unit CPAN distribution.

Report information
The Basics
Id: 107804
Status: new
Priority: 0/
Queue: Test-Unit

People
Owner: Nobody in particular
Requestors: ivanchenko.michael.work [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.25
Fixed in: (no value)



Subject: False positive detected when asserting an empty list
When given a empty list, the method `assert` should fail, but it doesn't: $self->assert( (), 'should fail' ); The workaround is to use `scalar`: $self->assert( scalar( () ), 'should fail' );
Subject: TestUnit.failure.pl
#!/usr/bin/env perl use strict; use warnings; use Test::Unit::HarnessUnit; my $r = Test::Unit::HarnessUnit->new(); $r->start('MyTest'); package MyTest; use base qw( Test::Unit::TestCase ); sub test_passes { my ($self) = @_; $self->assert( (), 'should fail' ); } sub test_fails { my ($self) = @_; $self->assert( scalar( () ), 'should fail' ); }
From: ivanchenko.michael.work [...] gmail.com
On Thu Oct 15 08:51:59 2015, ivanchenko.michael.work@gmail.com wrote: Show quoted text
> When given a empty list, the method `assert` should fail, but it doesn't: > > $self->assert( (), 'should fail' ); > > The workaround is to use `scalar`: > > $self->assert( scalar( () ), 'should fail' );
Oh, nevermind - the docs here: http://search.cpan.org/~mcast/Test-Unit-0.25/lib/Test/Unit/Assert.pm mention that the usage only implies a boolean argument, which should not be a list: assert(BOOLEAN [, MESSAGE]) "...the arguments to assert() are evaluated in list context, e.g. making a failing regex "pull" the message into the place of the first argument. Since this is usually just plain wrong, please use scalar() to force the regex comparison to yield a useful boolean value."