[Rt-commit] rt branch, 4.2/shredder-only-sqlite, created. rt-4.2.10-101-gc79ca54

Alex Vandiver alexmv at bestpractical.com
Wed Mar 4 17:09:00 EST 2015


The branch, 4.2/shredder-only-sqlite has been created
        at  c79ca54a530f0b5aac3f1d3754982825f408e6a0 (commit)

- Log -----------------------------------------------------------------
commit 3cd272041308a788178630c08e920015f713a01a
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Apr 18 13:42:14 2014 -0400

    Skip Shredder tests on all non-SQLite databases
    
    Shredder tests currently hardcode themselves to run against a SQLite
    database.  Until such time as the comparison functions work correctly on
    other databases, stop pretending that the tests are running on them.

diff --git a/lib/RT/Test/Shredder.pm b/lib/RT/Test/Shredder.pm
index 20851a0..630897b 100644
--- a/lib/RT/Test/Shredder.pm
+++ b/lib/RT/Test/Shredder.pm
@@ -106,7 +106,15 @@ Savepoints are named and you can create two or more savepoints.
 
 sub import {
     my $class = shift;
-    $class->SUPER::import(@_);
+
+    $class->SUPER::import(@_, tests => undef );
+
+    RT::Test::plan( skip_all => 'Shredder tests only work on SQLite' )
+          unless RT->Config->Get('DatabaseType') eq 'SQLite';
+
+    my %args = @_;
+    RT::Test::plan( tests => $args{'tests'} ) if $args{tests};
+
     $class->export_to_level(1);
 }
 

commit 7d1cb10064c571fe8a5f8860ff75d7fe54c26d1e
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Apr 18 13:44:51 2014 -0400

    bootstrap_more_config is now unnecessary, as tests only actually run on sqlite
    
    An adjustment to db_name is necessary, to point to where RT's standard
    testing framework writes the SQLite database during testing.  This
    exposes that the test suite writes the database to the installed
    $VarPath, rather than the temporary testing directory.

