[Bast-commits] r5197 - in DBIx-Class/0.08/branches/sqla_1.50_compat: . t t/lib t/lib/DBIC

norbi at dev.catalyst.perl.org norbi at dev.catalyst.perl.org
Tue Nov 25 01:11:22 GMT 2008


Author: norbi
Date: 2008-11-25 01:11:22 +0000 (Tue, 25 Nov 2008)
New Revision: 5197

Added:
   DBIx-Class/0.08/branches/sqla_1.50_compat/t/lib/DBIC/
   DBIx-Class/0.08/branches/sqla_1.50_compat/t/lib/DBIC/SqlMakerTest.pm
Modified:
   DBIx-Class/0.08/branches/sqla_1.50_compat/
   DBIx-Class/0.08/branches/sqla_1.50_compat/t/19quotes.t
   DBIx-Class/0.08/branches/sqla_1.50_compat/t/19quotes_newstyle.t
   DBIx-Class/0.08/branches/sqla_1.50_compat/t/41orrible.t
   DBIx-Class/0.08/branches/sqla_1.50_compat/t/76joins.t
   DBIx-Class/0.08/branches/sqla_1.50_compat/t/91debug.t
   DBIx-Class/0.08/branches/sqla_1.50_compat/t/95sql_maker.t
   DBIx-Class/0.08/branches/sqla_1.50_compat/t/95sql_maker_quote.t
Log:
 r5235 at vger:  mendel | 2008-11-25 00:32:57 +0100
  * Wrapped SQL::Abstract::Test functionality in a new module (DBIC::SqlMakerTest).
  * Made a test SKIP that does not work with SQL::Abstract < 1.49 (used to be a TODO test).



Property changes on: DBIx-Class/0.08/branches/sqla_1.50_compat
___________________________________________________________________
Name: svk:merge
   - 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/sqla_1.50_compat:5232
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class:32260
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class-CDBICompat:54993
9c88509d-e914-0410-b01c-b9530614cbfe:/vendor/DBIx-Class:31122
bd5ac9a7-f185-4d95-9186-dbb8b392a572:/local/os/bast/DBIx-Class/0.08/trunk:2798
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/cdbicompat_integration:4160
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/complex_join_rels:4589
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/file_column:3920
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/on_disconnect_do:3694
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/oracle_sequence:4173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/parser_fk_index:4485
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/replication_dedux:4600
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/savepoints:4223
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-ms-access:4142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioned_enhancements:4125
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioning:4578
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/trunk:5113
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3606
fe160bb6-dc1c-0410-9f2b-d64a711b54a5:/local/DBIC-trunk-0.08:10510
   + 168d5346-440b-0410-b799-f706be625ff1:/DBIx-Class-current:2207
462d4d0c-b505-0410-bf8e-ce8f877b3390:/local/bast/DBIx-Class:3159
4d5fae46-8e6a-4e08-abee-817e9fb894a2:/local/bast/DBIx-Class/0.08/branches/sqla_1.50_compat:5235
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class:32260
9c88509d-e914-0410-b01c-b9530614cbfe:/local/DBIx-Class-CDBICompat:54993
9c88509d-e914-0410-b01c-b9530614cbfe:/vendor/DBIx-Class:31122
bd5ac9a7-f185-4d95-9186-dbb8b392a572:/local/os/bast/DBIx-Class/0.08/trunk:2798
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/cdbicompat_integration:4160
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/complex_join_rels:4589
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/file_column:3920
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/on_disconnect_do:3694
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/oracle_sequence:4173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/parser_fk_index:4485
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/replication_dedux:4600
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/savepoints:4223
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/storage-ms-access:4142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioned_enhancements:4125
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/branches/versioning:4578
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/DBIx-Class/0.08/trunk:5113
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-C3:318
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-current:2222
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-joins:173
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class-resultset:570
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/datetime:1716
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_compat:1855
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/find_unique_query_fixes:2142
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/inflate:1988
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/many_to_many:2025
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/re_refactor_bugfix:1944
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/reorganize_tests:1827
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset-new-refactor:1766
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_2_electric_boogaloo:2175
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/resultset_cleanup:2102
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/branches/DBIx-Class/sqlt_tests_refactor:2043
bd8105ee-0ff8-0310-8827-fb3f25b6796d:/trunk/DBIx-Class:3606
fe160bb6-dc1c-0410-9f2b-d64a711b54a5:/local/DBIC-trunk-0.08:10510

