@@ -26,7 +26,7 @@ use DynaLoader ();
use Carp;
use vars qw( $VERSION @ISA @EXPORT_OK );
-$VERSION = "1.18";
+$VERSION = "1.19";
@ISA = qw( DynaLoader Exporter );
@EXPORT_OK = qw( csv );
bootstrap Text::CSV_XS $VERSION;
@@ -212,7 +212,7 @@ sub new
return;
}
if (defined $self->{callbacks} && ref $self->{callbacks} ne "HASH") {
- warn "The 'callbacks' attribute is set but is not a hash: ignored\n";
+ carp "The 'callbacks' attribute is set but is not a hash: ignored\n";
$self->{callbacks} = undef;
}
@@ -430,7 +430,12 @@ sub decode_utf8
sub keep_meta_info
{
my $self = shift;
- @_ and $self->_set_attr_X ("keep_meta_info", shift);
+ if (@_) {
+ my $v = shift;
+ !defined $v || $v eq "" and $v = 0;
+ $v =~ m/^[0-9]/ or $v = lc $v eq "false" ? 0 : 1; # true/truth = 1
+ $self->_set_attr_X ("keep_meta_info", $v);
+ }
$self->{keep_meta_info};
} # keep_meta_info
@@ -534,7 +539,7 @@ sub types
my $self = shift;
if (@_) {
if (my $types = shift) {
- $self->{_types} = join "", map { chr $_ } @{$types};
+ $self->{_types} = join "", map { chr } @{$types};
$self->{types} = $types;
}
else {
@@ -555,7 +560,7 @@ sub callbacks
my $cb;
my $hf = 0x00;
if (defined $_[0]) {
- grep { !defined $_ } @_ and croak ($self->SetDiag (1004));
+ grep { !defined } @_ and croak ($self->SetDiag (1004));
$cb = @_ == 1 && ref $_[0] eq "HASH" ? shift
: @_ % 2 == 0 ? { @_ }
: croak ($self->SetDiag (1004));
@@ -1112,13 +1117,13 @@ sub csv
}
}
$csv->callbacks (after_parse => sub {
- my ($csv, $r) = @_;
- foreach my $fld (sort keys %f) {
- local $_ = $r->[$fld - 1];
+ my ($CSV, $ROW) = @_; # lexical sub-variables in caps
+ foreach my $FLD (sort keys %f) {
+ local $_ = $ROW->[$FLD - 1];
local %_;
- @hdr and @_{@hdr} = @$r;
- $f{$fld}->($csv, $r) or return \"skip";
- $r->[$fld - 1] = $_;
+ @hdr and @_{@hdr} = @$ROW;
+ $f{$FLD}->($CSV, $ROW) or return \"skip";
+ $ROW->[$FLD - 1] = $_;
}
});
}
@@ -3001,8 +3006,8 @@ CSV generated like this, but map and filter are your friends again
=head2 The examples folder
-For more extended examples, see the F<examples/> C<1>) sub-directory in the
-original distribution or the git repository C<2>).
+For more extended examples, see the F<examples/> C<1>. sub-directory in the
+original distribution or the git repository C<2>.
1. https://github.com/Tux/Text-CSV_XS/tree/master/examples
2. https://github.com/Tux/Text-CSV_XS
@@ -175,7 +175,7 @@ typedef struct {
#define bool_opt(o) bool_opt_def (o, 0)
#define num_opt_def(o,d) \
(((svp = hv_fetchs (self, o, FALSE)) && *svp) ? SvIV (*svp) : d)
-#define num_opt(o) bool_opt_def (o, 0)
+#define num_opt(o) num_opt_def (o, 0)
typedef struct {
int xs_errno;
@@ -600,7 +600,6 @@ static void cx_SetupCsv (pTHX_ csv_t *csv, HV *self, SV *pself)
csv->binary = bool_opt ("binary");
csv->decode_utf8 = bool_opt ("decode_utf8");
- csv->keep_meta_info = bool_opt ("keep_meta_info");
csv->always_quote = bool_opt ("always_quote");
csv->quote_empty = bool_opt ("quote_empty");
csv->quote_space = bool_opt_def ("quote_space", 1);
@@ -616,6 +615,7 @@ static void cx_SetupCsv (pTHX_ csv_t *csv, HV *self, SV *pself)
csv->auto_diag = num_opt ("auto_diag");
csv->diag_verbose = num_opt ("diag_verbose");
+ csv->keep_meta_info = num_opt ("keep_meta_info");
sv_cache = newSVpvn ((char *)csv, sizeof (csv_t));
csv->cache = (byte *)SvPVX (sv_cache);
@@ -769,7 +769,7 @@ static int cx_Combine (pTHX_ csv_t *csv, SV *dst, AV *fields)
if (kmi >= 10) {
SV **svp;
- if ((svp = hv_fetchs (csv->self, "_FFLAGS", FALSE)) && *svp) {
+ if ((svp = hv_fetchs (csv->self, "_FFLAGS", FALSE)) && _is_arrayref (*svp)) {
AV *avp = (AV *)SvRV (*svp);
if (avp && av_len (avp) >= n)
qm = avp;
@@ -829,11 +829,11 @@ static int cx_Combine (pTHX_ csv_t *csv, SV *dst, AV *fields)
if ((CH_QUOTE && c == CH_QUOTE) ||
(CH_SEP && c == CH_SEP) ||
(csv->escape_char && c == csv->escape_char) ||
- (csv->quote_binary ? c >= 0x7f && c <= 0xa0 ||
- c < csv->first_safe_char
- : c == CH_NL || c == CH_CR ||
+ (csv->quote_binary ? (c >= 0x7f && c <= 0xa0) ||
+ c < csv->first_safe_char
+ : c == CH_NL || c == CH_CR ||
(csv->quote_space && (
- c == CH_SPACE || c == CH_TAB)))) {
+ c == CH_SPACE || c == CH_TAB)))) {
/* Binary character */
break;
}
@@ -1,3 +1,8 @@
+1.19 - 2015-06-17, H.Merijn Brand
+ * Guard tests against $PERL_UNICODE
+ * Numeric options were sometimes interpreted as boolean
+ * Safer meta_info use
+
1.18 - 2015-05-22, H.Merijn Brand
* Add quote_empty attribute
* Add database NULL documentation
@@ -1,36 +1,38 @@
{
+ "meta-spec" : {
+ "version" : "2",
+ "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec"
+ },
+ "author" : [
+ "H.Merijn Brand <h.m.brand@xs4all.nl>"
+ ],
"provides" : {
"Text::CSV_XS" : {
- "version" : "1.18",
+ "version" : "1.19",
"file" : "CSV_XS.pm"
}
},
"release_status" : "stable",
+ "dynamic_config" : 1,
+ "license" : [
+ "perl_5"
+ ],
"resources" : {
- "license" : [
- "http://dev.perl.org/licenses/"
- ],
+ "homepage" : "https://metacpan.org/pod/Text::CSV_XS",
"repository" : {
- "url" : "https://github.com/Tux/Text-CSV_XS",
+ "type" : "git",
"web" : "https://github.com/Tux/Text-CSV_XS",
- "type" : "git"
+ "url" : "https://github.com/Tux/Text-CSV_XS"
},
- "x_IRC" : "irc://irc.perl.org/#csv",
- "homepage" : "https://metacpan.org/pod/Text::CSV_XS"
- },
- "meta-spec" : {
- "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
- "version" : "2"
+ "license" : [
+ "http://dev.perl.org/licenses/"
+ ],
+ "x_IRC" : "irc://irc.perl.org/#csv"
},
+ "abstract" : "Comma-Separated Values manipulation routines",
+ "version" : "1.19",
"name" : "Text-CSV_XS",
- "generated_by" : "Author",
- "version" : "1.18",
"prereqs" : {
- "configure" : {
- "requires" : {
- "ExtUtils::MakeMaker" : "0"
- }
- },
"build" : {
"requires" : {
"Config" : "0"
@@ -38,27 +40,25 @@
},
"test" : {
"requires" : {
- "Tie::Scalar" : "0",
- "Test::More" : "0"
+ "Test::More" : "0",
+ "Tie::Scalar" : "0"
}
},
"runtime" : {
"requires" : {
"perl" : "5.006001",
- "IO::Handle" : "0",
- "DynaLoader" : "0"
+ "DynaLoader" : "0",
+ "IO::Handle" : "0"
},
"recommends" : {
"Encode" : "2.73"
}
+ },
+ "configure" : {
+ "requires" : {
+ "ExtUtils::MakeMaker" : "0"
+ }
}
},
- "license" : [
- "perl_5"
- ],
- "dynamic_config" : 1,
- "author" : [
- "H.Merijn Brand <h.m.brand@xs4all.nl>"
- ],
- "abstract" : "Comma-Separated Values manipulation routines"
+ "generated_by" : "Author"
}
@@ -7,7 +7,7 @@ build_requires:
configure_requires:
ExtUtils::MakeMaker: 0
dynamic_config: 1
-generated_by: Author, CPAN::Meta::Converter version 2.150001
+generated_by: Author, CPAN::Meta::Converter version 2.150005
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -16,7 +16,7 @@ name: Text-CSV_XS
provides:
Text::CSV_XS:
file: CSV_XS.pm
- version: '1.18'
+ version: '1.19'
recommends:
Encode: '2.73'
requires:
@@ -30,4 +30,4 @@ resources:
homepage: https://metacpan.org/pod/Text::CSV_XS
license: http://dev.perl.org/licenses/
repository: https://github.com/Tux/Text-CSV_XS
-version: '1.18'
+version: '1.19'
@@ -6,7 +6,7 @@
ppport.h -- Perl/Pollution/Portability Version 3.31
- Automatically created by Devel::PPPort running under perl 5.020002.
+ Automatically created by Devel::PPPort running under perl 5.022000.
Do NOT edit this file directly! -- Edit PPPort_pm.PL and the
includes in parts/inc/ instead.
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 222;
+use Test::More tests => 225;
BEGIN {
use_ok "Text::CSV_XS";
@@ -127,10 +127,13 @@ sub crnlsp
is ($csv->string,
qq{1,,, , ,f,g,"h""h",h\xe9lp,h\xeblp}, "string 1");
ok ($csv->parse (qq{1,,"", ," ",f,"g","h""h",h\xe9lp,"h\xeblp"}), "Parse");
- ok ($csv->keep_meta_info (11), "keep meta on out");
+ is ($csv->keep_meta_info (11), 11, "keep meta on out");
ok ($csv->combine (@f), "combine");
is ($csv->string,
qq{1,,"", ," ",f,"g","h""h",h\xe9lp,"h\xeblp"}, "string 11");
+ ok ($csv->parse (qq{1,,"1193-1",4,"",,6}), "parse under 11");
+ ok ($csv->combine ($csv->fields), "combine");
+ is ($csv->string, qq{1,,"1193-1",4,"",,6}, "return same");
}
{ my $csv = Text::CSV_XS->new ({ keep_meta_info => 1, eol => "\r" });
@@ -15,11 +15,13 @@ $| = 1;
$/ = "\n";
$\ = undef;
+my $tfn = "_20test.csv"; END { -f $tfn and unlink $tfn; }
+
my $csv = Text::CSV_XS->new ();
my $UTF8 = ($ENV{LANG} || "C").($ENV{LC_ALL} || "C") =~ m/utf-?8/i ? 1 : 0;
-open FH, ">", "_20test.csv" or die "_20test.csv: $!";
+open FH, ">", $tfn or die "$tfn: $!";
ok (!$csv->print (*FH, ["abc", "def\007", "ghi"]), "print bad character");
close FH;
@@ -39,15 +41,15 @@ for ( [ 1, 1, 1, '""' ],
) {
my ($tst, $validp, $validg, @arg, $row) = @$_;
- open FH, ">", "_20test.csv" or die "_20test.csv: $!";
+ open FH, ">", $tfn or die "$tfn: $!";
is ($csv->print (*FH, \@arg), $validp||"", "$tst - print ()");
close FH;
- open FH, ">", "_20test.csv" or die "_20test.csv: $!";
+ open FH, ">", $tfn or die "$tfn: $!";
print FH join ",", @arg;
close FH;
- open FH, "<", "_20test.csv" or die "_20test.csv: $!";
+ open FH, "<", $tfn or die "$tfn: $!";
$row = $csv->getline (*FH);
unless ($validg) {
is ($row, undef, "$tst - false getline ()");
@@ -61,12 +63,12 @@ for ( [ 1, 1, 1, '""' ],
}
}
-unlink "_20test.csv";
+unlink $tfn;
# This test because of a problem with DBD::CSV
ok (1, "Tests for DBD::CSV");
-open FH, ">", "_20test.csv" or die "_20test.csv: $!";
+open FH, ">", $tfn or die "$tfn: $!";
$csv->binary (1);
$csv->eol ("\r\n");
ok ($csv->print (*FH, [ "id", "name" ]), "Bad character");
@@ -86,14 +88,14 @@ id,name\015
5\015
CONTENTS
-open FH, "<", "_20test.csv" or die "_20test.csv: $!";
+open FH, "<", $tfn or die "$tfn: $!";
my $content = do { local $/; <FH> };
close FH;
is ($content, $expected, "Content");
-open FH, ">", "_20test.csv" or die "_20test.csv: $!";
+open FH, ">", $tfn or die "$tfn: $!";
print FH $content;
close FH;
-open FH, "<", "_20test.csv" or die "_20test.csv: $!";
+open FH, "<", $tfn or die "$tfn: $!";
my $fields;
print "# Retrieving data\n";
@@ -131,10 +133,11 @@ for ([ 1, 1, 0, "\n" ],
[ 22, 0, 2025, qq{"+\r\r+"\r} ],
) {
my ($tst, $valid, $err, $str) = @$_;
- open FH, ">", "_20test.csv" or die "_20test.csv: $!";
+ my $raw = $] < 5.008 ? "" : ":raw";
+ open FH, ">$raw", $tfn or die "$tfn: $!";
print FH $str;
close FH;
- open FH, "<", "_20test.csv" or die "_20test.csv: $!";
+ open FH, "<$raw", $tfn or die "$tfn: $!";
my $row = $csv->getline (*FH);
close FH;
my @err = $csv->error_diag;
@@ -146,5 +149,3 @@ for ([ 1, 1, 0, "\n" ],
is ($err[0], $err, "Error expected $err");
}
}
-
-unlink "_20test.csv";
@@ -16,11 +16,12 @@ $/ = "\n";
$\ = undef;
my $io;
+my $tfn = "_21test.csv"; END { -f $tfn and unlink $tfn; }
my $csv = Text::CSV_XS->new ();
my $UTF8 = ($ENV{LANG} || "C").($ENV{LC_ALL} || "C") =~ m/utf-?8/i ? 1 : 0;
-open $io, ">", "_21test.csv" or die "_21test.csv: $!";
+open $io, ">", $tfn or die "$tfn: $!";
ok (!$csv->print ($io, ["abc", "def\007", "ghi"]), "print bad character");
close $io;
@@ -40,15 +41,15 @@ for ( [ 1, 1, 1, '""' ],
) {
my ($tst, $validp, $validg, @arg, $row) = @$_;
- open $io, ">", "_21test.csv" or die "_21test.csv: $!";
+ open $io, ">", $tfn or die "$tfn: $!";
is ($csv->print ($io, \@arg), $validp||"", "$tst - print ()");
close $io;
- open $io, ">", "_21test.csv" or die "_21test.csv: $!";
+ open $io, ">", $tfn or die "$tfn: $!";
print $io join ",", @arg;
close $io;
- open $io, "<", "_21test.csv" or die "_21test.csv: $!";
+ open $io, "<", $tfn or die "$tfn: $!";
$row = $csv->getline ($io);
unless ($validg) {
is ($row, undef, "$tst - false getline ()");
@@ -62,12 +63,12 @@ for ( [ 1, 1, 1, '""' ],
}
}
-unlink "_21test.csv";
+unlink $tfn;
# This test because of a problem with DBD::CSV
ok (1, "Tests for DBD::CSV");
-open $io, ">", "_21test.csv" or die "_21test.csv: $!";
+open $io, ">", $tfn or die "$tfn: $!";
$csv->binary (1);
$csv->eol ("\r\n");
ok ($csv->print ($io, [ "id", "name" ]), "Bad character");
@@ -87,14 +88,14 @@ id,name\015
5\015
CONTENTS
-open $io, "<", "_21test.csv" or die "_21test.csv: $!";
+open $io, "<", $tfn or die "$tfn: $!";
my $content = do { local $/; <$io> };
close $io;
is ($content, $expected, "Content");
-open $io, ">", "_21test.csv" or die "_21test.csv: $!";
+open $io, ">", $tfn or die "$tfn: $!";
print $io $content;
close $io;
-open $io, "<", "_21test.csv" or die "_21test.csv: $!";
+open $io, "<", $tfn or die "$tfn: $!";
my $fields;
print "# Retrieving data\n";
@@ -132,10 +133,11 @@ for ([ 1, 1, 0, "\n" ],
[ 22, 0, 2025, qq{"+\r\r+"\r} ],
) {
my ($tst, $valid, $err, $str) = @$_;
- open my $io, ">", "_21test.csv" or die "_21test.csv: $!";
+ my $raw = $] < 5.008 ? "" : ":raw";
+ open my $io, ">$raw", $tfn or die "$tfn: $!";
print $io $str;
close $io;
- open $io, "<", "_21test.csv" or die "_21test.csv: $!";
+ open $io, "<$raw", $tfn or die "$tfn: $!";
my $row = $csv->getline ($io);
close $io;
my @err = $csv->error_diag;
@@ -147,5 +149,3 @@ for ([ 1, 1, 0, "\n" ],
is ($err[0], $err, "Error expected $err");
}
}
-
-unlink "_21test.csv";
@@ -32,7 +32,7 @@ my $io;
my $io_str = "";
my $csv = Text::CSV_XS->new ();
-open $io, ">", \$io_str or die "_22test.csv: $!";
+open $io, ">", \$io_str or die "IO: $!";
ok (!$csv->print ($io, ["abc", "def\007", "ghi"]), "print bad character");
close $io;
@@ -52,15 +52,15 @@ for ( [ 1, 1, 1, '""' ],
) {
my ($tst, $validp, $validg, @arg, $row) = @$_;
- open $io, ">", \$io_str or die "_22test.csv: $!";
+ open $io, ">", \$io_str or die "IO: $!";
is ($csv->print ($io, \@arg), $validp||"", "$tst - print ()");
close $io;
- open $io, ">", \$io_str or die "_22test.csv: $!";
+ open $io, ">", \$io_str or die "IO: $!";
print $io join ",", @arg;
close $io;
- open $io, "<", \$io_str or die "_22test.csv: $!";
+ open $io, "<", \$io_str or die "IO: $!";
$row = $csv->getline ($io);
unless ($validg) {
is ($row, undef, "$tst - false getline ()");
@@ -74,12 +74,10 @@ for ( [ 1, 1, 1, '""' ],
}
}
-unlink "_22test.csv";
-
# This test because of a problem with DBD::CSV
ok (1, "Tests for DBD::CSV");
-open $io, ">", \$io_str or die "_22test.csv: $!";
+open $io, ">", \$io_str or die "IO: $!";
$csv->binary (1);
$csv->eol ("\r\n");
ok ($csv->print ($io, [ "id", "name" ]), "Bad character");
@@ -99,14 +97,14 @@ id,name\015
5\015
CONTENTS
-open $io, "<", \$io_str or die "_22test.csv: $!";
+open $io, "<", \$io_str or die "IO: $!";
my $content = do { local $/; <$io> };
close $io;
is ($content, $expected, "Content");
-open $io, ">", \$io_str or die "_22test.csv: $!";
+open $io, ">", \$io_str or die "IO: $!";
print $io $content;
close $io;
-open $io, "<", \$io_str or die "_22test.csv: $!";
+open $io, "<", \$io_str or die "IO: $!";
my $fields;
print "# Retrieving data\n";
@@ -120,16 +118,16 @@ is ($csv->eof, 1, "EOF");
{ ok (my $csv = Text::CSV_XS->new ({ binary => 1, eol => "\n" }), "new csv");
my ($out1, $out2, @fld, $fh) = ("", "", qw( 1 aa 3.14 ahhrg ));
- open $fh, ">", \$out1;
+ open $fh, ">", \$out1 or die "IO: $!";
ok ($csv->print ($fh, \@fld), "Add line $_") for 1..3;
close $fh;
$csv->bind_columns (\(@fld));
- open $fh, ">", \$out2;
+ open $fh, ">", \$out2 or die "IO: $!";
ok ($csv->print ($fh, \@fld), "Add line $_") for 1..3;
close $fh;
is ($out2, $out1, "ignoring bound columns");
$out2 = "";
- open $fh, ">", \$out2;
+ open $fh, ">", \$out2 or die "IO: $!";
ok ($csv->print ($fh, undef), "Add line $_") for 1..3;
close $fh;
is ($out2, $out1, "using bound columns");
@@ -162,7 +160,7 @@ for ([ 1, 1, 0, "\n" ],
) {
my ($tst, $valid, $err, $str) = @$_;
$io_str = $str;
- open $io, "<", \$io_str or die "_22test.csv: $!";
+ open $io, "<", \$io_str or die "IO: $!"; binmode $io;
my $row = $csv->getline ($io);
close $io;
my @err = $csv->error_diag;
@@ -172,19 +170,19 @@ for ([ 1, 1, 0, "\n" ],
}
{ ok (my $csv = Text::CSV_XS->new, "new for sep=");
- open my $fh, "<", \qq{sep=;\n"a b";3\n};
+ open my $fh, "<", \qq{sep=;\n"a b";3\n} or die "IO: $!";
is_deeply ($csv->getline_all ($fh), [["a b", 3]], "valid sep=");
is (($csv->error_diag)[0], 2012, "EOF");
}
{ ok (my $csv = Text::CSV_XS->new, "new for sep=");
- open my $fh, "<", \qq{sep=;\n"a b",3\n};
+ open my $fh, "<", \qq{sep=;\n"a b",3\n} or die "IO: $!";
is_deeply (eval { $csv->getline_all ($fh); }, [], "invalid sep=");
is (($csv->error_diag)[0], 2023, "error");
}
{ ok (my $csv = Text::CSV_XS->new, "new for sep=");
- open my $fh, "<", \qq{sep=XX\n"a b"XX3\n};
+ open my $fh, "<", \qq{sep=XX\n"a b"XX3\n} or die "IO: $!";
is_deeply (eval { $csv->getline_all ($fh); },
[["a b", 3]], "multibyte sep=");
is (($csv->error_diag)[0], 2012, "error");
@@ -192,7 +190,7 @@ for ([ 1, 1, 0, "\n" ],
{ ok (my $csv = Text::CSV_XS->new, "new for sep=");
# To check that it is *only* supported on the first line
- open my $fh, "<", \qq{sep=;\n"a b";3\nsep=,\n"a b",3\n};
+ open my $fh, "<", \qq{sep=;\n"a b";3\nsep=,\n"a b",3\n} or die "IO: $!";
is_deeply ($csv->getline_all ($fh),
[["a b","3"],["sep=,"]], "sep= not on 1st line");
is (($csv->error_diag)[0], 2023, "error");
@@ -200,7 +198,7 @@ for ([ 1, 1, 0, "\n" ],
{ ok (my $csv = Text::CSV_XS->new, "new for sep=");
my $sep = "#" x 80;
- open my $fh, "<", \qq{sep=$sep\n"a b",3\n2,3\n};
+ open my $fh, "<", \qq{sep=$sep\n"a b",3\n2,3\n} or die "IO: $!";
my $r = $csv->getline_all ($fh);
is_deeply ($r, [["sep=$sep"],["a b","3"],[2,3]], "sep= too long");
is (($csv->error_diag)[0], 2012, "EOF");
@@ -39,6 +39,7 @@ my %exp = map {
($_ => $x);
} @pat;
my $line = ["", undef, "0\n", "", "\0\0\n0"];
+my $tfn = "_41test.csv"; END { -f $tfn and unlink $tfn; }
my $csv = Text::CSV_XS->new ({
eol => "\n",
@@ -50,12 +51,10 @@ my $csv = Text::CSV_XS->new ({
ok ($csv->combine (@$line), "combine [ ... ]");
is ($csv->string, qq{,,"0\n",,""0"0\n0"\n}, "string");
-open my $fh, ">", "__41test.csv" or die $!;
+open my $fh, ">", $tfn or die "$tfn: $!\n";
binmode $fh;
-for (@pat) {
- ok ($csv->print ($fh, [ $_ ]), "print $exp{$_}");
- }
+ok ($csv->print ($fh, [ $_ ]), "print $exp{$_}") for @pat;
$csv->always_quote (1);
@@ -63,7 +62,7 @@ ok ($csv->print ($fh, $line), "print [ ... ]");
close $fh;
-open $fh, "<", "__41test.csv" or die $!;
+open $fh, "<", $tfn or die "$tfn: $!\n";
binmode $fh;
foreach my $pat (@pat) {
@@ -73,9 +72,8 @@ foreach my $pat (@pat) {
is_deeply ($csv->getline ($fh), $line, "read [ ... ]");
-close $fh;
-
-unlink "__41test.csv";
+close $fh;
+unlink $tfn;
$csv = Text::CSV_XS->new ({
eol => "\n",
@@ -88,7 +86,7 @@ $csv = Text::CSV_XS->new ({
ok ($csv->combine (@$line), "combine [ ... ]");
is ($csv->string, qq{,,"0\n",,"\0\0\n0"\n}, "string");
-open $fh, ">", "__41test.csv" or die $!;
+open $fh, ">", $tfn or die "$tfn: $!\n";
binmode $fh;
for (@pat) {
@@ -101,7 +99,7 @@ ok ($csv->print ($fh, $line), "print [ ... ]");
close $fh;
-open $fh, "<", "__41test.csv" or die $!;
+open $fh, "<", $tfn or die "$tfn: $!\n";
binmode $fh;
foreach my $pat (@pat) {
@@ -112,5 +110,3 @@ foreach my $pat (@pat) {
is_deeply ($csv->getline ($fh), $line, "read [ ... ]");
close $fh;
-
-unlink "__41test.csv";
@@ -15,6 +15,7 @@ $| = 1;
# Embedded newline tests
+my $tfn = "_45eol.csv"; END { -f $tfn and unlink $tfn; }
my $def_rs = $/;
foreach my $rs ("\n", "\r\n", "\r") {
@@ -26,10 +27,10 @@ foreach my $rs ("\n", "\r\n", "\r") {
foreach my $pass (0, 1) {
my $fh;
if ($pass == 0) {
- open $fh, ">", "_eol.csv";
+ open $fh, ">", $tfn or die "$tfn: $!\n";
}
else {
- open $fh, "<", "_eol.csv";
+ open $fh, "<", $tfn or die "$tfn: $!\n";
}
foreach my $eol ("", "\r", "\n", "\r\n", "\n\r") {
@@ -69,7 +70,7 @@ foreach my $rs ("\n", "\r\n", "\r") {
close $fh;
}
- unlink "_eol.csv";
+ unlink $tfn;
}
}
$/ = $def_rs;
@@ -89,25 +90,25 @@ SKIP: {
$] < 5.008 and skip "\$\\ tests don't work in perl 5.6.x and older", 2;
{ local $\ = "#\r\n";
my $csv = Text::CSV_XS->new ();
- open my $fh, ">", "_eol.csv";
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
$csv->print ($fh, [ "a", 1 ]);
- close $fh;
- open $fh, "<", "_eol.csv";
+ close $fh;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
local $/;
is (<$fh>, "a,1#\r\n", "Strange \$\\");
- close $fh;
- unlink "_eol.csv";
+ close $fh;
+ unlink $tfn;
}
{ local $\ = "#\r\n";
my $csv = Text::CSV_XS->new ({ eol => $\ });
- open my $fh, ">", "_eol.csv";
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
$csv->print ($fh, [ "a", 1 ]);
- close $fh;
- open $fh, "<", "_eol.csv";
+ close $fh;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
local $/;
is (<$fh>, "a,1#\r\n", "Strange \$\\ + eol");
- close $fh;
- unlink "_eol.csv";
+ close $fh;
+ unlink $tfn;
}
}
$/ = $def_rs;
@@ -116,27 +117,27 @@ ok (1, "Auto-detecting \\r");
{ my @row = qw( a b c ); local $" = ",";
for (["\n", "\\n"], ["\r\n", "\\r\\n"], ["\r", "\\r"]) {
my ($eol, $s_eol) = @$_;
- open my $fh, ">", "_eol.csv";
- print $fh qq{@row$eol@row$eol@row$eol\x91};
- close $fh;
- open $fh, "<", "_eol.csv";
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh qq{@row$eol@row$eol@row$eol\x91};
+ close $fh;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
my $c = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 });
is ($c->eol (), "", "default EOL");
is_deeply ($c->getline ($fh), [ @row ], "EOL 1 $s_eol");
is ($c->eol (), $eol eq "\r" ? "\r" : "", "EOL");
is_deeply ($c->getline ($fh), [ @row ], "EOL 2 $s_eol");
is_deeply ($c->getline ($fh), [ @row ], "EOL 3 $s_eol");
- close $fh;
- unlink "_eol.csv";
+ close $fh;
+ unlink $tfn;
}
}
ok (1, "Specific \\r test from tfrayner");
{ $/ = "\r";
- open my $fh, ">", "_eol.csv";
- print $fh qq{a,b,c$/}, qq{"d","e","f"$/};
- close $fh;
- open $fh, "<", "_eol.csv";
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh qq{a,b,c$/}, qq{"d","e","f"$/};
+ close $fh;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
my $c = Text::CSV_XS->new ({ eol => $/ });
my $row;
@@ -147,25 +148,25 @@ ok (1, "Specific \\r test from tfrayner");
ok ($row = $c->getline ($fh), "getline 2");
is (scalar @$row, 3, "# fields");
is ("@$row", "d e f", "fields 2");
- close $fh;
- unlink "_eol.csv";
+ close $fh;
+ unlink $tfn;
}
$/ = $def_rs;
ok (1, "EOL undef");
{ $/ = "\r";
ok (my $csv = Text::CSV_XS->new ({ eol => undef }), "new csv with eol => undef");
- open my $fh, ">", "_eol.csv";
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
ok ($csv->print ($fh, [1, 2, 3]), "print");
ok ($csv->print ($fh, [4, 5, 6]), "print");
- close $fh;
+ close $fh;
- open $fh, "<", "_eol.csv";
+ open $fh, "<", $tfn or die "$tfn: $!\n";
ok (my $row = $csv->getline ($fh), "getline 1");
is (scalar @$row, 5, "# fields");
is_deeply ($row, [ 1, 2, 34, 5, 6], "fields 1");
- close $fh;
- unlink "_eol.csv";
+ close $fh;
+ unlink $tfn;
}
$/ = $def_rs;
@@ -177,7 +178,7 @@ foreach my $eol ("!", "!!", "!\n", "!\n!", "!!!!!!!!", "!!!!!!!!!!",
$s_eol =~ s/\0/\\0/g;
ok (1, "EOL $s_eol");
ok (my $csv = Text::CSV_XS->new ({ eol => $eol }), "new csv with eol => $s_eol");
- open my $fh, ">", "_eol.csv";
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
ok ($csv->print ($fh, [1, 2, 3]), "print");
ok ($csv->print ($fh, [4, 5, 6]), "print");
close $fh;
@@ -186,7 +187,7 @@ foreach my $eol ("!", "!!", "!\n", "!\n!", "!!!!!!!!", "!!!!!!!!!!",
local $/ = $rs;
(my $s_rs = defined $rs ? $rs : "-- undef --") =~ s/\n/\\n/g;
ok (1, "with RS $s_rs");
- open $fh, "<", "_eol.csv";
+ open $fh, "<", $tfn or die "$tfn: $!\n";
ok (my $row = $csv->getline ($fh), "getline 1");
is (scalar @$row, 3, "field count");
is_deeply ($row, [ 1, 2, 3], "fields 1");
@@ -195,11 +196,11 @@ foreach my $eol ("!", "!!", "!\n", "!\n!", "!!!!!!!!", "!!!!!!!!!!",
is_deeply ($row, [ 4, 5, 6], "fields 2");
close $fh;
}
- unlink "_eol.csv";
+ unlink $tfn;
}
$/ = $def_rs;
-{ open my $fh, "<", "files/macosx.csv" or die "Ouch $!";
+{ open my $fh, "<", "files/macosx.csv" or die "files/macosx.csv: $!";
ok (1, "MacOSX exported file");
ok (my $csv = Text::CSV_XS->new ({ auto_diag => 1, binary => 1 }), "new csv");
ok (my $row = $csv->getline ($fh), "getline 1");
@@ -262,17 +263,16 @@ $/ = $def_rs;
ok ($csv->parse (qq{1,"2--3",4,--}), ",eol");
is_deeply ([$csv->fields], [ "1", "2--3", 4, "" ], "parse");
- open my $fh, ">", "_eol.csv";
- print $fh qq{1,"2--3",4--};
- print $fh qq{1,"2--3",4,--};
- print $fh qq{1,"2--3",4};
- close $fh;
- open $fh, "<", "_eol.csv";
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh qq{1,"2--3",4--};
+ print $fh qq{1,"2--3",4,--};
+ print $fh qq{1,"2--3",4};
+ close $fh;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
is_deeply ($csv->getline ($fh), [ "1", "2--3", 4 ], "getline eol");
is_deeply ($csv->getline ($fh), [ "1", "2--3", 4, "" ], "getline ,eol");
is_deeply ($csv->getline ($fh), [ "1", "2--3", 4 ], "getline eof");
- close $fh;
- unlink "_eol.csv";
+ close $fh;
}
1;
@@ -42,10 +42,10 @@ foreach my $rs ("\n", "\r\n", "\r") {
foreach my $pass (0, 1) {
if ($pass == 0) {
$file = "";
- open $fh, ">", \$file;
+ open $fh, ">", \$file or die "IO: $!\n";
}
else {
- open $fh, "<", \$file;
+ open $fh, "<", \$file or die "IO: $!\n";
}
foreach my $eol ("", "\r", "\n", "\r\n", "\n\r") {
@@ -105,24 +105,24 @@ SKIP: {
{ local $\ = "#\r\n";
my $csv = Text::CSV_XS->new ();
$file = "";
- open my $fh, ">", \$file;
+ open my $fh, ">", \$file or die "IO: $!\n";
$csv->print ($fh, [ "a", 1 ]);
- close $fh;
- open $fh, "<", \$file;
+ close $fh;
+ open $fh, "<", \$file or die "IO: $!\n";
local $/;
is (<$fh>, "a,1#\r\n", "Strange \$\\");
- close $fh;
+ close $fh;
}
{ local $\ = "#\r\n";
my $csv = Text::CSV_XS->new ({ eol => $\ });
$file = "";
- open my $fh, ">", \$file;
+ open my $fh, ">", \$file or die "IO: $!\n";
$csv->print ($fh, [ "a", 1 ]);
- close $fh;
- open $fh, "<", \$file;
+ close $fh;
+ open $fh, "<", \$file or die "IO: $!\n";
local $/;
is (<$fh>, "a,1#\r\n", "Strange \$\\ + eol");
- close $fh;
+ close $fh;
}
}
$/ = $def_rs;
@@ -132,10 +132,10 @@ ok (1, "Auto-detecting \\r");
for (["\n", "\\n"], ["\r\n", "\\r\\n"], ["\r", "\\r"]) {
my ($eol, $s_eol) = @$_;
$file = "";
- open my $fh, ">", \$file;
- print $fh qq{@row$eol@row$eol@row$eol\x91};
- close $fh;
- open $fh, "<", \$file;
+ open my $fh, ">", \$file or die "IO: $!\n";
+ print $fh qq{@row$eol@row$eol@row$eol\x91};
+ close $fh;
+ open $fh, "<", \$file or die "IO: $!\n";
my $c = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 });
is ($c->eol (), "", "default EOL");
is_deeply ($c->getline ($fh), [ @row ], "EOL 1 $s_eol");
@@ -149,10 +149,10 @@ ok (1, "Auto-detecting \\r");
ok (1, "Specific \\r test from tfrayner");
{ $/ = "\r";
$file = "";
- open my $fh, ">", \$file;
- print $fh qq{a,b,c$/}, qq{"d","e","f"$/};
- close $fh;
- open $fh, "<", \$file;
+ open my $fh, ">", \$file or die "IO: $!\n";
+ print $fh qq{a,b,c$/}, qq{"d","e","f"$/};
+ close $fh;
+ open $fh, "<", \$file or die "IO: $!\n";
my $c = Text::CSV_XS->new ({ eol => $/ });
my $row;
@@ -171,12 +171,12 @@ ok (1, "EOL undef");
{ $/ = "\r";
ok (my $csv = Text::CSV_XS->new ({ eol => undef }), "new csv with eol => undef");
$file = "";
- open my $fh, ">", \$file;
+ open my $fh, ">", \$file or die "IO: $!\n";
ok ($csv->print ($fh, [1, 2, 3]), "print");
ok ($csv->print ($fh, [4, 5, 6]), "print");
close $fh;
- open $fh, "<", \$file;
+ open $fh, "<", \$file or die "IO: $!\n";
ok (my $row = $csv->getline ($fh), "getline 1");
is (scalar @$row, 5, "# fields");
is_deeply ($row, [ 1, 2, 34, 5, 6], "fields 1");
@@ -189,7 +189,7 @@ foreach my $eol ("!", "!!", "!\n", "!\n!") {
ok (1, "EOL $s_eol");
ok (my $csv = Text::CSV_XS->new ({ eol => $eol }), "new csv with eol => $s_eol");
$file = "";
- open my $fh, ">", \$file;
+ open my $fh, ">", \$file or die "IO: $!\n";
ok ($csv->print ($fh, [1, 2, 3]), "print");
ok ($csv->print ($fh, [4, 5, 6]), "print");
close $fh;
@@ -198,7 +198,7 @@ foreach my $eol ("!", "!!", "!\n", "!\n!") {
local $/ = $rs;
(my $s_rs = defined $rs ? $rs : "-- undef --") =~ s/\n/\\n/g;
ok (1, "with RS $s_rs");
- open $fh, "<", \$file;
+ open $fh, "<", \$file or die "IO: $!\n";
ok (my $row = $csv->getline ($fh), "getline 1");
is (scalar @$row, 3, "# fields");
is_deeply ($row, [ 1, 2, 3], "fields 1");
@@ -212,19 +212,19 @@ $/ = $def_rs;
{ ok (my $csv = Text::CSV_XS->new, "new for say");
my $foo;
- open my $fh, ">", \$foo;
+ open my $fh, ">", \$foo or die "IO: $!\n";
ok ($csv->say ($fh, [ 1, 2 ]), "say");
close $fh;
is ($foo, "1,2$/");
$foo = "";
$csv->eol ("#");
- open $fh, ">", \$foo;
+ open $fh, ">", \$foo or die "IO: $!\n";
ok ($csv->say ($fh, [ 1, 2 ]), "say");
close $fh;
is ($foo, "1,2#");
$foo = "";
$csv->eol ("0");
- open $fh, ">", \$foo;
+ open $fh, ">", \$foo or die "IO: $!\n";
ok ($csv->say ($fh, [ 1, 2 ]), "say");
close $fh;
is ($foo, "1,20");
@@ -20,6 +20,7 @@ BEGIN {
require "t/util.pl";
}
+my $tfn = "_50test.csv"; END { -f $tfn and unlink $tfn; }
# No binary => 1, as UTF8 is supposed to be allowed without it
my $csv = Text::CSV_XS->new ({
always_quote => 1,
@@ -106,10 +107,10 @@ ok ($csv->parse (qq{,1,"f\x{014d}o, 3""56",,bar,\r\n}), "example from XS");
is_deeply ([$csv->fields], [
"", 1, qq{f\x{014d}o, 3"56}, "", "bar", "" ], "content");
-open my $fh, ">:encoding(utf-8)", "_50test.csv";
-print $fh "euro\n\x{20ac}\neuro\n";
-close $fh;
-open $fh, "<:encoding(utf-8)", "_50test.csv";
+open my $fh, ">:encoding(utf-8)", $tfn or die "$tfn: $!\n";
+print $fh "euro\n\x{20ac}\neuro\n";
+close $fh;
+open $fh, "<:encoding(utf-8)", $tfn or die "$tfn: $!\n";
SKIP: {
my $out = "";
@@ -132,5 +133,4 @@ SKIP: {
is ($out, "euro", "euro");
ok (!$isutf8->(1), "not utf8");
close $fh;
- unlink "_50test.csv";
}
@@ -27,7 +27,8 @@ BEGIN {
@tests = (
# $test $perlio $data, $encoding $expect_w
# ---------------------------- ------------------- ----------- --------- ----------
- [ "Unicode default", "", $euro_ch, "utf8", "warn", ],
+ [ "Unicode default", "", $euro_ch, "utf8",
+ exists $ENV{PERL_UNICODE} ? "no warn" : "warn", ],
[ "Unicode binmode", "[binmode]", $euro_ch, "utf8", "warn", ],
[ "Unicode :utf8", ":utf8", $euro_ch, "utf8", "no warn", ],
[ "Unicode :encoding(utf8)", ":encoding(utf8)", $euro_ch, "utf8", "no warn", ],
@@ -75,12 +76,12 @@ for (@tests) {
my ($c_out, $c_fh) = ("");
if ($perlio eq "[binmode]") {
- open $p_fh, ">", \$p_out; binmode $p_fh;
- open $c_fh, ">", \$c_out; binmode $c_fh;
+ open $p_fh, ">", \$p_out or die "IO: $!\n"; binmode $p_fh;
+ open $c_fh, ">", \$c_out or die "IO: $!\n"; binmode $c_fh;
}
else {
- open $p_fh, ">$perlio", \$p_out;
- open $c_fh, ">$perlio", \$c_out;
+ open $p_fh, ">$perlio", \$p_out or die "IO: $!\n";
+ open $c_fh, ">$perlio", \$c_out or die "IO: $!\n";
}
my $p_warn = "";
@@ -121,7 +122,7 @@ for (@tests) {
my @read;
# Using getline ()
- open my $fh, "<", \$data;
+ open my $fh, "<", \$data or die "IO: $!\n"; binmode $fh;
$bc and $csv->bind_columns (\my ($f1, $f2, $f3));
is (scalar $csv->bind_columns, $bc, "Columns_bound?");
while (my $row = $csv->getline ($fh)) {
@@ -175,7 +176,7 @@ foreach my $new (0, 1, 2, 3) {
my $x = $csv->string;
is ($csv->string, $exp8, "string");
- open my $fh, ">:encoding(utf8)", \(my $out = "");
+ open my $fh, ">:encoding(utf8)", \(my $out = "") or die "IO: $!\n";
ok ($csv->print ($fh, $data), "print with UTF8 sep");
close $fh;
@@ -184,7 +185,7 @@ foreach my $new (0, 1, 2, 3) {
ok ($csv->parse ($expb), "parse");
is_deeply ([ $csv->fields ], $data, "fields");
- open $fh, "<", \$expb;
+ open $fh, "<", \$expb or die "IO: $!\n"; binmode $fh;
is_deeply ($csv->getline ($fh), $data, "data from getline ()");
close $fh;
@@ -193,7 +194,7 @@ foreach my $new (0, 1, 2, 3) {
ok ($csv->parse ($expb), "parse");
is_deeply ([ $csv->fields ], $data, "fields");
- open $fh, "<", \$expb;
+ open $fh, "<", \$expb or die "IO: $!\n"; binmode $fh;
is_deeply ($csv->getline ($fh), $data, "data from getline ()");
close $fh;
}
@@ -12,7 +12,7 @@ BEGIN {
require "t/util.pl";
}
-my $file = "_65test.csv";
+my $tfn = "_65test.csv"; END { -f $tfn and unlink $tfn; }
my $csv;
ok (1, "Allow unescaped quotes");
@@ -325,14 +325,14 @@ foreach my $bin (0, 1) {
}
ok (1, "verbatim on getline (*FH)");
- open FH, ">", $file;
+ open FH, ">", $tfn or die "$tfn: $!\n";
print FH @str, "M^Abe^*\r\n";
close FH;
foreach $gc (0, 1) {
$csv->verbatim ($gc);
- open FH, "<", $file;
+ open FH, "<", $tfn or die "$tfn: $!\n";
my $row;
ok ($row = $csv->getline (*FH), "#\\r\\n $gc getline");
@@ -358,27 +358,26 @@ foreach my $bin (0, 1) {
verbatim => 1,
eol => "#\r\n",
});
- open my $fh, ">", $file;
- print $fh $str[1];
- close $fh;
- open $fh, "<", $file;
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh $str[1];
+ close $fh;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
is ($csv->getline ($fh), undef, "#\\r\\n $gc getline 2030");
is (0 + $csv->error_diag, 2030, "Got 2030");
- close $fh;
-
- unlink $file;
+ close $fh;
+ unlink $tfn;
}
{ ok (1, "keep_meta_info on getline ()");
my $csv = Text::CSV_XS->new ({ eol => "\n" });
- open my $fh, ">", $file;
- print $fh qq{1,"",,"Q",2\n};
- close $fh;
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh qq{1,"",,"Q",2\n};
+ close $fh;
is ($csv->keep_meta_info (0), 0, "No meta info");
- open $fh, "<", $file;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
my $row = $csv->getline ($fh);
ok ($row, "Get 1st line");
$csv->error_diag ();
@@ -386,19 +385,19 @@ foreach my $bin (0, 1) {
is ($csv->is_quoted (3), undef, "Is field 3 quoted?");
close $fh;
- open $fh, ">", $file;
- print $fh qq{1,"",,"Q",2\n};
- close $fh;
+ open $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh qq{1,"",,"Q",2\n};
+ close $fh;
is ($csv->keep_meta_info (1), 1, "Keep meta info");
- open $fh, "<", $file;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
$row = $csv->getline ($fh);
ok ($row, "Get 2nd line");
$csv->error_diag ();
is ($csv->is_quoted (2), 0, "Is field 2 quoted?");
is ($csv->is_quoted (3), 1, "Is field 3 quoted?");
- close $fh;
- unlink $file;
+ close $fh;
+ unlink $tfn;
}
{ my $csv = Text::CSV_XS->new ({});
@@ -12,8 +12,7 @@ BEGIN {
require "t/util.pl";
}
-my $csv_file = "_70test.csv";
-END { unlink $csv_file }
+my $tfn = "_70test.csv"; END { unlink $tfn, "_$tfn"; }
my ($rt, %input, %desc);
while (<DATA>) {
@@ -46,11 +45,11 @@ while (<DATA>) {
{ # http://rt.cpan.org/Ticket/Display.html?id=21530
$rt = 21530; # getline () does not return documented value at end of
# filehandle IO::Handle was first released with perl 5.00307
- open my $fh, ">", $csv_file;
- print $fh @{$input{$rt}};
- close $fh;
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh @{$input{$rt}};
+ close $fh;
ok (my $csv = Text::CSV_XS->new ({ binary => 1 }), "RT-$rt: $desc{$rt}");
- open $fh, "<", $csv_file;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
my $row;
foreach my $line (1 .. 5) {
ok ($row = $csv->getline ($fh), "getline $line");
@@ -59,8 +58,8 @@ while (<DATA>) {
}
ok (eof $fh, "EOF");
is ($row = $csv->getline ($fh), undef, "getline EOF");
- close $fh;
- unlink $csv_file;
+ close $fh;
+ unlink $tfn;
}
{ # http://rt.cpan.org/Ticket/Display.html?id=21530
@@ -97,12 +96,12 @@ while (<DATA>) {
{ # http://rt.cpan.org/Ticket/Display.html?id=34474
$rt = 34474; # wish: integrate row-as-hashref feature from Parse::CSV
- open my $fh, ">$csv_file";
- print $fh @{$input{$rt}};
- close $fh;
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh @{$input{$rt}};
+ close $fh;
ok (my $csv = Text::CSV_XS->new (), "RT-$rt: $desc{$rt}");
is ($csv->column_names, undef, "No headers yet");
- open $fh, "<$csv_file";
+ open $fh, "<", $tfn or die "$tfn: $!\n";
my $row;
ok ($row = $csv->getline ($fh), "getline headers");
is ($row->[0], "code", "Header line");
@@ -114,24 +113,24 @@ while (<DATA>) {
ok (exists $hr->{name}, "Line has a name field");
like ($hr->{name}, qr/^[A-Z][a-z]+$/, "Name");
}
- close $fh;
- unlink $csv_file;
+ close $fh;
+ unlink $tfn;
}
{ # http://rt.cpan.org/Ticket/Display.html?id=38960
$rt = 38960; # print () on invalid filehandle warns and returns success
- open my $fh, ">", $csv_file;
- print $fh "";
- close $fh;
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh "";
+ close $fh;
my $err = "";
- open $fh, "<", $csv_file;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
ok (my $csv = Text::CSV_XS->new (), "RT-$rt: $desc{$rt}");
local $SIG{__WARN__} = sub { $err = "Warning" };
ok (!$csv->print ($fh, [ 1 .. 4 ]), "print ()");
is ($err, "Warning", "IO::Handle triggered a warning");
is (($csv->error_diag)[0], 2200, "error 2200");
- close $fh;
- unlink $csv_file;
+ close $fh;
+ unlink $tfn;
}
{ # http://rt.cpan.org/Ticket/Display.html?id=40507
@@ -157,18 +156,18 @@ while (<DATA>) {
SKIP: {
$] < 5.008002 and skip "UTF8 unreliable in perl $]", 6;
- open my $fh, ">", $csv_file;
- print $fh @{$input{$rt}};
- close $fh;
+ open my $fh, ">:raw", $tfn or die "$tfn: $!\n";
+ print $fh @{$input{$rt}};
+ close $fh;
my ($sep, $quo) = ("\x14", "\xfe");
chop ($_ = "$_\x{20ac}") for $sep, $quo;
ok (my $csv = Text::CSV_XS->new ({ binary => 1, sep_char => $sep }), "RT-$rt: $desc{$rt}");
ok ($csv->quote_char ($quo), "Set quote_char");
- open $fh, "<", $csv_file;
+ open $fh, "<:raw", $tfn or die "$tfn: $!\n";
ok (my $row = $csv->getline ($fh), "getline () with decode sep/quo");
$csv->error_diag ();
- close $fh;
- unlink $csv_file;
+ close $fh;
+ unlink $tfn;
is_deeply ($row, [qw( DOG CAT WOMBAT BANDERSNATCH )], "fields ()");
ok ($csv->parse ($input{$rt}[1]), "parse () with decoded sep/quo");
is_deeply ([ $csv->fields ], [ 0..3 ], "fields ()");
@@ -177,24 +176,24 @@ while (<DATA>) {
{ # http://rt.cpan.org/Ticket/Display.html?id=43927
$rt = 43927; # Is bind_columns broken or am I using it wrong?
- open my $fh, ">", $csv_file;
- print $fh @{$input{$rt}};
- close $fh;
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh @{$input{$rt}};
+ close $fh;
my ($c1, $c2);
ok (my $csv = Text::CSV_XS->new ({ binary => 1 }), "RT-$rt: $desc{$rt}");
ok ($csv->bind_columns (\$c1, \$c2), "bind columns");
- open $fh, "<", $csv_file;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
ok (my $row = $csv->getline ($fh), "getline () with bound columns");
$csv->error_diag ();
- close $fh;
- unlink $csv_file;
+ close $fh;
+ unlink $tfn;
is_deeply ($row, [], "should return empty ref");
is_deeply ([ $c1, $c2], [ 1, 2 ], "fields ()");
}
{ # http://rt.cpan.org/Ticket/Display.html?id=44402
$rt = 44402; # Unexpected results parsing tab-separated spaces
- open my $fh, ">", $csv_file;
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
my @ws = ("", " ", " ");
foreach my $f1 (@ws) {
foreach my $f2 (@ws) {
@@ -209,7 +208,7 @@ while (<DATA>) {
ok ($csv = Text::CSV_XS->new ({
sep_char => "\t",
}), "RT-$rt: $desc{$rt}");
- open $fh, "<", $csv_file;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
while (my $row = $csv->getline ($fh)) {
ok ($row, "getline $.");
my @row = @$row;
@@ -223,7 +222,7 @@ while (<DATA>) {
sep_char => "\t",
allow_whitespace => 1,
}), "RT-$rt: $desc{$rt}");
- open $fh, "<", $csv_file;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
while (my $row = $csv->getline ($fh)) {
ok ($row, "getline $.");
my @row = @$row;
@@ -231,8 +230,8 @@ while (<DATA>) {
is ($row[$_], "", "field $_ empty") for 0..2;
}
ok ($csv->eof, "read complete file");
- close $fh;
- unlink $csv_file;
+ close $fh;
+ unlink $tfn;
ok ($csv->parse (" \t \t "), "parse ()");
is_deeply ([$csv->fields],["","",""],"3 empty fields");
@@ -240,9 +239,9 @@ while (<DATA>) {
{ # Detlev reported an inconsistent difference between _XS and _PP
$rt = "x1000";
- open my $fh, ">", $csv_file;
- print $fh @{$input{$rt}};
- close $fh;
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh @{$input{$rt}};
+ close $fh;
my ($c1, $c2);
ok (my $csv = Text::CSV_XS->new ({
binary => 1,
@@ -251,7 +250,7 @@ while (<DATA>) {
escape_char => undef,
quote_char => undef,
binary => 1 }), "RT-$rt: $desc{$rt}");
- open $fh, "<", $csv_file;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
for (1 .. 4) {
ok (my $row = $csv->getline ($fh), "getline ()");
is (scalar @$row, 27, "Line $_: 27 columns");
@@ -261,26 +260,26 @@ while (<DATA>) {
is (scalar @$row, 1, "Line $_: 1 column");
}
$csv->error_diag ();
- close $fh;
- unlink $csv_file;
+ close $fh;
+ unlink $tfn;
}
{ # Ruslan reported a case where only Text::CSV_PP misbehaved (regression test)
$rt = "x1001";
- open my $fh, ">", $csv_file;
- print $fh @{$input{$rt}};
- close $fh;
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh @{$input{$rt}};
+ close $fh;
my ($c1, $c2);
ok (my $csv = Text::CSV_XS->new (), "RT-$rt: $desc{$rt}");
- open $fh, "<", $csv_file;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
for (1 .. 4) {
ok (my $row = $csv->getline ($fh), "getline ($_)");
is (scalar @$row, 2, "Line $_: 2 columns");
my @exp = $_ <= 2 ? ("0", "A") : ("A", "0");
is_deeply ($row, \@exp, "@exp");
}
- close $fh;
- unlink $csv_file;
+ close $fh;
+ unlink $tfn;
}
{ # http://rt.cpan.org/Ticket/Display.html?id=58356
@@ -308,19 +307,19 @@ while (<DATA>) {
auto_diag => 1,
}), "RT-$rt: $desc{$rt} - eol = $s_eol (1)");
- open my $fh, ">", $csv_file;
- print $fh join $eol => qw( "a":"b" "c":"d" "e":"x!y" "!!":"z" );
- close $fh;
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh join $eol => qw( "a":"b" "c":"d" "e":"x!y" "!!":"z" );
+ close $fh;
- open $fh, "<", $csv_file;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
is_deeply ($csv->getline ($fh), [ "a", "b" ], "Pair 1");
is_deeply ($csv->getline ($fh), [ "c", "d" ], "Pair 2");
is_deeply ($csv->getline ($fh), [ "e", "x!y" ], "Pair 3");
is_deeply ($csv->getline ($fh), [ "!!", "z" ], "Pair 4");
is ($csv->getline ($fh), undef, "no more pairs");
ok ($csv->eof, "EOF");
- close $fh;
- unlink $csv_file;
+ close $fh;
+ unlink $tfn;
}
# And secondly with eol as method only if not one of the defaults
@@ -336,30 +335,31 @@ while (<DATA>) {
}), "RT-$rt: $desc{$rt} - eol = $s_eol (2)");
$eol eq "!" and $csv->eol ($eol);
- open my $fh, ">", $csv_file;
- print $fh join $eol => qw( "a":"b" "c":"d" "e":"x!y" "!!":"z" );
- close $fh;
- open $fh, "<", $csv_file;
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh join $eol => qw( "a":"b" "c":"d" "e":"x!y" "!!":"z" );
+ close $fh;
+
+ open $fh, "<", $tfn or die "$tfn: $!\n";
is_deeply ($csv->getline ($fh), [ "a", "b" ], "Pair 1");
is_deeply ($csv->getline ($fh), [ "c", "d" ], "Pair 2");
is_deeply ($csv->getline ($fh), [ "e", "x!y" ], "Pair 3");
is_deeply ($csv->getline ($fh), [ "!!", "z" ], "Pair 4");
is ($csv->getline ($fh), undef, "no more pairs");
ok ($csv->eof, "EOF");
- close $fh;
- unlink $csv_file;
+ close $fh;
+ unlink $tfn;
}
}
{ # http://rt.cpan.org/Ticket/Display.html?id=74216
$rt = "74216"; # setting 'eol' affects global input record separator
- open my $fh, ">", $csv_file;
- print $fh @{$input{$rt}};
- close $fh;
+ open my $fh, ">", $tfn or die "$tfn: $!\n";
+ print $fh @{$input{$rt}};
+ close $fh;
my $slurp_check = sub {
- open $fh, "<", $csv_file;
+ open $fh, "<", $tfn or die "$tfn: $!\n";
is (scalar @{[<$fh>]}, 4);
close $fh;
};
@@ -367,14 +367,14 @@ while (<DATA>) {
$slurp_check->();
my $crlf = "\015\012";
- open my $fhx, ">", "_$csv_file";
- print $fhx "a,b,c" . $crlf . "1,2,3" . $crlf;
- close $fhx;
- open $fhx, "<", "_$csv_file";
+ open my $fhx, ">", "_$tfn" or die "_$tfn: $!\n";
+ print $fhx "a,b,c" . $crlf . "1,2,3" . $crlf;
+ close $fhx;
+ open $fhx, "<", "_$tfn" or die "_$tfn: $!\n";
my $csv = Text::CSV_XS->new ({ eol => $crlf });
is_deeply ($csv->getline ($fhx), [qw( a b c )]);
- close $fhx;
- unlink "_$csv_file";
+ close $fhx;
+ unlink "_$tfn";
$slurp_check->();
@@ -422,7 +422,7 @@ SKIP: { # http://rt.cpan.org/Ticket/Display.html?id=80680
my $enc = Encode::encode ("UTF-8", $data);
my $exp = qq{1,"$enc"};
my $out = "";
- open my $fh, ">:encoding(utf-8)", \$out;
+ open my $fh, ">:encoding(utf-8)", \$out or die "IO: $!\n";
$csv->print ($fh, [ 1, $data ]);
close $fh;
@@ -11,7 +11,9 @@ BEGIN {
plan skip_all => "Cannot load Text::CSV_XS" if $@;
}
-open my $fh, ">", "_75test.csv";
+my $tfn = "_75hashref.csv"; END { -f $tfn and unlink $tfn; }
+
+open my $fh, ">", $tfn or die "$tfn: $!\n";
print $fh <<EOC;
code,name,price,description
1,Dress,240.00,"Evening gown"
@@ -46,7 +48,7 @@ is ($csv->error_diag () + 0, 3002, "error code");
ok ($csv->column_names ("name", "code"), "column_names (list)");
is_deeply ([ $csv->column_names ], [ "name", "code" ], "well set");
-open $fh, "<", "_75test.csv";
+open $fh, "<", $tfn or die "$tfn: $!\n";
my $row;
ok ($row = $csv->getline ($fh), "getline headers");
is ($row->[0], "code", "Header line");
@@ -76,7 +78,7 @@ eval { $csv->bind_columns ([undef]) };
is ($csv->error_diag () + 0, 3004, "legal header defenition");
my @bcr = \($code, $name, $price, $desc);
-open $fh, "<", "_75test.csv";
+open $fh, "<", $tfn or die "$tfn: $!\n";
ok ($row = $csv->getline ($fh), "getline headers");
ok ($csv->bind_columns (@bcr), "Bind columns");
ok ($csv->column_names ($row), "column_names from array_ref");
@@ -109,7 +111,7 @@ is ($csv->error_diag () + 0, 3006, "cannot read all fields");
close $fh;
-open $fh, "<", "_75test.csv";
+open $fh, "<", $tfn or die "$tfn: $!\n";
is ($csv->column_names (undef), undef, "reset column headers");
is ($csv->bind_columns (undef), undef, "reset bound columns");
@@ -122,7 +124,7 @@ is_deeply ($hr, { "\cAUNDEF\cA" => "code", "" => "name", "name" => "description"
close $fh;
-open $fh, ">", "_75test.csv";
+open $fh, ">", $tfn or die "$tfn: $!\n";
$hr = { c_foo => 1, foo => "poison", zebra => "Of course" };
is ($csv->column_names (undef), undef, "reset column headers");
ok ($csv->column_names (sort keys %$hr), "set column names");
@@ -132,7 +134,7 @@ ok ($csv->print_hr ($fh, $hr), "print_hr");
ok ($csv->print ($fh, []), "empty print");
close $fh;
ok ($csv->keep_meta_info (1), "keep meta info");
-open $fh, "<", "_75test.csv";
+open $fh, "<", $tfn or die "$tfn: $!\n";
ok ($csv->column_names ($csv->getline ($fh)), "get column names");
is_deeply ($csv->getline_hr ($fh), $hr, "compare to written hr");
@@ -140,5 +142,3 @@ is_deeply ($csv->getline_hr ($fh),
{ c_foo => "", foo => undef, zebra => undef }, "compare to written hr");
is ($csv->is_missing (1), 1, "No col 1");
close $fh;
-
-unlink "_75test.csv";
@@ -11,6 +11,7 @@ BEGIN {
plan skip_all => "Cannot load Text::CSV_XS" if $@;
}
+my $tfn = "_76test.csv"; END { -f $tfn and unlink $tfn; }
my $csv = Text::CSV_XS->new ({ binary => 1, eol => "\n" });
my $fh;
@@ -30,12 +31,12 @@ untie $bar;
is_deeply ([$csv->fields], \@foo, "column_names ()");
tie $foo, "Foo";
-open $fh, ">", "_76test.csv";
+open $fh, ">", $tfn or die "$tfn: $!\n";
ok ($csv->print ($fh, $foo), "print with unused magic scalar");
close $fh;
untie $foo;
-open $fh, "<", "_76test.csv";
+open $fh, "<", $tfn or die "$tfn: $!\n";
is_deeply ($csv->getline ($fh), \@foo, "Content read-back");
close $fh;
@@ -44,7 +45,7 @@ ok ($csv->column_names ($foo), "column_names () from magic");
untie $foo;
is_deeply ([$csv->column_names], \@foo, "column_names ()");
-open $fh, "<", "_76test.csv";
+open $fh, "<", $tfn or die "$tfn: $!\n";
tie $bar, "Bar";
ok ($csv->bind_columns (\$bar, \my ($f0, $f1, $f2)), "bind");
ok ($csv->getline ($fh), "fetch with magic");
@@ -54,8 +55,6 @@ is ($csv->bind_columns (undef), undef, "bind column clear");
untie $bar;
close $fh;
-unlink "_76test.csv";
-
{ package Foo;
use strict;
use warnings;
@@ -13,6 +13,7 @@ BEGIN {
$| = 1;
+my $tfn = "_77test.csv"; END { -f $tfn and unlink $tfn; }
my @testlist = (
[ 1, "a", "\x01", "A" ],
[ 2, "b", "\x02", "B" ],
@@ -42,7 +43,7 @@ foreach my $eol ("\n", "\r") {
@list = @testlist;
{ ok (my $csv = Text::CSV_XS->new ({ binary => 1, eol => $eol }), "csv out EOL "._readable ($eol));
- open my $fh, ">", "_77test.csv" or die "_77test.csv: $!";
+ open my $fh, ">", $tfn or die "$tfn: $!";
ok ($csv->print ($fh, $_), "write $_->[0]") for @list;
close $fh;
}
@@ -51,7 +52,7 @@ foreach my $eol ("\n", "\r") {
do_tests (sub {
my ($expect, @args) = @_;
- open my $fh, "<", "_77test.csv" or die "_77test.csv: $!";
+ open my $fh, "<", $tfn or die "$tfn: $!";
my $s_args = join ", " => @args;
is_deeply ($csv->getline_all ($fh, @args), $expect, "getline_all ($s_args)");
close $fh;
@@ -64,7 +65,7 @@ foreach my $eol ("\n", "\r") {
do_tests (sub {
my ($expect, @args) = @_;
- open my $fh, "<", "_77test.csv" or die "_77test.csv: $!";
+ open my $fh, "<", $tfn or die "$tfn: $!";
my $s_args = join ", " => @args;
is_deeply ($csv->getline_hr_all ($fh, @args), $expect, "getline_hr_all ($s_args)");
close $fh;
@@ -72,10 +73,8 @@ foreach my $eol ("\n", "\r") {
}
{ ok (my $csv = Text::CSV_XS->new ({ binary => 1 }), "csv in");
- open my $fh, "<", "_77test.csv" or die "_77test.csv: $!";
+ open my $fh, "<", $tfn or die "$tfn: $!";
eval { my $row = $csv->getline_hr_all ($fh); };
is ($csv->error_diag () + 0, 3002, "Use _hr before colnames ()");
}
-
- unlink "_77test.csv";
}
@@ -80,23 +80,23 @@ my @test = (
my $todo = "";
my $data = join "" => <DATA>;
while (my ($spec, $expect) = splice @test, 0, 2) {
- open my $io, "<", \$data;
+ open my $io, "<", \$data or die "IO: $!\n";
my $aoa = $csv->fragment ($io, $spec);
is_deeply ($aoa, $expect, "${todo}Fragment $spec");
}
{ $csv->column_names ("c3", "c4");
- open my $io, "<", \$data;
+ open my $io, "<", \$data or die "IO: $!\n";
is_deeply ($csv->fragment ($io, "cell=3,2-4,3"),
[ { c3 => 32, c4 => 33 }, { c3 => 42, c4 => 43 }], "Fragment to AoH");
}
{ $csv->column_names ("C1", "C2");
- open my $io, "<", \$data;
+ open my $io, "<", \$data or die "IO: $!\n";
is_deeply ($csv->fragment ($io, "row=3"),
[ { C1 => 31, C2 => 32 }], "Fragment row with headers to AoH");
}
{ $csv->column_names ("C1");
- open my $io, "<", \$data;
+ open my $io, "<", \$data or die "IO: $!\n";
is_deeply ($csv->fragment ($io, "col=2"),
[ map +{ C1 => $_.2 } => 1 .. 9 ], "Fragment col with headers to AoH");
}
@@ -15,6 +15,7 @@ BEGIN {
$| = 1;
my $csv;
+my $tfn = "_79test.csv"; END { -f $tfn and unlink $tfn; }
# These tests are for the constructor
{ my $warn;
@@ -23,22 +24,22 @@ my $csv;
is ($warn, undef, "no warn for undef");
is ($csv->callbacks, $warn = undef, "no callbacks for undef");
ok ($csv = Text::CSV_XS->new ({ callbacks => 0 }), "new");
- like ($warn, qr{: ignored$}, "warn for 0");
+ like ($warn, qr{: ignored\n}, "warn for 0");
is ($csv->callbacks, $warn = undef, "no callbacks for 0");
ok ($csv = Text::CSV_XS->new ({ callbacks => 1 }), "new");
- like ($warn, qr{: ignored$}, "warn for 1");
+ like ($warn, qr{: ignored\n}, "warn for 1");
is ($csv->callbacks, $warn = undef, "no callbacks for 1");
ok ($csv = Text::CSV_XS->new ({ callbacks => \1 }), "new");
- like ($warn, qr{: ignored$}, "warn for \\1");
+ like ($warn, qr{: ignored\n}, "warn for \\1");
is ($csv->callbacks, $warn = undef, "no callbacks for \\1");
ok ($csv = Text::CSV_XS->new ({ callbacks => "" }), "new");
- like ($warn, qr{: ignored$}, "warn for ''");
+ like ($warn, qr{: ignored\n}, "warn for ''");
is ($csv->callbacks, $warn = undef, "no callbacks for ''");
ok ($csv = Text::CSV_XS->new ({ callbacks => [] }), "new");
- like ($warn, qr{: ignored$}, "warn for []");
+ like ($warn, qr{: ignored\n}, "warn for []");
is ($csv->callbacks, $warn = undef, "no callbacks for []");
ok ($csv = Text::CSV_XS->new ({ callbacks => sub {} }), "new");
- like ($warn, qr{: ignored$}, "warn for sub {}");
+ like ($warn, qr{: ignored\n}, "warn for sub {}");
is ($csv->callbacks, $warn = undef, "no callbacks for sub {}");
}
@@ -125,17 +126,14 @@ is_deeply ($row, [ 1, 2, 3, "NEW" ], "fetch + value from hook");
$error = 2012; # EOF
ok ($csv->getline (*DATA), "parse past eof");
-my $fn = "_79test.csv";
-END { unlink $fn; }
-
ok ($csv->eol ("\n"), "eol for output");
-open my $fh, ">", $fn or die "$fn: $!";
+open my $fh, ">", $tfn or die "$tfn: $!";
ok ($csv->print ($fh, [ 0, "foo" ]), "print OK");
ok ($csv->print ($fh, [ 0, "bar", 3 ]), "print too many");
ok ($csv->print ($fh, [ 0 ]), "print too few");
close $fh;
-open $fh, "<", $fn or die "$fn: $!";
+open $fh, "<", $tfn or die "$tfn: $!";
is (do { local $/; <$fh> }, "1,foo\n2,bar\n3,\n", "Modified output");
close $fh;
@@ -148,10 +146,10 @@ is ($csv->string, qq{11,fri,22,18\n}, "string");
is ($csv->callbacks (undef), undef, "clear callbacks");
-is_deeply (Text::CSV_XS::csv (in => $fn, callbacks => $callbacks),
+is_deeply (Text::CSV_XS::csv (in => $tfn, callbacks => $callbacks),
[[1,"foo","NEW"],[2,"bar","NEW"],[3,"","NEW"]], "using getline_all");
-open $fh, ">", $fn;
+open $fh, ">", $tfn or die "$tfn: $!\n";
print $fh <<"EOC";
1,foo
2,bar
@@ -160,7 +158,7 @@ print $fh <<"EOC";
EOC
close $fh;
-open $fh, "<", $fn;
+open $fh, "<", $tfn or die "$tfn: $!\n";
$csv->callbacks (after_parse => sub { $_[1][0] eq 3 and return \"skip" });
is_deeply ($csv->getline_all ($fh), [[1,"foo"],[2,"bar"],[4,"zoo"]]);
close $fh;
@@ -207,15 +207,15 @@ foreach my $spec (
}
my $diag_file = "_$$.out";
-open EH, ">&STDERR";
-open STDERR, ">", $diag_file;
+open EH, ">&STDERR" or die "STDERR: $!\n";
+open STDERR, ">", $diag_file or die "STDERR: $!\n";
# Trigger extra output for longer quote and sep
is ($csv->sep ("--"), "--", "set longer sep");
is ($csv->quote ("^^"), "^^", "set longer quote");
ok ($csv->_cache_diag, "Cache debugging output");
close STDERR;
-open STDERR, ">&EH";
-open EH, "<", $diag_file;
+open STDERR, ">&EH" or die "STDERR: $!\n";
+open EH, "<", $diag_file or die "STDERR: $!\n";
is (scalar <EH>, "CACHE:\n", "Title");
while (<EH>) {
like ($_, qr{^ \w+\s+[0-9a-f]+:(?:".*"|\s*[0-9]+)$}, "Content");
@@ -13,12 +13,12 @@ BEGIN {
require "t/util.pl";
}
-my $file = "_90test.csv"; END { -f $file and unlink $file }
+my $tfn = "_90test.csv"; END { -f $tfn and unlink $tfn }
my $data =
"foo,bar,baz\n".
"1,2,3\n".
"2,a b,\n";
-open FH, ">", $file or die "$file: $!";
+open FH, ">", $tfn or die "$tfn: $!";
print FH $data;
close FH;
@@ -33,34 +33,34 @@ my $aoh = [
{ foo => 2, bar => "a b", baz => "" },
];
-SKIP: for my $io ([ $file, "file" ], [ \*FH, "globref" ], [ *FH, "glob" ], [ \$data, "ScalarIO"] ) {
+SKIP: for my $io ([ $tfn, "file" ], [ \*FH, "globref" ], [ *FH, "glob" ], [ \$data, "ScalarIO"] ) {
$] < 5.008 && ref $io->[0] eq "SCALAR" and skip "No ScalarIO support for $]", 1;
- open FH, "<", $file;
+ open FH, "<", $tfn or die "$tfn: $!\n";
is_deeply (csv ({ in => $io->[0] }), $aoa, "AOA $io->[1]");
close FH;
}
-SKIP: for my $io ([ $file, "file" ], [ \*FH, "globref" ], [ *FH, "glob" ], [ \$data, "ScalarIO"] ) {
+SKIP: for my $io ([ $tfn, "file" ], [ \*FH, "globref" ], [ *FH, "glob" ], [ \$data, "ScalarIO"] ) {
$] < 5.008 && ref $io->[0] eq "SCALAR" and skip "No ScalarIO support for $]", 1;
- open FH, "<", $file;
+ open FH, "<", $tfn or die "$tfn: $!\n";
is_deeply (csv (in => $io->[0], headers => "auto"), $aoh, "AOH $io->[1]");
close FH;
}
-is_deeply (csv (in => $file, headers => { bar => "tender" }), [
+is_deeply (csv (in => $tfn, headers => { bar => "tender" }), [
{ foo => 1, tender => 2, baz => 3 },
{ foo => 2, tender => "a b", baz => "" },
], "AOH with header map");
my @aoa = @{$aoa}[1,2];
-is_deeply (csv (file => $file, headers => "skip"), \@aoa, "AOA skip");
-is_deeply (csv (file => $file, fragment => "row=2-3"), \@aoa, "AOA fragment");
+is_deeply (csv (file => $tfn, headers => "skip"), \@aoa, "AOA skip");
+is_deeply (csv (file => $tfn, fragment => "row=2-3"), \@aoa, "AOA fragment");
if ($] >= 5.008001) {
- is_deeply (csv (in => $file, encoding => "utf-8", headers => ["a", "b", "c"],
+ is_deeply (csv (in => $tfn, encoding => "utf-8", headers => ["a", "b", "c"],
fragment => "row=2", sep_char => ","),
[{ a => 1, b => 2, c => 3 }], "AOH headers fragment");
- is_deeply (csv (in => $file, enc => "utf-8", headers => ["a", "b", "c"],
+ is_deeply (csv (in => $tfn, enc => "utf-8", headers => ["a", "b", "c"],
fragment => "row=2", sep_char => ","),
[{ a => 1, b => 2, c => 3 }], "AOH headers fragment");
}
@@ -69,31 +69,31 @@ else {
ok (1, q{This perl does not support open with "<:encoding(...)"});
}
-ok (csv (in => $aoa, out => $file), "AOA out file");
-is_deeply (csv (in => $file), $aoa, "AOA parse out");
+ok (csv (in => $aoa, out => $tfn), "AOA out file");
+is_deeply (csv (in => $tfn), $aoa, "AOA parse out");
-ok (csv (in => $aoh, out => $file, headers => "auto"), "AOH out file");
-is_deeply (csv (in => $file, headers => "auto"), $aoh, "AOH parse out");
+ok (csv (in => $aoh, out => $tfn, headers => "auto"), "AOH out file");
+is_deeply (csv (in => $tfn, headers => "auto"), $aoh, "AOH parse out");
-ok (csv (in => $aoh, out => $file, headers => "skip"), "AOH out file no header");
-is_deeply (csv (in => $file, headers => [keys %{$aoh->[0]}]),
+ok (csv (in => $aoh, out => $tfn, headers => "skip"), "AOH out file no header");
+is_deeply (csv (in => $tfn, headers => [keys %{$aoh->[0]}]),
$aoh, "AOH parse out no header");
my $idx = 0;
sub getrowa { return $aoa->[$idx++]; }
sub getrowh { return $aoh->[$idx++]; }
-ok (csv (in => \&getrowa, out => $file), "out from CODE/AR");
-is_deeply (csv (in => $file), $aoa, "data from CODE/AR");
+ok (csv (in => \&getrowa, out => $tfn), "out from CODE/AR");
+is_deeply (csv (in => $tfn), $aoa, "data from CODE/AR");
$idx = 0;
-ok (csv (in => \&getrowh, out => $file, headers => \@hdr), "out from CODE/HR");
-is_deeply (csv (in => $file, headers => "auto"), $aoh, "data from CODE/HR");
+ok (csv (in => \&getrowh, out => $tfn, headers => \@hdr), "out from CODE/HR");
+is_deeply (csv (in => $tfn, headers => "auto"), $aoh, "data from CODE/HR");
$idx = 0;
-ok (csv (in => \&getrowh, out => $file), "out from CODE/HR (auto headers)");
-is_deeply (csv (in => $file, headers => "auto"), $aoh, "data from CODE/HR");
-unlink $file;
+ok (csv (in => \&getrowh, out => $tfn), "out from CODE/HR (auto headers)");
+is_deeply (csv (in => $tfn, headers => "auto"), $aoh, "data from CODE/HR");
+unlink $tfn;
# Basic "key" checks
SKIP: {
@@ -105,14 +105,14 @@ SKIP: {
}
# Some "out" checks
-open my $fh, ">", $file;
+open my $fh, ">", $tfn or die "$tfn: $!\n";
csv (in => [{ a => 1 }], out => $fh);
csv (in => [{ a => 1 }], out => $fh, headers => undef);
csv (in => [{ a => 1 }], out => $fh, headers => "auto");
csv (in => [{ a => 1 }], out => $fh, headers => ["a"]);
csv (in => [{ b => 1 }], out => $fh, headers => { b => "a" });
close $fh;
-open $fh, "<", $file;
+open $fh, "<", $tfn or die "$tfn: $!\n";
is (do {local $/; <$fh>}, "a\r\n1\r\n" x 5, "AoH to out");
close $fh;
@@ -128,13 +128,15 @@ close $fh;
is ($csv->eol, "\r\n", "default eol");
} # check
- open my $fh, ">", \my $out;
+ # Note that 5.6.x writes to a *file* named SCALAR(0x50414A10)
+ open my $fh, ">", \my $out or die "IO: $!\n";
csv (in => [[1,2]], out => $fh, on_in => \&check);
# Check that I can overrule auto_diag
$ad = 0;
csv (in => [[1,2]], out => $fh, on_in => \&check, auto_diag => 0);
}
+$] < 5.008 and unlink glob "SCALAR(*)";
# errors
{ my $err;
@@ -151,7 +153,7 @@ eval {
$] >= 5.008 &&
$Config{useperlio} eq "define" or skip "No scalar ref in this perl", 4;
my $out = "";
- open my $fh, ">", \$out;
+ open my $fh, ">", \$out or die "IO: $!\n";
ok (csv (in => [[ 1, 2, 3 ]], out => $fh), "out to fh to scalar ref");
is ($out, "1,2,3\r\n", "Scalar out");
$out = "";
@@ -161,17 +163,17 @@ eval {
{ my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 });
my $expect = [["a"],[1],["a"],[1],["a"],[1],["a"],[1],["a"],[1]];
- is_deeply ($csv->csv (in => $file), $expect, "csv from object");
- is_deeply (csv (in => $file, csv => $csv), $expect, "csv from attribute");
+ is_deeply ($csv->csv (in => $tfn), $expect, "csv from object");
+ is_deeply (csv (in => $tfn, csv => $csv), $expect, "csv from attribute");
}
{ local *STDOUT;
my $ofn = "_STDOUT.csv";
- open STDOUT, ">", $ofn;
- csv (in => $file, quote_always => 1, fragment => "row=1-2",
+ open STDOUT, ">", $ofn or die "$ofn: $!\n";
+ csv (in => $tfn, quote_always => 1, fragment => "row=1-2",
on_in => sub { splice @{$_[1]}, 1; });
close STDOUT;
- open my $oh, "<", $ofn;
+ open my $oh, "<", $ofn or die "$ofn: $!\n";
is (do { local (@ARGV, $/) = $ofn; <> },
qq{"a"\r\n"1"\r\n}, "Chained csv call inherited attributes");
unlink $ofn;
@@ -12,12 +12,12 @@ BEGIN {
require "t/util.pl";
}
-my $file = "_91test.csv"; END { -f $file and unlink $file }
+my $tfn = "_91test.csv"; END { -f $tfn and unlink $tfn }
my $data =
"foo,bar,baz\n".
"1,2,3\n".
"2,a b,\n";
-open FH, ">", $file or die "$file: $!";
+open FH, ">", $tfn or die "$tfn: $!";
print FH $data;
close FH;
@@ -32,43 +32,43 @@ my $aoh = [
];
for (qw( after_in on_in before_out )) {
- is_deeply (csv (in => $file, $_ => sub {}), $aoa, "callback $_ on AOA with empty sub");
- is_deeply (csv (in => $file, callbacks => { $_ => sub {} }), $aoa, "callback $_ on AOA with empty sub");
+ is_deeply (csv (in => $tfn, $_ => sub {}), $aoa, "callback $_ on AOA with empty sub");
+ is_deeply (csv (in => $tfn, callbacks => { $_ => sub {} }), $aoa, "callback $_ on AOA with empty sub");
}
-is_deeply (csv (in => $file, after_in => sub {},
+is_deeply (csv (in => $tfn, after_in => sub {},
callbacks => { on_in => sub {} }), $aoa, "callback after_in and on_in on AOA");
for (qw( after_in on_in before_out )) {
- is_deeply (csv (in => $file, headers => "auto", $_ => sub {}), $aoh, "callback $_ on AOH with empty sub");
- is_deeply (csv (in => $file, headers => "auto", callbacks => { $_ => sub {} }), $aoh, "callback $_ on AOH with empty sub");
+ is_deeply (csv (in => $tfn, headers => "auto", $_ => sub {}), $aoh, "callback $_ on AOH with empty sub");
+ is_deeply (csv (in => $tfn, headers => "auto", callbacks => { $_ => sub {} }), $aoh, "callback $_ on AOH with empty sub");
}
-is_deeply (csv (in => $file, headers => "auto", after_in => sub {},
+is_deeply (csv (in => $tfn, headers => "auto", after_in => sub {},
callbacks => { on_in => sub {} }), $aoh, "callback after_in and on_in on AOH");
-is_deeply (csv (in => $file, after_in => sub { push @{$_[1]}, "A" }), [
+is_deeply (csv (in => $tfn, after_in => sub { push @{$_[1]}, "A" }), [
[qw( foo bar baz A )],
[ 1, 2, 3, "A" ],
[ 2, "a b", "", "A" ],
], "AOA ith after_in callback");
-is_deeply (csv (in => $file, headers => "auto", after_in => sub { $_[1]{baz} = "A" }), [
+is_deeply (csv (in => $tfn, headers => "auto", after_in => sub { $_[1]{baz} = "A" }), [
{ foo => 1, bar => 2, baz => "A" },
{ foo => 2, bar => "a b", baz => "A" },
], "AOH with after_in callback");
-is_deeply (csv (in => $file, filter => { 2 => sub { /a/ }}), [
+is_deeply (csv (in => $tfn, filter => { 2 => sub { /a/ }}), [
[qw( foo bar baz )],
[ 2, "a b", "" ],
], "AOA with filter on col 2");
-is_deeply (csv (in => $file, filter => { 2 => sub { /a/ },
+is_deeply (csv (in => $tfn, filter => { 2 => sub { /a/ },
1 => sub { length > 1 }}), [
[qw( foo bar baz )],
], "AOA with filter on col 1 and 2");
-is_deeply (csv (in => $file, filter => { foo => sub { $_ > 1 }}), [
+is_deeply (csv (in => $tfn, filter => { foo => sub { $_ > 1 }}), [
{ foo => 2, bar => "a b", baz => "" },
], "AOH with filter on column name");
-open FH, ">>", $file or die "$file: $!";
+open FH, ">>", $tfn or die "$tfn: $!";
print FH <<"EOD";
3,3,3
4,5,6
@@ -79,7 +79,7 @@ print FH <<"EOD";
EOD
close FH;
-is_deeply (csv (in => $file,
+is_deeply (csv (in => $tfn,
filter => { foo => sub { $_ > 2 && $_[1][2] - $_[1][1] < 4 }}), [
{ foo => 3, bar => 3, baz => 3 },
{ foo => 4, bar => 5, baz => 6 },
@@ -87,7 +87,7 @@ is_deeply (csv (in => $file,
{ foo => 6, bar => 9, baz => 12 },
], "AOH with filter on column name + on other numbered fields");
-is_deeply (csv (in => $file,
+is_deeply (csv (in => $tfn,
filter => { foo => sub { $_ > 2 && $_{baz} - $_{bar} < 4 }}), [
{ foo => 3, bar => 3, baz => 3 },
{ foo => 4, bar => 5, baz => 6 },