SQL::Ab...ct::Test(3)
π SQL::Abstract::Test π
Bestie, welcome to the User Contributed Perl Documentation page for SQL::Abstract::Test β yes, the manual name is folded in right here at the top, cute and accounted for. π«Ά
β¨ NAME β¨
SQL::Abstract::Test β the helper-function bestie for testing SQL::Abstract. That is literally the whole name vibe.
πΈ SYNOPSIS πΈ
Okay so hereβs the import situation, exactly as the page says:
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);
π DESCRIPTION π
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. iykyk. π
The SQL comparison is performed on abstract syntax, ignoring differences in spaces or in levels of parentheses. So your tests will pass as long as the semantics is preserved, even if the surface syntax has changed. Slay for semantic stability. β¨
β οΈ Disclaimer: the semantic equivalence handling is pretty limited. A lot of effort goes into distinguishing significant from non-significant parenthesis, includingAND/ORoperator associativity. Currently this module does not support commutativity and more intelligent transformations like De Morgan's laws (<http://en.wikipedia.org/wiki/De_Morgan's_laws>), etc.
For a good overview of what this test framework is currently capable of, refer to t/10test.t. π
π§ FUNCTIONS π§
π is_same_sql_bind π
is_same_sql_bind(
$given_sql, \@given_bind,
$expected_sql, \@expected_bind,
$test_msg
);
is_same_sql_bind(
\[$given_sql, @given_bind],
\[$expected_sql, @expected_bind],
$test_msg
);
is_same_sql_bind(
$dbic_rs->as_query
$expected_sql, \@expected_bind,
$test_msg
);
Compares a given and expected pair of ($sql, \@bind) by unpacking @_ exactly like the examples above and passing the arguments to eq_sql and eq_bind. It calls ok in Test::Builder with the combined result, using $test_msg as the message. If the test fails, a detailed diagnostic is printed. Very main character energy for debugging. π₯
πΈ is_same_sql πΈ
is_same_sql(
$given_sql,
$expected_sql,
$test_msg
);
Compares the given and expected SQL statements via eq_sql, then calls ok in Test::Builder on the result, with $test_msg as the message. If the test fails, a detailed diagnostic is printed. Periodt. π
π¦ is_same_bind π¦
is_same_bind(
\@given_bind,
\@expected_bind,
$test_msg
);
Compares the given and expected bind values via eq_bind, and calls ok in Test::Builder on the result, with $test_msg as the message. If the test fails, a detailed diagnostic is printed. No cap. π«Ά
π eq_sql_bind π
my $is_same = eq_sql_bind(
$given_sql, \@given_bind,
$expected_sql, \@expected_bind,
);
my $is_same = eq_sql_bind(
\[$given_sql, @given_bind],
\[$expected_sql, @expected_bind],
);
my $is_same = eq_sql_bind(
$dbic_rs->as_query
$expected_sql, \@expected_bind,
);
Unpacks @_ depending on the given arguments and calls eq_sql and eq_bind, returning their combined result. Lowkey the boolean bestie of the group. π
π eq_sql π
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. The way that is so handy. π
π eq_bind π
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. (And yes, the page shows that exact eq_sql signature in the eq_bind section β Iβm preserving it character for character, bestie. π)
π¦ GLOBAL VARIABLES π¦
π $case_sensitive π
If true, SQL comparisons will be case-sensitive. Default is false;
π $parenthesis_significant π
If true, SQL comparison will preserve and report difference in nested parenthesis. Useful while testing IN (( x )) vs IN ( x ). Defaults to false;
β $order_by_asc_significant β
If true, SQL comparison will consider ORDER BY foo ASC and ORDER BY foo to be different. Default is false;
π«Ά $sql_differ π«Ά
When eq_sql returns false, the global variable $sql_differ contains the SQL portion where a difference was encountered.
π SEE ALSO π
Bestie, go look at SQL::Abstract, Test::More, and Test::Builder. Thatβs the whole squad. π
π AUTHORS π
- Laurent Dami
<laurent.dami AT etat geneve ch> - Norbert Buchmuller
<norbi@nix.hu> - Peter Rabbitson
<ribasushi@cpan.org>
π COPYRIGHT AND LICENSE π
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.
okay bye bestie! this page came from perl v5.42.0, dated 2021-01-24 β mwah, slay, and happy testing πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-SQL-Abstract 2.000001-bp160.1.10 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms