1 package DBIC::SqlMakerTest;
6 use base qw/Test::Builder::Module Exporter/;
18 package DBIC::SqlMakerTest::SQLATest;
20 # replacement for SQL::Abstract::Test if not available
25 use base qw/Test::Builder::Module Exporter/;
27 use Scalar::Util qw(looks_like_number blessed reftype);
30 use Test::Deep qw(eq_deeply);
32 our $tb = __PACKAGE__->builder;
36 my ($sql1, $bind_ref1, $sql2, $bind_ref2, $msg) = @_;
38 my $same_sql = eq_sql($sql1, $sql2);
39 my $same_bind = eq_bind($bind_ref1, $bind_ref2);
41 $tb->ok($same_sql && $same_bind, $msg);
44 $tb->diag("SQL expressions differ\n"
50 $tb->diag("BIND values differ\n"
51 . " got: " . Dumper($bind_ref1)
52 . "expected: " . Dumper($bind_ref2)
59 my ($left, $right) = @_;
64 return $left eq $right;
69 my ($bind_ref1, $bind_ref2) = @_;
71 return eq_deeply($bind_ref1, $bind_ref2);
75 eval "use SQL::Abstract::Test;";
77 # SQL::Abstract::Test available
79 *is_same_sql_bind = \&SQL::Abstract::Test::is_same_sql_bind;
80 *eq_sql = \&SQL::Abstract::Test::eq_sql;
81 *eq_bind = \&SQL::Abstract::Test::eq_bind;
85 *is_same_sql_bind = \&DBIC::SqlMakerTest::SQLATest::is_same_sql_bind;
86 *eq_sql = \&DBIC::SqlMakerTest::SQLATest::eq_sql;
87 *eq_bind = \&DBIC::SqlMakerTest::SQLATest::eq_bind;
98 DBIC::SqlMakerTest - Helper package for testing sql_maker component of DBIC
103 use DBIC::SqlMakerTest;
105 my ($sql, @bind) = $schema->storage->sql_maker->select(%args);
108 $expected_sql, \@expected_bind,
114 Exports functions that can be used to compare generated SQL and bind values.
116 If L<SQL::Abstract::Test> (packaged in L<SQL::Abstract> versions 1.50 and
117 above) is available, then it is used to perform the comparisons (all functions
118 are delegated to id). Otherwise uses simple string comparison for the SQL
119 statements and simple L<Data::Dumper>-like recursive stringification for
120 comparison of bind values.
125 =head2 is_same_sql_bind
128 $given_sql, \@given_bind,
129 $expected_sql, \@expected_bind,
133 Compares given and expected pairs of C<($sql, \@bind)>, and calls
134 L<Test::Builder/ok> on the result, with C<$test_msg> as message.
138 my $is_same = eq_sql($given_sql, $expected_sql);
140 Compares the two SQL statements. Returns true IFF they are equivalent.
144 my $is_same = eq_sql(\@given_bind, \@expected_bind);
146 Compares two lists of bind values. Returns true IFF their values are the same.
151 L<SQL::Abstract::Test>, L<Test::More>, L<Test::Builder>.
155 Norbert Buchmuller, <norbi@nix.hu>
157 =head1 COPYRIGHT AND LICENSE
159 Copyright 2008 by Norbert Buchmuller.
161 This library is free software; you can redistribute it and/or modify
162 it under the same terms as Perl itself.