Kill leaktest on smokers with 1.3xx Test::More alphas
[dbsrgits/DBIx-Class.git] / t / sqlmaker / dbihacks_internals.t
index ced331f..cd229fd 100644 (file)
@@ -8,6 +8,12 @@ use DBICTest ':DiffSQL';
 use DBIx::Class::_Util 'UNRESOLVABLE_CONDITION';
 
 use Data::Dumper;
+BEGIN {
+  if ( eval { require Test::Differences } ) {
+    no warnings 'redefine';
+    *is_deeply = \&Test::Differences::eq_or_diff;
+  }
+}
 
 my $schema = DBICTest->init_schema( no_deploy => 1);
 my $sm = $schema->storage->sql_maker;
@@ -75,11 +81,18 @@ for my $t (
   },
   {
     where => { -and => [ \'foo=bar',  [ { artistid => { '=', $num } } ], { name => 'Caterwauler McCrae'} ] },
-    cc_result => { '' => \'foo=bar', name => 'Caterwauler McCrae', artistid => $num },
+    cc_result => { -and => [ \'foo=bar' ], name => 'Caterwauler McCrae', artistid => $num },
     sql => 'WHERE foo=bar AND artistid = ? AND name = ?',
     efcc_result => { name => 'Caterwauler McCrae', artistid => $num },
   },
   {
+    where => { -and => [ \'foo=bar',  [ { artistid => { '=', $num } } ], { name => 'Caterwauler McCrae'}, \'buzz=bozz' ] },
+    cc_result => { -and => [ \'foo=bar', \'buzz=bozz' ], name => 'Caterwauler McCrae', artistid => $num },
+    sql => 'WHERE foo=bar AND artistid = ? AND name = ? AND buzz=bozz',
+    collapsed_sql => 'WHERE foo=bar AND buzz=bozz AND artistid = ? AND name = ?',
+    efcc_result => { name => 'Caterwauler McCrae', artistid => $num },
+  },
+  {
     where => { artistid => [ $num ], rank => [ 13, 2, 3 ], charfield => [ undef ] },
     cc_result => { artistid => $num, charfield => undef, rank => [13, 2, 3] },
     sql => 'WHERE artistid = ? AND charfield IS NULL AND ( rank = ? OR rank = ? OR rank = ? )',
@@ -128,6 +141,7 @@ for my $t (
     efcc_result => {},
     efcc_n_result => {},
   } } (
+
     { -and => [
       -or => [ rank => { '=' => \13 }, charfield => { '=' => undef }, artistid => 1 ],
       -or => { artistid => { '=' => 1 }, charfield => undef, rank => { '!=' => \42 } },
@@ -137,8 +151,26 @@ for my $t (
       -OR => [ rank => { '=' => \13 }, charfield => { '=' => undef }, artistid => 1 ],
       -or => { artistid => { '=' => 1 }, charfield => undef, rank => { '!=' => \42 } },
     },
+
   ) ),
   {
+    where => { -or => [
+      -and => [ foo => { '!=', { -value => undef } }, bar => { -in => [ 69, 42 ] } ],
+      foo => { '=', { -value => undef } },
+      baz => { '!=' => { -ident => 'bozz' } },
+      baz => { -ident => 'buzz' },
+    ] },
+    sql => 'WHERE ( foo IS NOT NULL AND bar IN ( ?, ? ) ) OR foo IS NULL OR baz != bozz OR baz = buzz',
+    collapsed_sql => 'WHERE baz != bozz OR baz = buzz OR foo IS NULL OR ( bar IN ( ?, ? ) AND foo IS NOT NULL )',
+    cc_result => { -or => [
+      baz => { '!=' => { -ident => 'bozz' } },
+      baz => { '=' => { -ident => 'buzz' } },
+      foo => undef,
+      { bar => { -in => [ 69, 42 ] }, foo => { '!=', undef } }
+    ] },
+    efcc_result => {},
+  },
+  {
     where => { -or => [ rank => { '=' => \13 }, charfield => { '=' => undef }, artistid => { '=' => 1 }, genreid => { '=' => \['?', 2] } ] },
     sql => 'WHERE rank = 13 OR charfield IS NULL OR artistid = ? OR genreid = ?',
     collapsed_sql => 'WHERE artistid = ? OR charfield IS NULL OR genreid = ? OR rank = 13',
@@ -332,15 +364,82 @@ for my $t (
         [ { 'me.title' => 'Spoonful of bees' } ],
     ]},
     cc_result => {
-      '' => \[
+      -and => [ \[
         "LOWER(me.title) LIKE ?",
         '%spoon%',
-      ],
+      ]],
       'me.title' => 'Spoonful of bees',
     },
     sql => 'WHERE LOWER(me.title) LIKE ? AND me.title = ?',
     efcc_result => { 'me.title' => 'Spoonful of bees' },
-  }
+  },
+
+  # crazy literals
+  {
+    where => {
+      -or => [
+        \'foo = bar',
+      ],
+    },
+    sql => 'WHERE foo = bar',
+    cc_result => {
+      -and => [
+        \'foo = bar',
+      ],
+    },
+    efcc_result => {},
+  },
+  {
+    where => {
+      -or => [
+        \'foo = bar',
+        \'baz = ber',
+      ],
+    },
+    sql => 'WHERE foo = bar OR baz = ber',
+    collapsed_sql => 'WHERE baz = ber OR foo = bar',
+    cc_result => {
+      -or => [
+        \'baz = ber',
+        \'foo = bar',
+      ],
+    },
+    efcc_result => {},
+  },
+  {
+    where => {
+      -and => [
+        \'foo = bar',
+        \'baz = ber',
+      ],
+    },
+    sql => 'WHERE foo = bar AND baz = ber',
+    cc_result => {
+      -and => [
+        \'foo = bar',
+        \'baz = ber',
+      ],
+    },
+    efcc_result => {},
+  },
+  {
+    where => {
+      -and => [
+        \'foo = bar',
+        \'baz = ber',
+        x => { -ident => 'y' },
+      ],
+    },
+    sql => 'WHERE foo = bar AND baz = ber AND x = y',
+    cc_result => {
+      -and => [
+        \'foo = bar',
+        \'baz = ber',
+      ],
+      x => { '=' => { -ident => 'y' } }
+    },
+    efcc_result => { x => { -ident => 'y' } },
+  },
 ) {
 
   for my $w (
@@ -365,14 +464,14 @@ for my $t (
     is_same_sql ( $generated_sql, $t->{sql}, "Expected SQL from $name" )
       if exists $t->{sql};
 
-    my $collapsed_cond = $schema->storage->_collapse_cond($w);
-
     is_same_sql(
-      ($sm->where($collapsed_cond))[0],
+      ($sm->where($t->{cc_result}))[0],
       ( $t->{collapsed_sql} || $t->{sql} || $generated_sql ),
       "Collapse did not alter *the semantics* of the final SQL based on $name",
     );
 
+    my $collapsed_cond = $schema->storage->_collapse_cond($w);
+
     is_deeply(
       $collapsed_cond,
       $t->{cc_result},
@@ -390,6 +489,8 @@ for my $t (
       $t->{efcc_n_result},
       "Expected fixed_condition including NULLs produced on $name",
     ) if $t->{efcc_n_result};
+
+    die unless Test::Builder->new->is_passing;
   }
 }