1 package # hide from PAUSE
7 use base qw/Test::Builder::Module Exporter/;
19 package # hide from PAUSE
20 DBIC::SqlMakerTest::SQLATest;
22 # replacement for SQL::Abstract::Test if not available
27 use base qw/Test::Builder::Module Exporter/;
29 use Scalar::Util qw(looks_like_number blessed reftype);
32 use Test::Deep qw(eq_deeply);
34 our $tb = __PACKAGE__->builder;
38 my ($sql1, $bind_ref1, $sql2, $bind_ref2, $msg) = @_;
40 my $same_sql = eq_sql($sql1, $sql2);
41 my $same_bind = eq_bind($bind_ref1, $bind_ref2);
43 $tb->ok($same_sql && $same_bind, $msg);
46 $tb->diag("SQL expressions differ\n"
52 $tb->diag("BIND values differ\n"
53 . " got: " . Dumper($bind_ref1)
54 . "expected: " . Dumper($bind_ref2)
61 my ($left, $right) = @_;
66 return $left eq $right;
69 # lifted from SQL::Abstract::Test
72 my ($bind_ref1, $bind_ref2) = @_;
74 return eq_deeply($bind_ref1, $bind_ref2);
78 eval "use SQL::Abstract::Test;";
80 # SQL::Abstract::Test available
82 *is_same_sql_bind = \&SQL::Abstract::Test::is_same_sql_bind;
83 *eq_sql = \&SQL::Abstract::Test::eq_sql;
84 *eq_bind = \&SQL::Abstract::Test::eq_bind;
88 *is_same_sql_bind = \&DBIC::SqlMakerTest::SQLATest::is_same_sql_bind;
89 *eq_sql = \&DBIC::SqlMakerTest::SQLATest::eq_sql;
90 *eq_bind = \&DBIC::SqlMakerTest::SQLATest::eq_bind;
101 DBIC::SqlMakerTest - Helper package for testing sql_maker component of DBIC
106 use DBIC::SqlMakerTest;
108 my ($sql, @bind) = $schema->storage->sql_maker->select(%args);
111 $expected_sql, \@expected_bind,
117 Exports functions that can be used to compare generated SQL and bind values.
119 If L<SQL::Abstract::Test> (packaged in L<SQL::Abstract> versions 1.50 and
120 above) is available, then it is used to perform the comparisons (all functions
121 are delegated to id). Otherwise uses simple string comparison for the SQL
122 statements and simple L<Data::Dumper>-like recursive stringification for
123 comparison of bind values.
128 =head2 is_same_sql_bind
131 $given_sql, \@given_bind,
132 $expected_sql, \@expected_bind,
136 Compares given and expected pairs of C<($sql, \@bind)>, and calls
137 L<Test::Builder/ok> on the result, with C<$test_msg> as message.
141 my $is_same = eq_sql($given_sql, $expected_sql);
143 Compares the two SQL statements. Returns true IFF they are equivalent.
147 my $is_same = eq_sql(\@given_bind, \@expected_bind);
149 Compares two lists of bind values. Returns true IFF their values are the same.
154 L<SQL::Abstract::Test>, L<Test::More>, L<Test::Builder>.
158 Norbert Buchmuller, <norbi@nix.hu>
160 =head1 COPYRIGHT AND LICENSE
162 Copyright 2008 by Norbert Buchmuller.
164 This library is free software; you can redistribute it and/or modify
165 it under the same terms as Perl itself.