[Jifty-commit] r1899 - jifty/trunk/lib/Jifty jifty/trunk/t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Wed Aug 30 20:14:33 EDT 2006


Author: schwern
Date: Wed Aug 30 20:14:32 2006
New Revision: 1899

Added:
   jifty/trunk/t/04-test_file.t   (contents, props changed)
Modified:
   /   (props changed)
   jifty/trunk/META.yml
   jifty/trunk/Makefile.PL
   jifty/trunk/lib/Jifty/Test.pm

Log:
 r17638 at windhund:  schwern | 2006-08-30 20:11:09 -0400
 Add Jifty::Test->test_file() to declare files created only for testing and
 which should be cleaned up.


Modified: jifty/trunk/META.yml
==============================================================================
--- jifty/trunk/META.yml	(original)
+++ jifty/trunk/META.yml	Wed Aug 30 20:14:32 2006
@@ -13,6 +13,21 @@
   package: 
     - DB
     - inc
+recommends: 
+  Class::Accessor::Named: 0
+  DBD::SQLite: 0
+  Devel::Cover: 0
+  Module::CoreList: 0
+  Module::Install::Admin: 0.50
+  Module::Refresh: 0.09
+  PAR::Dist::FromCPAN: 0
+  Test::Base: 0.44
+  Test::HTML::Lint: 0
+  Test::HTTP::Server::Simple: 0.02
+  Test::More: 0.62
+  Test::Pod::Coverage: 0
+  Test::WWW::Mechanize: 1.04
+  WWW::Mechanize: 1.12
 requires: 
   App::CLI: 0.03
   CGI::Cookie::Splitter: 0
@@ -20,13 +35,11 @@
   Cache::Cache: 0
   Calendar::Simple: 0
   Class::Accessor: 0
-  Class::Accessor::Named: 0
   Class::Container: 0
   Class::Data::Inheritable: 0
   Compress::Zlib: 0
   Crypt::CBC: 0
   Crypt::Rijndael: 0
-  DBD::SQLite: 1.11
   Data::Page: 0
   Date::Manip: 0
   DateTime: 0
@@ -59,27 +72,17 @@
   Locale::Maketext::Lexicon: 0.60
   Log::Log4perl: 0
   MIME::Types: 0
-  Module::CoreList: 0
-  Module::Install::Admin: 0.50
   Module::Pluggable: 2.95
-  Module::Refresh: 0.09
   Module::ScanDeps: 0
   Object::Declare: 0.13
-  PAR::Dist::FromCPAN: 0
   Params::Validate: 0
   PerlIO::gzip: 0
   Pod::Simple: 0
   Scalar::Defer: 0.06
+  Shell::Command: 0
   String::Koremutake: 0
-  Test::Base: 0.44
-  Test::HTML::Lint: 0
-  Test::HTTP::Server::Simple: 0.02
-  Test::More: 0.62
-  Test::Pod::Coverage: 0
-  Test::WWW::Mechanize: 1.04
   UNIVERSAL::require: 0
   URI: 0
-  WWW::Mechanize: 1.12
   XML::Simple: 0
   XML::Writer: 0
   XML::XPath: 0

Modified: jifty/trunk/Makefile.PL
==============================================================================
--- jifty/trunk/Makefile.PL	(original)
+++ jifty/trunk/Makefile.PL	Wed Aug 30 20:14:32 2006
@@ -51,6 +51,7 @@
 requires('Params::Validate');
 requires('PerlIO::gzip');
 requires('Scalar::Defer' => '0.06');
+requires('Shell::Command');
 requires('String::Koremutake');
 requires('UNIVERSAL::require');
 requires('URI');

Modified: jifty/trunk/lib/Jifty/Test.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Test.pm	(original)
+++ jifty/trunk/lib/Jifty/Test.pm	Wed Aug 30 20:14:32 2006
@@ -113,7 +113,7 @@
     Jifty::YAML::DumpFile($test_config, $class->test_config(Jifty::Config->new));
     # Invoking bin/jifty and friends will now have the test config ready.
     $ENV{'JIFTY_TEST_CONFIG'} ||= $test_config;
-    Jifty::Test->builder->{test_config} = $test_config;
+    $class->builder->{test_config} = $test_config;
     {
         # Cache::Memcached stores things. And doesn't let them expire
         # from the cache easily. This is fine in production, but
@@ -296,6 +296,31 @@
 }
 
 
+=head2 test_file
+
+  my @files = Jifty::Test->test_file(@files);
+
+Register @files as having been created by the test.  They will be
+cleaned up at the end of the test run I<if and only if> the test
+passes.  Otherwise they will be left alone.
+
+It returns @files so you can do this:
+
+  my @files = Jifty::Test->test_file( Jifty::Util->absolute_path("t/foo") );
+
+=cut
+
+my @Test_Files_To_Cleanup;
+sub test_file {
+    my $class = shift;
+    my @files = @_;
+
+    push @Test_Files_To_Cleanup, @files;
+
+    return @files;
+}
+
+
 =head2 test_in_isolation
 
   my $return = Jifty::Test->test_in_isolation( sub {
@@ -342,7 +367,10 @@
 }
 
 
-END {
+# Stick the END block in a method so we can test it.
+END { Jifty::Test->_ending }
+
+sub _ending {
     my $Test = Jifty::Test->builder;
     # Such a hack -- try to detect if this is a forked copy and don't
     # do cleanup in that case.
@@ -362,6 +390,9 @@
             $schema->run;
             Log::Log4perl->get_logger("SchemaTool")->more_logging(3);
         }
+
+        # Unlink test files
+        unlink @Test_Files_To_Cleanup;
     }
 
     # Unlink test file

Added: jifty/trunk/t/04-test_file.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/04-test_file.t	Wed Aug 30 20:14:32 2006
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Shell::Command;
+
+use Jifty::Test 'no_plan';
+
+{
+    my $tmpfile = "t/foo";
+    is_deeply( [Jifty::Test->test_file( $tmpfile )], [$tmpfile] );
+    touch( $tmpfile );
+
+    is_deeply( [Jifty::Test->test_file( $tmpfile )], [$tmpfile] );
+    touch( $tmpfile );
+
+    ok -e $tmpfile;
+    Jifty::Test->_ending;
+    ok !-e $tmpfile;
+}
+
+{
+    my $tmpfile = "t/bar";
+    Jifty::Test->test_in_isolation( sub {
+        fail();
+        touch $tmpfile;
+        Jifty::Test->_ending;
+    });
+
+    ok -e $tmpfile;
+}


More information about the Jifty-commit mailing list