Modified: DBIx-Class/0.08/branches/sqla_1.50_compat/t/19quotes.t
===================================================================
--- DBIx-Class/0.08/branches/sqla_1.50_compat/t/19quotes.t	2008-11-25 01:11:13 UTC (rev 5196)
+++ DBIx-Class/0.08/branches/sqla_1.50_compat/t/19quotes.t	2008-11-25 01:11:22 UTC (rev 5197)
@@ -3,7 +3,7 @@
 
 use Test::More;
 use IO::File;
-use SQL::Abstract::Test import => ['is_same_sql_bind'];
+use DBIC::SqlMakerTest;
 
 BEGIN {
     eval "use DBD::SQLite";

Modified: DBIx-Class/0.08/branches/sqla_1.50_compat/t/19quotes_newstyle.t
===================================================================
--- DBIx-Class/0.08/branches/sqla_1.50_compat/t/19quotes_newstyle.t	2008-11-25 01:11:13 UTC (rev 5196)
+++ DBIx-Class/0.08/branches/sqla_1.50_compat/t/19quotes_newstyle.t	2008-11-25 01:11:22 UTC (rev 5197)
@@ -3,7 +3,7 @@
 
 use Test::More;
 use IO::File;
-use SQL::Abstract::Test import => ['is_same_sql_bind'];
+use DBIC::SqlMakerTest;
 
 BEGIN {
     eval "use DBD::SQLite";

Modified: DBIx-Class/0.08/branches/sqla_1.50_compat/t/41orrible.t
===================================================================
--- DBIx-Class/0.08/branches/sqla_1.50_compat/t/41orrible.t	2008-11-25 01:11:13 UTC (rev 5196)
+++ DBIx-Class/0.08/branches/sqla_1.50_compat/t/41orrible.t	2008-11-25 01:11:22 UTC (rev 5197)
@@ -3,7 +3,7 @@
 
 use Test::More;
 #use DBIx::Class::Storage::DBI;
-use SQL::Abstract::Test import => ['is_same_sql_bind'];
+use DBIC::SqlMakerTest;
 use DBIx::Class::Storage::DBI::Oracle::WhereJoins;
 
 plan tests => 4;

Modified: DBIx-Class/0.08/branches/sqla_1.50_compat/t/76joins.t
===================================================================
--- DBIx-Class/0.08/branches/sqla_1.50_compat/t/76joins.t	2008-11-25 01:11:13 UTC (rev 5196)
+++ DBIx-Class/0.08/branches/sqla_1.50_compat/t/76joins.t	2008-11-25 01:11:22 UTC (rev 5197)
@@ -5,7 +5,7 @@
 use lib qw(t/lib);
 use DBICTest;
 use Data::Dumper;
-use SQL::Abstract::Test import => ['is_same_sql_bind'];
+use DBIC::SqlMakerTest;
 
 my $schema = DBICTest->init_schema();
 

Modified: DBIx-Class/0.08/branches/sqla_1.50_compat/t/91debug.t
===================================================================
--- DBIx-Class/0.08/branches/sqla_1.50_compat/t/91debug.t	2008-11-25 01:11:13 UTC (rev 5196)
+++ DBIx-Class/0.08/branches/sqla_1.50_compat/t/91debug.t	2008-11-25 01:11:22 UTC (rev 5197)
@@ -5,7 +5,7 @@
 use lib qw(t/lib);
 use DBICTest;
 use DBICTest::DBICDebugObj;
-use SQL::Abstract::Test import => ['is_same_sql_bind'];
+use DBIC::SqlMakerTest;
 
 my $schema = DBICTest->init_schema();
 

Modified: DBIx-Class/0.08/branches/sqla_1.50_compat/t/95sql_maker.t
===================================================================
--- DBIx-Class/0.08/branches/sqla_1.50_compat/t/95sql_maker.t	2008-11-25 01:11:13 UTC (rev 5196)
+++ DBIx-Class/0.08/branches/sqla_1.50_compat/t/95sql_maker.t	2008-11-25 01:11:22 UTC (rev 5197)
@@ -2,7 +2,7 @@
 use warnings;
 
 use Test::More;
-use SQL::Abstract::Test import => ['is_same_sql_bind'];
+use DBIC::SqlMakerTest;
 
 
 BEGIN {

Modified: DBIx-Class/0.08/branches/sqla_1.50_compat/t/95sql_maker_quote.t
===================================================================
--- DBIx-Class/0.08/branches/sqla_1.50_compat/t/95sql_maker_quote.t	2008-11-25 01:11:13 UTC (rev 5196)
+++ DBIx-Class/0.08/branches/sqla_1.50_compat/t/95sql_maker_quote.t	2008-11-25 01:11:22 UTC (rev 5197)
@@ -2,7 +2,7 @@
 use warnings;
 
 use Test::More;
-use SQL::Abstract::Test import => ['is_same_sql_bind'];
+use DBIC::SqlMakerTest;
 
 
 BEGIN {
@@ -237,27 +237,31 @@
   'quoted table names for UPDATE'
 );
 
+SKIP: {
+  skip 1, "select attr with star does not work in SQL::Abstract < 1.49"
+    if $SQL::Abstract::VERSION < 1.49;
 
-($sql, @bind) = $sql_maker->select(
-      [
-        {
-          'me' => 'cd'
-        }
-      ],
-      [
-        'me.*'
-      ],
-      undef,
-      [],
-      undef,
-      undef    
-);
+  ($sql, @bind) = $sql_maker->select(
+        [
+          {
+            'me' => 'cd'
+          }
+        ],
+        [
+          'me.*'
+        ],
+        undef,
+        [],
+        undef,
+        undef    
+  );
 
-is_same_sql_bind(
-  $sql, \@bind,
-  q/SELECT `me`.* FROM `cd` `me`/, [],
-  'select attr with me.* is right'
-);
+  is_same_sql_bind(
+    $sql, \@bind,
+    q/SELECT `me`.* FROM `cd` `me`/, [],
+    'select attr with me.* is right'
+  );
+}
 
 
 $sql_maker->quote_char([qw/[ ]/]);

Added: DBIx-Class/0.08/branches/sqla_1.50_compat/t/lib/DBIC/SqlMakerTest.pm
===================================================================
--- DBIx-Class/0.08/branches/sqla_1.50_compat/t/lib/DBIC/SqlMakerTest.pm	                        (rev 0)
+++ DBIx-Class/0.08/branches/sqla_1.50_compat/t/lib/DBIC/SqlMakerTest.pm	2008-11-25 01:11:22 UTC (rev 5197)
@@ -0,0 +1,177 @@
+package # hide from PAUSE
+  DBIC::SqlMakerTest;
+
+use strict;
+use warnings;
+
+use base qw/Test::Builder::Module Exporter/;
+
+use Exporter;
+use Data::Dumper;
+
+our @EXPORT = qw/
+  &is_same_sql_bind
+  &eq_sql
+  &eq_bind
+/;
+
+
+{
+  package # hide from PAUSE
+    DBIC::SqlMakerTest::SQLATest;
+
+  # replacement for SQL::Abstract::Test if not available
+
+  use strict;
+  use warnings;
+
+  use base qw/Test::Builder::Module Exporter/;
+
+  use Data::Dumper;
+
+  our $tb = __PACKAGE__->builder;
+
+  sub is_same_sql_bind
+  {
+    my ($sql1, $bind_ref1, $sql2, $bind_ref2, $msg) = @_;
+
+    my $same_sql = eq_sql($sql1, $sql2);
+    my $same_bind = eq_bind($bind_ref1, $bind_ref2);
+
+    $tb->ok($same_sql && $same_bind, $msg);
+
+    if (!$same_sql) {
+      $tb->diag("SQL expressions differ\n"
+        . "     got: $sql1\n"
+        . "expected: $sql2\n"
+      );
+    }
+    if (!$same_bind) {
+      $tb->diag("BIND values differ\n"
+        . "     got: " . Dumper($bind_ref1)
+        . "expected: " . Dumper($bind_ref2)
+      );
+    }
+  }
+
+  sub eq_sql
+  {
+    my ($left, $right) = @_;
+
+    $left =~ s/\s+//g;
+    $right =~ s/\s+//g;
+
+    return $left eq $right;
+  }
+
+  sub eq_bind
+  {
+    my ($bind_ref1, $bind_ref2) = @_;
+
+    return stringify_bind($bind_ref1) eq stringify_bind($bind_ref2);
+  }
+
+  sub stringify_bind
+  {
+    my ($bind) = @_;
+
+    foreach (ref $bind) {
+      /^$/ and return $bind;
+      /^ARRAY$/ and return join("\n", map { stringify_bind($_) } @$bind);
+      /^HASH$/ and return join(
+        "\n", map { $_ . " => " . stringify_bind($bind->{$_}) } keys %$bind
+      );
+      /^SCALAR$/ and return "\\" . stringify_bind($$bind);
+      return '' . $bind;
+    }
+  }
+}
+
+eval "use SQL::Abstract::Test;";
+if ($@ eq '') {
+  # SQL::Abstract::Test available
+
+  *is_same_sql_bind = \&SQL::Abstract::Test::is_same_sql_bind;
+  *eq_sql = \&SQL::Abstract::Test::eq_sql;
+  *eq_bind = \&SQL::Abstract::Test::eq_bind;
+} else {
+  # old SQL::Abstract
+
+  *is_same_sql_bind = \&DBIC::SqlMakerTest::SQLATest::is_same_sql_bind;
+  *eq_sql = \&DBIC::SqlMakerTest::SQLATest::eq_sql;
+  *eq_bind = \&DBIC::SqlMakerTest::SQLATest::eq_bind;
+}
+
+
+1;
+
+__END__
+
+
+=head1 NAME
+
+DBIC::SqlMakerTest - Helper package for testing sql_maker component of DBIC
+
+=head1 SYNOPSIS
+
+  use Test::More;
+  use DBIC::SqlMakerTest;
+  
+  my ($sql, @bind) = $schema->storage->sql_maker->select(%args);
+  is_same_sql_bind(
+    $sql, \@bind, 
+    $expected_sql, \@expected_bind,
+    'foo bar works'
+  );
+
+=head1 DESCRIPTION
+
+Exports functions that can be used to compare generated SQL and bind values.
+
+If L<SQL::Abstract::Test> (packaged in L<SQL::Abstract> versions 1.50 and
+above) is available, then it is used to perform the comparisons (all functions
+are delegated to id). Otherwise uses simple string comparison for the SQL
+statements and simple L<Data::Dumper>-like recursive stringification for
+comparison of bind values.
+
+
+=head1 FUNCTIONS
+
+=head2 is_same_sql_bind
+
+  is_same_sql_bind(
+    $given_sql, \@given_bind, 
+    $expected_sql, \@expected_bind,
+    $test_msg
+  );
+
+Compares given and expected pairs of C<($sql, \@bind)>, and calls
+L<Test::Builder/ok> on the result, with C<$test_msg> as message.
+
+=head2 eq_sql
+
+  my $is_same = eq_sql($given_sql, $expected_sql);
+
+Compares the two SQL statements. Returns true IFF they are equivalent.
+
+=head2 eq_bind
+
+  my $is_same = eq_sql(\@given_bind, \@expected_bind);
+
+Compares two lists of bind values. Returns true IFF their values are the same.
+
+
+=head1 SEE ALSO
+
+L<SQL::Abstract::Test>, L<Test::More>, L<Test::Builder>.
+
+=head1 AUTHOR
+
+Norbert Buchmuller, <norbi at nix.hu>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2008 by Norbert Buchmuller.
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself. 


Property changes on: DBIx-Class/0.08/branches/sqla_1.50_compat/t/lib/DBIC/SqlMakerTest.pm
___________________________________________________________________
Name: svn:eol-style
   + native




More information about the Bast-commits mailing list