X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F00new.t;h=7cb7103baffdeace11be86be02c914e2e9de21bf;hb=cf5b7ab163f8ac123ebc9bb1156e79646cd5bd2f;hp=b90dc8a998ed492355eca1d0c3d910920f299606;hpb=41751122477eb5028a8849fe38ed59bf33fd522f;p=scpubgit%2FQ-Branch.git diff --git a/t/00new.t b/t/00new.t old mode 100755 new mode 100644 index b90dc8a..7cb7103 --- a/t/00new.t +++ b/t/00new.t @@ -1,19 +1,17 @@ -#!/usr/bin/perl - use strict; use warnings; use Test::More; +use Test::Warn; +use Test::Exception; - -plan tests => 15; - -use_ok('SQL::Abstract'); +use SQL::Abstract::Test import => [ qw(is_same_sql dumper) ]; +use SQL::Abstract; my @handle_tests = ( #1 { args => {logic => 'OR'}, - stmt => 'SELECT * FROM test WHERE ( a = ? OR b = ? )' + stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )' }, #2 { @@ -33,7 +31,7 @@ my @handle_tests = ( #5 { args => {cmp => "=", logic => 'or'}, - stmt => 'SELECT * FROM test WHERE ( a = ? OR b = ? )' + stmt => 'SELECT * FROM test WHERE ( a = ? AND b = ? )' }, #6 { @@ -43,7 +41,7 @@ my @handle_tests = ( #7 { args => {logic => "or", cmp => "like"}, - stmt => 'SELECT * FROM test WHERE ( a LIKE ? OR b LIKE ? )' + stmt => 'SELECT * FROM test WHERE ( a LIKE ? AND b LIKE ? )' }, #8 { @@ -74,25 +72,36 @@ my @handle_tests = ( { args => {convert => "lower"}, stmt => 'SELECT * FROM test WHERE ( ( LOWER(ticket) = LOWER(?) ) OR ( LOWER(hostname) = LOWER(?) ) OR ( LOWER(taco) = LOWER(?) ) OR ( LOWER(salami) = LOWER(?) ) )', - bind => [ { ticket => 11 }, { hostname => 11 }, { taco => 'salad' }, { salami => 'punch' } ], + where => [ { ticket => 11 }, { hostname => 11 }, { taco => 'salad' }, { salami => 'punch' } ], }, #14 { args => {convert => "upper"}, stmt => 'SELECT * FROM test WHERE ( ( UPPER(hostname) IN ( UPPER(?), UPPER(?), UPPER(?), UPPER(?) ) AND ( ( UPPER(ticket) = UPPER(?) ) OR ( UPPER(ticket) = UPPER(?) ) OR ( UPPER(ticket) = UPPER(?) ) ) ) OR ( UPPER(tack) BETWEEN UPPER(?) AND UPPER(?) ) OR ( ( ( UPPER(a) = UPPER(?) ) OR ( UPPER(a) = UPPER(?) ) OR ( UPPER(a) = UPPER(?) ) ) AND ( ( UPPER(e) != UPPER(?) ) OR ( UPPER(e) != UPPER(?) ) ) AND UPPER(q) NOT IN ( UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?), UPPER(?) ) ) )', - bind => [ { ticket => [11, 12, 13], hostname => { in => ['ntf', 'avd', 'bvd', '123'] } }, + where => [ { ticket => [11, 12, 13], + hostname => { in => ['ntf', 'avd', 'bvd', '123'] } }, { tack => { between => [qw/tick tock/] } }, - { a => [qw/b c d/], e => { '!=', [qw(f g)] }, q => { 'not in', [14..20] } } ], + { a => [qw/b c d/], + e => { '!=', [qw(f g)] }, + q => { 'not in', [14..20] } } ], + warns => qr/\QA multi-element arrayref as an argument to the inequality op '!=' is technically equivalent to an always-true 1=1/, }, ); for (@handle_tests) { - local $" = ', '; - #print "creating a handle with args ($_->{args}): "; - my $sql = SQL::Abstract->new($_->{args}); - my $bind = $_->{bind} || { a => 4, b => 0}; - my($stmt, @bind) = $sql->select('test', '*', $bind); - ok($stmt eq $_->{stmt} && @bind); -} + my $sqla = SQL::Abstract->new($_->{args}); + my $stmt; + lives_ok(sub { + (warnings_exist { + $stmt = $sqla->select( + 'test', + '*', + $_->{where} || { a => 4, b => 0} + ); + } $_->{warns} || []) || diag dumper($_); + }) or diag dumper({ %$_, threw => $@ }); + is_same_sql($stmt, $_->{stmt}); +} +done_testing;