Get rid of Path::Class ( that *does* feel good )
[dbsrgits/DBIx-Class.git] / t / storage / replicated.t
index c480541..9ecc7e8 100644 (file)
@@ -1,35 +1,30 @@
+BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
+use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_replicated';
+
 use strict;
 use warnings;
 
 use Test::More;
+use DBIx::Class::_Util 'modver_gt_or_eq_and_lt';
 
-use lib qw(t/lib);
 use DBICTest;
 
 BEGIN {
-    require DBIx::Class;
-    plan skip_all => 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('test_replicated')
-      unless DBIx::Class::Optional::Dependencies->req_ok_for ('test_replicated');
-
-    if (DBICTest::RunMode->is_smoker) {
-      my $mver = Moose->VERSION;
-      plan skip_all => "A trial version $mver of Moose detected known to break replication - skipping test known to fail"
-        if ($mver >= 1.99 and $mver <= 1.9902);
-    }
-
+  plan skip_all => "A trial version of Moose detected known to break replication - skipping test known to fail" if (
+    DBICTest::RunMode->is_smoker
+      and
+    modver_gt_or_eq_and_lt( 'Moose', '1.99', '1.9903' )
+  )
 }
 
 use Test::Moose;
 use Test::Exception;
-use List::Util 'first';
 use Scalar::Util 'reftype';
-use File::Spec;
-use IO::Handle;
 use Moose();
 use MooseX::Types();
 note "Using Moose version $Moose::VERSION and MooseX::Types version $MooseX::Types::VERSION";
 
-my $var_dir = quotemeta ( File::Spec->catdir(qw/t var/) );
+my $var_dir_re = qr{ t [\/\\] var [\/\\] }x;
 
 ## Add a connect_info option to test option merging.
 use DBIx::Class::Storage::DBI::Replicated;
@@ -160,8 +155,8 @@ TESTSCHEMACLASSES: {
 
         $self->master_path( DBICTest->_sqlite_dbfilename );
         $self->slave_paths([
-            File::Spec->catfile(qw/t var DBIxClass_slave1.db/),
-            File::Spec->catfile(qw/t var DBIxClass_slave2.db/),
+            't/var/DBIxClass_slave1.db',
+            't/var/DBIxClass_slave2.db',
         ]);
 
         return $self;
@@ -208,6 +203,7 @@ TESTSCHEMACLASSES: {
 
     sub cleanup {
         my $self = shift @_;
+        $_->disconnect for values %{ $self->schema->storage->replicants };
         foreach my $slave (@{$self->slave_paths}) {
             if(-e $slave) {
                 unlink $slave;
@@ -378,7 +374,7 @@ ok @replicant_names, "found replicant names @replicant_names";
 ## Silence warning about not supporting the is_replicating method if using the
 ## sqlite dbs.
 $replicated->schema->storage->debugobj->silence(1)
-  if first { $_ =~ /$var_dir/ } @replicant_names;
+  if grep { $_ =~ $var_dir_re } @replicant_names;
 
 isa_ok $replicated->schema->storage->balancer->current_replicant
     => 'DBIx::Class::Storage::DBI';
@@ -426,7 +422,7 @@ $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
 ## Silence warning about not supporting the is_replicating method if using the
 ## sqlite dbs.
 $replicated->schema->storage->debugobj->silence(1)
-  if first { $_ =~ /$var_dir/ } @replicant_names;
+  if grep { $_ =~ $var_dir_re } @replicant_names;
 
 $replicated->schema->storage->pool->validate_replicants;
 
@@ -609,7 +605,7 @@ $replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
 ## Silence warning about not supporting the is_replicating method if using the
 ## sqlite dbs.
 $replicated->schema->storage->debugobj->silence(1)
-  if first { $_ =~ /$var_dir/ } @replicant_names;
+  if grep { $_ =~ $var_dir_re } @replicant_names;
 
 $replicated->schema->storage->pool->validate_replicants;
 
@@ -914,7 +910,6 @@ is $debug{storage_type}, 'REPLICANT', "got last query from a replicant: $debug{d
 }
 
 ## Delete the old database files
-$_->disconnect for values %{ $replicated->schema->storage->replicants };
 $replicated->cleanup;
 
 done_testing;