| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
# perl5.27.2 -DD -Mblib t/02_free_unref_scalar.t > & alloc-free.log |
| 7 |
# ^^^ |
| 8 |
# -DD Cleaning up |
| 9 |
|
| 10 |
#use Devel::Peek; |
| 11 |
#use Data::Peek; |
| 12 |
use Test::More; |
| 13 |
#use Test::NoWarnings; |
| 14 |
|
| 15 |
require Text::CSV_XS; |
| 16 |
$Text::CSV_XS::VERSION < 1.35 and plan skip_all => "This leak should be fixed in Text::CSV_XS 1.35"; |
| 17 |
|
| 18 |
use_ok "DBI"; |
| 19 |
require "./t/lib.pl"; |
| 20 |
|
| 21 |
$SIG{__WARN__} = sub { |
| 22 |
$_[0] =~ m/^Attempt to free unreferenced scalar: SV (0x[0-9a-f]+)(, \<\w+\> line \d+)?.* during global destruction\.$/ and |
| 23 |
fail ("there was an attempt to free unreferenced scalar"); |
| 24 |
diag "@_"; |
| 25 |
}; |
| 26 |
|
| 27 |
sub DBD::CSV::Table::DESTROY { |
| 28 |
my $self = shift; |
| 29 |
|
| 30 |
delete $self->{meta}{csv_in}; |
| 31 |
} # DBD::CSV::Table::DESTROY |
| 32 |
|
| 33 |
sub test_with_options { |
| 34 |
my (%opts) = @_; |
| 35 |
my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { |
| 36 |
f_schema => undef, |
| 37 |
f_dir => 't', |
| 38 |
f_dir_search => [], |
| 39 |
f_ext => ".csv/r", |
| 40 |
f_lock => 2, |
| 41 |
f_encoding => "utf8", |
| 42 |
|
| 43 |
%opts, |
| 44 |
|
| 45 |
RaiseError => 1, |
| 46 |
PrintError => 1, |
| 47 |
FetchHashKeyName => "NAME_lc", |
| 48 |
}) or die "$DBI::errstr\n" || $DBI::errstr; |
| 49 |
|
| 50 |
my %tbl = map { $_ => 1 } $dbh->tables (undef, undef, undef, undef); |
| 51 |
|
| 52 |
is ($tbl{$_}, 1, "Table $_ found") for qw( tmp ); |
| 53 |
|
| 54 |
my %data = ( |
| 55 |
tmp => { # t/tmp.csv |
| 56 |
1 => "ape", |
| 57 |
2 => (grep (m/^csv_callbacks$/ => keys %opts) ? "new world monkey" : "monkey"), |
| 58 |
3 => "gorilla", |
| 59 |
}, |
| 60 |
); |
| 61 |
|
| 62 |
foreach my $tbl (sort keys %data) { |
| 63 |
my $sth = $dbh->prepare ("select * from $tbl"); |
| 64 |
$sth->execute; |
| 65 |
while (my $row = $sth->fetch) { |
| 66 |
is ($row->[1], $data{$tbl}{$row->[0]}, "$tbl ($row->[0], ...)"); |
| 67 |
} |
| 68 |
$sth->finish (); |
| 69 |
} |
| 70 |
|
| 71 |
$dbh->disconnect; |
| 72 |
} |
| 73 |
|
| 74 |
sub new_world_monkeys { |
| 75 |
my ($csv, $data) = @_; |
| 76 |
|
| 77 |
$data->[1] =~ s/^monkey$/new world monkey/; |
| 78 |
|
| 79 |
return; |
| 80 |
} |
| 81 |
|
| 82 |
my $callbacks = { |
| 83 |
csv_callbacks => { |
| 84 |
after_parse => \&new_world_monkeys, |
| 85 |
}, |
| 86 |
}; |
| 87 |
|
| 88 |
test_with_options ( |
| 89 |
csv_tables => { tmp => { f_file => "tmp.csv"} }, |
| 90 |
%$callbacks, |
| 91 |
); |
| 92 |
|
| 93 |
test_with_options ( |
| 94 |
csv_auto_diag => 0, |
| 95 |
%$callbacks, |
| 96 |
) for (1 .. 200); |
| 97 |
|
| 98 |
done_testing (); |