perl-test-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fred Moyer <f...@taperfriendlymusic.org>
Subject [patch] add method for writing temporary test libraries
Date Thu, 15 Nov 2007 22:47:39 GMT
Please find attached a patch which adds t_write_test_lib, a method use 
to create temporary perl packages used in testing.  The patch adds a 
temp dir to @INC in modperl_inc.pl.

- Fred

Index: lib/Apache/TestConfigPerl.pm
===================================================================
--- lib/Apache/TestConfigPerl.pm        (revision 594783)
+++ lib/Apache/TestConfigPerl.pm        (working copy)
@@ -206,6 +206,15 @@
              print $fh "use lib '$tlib';\n";
          }

+        # directory for temp packages which can change during testing
+        # e.g. Apache::Reload
+        eval { require Apache::TestUtil; };
+        if ($@) {
+            warn("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 <fred@redhotpenguin.com>]
+
  Fix syntax error in generated PHP files t/conf/*.php.in
  [Philippe M. Chiasson]


Mime
View raw message