SQL::Abstract::Test - Helper function for testing SQL::Abstract
use SQL::Abstract; use Test::More; use SQL::Abstract::Test import => [qw/ is_same_sql_bind is_same_sql is_same_bind eq_sql_bind eq_sql eq_bind /]; my ($sql, @bind) = SQL::Abstract->new->select(%args); is_same_sql_bind($given_sql, \@given_bind, $expected_sql, \@expected_bind, $test_msg); is_same_sql($given_sql, $expected_sql, $test_msg); is_same_bind(\@given_bind, \@expected_bind, $test_msg); my $is_same = eq_sql_bind($given_sql, \@given_bind, $expected_sql, \@expected_bind); my $sql_same = eq_sql($given_sql, $expected_sql); my $bind_same = eq_bind(\@given_bind, \@expected_bind);
This module is only intended for authors of tests on SQL::Abstract and related modules; it exports functions for comparing two SQL statements and their bound values.
The SQL comparison is performed on abstract syntax, ignoring differences in spaces or in levels of parentheses. Therefore the tests will pass as long as the semantics is preserved, even if the surface syntax has changed.
Disclaimer : the semantic equivalence handling is pretty limited. A lot of effort goes into distinguishing significant from non-significant parenthesis, including AND/OR operator associativity. Currently this module does not support commutativity and more intelligent transformations like Morgan laws, etc.
For a good overview of what this test framework is capable of refer to t/10test.t
t/10test.t
is_same_sql_bind($given_sql, \@given_bind, $expected_sql, \@expected_bind, $test_msg);
Compares given and expected pairs of ($sql, \@bind), and calls "ok" in Test::Builder on the result, with $test_msg as message. If the test fails, a detailed diagnostic is printed. For clients which use Test::More, this is the one of the three functions ("is_same_sql_bind", "is_same_sql", "is_same_bind") that needs to be imported.
($sql, \@bind)
$test_msg
is_same_sql($given_sql, $expected_sql, $test_msg);
Compares given and expected SQL statements, and calls "ok" in Test::Builder on the result, with $test_msg as message. If the test fails, a detailed diagnostic is printed. For clients which use Test::More, this is the one of the three functions ("is_same_sql_bind", "is_same_sql", "is_same_bind") that needs to be imported.
is_same_bind(\@given_bind, \@expected_bind, $test_msg);
Compares given and expected bind values, and calls "ok" in Test::Builder on the result, with $test_msg as message. If the test fails, a detailed diagnostic is printed. For clients which use Test::More, this is the one of the three functions ("is_same_sql_bind", "is_same_sql", "is_same_bind") that needs to be imported.
my $is_same = eq_sql_bind($given_sql, \@given_bind, $expected_sql, \@expected_bind);
Compares given and expected pairs of ($sql, \@bind). Similar to "is_same_sql_bind", but it just returns a boolean value and does not print diagnostics or talk to Test::Builder.
my $is_same = eq_sql($given_sql, $expected_sql);
Compares the abstract syntax of two SQL statements. Similar to "is_same_sql", but it just returns a boolean value and does not print diagnostics or talk to Test::Builder. If the result is false, the global variable "$sql_differ" will contain the SQL portion where a difference was encountered; this is useful for printing diagnostics.
my $is_same = eq_sql(\@given_bind, \@expected_bind);
Compares two lists of bind values, taking into account the fact that some of the values may be arrayrefs (see "bindtype" in SQL::Abstract). Similar to "is_same_bind", but it just returns a boolean value and does not print diagnostics or talk to Test::Builder.
If true, SQL comparisons will be case-sensitive. Default is false;
If true, SQL comparison will preserve and report difference in nested parenthesis. Useful for testing the -nest modifier. Defaults to false;
-nest
When "eq_sql" returns false, the global variable $sql_differ contains the SQL portion where a difference was encountered.
$sql_differ
SQL::Abstract, Test::More, Test::Builder.
Laurent Dami, <laurent.dami AT etat geneve ch>
Norbert Buchmuller <norbi@nix.hu>
Peter Rabbitson <ribasushi@cpan.org>
Copyright 2008 by Laurent Dami.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install SQL::Abstract, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SQL::Abstract
CPAN shell
perl -MCPAN -e shell install SQL::Abstract
For more information on module installation, please visit the detailed CPAN module installation guide.