1SQL::Abstract::Test(3)User Contributed Perl DocumentationSQL::Abstract::Test(3)
2
3
4
6 SQL::Abstract::Test - Helper function for testing SQL::Abstract
7
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
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 Morgan laws, etc.
45
46 For a good overview of what this test framework is capable of refer to
47 "t/10test.t"
48
50 is_same_sql_bind
51 is_same_sql_bind($given_sql, \@given_bind,
52 $expected_sql, \@expected_bind, $test_msg);
53
54 Compares given and expected pairs of "($sql, \@bind)", and calls "ok"
55 in Test::Builder on the result, with $test_msg as message. If the test
56 fails, a detailed diagnostic is printed. For clients which use
57 Test::More, this is the one of the three functions ("is_same_sql_bind",
58 "is_same_sql", "is_same_bind") that needs to be imported.
59
60 is_same_sql
61 is_same_sql($given_sql, $expected_sql, $test_msg);
62
63 Compares given and expected SQL statements, and calls "ok" in
64 Test::Builder on the result, with $test_msg as message. If the test
65 fails, a detailed diagnostic is printed. For clients which use
66 Test::More, this is the one of the three functions ("is_same_sql_bind",
67 "is_same_sql", "is_same_bind") that needs to be imported.
68
69 is_same_bind
70 is_same_bind(\@given_bind, \@expected_bind, $test_msg);
71
72 Compares given and expected bind values, and calls "ok" in
73 Test::Builder on the result, with $test_msg as message. If the test
74 fails, a detailed diagnostic is printed. For clients which use
75 Test::More, this is the one of the three functions ("is_same_sql_bind",
76 "is_same_sql", "is_same_bind") that needs to be imported.
77
78 eq_sql_bind
79 my $is_same = eq_sql_bind($given_sql, \@given_bind,
80 $expected_sql, \@expected_bind);
81
82 Compares given and expected pairs of "($sql, \@bind)". Similar to
83 "is_same_sql_bind", but it just returns a boolean value and does not
84 print diagnostics or talk to Test::Builder.
85
86 eq_sql
87 my $is_same = eq_sql($given_sql, $expected_sql);
88
89 Compares the abstract syntax of two SQL statements. Similar to
90 "is_same_sql", but it just returns a boolean value and does not print
91 diagnostics or talk to Test::Builder. If the result is false, the
92 global variable "$sql_differ" will contain the SQL portion where a
93 difference was encountered; this is useful for printing diagnostics.
94
95 eq_bind
96 my $is_same = eq_sql(\@given_bind, \@expected_bind);
97
98 Compares two lists of bind values, taking into account the fact that
99 some of the values may be arrayrefs (see "bindtype" in SQL::Abstract).
100 Similar to "is_same_bind", but it just returns a boolean value and does
101 not print diagnostics or talk to Test::Builder.
102
104 $case_sensitive
105 If true, SQL comparisons will be case-sensitive. Default is false;
106
107 $parenthesis_significant
108 If true, SQL comparison will preserve and report difference in nested
109 parenthesis. Useful for testing the "-nest" modifier. Defaults to
110 false;
111
112 $sql_differ
113 When "eq_sql" returns false, the global variable $sql_differ contains
114 the SQL portion where a difference was encountered.
115
117 SQL::Abstract, Test::More, Test::Builder.
118
120 Laurent Dami, <laurent.dami AT etat geneve ch>
121
122 Norbert Buchmuller <norbi@nix.hu>
123
124 Peter Rabbitson <ribasushi@cpan.org>
125
127 Copyright 2008 by Laurent Dami.
128
129 This library is free software; you can redistribute it and/or modify it
130 under the same terms as Perl itself.
131
132
133
134perl v5.12.1 2010-05-31 SQL::Abstract::Test(3)