diff --git a/lib/RT/Test/Shredder.pm b/lib/RT/Test/Shredder.pm
index 630897b..ad3c55a 100644
--- a/lib/RT/Test/Shredder.pm
+++ b/lib/RT/Test/Shredder.pm
@@ -120,40 +120,16 @@ sub import {
 
 =head1 FUNCTIONS
 
-=head2 RT CONFIG
-
-=head3 rewrite_rtconfig
-
-Call this sub after C<RT::LoadConfig>. It changes the RT config
-options necessary to switch to a local SQLite database.
-
-=cut
-
-sub bootstrap_more_config {
-    my $self = shift;
-    my $config = shift;
-
-    print $config <<'END';
-Set($DatabaseType       , 'SQLite');
-Set($DatabaseHost       , 'localhost' );
-Set($DatabaseRTHost     , 'localhost' );
-Set($DatabasePort       , '' );
-END
-
-    print $config "Set(\$DatabaseName, '". $self->db_name ."');\n";
-    return;
-}
-
 =head2 DATABASES
 
 =head3 db_name
 
 Returns the absolute file path to the current DB.
-It is C<<RT::Test->temp_directory . 'main.db'>>.
+It is C<<$RT::VarPath . "rt4test" >>.
 
 =cut
 
-sub db_name { return File::Spec->catfile((shift)->temp_directory, "main.db") }
+sub db_name { return File::Spec->catfile($RT::VarPath, RT->Config->Get("DatabaseName")) }
 
 =head3 connect_sqlite
 

commit 2649bba06c680929140eb78ce4dc06cc98e3198e
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Apr 18 14:21:23 2014 -0400

    Split the Set override into WriteSet, to allow it to be called explicitly

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 14d620c..b4f5496 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -397,6 +397,56 @@ sub set_config_wrapper {
 
     my $old_sub = \&RT::Config::Set;
     no warnings 'redefine';
+
+    *RT::Config::WriteSet = sub {
+        my ($self, $name) = @_;
+        my $type = $RT::Config::META{$name}->{'Type'} || 'SCALAR';
+        my %sigils = (
+            HASH   => '%',
+            ARRAY  => '@',
+            SCALAR => '$',
+        );
+        my $sigil = $sigils{$type} || $sigils{'SCALAR'};
+        open( my $fh, '<', $tmp{'config'}{'RT'} )
+            or die "Couldn't open config file: $!";
+        my @lines;
+        while (<$fh>) {
+            if (not @lines or /^Set\(/) {
+                push @lines, $_;
+            } else {
+                $lines[-1] .= $_;
+            }
+        }
+        close $fh;
+
+        # Traim trailing newlines and "1;"
+        $lines[-1] =~ s/(^1;\n|^\n)*\Z//m;
+
+        # Remove any previous definitions of this var
+        @lines = grep {not /^Set\(\s*\Q$sigil$name\E\b/} @lines;
+
+        # Format the new value for output
+        require Data::Dumper;
+        local $Data::Dumper::Terse = 1;
+        my $dump = Data::Dumper::Dumper([@_[2 .. $#_]]);
+        $dump =~ s/;?\s+\Z//;
+        push @lines, "Set( ${sigil}${name}, \@{". $dump ."});\n";
+        push @lines, "\n1;\n";
+
+        # Re-write the configuration file
+        open( $fh, '>', $tmp{'config'}{'RT'} )
+            or die "Couldn't open config file: $!";
+        print $fh $_ for @lines;
+        close $fh;
+
+        if ( @SERVERS ) {
+            warn "you're changing config option in a test file"
+                ." when server is active";
+        }
+
+        return $old_sub->(@_);
+    };
+
     *RT::Config::Set = sub {
         # Determine if the caller is either from a test script, or
         # from helper functions called by test script to alter
@@ -406,52 +456,9 @@ sub set_config_wrapper {
         my @caller = caller(1); # preserve list context
         @caller = caller(0) unless @caller;
 
-        if ( ($caller[1]||'') =~ /\.t$/) {
-            my ($self, $name) = @_;
-            my $type = $RT::Config::META{$name}->{'Type'} || 'SCALAR';
-            my %sigils = (
-                HASH   => '%',
-                ARRAY  => '@',
-                SCALAR => '$',
-            );
-            my $sigil = $sigils{$type} || $sigils{'SCALAR'};
-            open( my $fh, '<', $tmp{'config'}{'RT'} )
-                or die "Couldn't open config file: $!";
-            my @lines;
-            while (<$fh>) {
-                if (not @lines or /^Set\(/) {
-                    push @lines, $_;
-                } else {
-                    $lines[-1] .= $_;
-                }
-            }
-            close $fh;
-
-            # Traim trailing newlines and "1;"
-            $lines[-1] =~ s/(^1;\n|^\n)*\Z//m;
-
-            # Remove any previous definitions of this var
-            @lines = grep {not /^Set\(\s*\Q$sigil$name\E\b/} @lines;
-
-            # Format the new value for output
-            require Data::Dumper;
-            local $Data::Dumper::Terse = 1;
-            my $dump = Data::Dumper::Dumper([@_[2 .. $#_]]);
-            $dump =~ s/;?\s+\Z//;
-            push @lines, "Set( ${sigil}${name}, \@{". $dump ."});\n";
-            push @lines, "\n1;\n";
-
-            # Re-write the configuration file
-            open( $fh, '>', $tmp{'config'}{'RT'} )
-                or die "Couldn't open config file: $!";
-            print $fh $_ for @lines;
-            close $fh;
-
-            if ( @SERVERS ) {
-                warn "you're changing config option in a test file"
-                    ." when server is active";
-            }
-        }
+        return RT::Config::WriteSet(@_)
+            if ($caller[1]||'') =~ /\.t$/;
+
         return $old_sub->(@_);
     };
 }

commit fd08a2f094a5726de1454a15e95ca1299de36dde
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Apr 18 14:22:26 2014 -0400

    Store the SQLite database under the temporary directory
    
    This must be done _after_ the initial RT_SiteConfig write, because the
    DatabaseType is in RT_Config.pm, and thus only known after both
    RT_Siteconfig and RT_Config have been loaded.  This necessitates moving
    set_config_wrapper to before the call to bootstrap_db, and calling
    WriteSet explicitly, as the override used in Set only catches calls to
    Set() from .t files, not from RT::Test -- and the change must be written
    out, or rt-validator will not find the database in the correct location.

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index b4f5496..ceeeb2b 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -159,6 +159,8 @@ sub import {
     RT::InitClasses();
 
     RT::I18N->Init();
+
+    $class->set_config_wrapper;
     $class->bootstrap_db( %args );
 
     __reconnect_rt()
@@ -170,8 +172,6 @@ sub import {
 
     RT->Config->PostLoadCheck;
 
-    $class->set_config_wrapper;
-
     $class->encode_output;
 
     my $screen_logger = $RT::Logger->remove( 'screen' );
@@ -494,6 +494,11 @@ sub bootstrap_db {
     }
 
     my $db_type = RT->Config->Get('DatabaseType');
+
+    if ($db_type eq "SQLite") {
+        RT->Config->WriteSet( DatabaseName => File::Spec->catfile( $self->temp_directory, "rt4test" ) );
+    }
+
     __create_database();
     __reconnect_rt('as dba');
     $RT::Handle->InsertSchema;
diff --git a/lib/RT/Test/Shredder.pm b/lib/RT/Test/Shredder.pm
index ad3c55a..e6314e7 100644
--- a/lib/RT/Test/Shredder.pm
+++ b/lib/RT/Test/Shredder.pm
@@ -125,11 +125,11 @@ sub import {
 =head3 db_name
 
 Returns the absolute file path to the current DB.
-It is C<<$RT::VarPath . "rt4test" >>.
+It is C<<RT::Test->temp_directory . "rt4test" >>.
 
 =cut
 
-sub db_name { return File::Spec->catfile($RT::VarPath, RT->Config->Get("DatabaseName")) }
+sub db_name { return RT->Config->Get("DatabaseName") }
 
 =head3 connect_sqlite
 

commit c79ca54a530f0b5aac3f1d3754982825f408e6a0
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Thu May 15 13:21:24 2014 -0400

    Split the assignment to work around a bug in perl < 5.14
    
    Assigning to a hash from a list with duplicates produced garbage results
    in list context; this was fixed in perl.git in 45960564 (in 5.14.0).
    Switch to using two separate statements to work around this bug.

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index ceeeb2b..6afb311 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -117,7 +117,8 @@ BEGIN {
 
 sub import {
     my $class = shift;
-    my %args = %rttest_opt = @_;
+    my %args = @_;
+    %rttest_opt = %args;
 
     $rttest_opt{'nodb'} = $args{'nodb'} = 1 if $^C;
 

-----------------------------------------------------------------------


More information about the rt-commit mailing list