This queue is for tickets about the Text-CSV_XS CPAN distribution.

Report information
The Basics
Id:
117495
Status:
resolved
Priority:
Low/Low
Queue:

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

BugTracker
Severity:
(no value)
Broken in:
0.81
Fixed in:
1.26



Subject: is_missing(0) might be broken?
Hi, I'm looking through Text::CSV's issues, and wondering why one of the following tests fails. Am I missing something? Or, this is a bug in XS/PP? (cf. https://github.com/makamaka/Text-CSV/issues/27 , though the test attached there seems broken in a few ways) ---------------- #!/usr/bin/perl use strict; use warnings; #use Test::More "no_plan"; use Test::More tests => 13; BEGIN { use_ok "Text::CSV_XS"; plan skip_all => "Cannot load Text::CSV_XS" if $@; require "t/util.pl"; } my $tfn = "_92test.csv"; END { -f $tfn and unlink $tfn } open FH, ">", $tfn or die "$tfn: $!"; print FH "\n"; # empty line print FH "1,2\n"; print FH "3\n"; # empty column close FH; my $csv = Text::CSV_XS->new({ keep_meta_info => 1, blank_is_undef => 1, empty_is_undef => 1, }); is $csv->is_missing(0), undef, "is_missing() is not defined yet"; open IN, "<", $tfn or die "$tfn: $!"; $csv->column_names(qw/first second/); { my $hr = $csv->getline_hr(*IN); ok $csv->is_missing(0), "empty line: is_missing() should return true"; # <= FAILS ok $csv->is_missing(1), "empty line: is_missing() should return true"; ok exists $hr->{first} && !defined $hr->{first}; ok exists $hr->{second} && !defined $hr->{second}; } { my $hr = $csv->getline_hr(*IN); ok !$csv->is_missing(0), "not empty: is_missing() should not return true"; ok exists $hr->{first} && defined $hr->{first}; ok exists $hr->{second} && defined $hr->{second}; } { my $hr = $csv->getline_hr(*IN); ok !$csv->is_missing(0), "not empty column: is_missing() should not return true"; ok $csv->is_missing(1), "empty column: is_missing() should return true"; ok exists $hr->{first} && defined $hr->{first}; ok exists $hr->{second} && !defined $hr->{second}; }
I'd say there is no bug here: an empty line is completely valid CSV consisting of a single empty field (which thus is not missing) --8<--- use Test::More; BEGIN { use_ok "Text::CSV_XS"; plan skip_all => "Cannot load Text::CSV_XS" if $@; require "t/util.pl"; } my $data = <<"EOD"; 1,2 3 EOD my $csv = Text::CSV_XS->new ({ keep_meta_info => 1, blank_is_undef => 1, empty_is_undef => 1, }); is $csv->is_missing (0), undef, "is_missing () is not defined yet"; open my $fh, "<", \$data; $csv->column_names (qw/first second/); { my $hr = $csv->getline_hr ($fh); ok !$csv->is_missing (0), "empty line: is_missing (0) should NOT return true"; # NOT MISSING! ok $csv->is_missing (1), "empty line: is_missing (1) should return true"; ok exists $hr->{first} && !defined $hr->{first}; ok exists $hr->{second} && !defined $hr->{second}; } { my $hr = $csv->getline_hr ($fh); ok !$csv->is_missing (0), "not empty: is_missing (0) should not return true"; ok exists $hr->{first} && defined $hr->{first}; ok exists $hr->{second} && defined $hr->{second}; } { my $hr = $csv->getline_hr ($fh); ok !$csv->is_missing (0), "not empty column: is_missing () should not return true"; ok $csv->is_missing (1), "empty column: is_missing (1) should return true"; ok exists $hr->{first} && defined $hr->{first}; ok exists $hr->{second} && !defined $hr->{second}; } done_testing (); -->8--- ==> --8<--- ok 1 - use Text::CSV_XS; ok 2 - is_missing () is not defined yet ok 3 - empty line: is_missing (0) should NOT return true ok 4 - empty line: is_missing (1) should return true ok 5 ok 6 ok 7 - not empty: is_missing (0) should not return true ok 8 ok 9 ok 10 - not empty column: is_missing () should not return true ok 11 - empty column: is_missing (1) should return true ok 12 ok 13 1..13 ok 1 - use Text::CSV_XS; ok 2 - is_missing () is not defined yet ok 3 - empty line: is_missing (0) should NOT return true ok 4 - empty line: is_missing (1) should return true ok 5 ok 6 ok 7 - not empty: is_missing (0) should not return true ok 8 ok 9 ok 10 - not empty column: is_missing () should not return true ok 11 - empty column: is_missing (1) should return true ok 12 ok 13 1..13 -->8--- So, unless you can come with good arguments against this, I will reject this ticket in a few days.


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.