1SQL::Abstract::Test(3)User Contributed Perl DocumentationSQL::Abstract::Test(3)
2
3
4

NAME

6       SQL::Abstract::Test - Helper function for testing SQL::Abstract
7

SYNOPSIS

9         use SQL::Abstract;
10         use Test::More;
11         use SQL::Abstract::Test import => [qw/
12           is_same_sql_bind is_same_sql is_same_bind
13           eq_sql_bind eq_sql eq_bind
14         /];
15
16         my ($sql, @bind) = SQL::Abstract->new->select(%args);
17
18         is_same_sql_bind($given_sql,    \@given_bind,
19                          $expected_sql, \@expected_bind, $test_msg);
20
21         is_same_sql($given_sql, $expected_sql, $test_msg);
22         is_same_bind(\@given_bind, \@expected_bind, $test_msg);
23
24         my $is_same = eq_sql_bind($given_sql,    \@given_bind,
25                                   $expected_sql, \@expected_bind);
26
27         my $sql_same = eq_sql($given_sql, $expected_sql);
28         my $bind_same = eq_bind(\@given_bind, \@expected_bind);
29

DESCRIPTION

31       This module is only intended for authors of tests on SQL::Abstract and
32       related modules; it exports functions for comparing two SQL statements
33       and their bound values.
34
35       The SQL comparison is performed on abstract syntax, ignoring
36       differences in spaces or in levels of parentheses.  Therefore the tests
37       will pass as long as the semantics is preserved, even if the surface
38       syntax has changed.
39
40       Disclaimer : the semantic equivalence handling is pretty limited.  A
41       lot of effort goes into distinguishing significant from non-significant
42       parenthesis, including AND/OR operator associativity.  Currently this
43       module does not support commutativity and more intelligent
44       transformations like De Morgan's laws
45        <http://en.wikipedia.org/wiki/De_Morgan's_laws>, etc.
46
47       For a good overview of what this test framework is currently capable of
48       refer to "t/10test.t"
49

FUNCTIONS

51   is_same_sql_bind
52         is_same_sql_bind(
53           $given_sql, \@given_bind,
54           $expected_sql, \@expected_bind,
55           $test_msg
56         );
57
58         is_same_sql_bind(
59           \[$given_sql, @given_bind],
60           \[$expected_sql, @expected_bind],
61           $test_msg
62         );
63
64         is_same_sql_bind(
65           $dbic_rs->as_query
66           $expected_sql, \@expected_bind,
67           $test_msg
68         );
69
70       Compares given and expected pairs of "($sql, \@bind)" by unpacking @_
71       as shown in the examples above and passing the arguments to "eq_sql"
72       and "eq_bind". Calls "ok" in Test::Builder with the combined result,
73       with $test_msg as message.  If the test fails, a detailed diagnostic is
74       printed.
75
76   is_same_sql
77         is_same_sql(
78           $given_sql,
79           $expected_sql,
80           $test_msg
81         );
82
83       Compares given and expected SQL statements via "eq_sql", and calls "ok"
84       in Test::Builder on the result, with $test_msg as message.  If the test
85       fails, a detailed diagnostic is printed.
86
87   is_same_bind
88         is_same_bind(
89           \@given_bind,
90           \@expected_bind,
91           $test_msg
92         );
93
94       Compares given and expected bind values via "eq_bind", and calls "ok"
95       in Test::Builder on the result, with $test_msg as message.  If the test
96       fails, a detailed diagnostic is printed.
97
98   eq_sql_bind
99         my $is_same = eq_sql_bind(
100           $given_sql, \@given_bind,
101           $expected_sql, \@expected_bind,
102         );
103
104         my $is_same = eq_sql_bind(
105           \[$given_sql, @given_bind],
106           \[$expected_sql, @expected_bind],
107         );
108
109         my $is_same = eq_sql_bind(
110           $dbic_rs->as_query
111           $expected_sql, \@expected_bind,
112         );
113
114       Unpacks @_ depending on the given arguments and calls "eq_sql" and
115       "eq_bind", returning their combined result.
116
117   eq_sql
118         my $is_same = eq_sql($given_sql, $expected_sql);
119
120       Compares the abstract syntax of two SQL statements. Similar to
121       "is_same_sql", but it just returns a boolean value and does not print
122       diagnostics or talk to Test::Builder. If the result is false, the
123       global variable "$sql_differ" will contain the SQL portion where a
124       difference was encountered; this is useful for printing diagnostics.
125
126   eq_bind
127         my $is_same = eq_sql(\@given_bind, \@expected_bind);
128
129       Compares two lists of bind values, taking into account the fact that
130       some of the values may be arrayrefs (see "bindtype" in SQL::Abstract).
131       Similar to "is_same_bind", but it just returns a boolean value and does
132       not print diagnostics or talk to Test::Builder.
133

GLOBAL VARIABLES

135   $case_sensitive
136       If true, SQL comparisons will be case-sensitive. Default is false;
137
138   $parenthesis_significant
139       If true, SQL comparison will preserve and report difference in nested
140       parenthesis. Useful while testing "IN (( x ))" vs "IN ( x )".  Defaults
141       to false;
142
143   $order_by_asc_significant
144       If true SQL comparison will consider "ORDER BY foo ASC" and "ORDER BY
145       foo" to be different. Default is false;
146
147   $sql_differ
148       When "eq_sql" returns false, the global variable $sql_differ contains
149       the SQL portion where a difference was encountered.
150

SEE ALSO

152       SQL::Abstract, Test::More, Test::Builder.
153

AUTHORS

155       Laurent Dami <laurent.dami AT etat  geneve  ch>
156
157       Norbert Buchmuller <norbi@nix.hu>
158
159       Peter Rabbitson <ribasushi@cpan.org>
160
162       Copyright 2008 by Laurent Dami.
163
164       This library is free software; you can redistribute it and/or modify it
165       under the same terms as Perl itself.
166
167
168
169perl v5.30.0                      2019-07-26            SQL::Abstract::Test(3)
Impressum