Geoffrey Young wrote:

Philippe M. Chiasson wrote:
How do you make sure that tmp directory gets cleaned up at the end of the
test run ?

he's using t_write_file() under the hood, which keeps track of
directories it creates and cleans them up afterward.

Updated patch attached with dies instead of warns if Apache::TestUtil can't be loaded.
Index: lib/Apache/TestConfigPerl.pm
===================================================================
--- lib/Apache/TestConfigPerl.pm        (revision 594783)
+++ lib/Apache/TestConfigPerl.pm        (working copy)
@@ -206,6 +206,17 @@
             print $fh "use lib '$tlib';\n";
         }
 
+        # directory for temp packages which can change during testing
+        # we use require here since a circular dependency exists
+        # between Apache::TestUtil and Apache::TestConfigPerl, so
+        # use does not work here
+        eval { require Apache::TestUtil; };
+        if ($@) {
+            die "could not require Apache::TestUtil: $@";
+        } else {
+            print $fh "use lib '" . Apache::TestUtil::_temp_package_dir() . 
"';\n";
+        }
+
         # if Apache::Test is used to develop a project, we want the
         # project/lib directory to be first in @INC (loaded last)
         if ($ENV{APACHE_TEST_LIVE_DEV}) {
Index: lib/Apache/TestUtil.pm
===================================================================
--- lib/Apache/TestUtil.pm      (revision 594783)
+++ lib/Apache/TestUtil.pm      (working copy)
@@ -24,7 +24,7 @@
 use Carp ();
 use Config;
 use File::Basename qw(dirname);
-use File::Spec::Functions qw(catfile file_name_is_absolute);
+use File::Spec::Functions qw(catfile catdir file_name_is_absolute tmpdir);
 use Symbol ();
 use Fcntl qw(SEEK_END);
 
@@ -37,7 +37,7 @@
 @ISA     = qw(Exporter);
 
 @EXPORT = qw(t_cmp t_debug t_append_file t_write_file t_open_file
-    t_mkdir t_rmtree t_is_equal t_filepath_cmp
+    t_mkdir t_rmtree t_is_equal t_filepath_cmp t_write_test_lib
     t_server_log_error_is_expected t_server_log_warn_is_expected
     t_client_log_error_is_expected t_client_log_warn_is_expected
 );
@@ -191,6 +191,14 @@
     return $fh;
 }
 
+sub _temp_package_dir {
+    return catdir(tmpdir(), 'apache_test');
+}
+
+sub t_write_test_lib {
+    return t_write_file(catdir(_temp_package_dir(), shift), @_);
+}
+
 sub t_write_file {
     my $file = shift;
 
@@ -547,6 +555,17 @@
 
 This function is exported by default.
 
+=item t_write_test_lib()
+
+  t_write_test_lib($filename, @lines)
+
+t_write_test_lib() creates a new file at I<$filename> or overwrites
+the existing file with the content passed in I<@lines>.  The file
+is created in a temporary directory which is added to @INC at
+test configuration time.  It is intended to be used for creating
+temporary packages for testing which can be modified at run time,
+see the Apache::Reload unit tests for an example.
+
 =item t_write_file()
 
   t_write_file($filename, @lines);
Index: Changes
===================================================================
--- Changes     (revision 594783)
+++ Changes     (working copy)
@@ -8,6 +8,9 @@
 
 =item 1.30-dev
 
+Added t_write_test_lib for temporary testing packages
+[Fred Moyer <[EMAIL PROTECTED]>]
+
 Fix syntax error in generated PHP files t/conf/*.php.in
 [Philippe M. Chiasson]
 

Reply via email to