1 package DBIC::SqlMakerTest;
9 use SQL::Abstract::Test;
22 sub is_same_sql_bind {
23 # unroll possible as_query arrayrefrefs
29 if ( ref $chunk eq 'REF' and ref $$chunk eq 'ARRAY' ) {
30 my ($sql, @bind) = @$$chunk;
31 push @args, ($sql, \@bind);
34 push @args, $chunk, shift @_;
41 croak "Unexpected argument(s) supplied to is_same_sql_bind: " . join ('; ', @_)
44 SQL::Abstract::Test::is_same_sql_bind (@args);
47 *is_same_sql = \&SQL::Abstract::Test::is_same_sql;
48 *is_same_bind = \&SQL::Abstract::Test::is_same_bind;
49 *eq_sql = \&SQL::Abstract::Test::eq_sql;
50 *eq_bind = \&SQL::Abstract::Test::eq_bind;
51 *eq_sql_bind = \&SQL::Abstract::Test::eq_sql_bind;
60 DBIC::SqlMakerTest - Helper package for testing sql_maker component of DBIC
65 use DBIC::SqlMakerTest;
67 my ($sql, @bind) = $schema->storage->sql_maker->select(%args);
70 $expected_sql, \@expected_bind,
76 Exports functions that can be used to compare generated SQL and bind values.
78 This is a thin wrapper around L<SQL::Abstract::Test>, which makes it easier
79 to compare as_query sql/bind arrayrefrefs directly.
83 =head2 is_same_sql_bind
86 $given_sql, \@given_bind,
87 $expected_sql, \@expected_bind,
93 $expected_sql, \@expected_bind,
98 \[$given_sql, @given_bind],
99 $expected_sql, \@expected_bind,
103 Compares given and expected pairs of C<($sql, \@bind)>, and calls
104 L<Test::Builder/ok> on the result, with C<$test_msg> as message.
114 Compares given and expected SQL statement, and calls L<Test::Builder/ok> on the
115 result, with C<$test_msg> as message.
125 Compares given and expected bind value lists, and calls L<Test::Builder/ok> on
126 the result, with C<$test_msg> as message.
130 my $is_same = eq_sql($given_sql, $expected_sql);
132 Compares the two SQL statements. Returns true IFF they are equivalent.
136 my $is_same = eq_sql(\@given_bind, \@expected_bind);
138 Compares two lists of bind values. Returns true IFF their values are the same.
142 my $is_same = eq_sql_bind(
143 $given_sql, \@given_bind,
144 $expected_sql, \@expected_bind
147 Compares the two SQL statements and the two lists of bind values. Returns true
148 IFF they are equivalent and the bind values are the same.
153 L<SQL::Abstract::Test>, L<Test::More>, L<Test::Builder>.
157 Norbert Buchmuller, <norbi@nix.hu>
159 =head1 COPYRIGHT AND LICENSE
161 Copyright 2008 by Norbert Buchmuller.
163 This library is free software; you can redistribute it and/or modify
164 it under the same terms as Perl itself.