use strict;
use warnings;
-use base qw/Test::Builder::Module Exporter/;
+use base qw(Test::Builder::Module Exporter);
use Data::Dumper;
use Test::Builder;
use Test::Deep ();
use SQL::Abstract::Tree;
-our @EXPORT_OK = qw/&is_same_sql_bind &is_same_sql &is_same_bind
- &eq_sql_bind &eq_sql &eq_bind
- $case_sensitive $sql_differ/;
+our @EXPORT_OK = qw(
+ is_same_sql_bind is_same_sql is_same_bind
+ eq_sql_bind eq_sql eq_bind dumper diag_where
+ $case_sensitive $sql_differ
+);
my $sqlat = SQL::Abstract::Tree->new;
return $ret;
}
+sub dumper {
+ Data::Dumper->new([])->Terse(1)->Indent(1)->Useqq(1)->Deparse(1)->Quotekeys(0)->Sortkeys(1)->Maxdepth(0)->Values([@_])->Dump;
+}
+
+sub diag_where{
+ $tb->diag( "Search term:\n" . &dumper );
+}
+
sub _sql_differ_diag {
my ($sql1, $sql2) = @_;
sub _bind_differ_diag {
my ($bind_ref1, $bind_ref2) = @_;
- local $Data::Dumper::Maxdepth;
-
$tb->${\( $tb->in_todo ? 'note' : 'diag')} (
"BIND values differ\n"
- ." got: " . Dumper($bind_ref1)
- ."expected: " . Dumper($bind_ref2)
+ ." got: " . dumper($bind_ref1)
+ ."expected: " . dumper($bind_ref2)
);
}
use warnings;
use Test::More;
use Test::Exception;
-use SQL::Abstract::Test import => ['is_same_sql_bind'];
+use SQL::Abstract::Test import => [qw(is_same_sql_bind diag_where) ];
-use Data::Dumper;
use SQL::Abstract;
# Make sure to test the examples, since having them break is somewhat
);
for my $case (@handle_tests) {
- local $Data::Dumper::Terse = 1;
my $sql = SQL::Abstract->new;
- my($stmt, @bind);
- lives_ok (sub {
- ($stmt, @bind) = $sql->where($case->{where}, $case->{order});
- is_same_sql_bind($stmt, \@bind, $case->{stmt}, $case->{bind})
- || diag "Search term:\n" . Dumper $case->{where};
- });
+ my ($stmt, @bind) = $sql->where($case->{where}, $case->{order});
+ is_same_sql_bind($stmt, \@bind, $case->{stmt}, $case->{bind})
+ || diag_where ( $case->{where} );
}
dies_ok {
use warnings;
use Test::More;
use Test::Exception;
-use SQL::Abstract::Test import => ['is_same_sql_bind'];
+use SQL::Abstract::Test import => [qw(is_same_sql_bind diag_where)];
-use Data::Dumper;
use SQL::Abstract;
use Storable 'dclone';
TODO: {
local $TODO = $case->{todo} if $case->{todo};
- local $Data::Dumper::Terse = 1;
-
my @w;
local $SIG{__WARN__} = sub { push @w, @_ };
\@bind,
$case->{stmt},
$case->{bind},
- )
- || diag "Search term:\n" . Dumper $case->{where};
+ ) || diag_where( $case->{where} );
});
is (@w, 0, 'No warnings within and-or tests')
|| diag join "\n", 'Emitted warnings:', @w;
local $TODO = $case->{todo} if $case->{todo};
local $SQL::Abstract::Test::parenthesis_significant = 1;
- local $Data::Dumper::Terse = 1;
my $sql = SQL::Abstract->new ($case->{args} || {});
lives_ok (sub {
\@bind,
$case->{stmt},
$case->{bind},
- )
- || diag "Search term:\n" . Dumper $case->{where};
+ ) || diag_where ( $case->{where} );
});
}
}
TODO: {
local $TODO = $case->{todo} if $case->{todo};
- local $Data::Dumper::Terse = 1;
-
my @w;
local $SIG{__WARN__} = sub { push @w, @_ };
my $sql = SQL::Abstract->new ($case->{args} || {});
$old_s, \@old_b,
$new_s, \@new_b,
'Backcompat and the correct(tm) syntax result in identical statements',
- ) || diag "Search terms:\n" . Dumper {
- backcompat => $case->{backcompat},
- correct => $case->{correct},
- };
+ ) || diag_where ( {
+ backcompat => $case->{backcompat},
+ correct => $case->{correct},
+ });
});
ok (@w, 'Warnings were emitted about a mod_N construct');
use warnings;
use Test::More;
use Test::Exception;
-use SQL::Abstract::Test import => ['is_same_sql_bind'];
+use SQL::Abstract::Test import => [qw(is_same_sql_bind diag_where)];
-use Data::Dumper;
use SQL::Abstract;
my @in_between_tests = (
local $TODO = $case->{todo} if $case->{todo};
local $SQL::Abstract::Test::parenthesis_significant = $case->{parenthesis_significant};
- local $Data::Dumper::Terse = 1;
my @w;
local $SIG{__WARN__} = sub { push @w, @_ };
+
my $sql = SQL::Abstract->new ($case->{args} || {});
if ($case->{exception}) {
throws_ok { $sql->where($case->{where}) } $case->{exception};
}
else {
- lives_ok {
- my ($stmt, @bind) = $sql->where($case->{where});
- is_same_sql_bind(
- $stmt,
- \@bind,
- $case->{stmt},
- $case->{bind},
- ) || diag "Search term:\n" . Dumper $case->{where};
- } "$case->{test} doesn't die";
+ my ($stmt, @bind) = $sql->where($case->{where});
+ is_same_sql_bind(
+ $stmt,
+ \@bind,
+ $case->{stmt},
+ $case->{bind},
+ ) || diag_where ( $case->{where} );
}
is (@w, 0, $case->{test} || 'No warnings within in-between tests')
use strict;
use warnings;
-use List::Util qw(sum);
use Test::More;
-use Data::Dumper;
-$Data::Dumper::Terse = 1;
-$Data::Dumper::Sortkeys = 1;
+use SQL::Abstract::Test import => [qw(
+ eq_sql_bind eq_sql eq_bind is_same_sql_bind dumper $sql_differ
+)];
my @sql_tests = (
# WHERE condition - equal
},
);
-use_ok('SQL::Abstract::Test', import => [qw(
- eq_sql_bind eq_sql eq_bind is_same_sql_bind
-)]);
-
for my $test ( @sql_tests ) {
# this does not work on 5.8.8 and earlier :(
if ($equal ^ $test->{equal}) {
my ($ast1, $ast2) = map { SQL::Abstract::Test::parse ($_) } ($sql1, $sql2);
- $_ = Dumper $_ for ($ast1, $ast2);
+ $_ = dumper($_) for ($ast1, $ast2);
diag "sql1: $sql1";
diag "sql2: $sql2";
- note $SQL::Abstract::Test::sql_differ;
+ note $sql_differ || 'No differences found';
note "ast1: $ast1";
note "ast2: $ast2";
}
}
if ($equal ^ $test->{equal}) {
- diag("bind1: " . Dumper($bind1));
- diag("bind2: " . Dumper($bind2));
+ diag("bind1: " . dumper($bind1));
+ diag("bind2: " . dumper($bind2));
}
}
}
'SELECT owner_name FROM books me WHERE ( sUOrce = ? )',
));
like(
- $SQL::Abstract::Test::sql_differ,
+ $sql_differ,
qr/\Q[ source ] != [ sUOrce ]/,
'expected debug of literal diff',
);
'SELECT owner_name FROM books me GROUP BY owner_name',
));
like(
- $SQL::Abstract::Test::sql_differ,
+ $sql_differ,
qr/\QOP [ORDER BY] != [GROUP BY]/,
'expected debug of op diff',
);
));
like(
- $SQL::Abstract::Test::sql_differ,
+ $sql_differ,
qr|\Q[WHERE source = ?] != [N/A]|,
'expected debug of missing branch',
);
use Test::More;
use Test::Exception;
-use Data::Dumper;
-$Data::Dumper::Terse = 1;
-$Data::Dumper::Sortkeys = 1;
-
-use SQL::Abstract::Test import => ['is_same_sql'];
+use SQL::Abstract::Test import => [qw(is_same_sql dumper)];
use SQL::Abstract::Tree;
my $sqlat = SQL::Abstract::Tree->new;
lc($orig),
sprintf( 'roundtrip works (%s...)', substr $orig, 0, 20 )
) or do {
- my ($ast1, $ast2) = map { Dumper $sqlat->parse($_) } ( $orig, $reassembled );
+ my ($ast1, $ast2) = map { dumper( $sqlat->parse($_) ) } ( $orig, $reassembled );
note "ast1: $ast1";
note "ast2: $ast2";