From: Peter Rabbitson Date: Mon, 9 Mar 2009 01:24:34 +0000 (+0000) Subject: Better handling of borked sql in tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=939db550bf338c5ae96b2ba075577911423e4416;p=scpubgit%2FQ-Branch.git Better handling of borked sql in tests --- diff --git a/lib/SQL/Abstract/Test.pm b/lib/SQL/Abstract/Test.pm index ed68506..edda905 100644 --- a/lib/SQL/Abstract/Test.pm +++ b/lib/SQL/Abstract/Test.pm @@ -161,15 +161,19 @@ sub _eq_sql { my ($left, $right) = @_; # ignore top-level parentheses - while ($left->[0] and $left->[0] eq 'PAREN') {$left = $left->[1] } - while ($right->[0] and $right->[0] eq 'PAREN') {$right = $right->[1]} + while ($left and $left->[0] and $left->[0] eq 'PAREN') {$left = $left->[1]} + while ($right and $right->[0] and $right->[0] eq 'PAREN') {$right = $right->[1]} - # if both are undef i.e. () - if (not grep { defined $_ } ($left->[0], $right->[0]) ) { + # one is defined the other not + if ( (defined $left) xor (defined $right) ) { + return 0; + } + # one is undefined, then so is the other + elsif (not defined $left) { return 1; } # if operators are different - elsif ($left->[0] ne $right->[0]) { + elsif ($left->[0] ne $right->[0]) { $sql_differ = sprintf "OP [$left->[0]] != [$right->[0]] in\nleft: %s\nright: %s\n", unparse($left), unparse($right);