ingydotnet / test-base-pm

Extendable Perl Testing
http://search.cpan.org/dist/Test-Base/
13 stars 12 forks source link

Can't test subroutines returning an empty string #17

Closed choroba closed 6 years ago

choroba commented 9 years ago

If a subroutine returns an empty string, the input value is used in the test instead.

Sample (test "zero" shouldn't fail):

#!/usr/bin/perl
use warnings;
use strict;

use Test::Base tests => 2;

sub func {
    'X' x $_
}

run_is input => 'expected';

__END__
=== one
--- input func
1
--- expected chomp
X
=== zero
--- input func
0
--- expected chomp
ingydotnet commented 6 years ago

Greetings from the future (2018)!

The code seems to stem from https://github.com/ingydotnet/test-base-pm/blob/master/lib/Test/Base.pm#L637-L644

Which deals with using $_ for filter simplicity which on the whole was probably a bad API design to go with.

The simple fix appears to be to change your filter to use:

$_  =  'X' x $_

In 2018 Test::Base has been replaced with a shiny new TestML. If you are still interested in Perl by then, check it out. :)