You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-commits@perl.apache.org by ph...@apache.org on 2007/11/16 00:45:45 UTC

svn commit: r595491 - in /perl/Apache-Test/trunk: Changes lib/Apache/TestConfigPerl.pm lib/Apache/TestUtil.pm

Author: phred
Date: Thu Nov 15 15:45:44 2007
New Revision: 595491

URL: http://svn.apache.org/viewvc?rev=595491&view=rev
Log:
Add t_write_test_lib method to be used for volatile test packages.

Modified:
    perl/Apache-Test/trunk/Changes
    perl/Apache-Test/trunk/lib/Apache/TestConfigPerl.pm
    perl/Apache-Test/trunk/lib/Apache/TestUtil.pm

Modified: perl/Apache-Test/trunk/Changes
URL: http://svn.apache.org/viewvc/perl/Apache-Test/trunk/Changes?rev=595491&r1=595490&r2=595491&view=diff
==============================================================================
--- perl/Apache-Test/trunk/Changes (original)
+++ perl/Apache-Test/trunk/Changes Thu Nov 15 15:45:44 2007
@@ -8,6 +8,9 @@
 
 =item 1.30-dev
 
+Added t_write_test_lib for temporary testing packages
+[Fred Moyer <fr...@redhotpenguin.com>]
+
 Fix syntax error in generated PHP files t/conf/*.php.in
 [Philippe M. Chiasson]
 

Modified: perl/Apache-Test/trunk/lib/Apache/TestConfigPerl.pm
URL: http://svn.apache.org/viewvc/perl/Apache-Test/trunk/lib/Apache/TestConfigPerl.pm?rev=595491&r1=595490&r2=595491&view=diff
==============================================================================
--- perl/Apache-Test/trunk/lib/Apache/TestConfigPerl.pm (original)
+++ perl/Apache-Test/trunk/lib/Apache/TestConfigPerl.pm Thu Nov 15 15:45:44 2007
@@ -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}) {

Modified: perl/Apache-Test/trunk/lib/Apache/TestUtil.pm
URL: http://svn.apache.org/viewvc/perl/Apache-Test/trunk/lib/Apache/TestUtil.pm?rev=595491&r1=595490&r2=595491&view=diff
==============================================================================
--- perl/Apache-Test/trunk/lib/Apache/TestUtil.pm (original)
+++ perl/Apache-Test/trunk/lib/Apache/TestUtil.pm Thu Nov 15 15:45:44 2007
@@ -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,18 @@
     return $fh;
 }
 
+sub _temp_package_dir {
+    return catdir(tmpdir(), 'apache_test');
+}
+
+sub t_write_test_lib {
+    my $file = shift;
+
+    die "must pass a filename" unless defined $file;
+
+    t_write_file(catdir(_temp_package_dir(), $file), @_);
+}
+
 sub t_write_file {
     my $file = shift;
 
@@ -546,6 +558,17 @@
 circumstances unless running under verbose mode.
 
 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()