Audit and minimize use of last major indirect method: search()
[dbsrgits/DBIx-Class.git] / t / 749sqlanywhere.t
index 0999f6d..ed9c382 100644 (file)
@@ -1,12 +1,13 @@
+BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
+
 use strict;
 use warnings;
 
 use Test::More;
 use Test::Exception;
-use Scope::Guard ();
-use Try::Tiny;
 use DBIx::Class::Optional::Dependencies ();
-use lib qw(t/lib);
+use DBIx::Class::_Util 'scope_guard';
+
 use DBICTest;
 
 my ($dsn, $user, $pass)    = @ENV{map { "DBICTEST_SQLANYWHERE_${_}" }      qw/DSN USER PASS/};
@@ -23,6 +24,8 @@ plan skip_all => 'Test needs ' .
     or
     (not $dsn || $dsn2);
 
+DBICTest::Schema->load_classes('ArtistGUID');
+
 # tests stolen from 748informix.t
 
 plan skip_all => <<'EOF' unless $dsn || $dsn2;
@@ -30,9 +33,6 @@ Set $ENV{DBICTEST_SQLANYWHERE_DSN} and/or $ENV{DBICTEST_SQLANYWHERE_ODBC_DSN},
 _USER and _PASS to run these tests
 EOF
 
-require DBICTest::Schema;
-DBICTest::Schema->load_classes('ArtistGUID');
-
 my @info = (
   [ $dsn,  $user,  $pass  ],
   [ $dsn2, $user2, $pass2 ],
@@ -49,7 +49,7 @@ foreach my $info (@info) {
     auto_savepoint => 1
   });
 
-  my $guard = Scope::Guard->new(sub{ cleanup($schema) });
+  my $guard = scope_guard { cleanup($schema) };
 
   my $dbh = $schema->storage->dbh;
 
@@ -151,9 +151,7 @@ EOF
     id     INT          NOT NULL PRIMARY KEY,
     bytea  INT          NULL,
     blob   LONG BINARY  NULL,
-    blob2  LONG BINARY  NULL,
     clob   LONG VARCHAR NULL,
-    clob2  LONG VARCHAR NULL,
     a_memo INT          NULL
   )
   ],{ RaiseError => 1, PrintError => 1 });
@@ -227,35 +225,54 @@ SQL
     );
     diag $@ if $@;
 
-    my $row_from_db = try { $schema->resultset('ArtistGUID')
-      ->search({ name => 'mtfnpy' })->first }
-      catch { diag $_ };
+    my $row_from_db;
+    lives_ok {
+      $row_from_db = $schema->resultset('ArtistGUID')->search({ name => 'mtfnpy' })->first
+    };
 
-    is try { $row_from_db->artistid }, $row->artistid,
-      'PK GUID round trip (via ->search->next)';
+    is(
+      eval { $row_from_db->artistid },
+      $row->artistid,
+      'PK GUID round trip (via ->search->next)'
+    );
 
-    is try { $row_from_db->a_guid }, $row->a_guid,
-      'NON-PK GUID round trip (via ->search->next)';
+    is(
+      eval { $row_from_db->a_guid },
+      $row->a_guid,
+      'NON-PK GUID round trip (via ->search->next)'
+    );
 
-    $row_from_db = try { $schema->resultset('ArtistGUID')
-      ->find($row->artistid) }
-      catch { diag $_ };
+    lives_ok {
+      $row_from_db = $schema->resultset('ArtistGUID')->find($row->artistid)
+    };
 
-    is try { $row_from_db->artistid }, $row->artistid,
-      'PK GUID round trip (via ->find)';
+    is(
+      eval { $row_from_db->artistid },
+      $row->artistid,
+      'PK GUID round trip (via ->find)'
+    );
 
-    is try { $row_from_db->a_guid }, $row->a_guid,
-      'NON-PK GUID round trip (via ->find)';
+    is(
+      eval { $row_from_db->a_guid },
+      $row->a_guid,
+      'NON-PK GUID round trip (via ->find)'
+    );
 
-    ($row_from_db) = try { $schema->resultset('ArtistGUID')
-      ->search({ name => 'mtfnpy' })->all }
-      catch { diag $_ };
+    lives_ok {
+      ($row_from_db) = $schema->resultset('ArtistGUID')->search({ name => 'mtfnpy' })->all
+    };
 
-    is try { $row_from_db->artistid }, $row->artistid,
-      'PK GUID round trip (via ->search->all)';
+    is(
+      eval { $row_from_db->artistid },
+      $row->artistid,
+      'PK GUID round trip (via ->search->all)'
+    );
 
-    is try { $row_from_db->a_guid }, $row->a_guid,
-      'NON-PK GUID round trip (via ->search->all)';
+    is(
+      eval { $row_from_db->a_guid },
+      $row->a_guid,
+      'NON-PK GUID round trip (via ->search->all)'
+    );
   }
 }