From Code to Community: Sponsoring The Perl and Raku Conference 2025 Learn more

=for comment POD_DERIVED_INDEX_GENERATED
The following documentation is automatically generated. Please do not edit
this file, but rather the original, inline with SQL::Abstract::Test
at lib/DBIx/Class/_TempExtlib/SQL/Abstract/Test.pm
(on the system that originally ran this).
If you do edit this file, and don't want your changes to be removed, make
sure you change the first line.
=cut
=head1 NAME
SQL::Abstract::Test - Helper function for testing SQL::Abstract
=head1 SYNOPSIS
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);
=head1 DESCRIPTION
This module is only intended for authors of tests on
L<SQL::Abstract|SQL::Abstract> and related modules;
it exports functions for comparing two SQL statements
and their bound values.
The SQL comparison is performed on I<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.
B<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 L<De Morgan's laws
For a good overview of what this test framework is currently capable of refer
to C<t/10test.t>
=head1 FUNCTIONS
=head2 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 given and expected pairs of C<($sql, \@bind)> by unpacking C<@_>
as shown in the examples above and passing the arguments to L</eq_sql> and
L</eq_bind>. Calls L<Test::Builder/ok> with the combined result, with
C<$test_msg> as message.
If the test fails, a detailed diagnostic is printed.
=head2 is_same_sql
is_same_sql(
$given_sql,
$expected_sql,
$test_msg
);
Compares given and expected SQL statements via L</eq_sql>, and calls
L<Test::Builder/ok> on the result, with C<$test_msg> as message.
If the test fails, a detailed diagnostic is printed.
=head2 is_same_bind
is_same_bind(
\@given_bind,
\@expected_bind,
$test_msg
);
Compares given and expected bind values via L</eq_bind>, and calls
L<Test::Builder/ok> on the result, with C<$test_msg> as message.
If the test fails, a detailed diagnostic is printed.
=head2 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 C<@_> depending on the given arguments and calls L</eq_sql> and
L</eq_bind>, returning their combined result.
=head2 eq_sql
my $is_same = eq_sql($given_sql, $expected_sql);
Compares the abstract syntax of two SQL statements. Similar to L</is_same_sql>,
but it just returns a boolean value and does not print diagnostics or talk to
L<Test::Builder>. If the result is false, the global variable L</$sql_differ>
will contain the SQL portion where a difference was encountered; this is useful
for printing diagnostics.
=head2 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 L<SQL::Abstract/bindtype>). Similar to
L</is_same_bind>, but it just returns a boolean value and does not print
diagnostics or talk to L<Test::Builder>.
=head1 GLOBAL VARIABLES
=head2 $case_sensitive
If true, SQL comparisons will be case-sensitive. Default is false;
=head2 $parenthesis_significant
If true, SQL comparison will preserve and report difference in nested
parenthesis. Useful while testing C<IN (( x ))> vs C<IN ( x )>.
Defaults to false;
=head2 $order_by_asc_significant
If true SQL comparison will consider C<ORDER BY foo ASC> and
C<ORDER BY foo> to be different. Default is false;
=head2 $sql_differ
When L</eq_sql> returns false, the global variable
C<$sql_differ> contains the SQL portion
where a difference was encountered.
=head1 SEE ALSO
L<SQL::Abstract>, L<Test::More>, L<Test::Builder>.
=head1 INHERITED METHODS
=over 4
=item L<Test::Builder::Module>
L<builder|Test::Builder::Module/builder>, L<import|Test::Builder::Module/import>, L<import_extra|Test::Builder::Module/import_extra>
=back
=head1 AUTHORS
Laurent Dami <laurent.dami AT etat geneve ch>
Norbert Buchmuller <norbi@nix.hu>
Peter Rabbitson <ribasushi@cpan.org>
=head1 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.