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 ge...@apache.org on 2005/05/31 22:17:44 UTC

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

Author: geoff
Date: Tue May 31 13:17:43 2005
New Revision: 179269

URL: http://svn.apache.org/viewcvs?rev=179269&view=rev
Log:
provide $Apache::TestUtil::DEBUG_OUTPUT as target for t_debug()
statements, defaulting to STDOUT.  this allows for changing
t_debug() to STDERR when using functions like t_write_file()
from within handler() server-side tests


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

Modified: perl/Apache-Test/trunk/Changes
URL: http://svn.apache.org/viewcvs/perl/Apache-Test/trunk/Changes?rev=179269&r1=179268&r2=179269&view=diff
==============================================================================
--- perl/Apache-Test/trunk/Changes (original)
+++ perl/Apache-Test/trunk/Changes Tue May 31 13:17:43 2005
@@ -8,6 +8,11 @@
 
 =item 1.25-dev
 
+provide $Apache::TestUtil::DEBUG_OUTPUT as target for t_debug()
+statements, defaulting to STDOUT.  this allows for changing
+t_debug() to STDERR when using functions like t_write_file()
+from within handler() server-side tests.  [Geoffrey Young]
+
 adjust need_module()/have_module() to not try to require a module if
 it was explicitly passed with a .c extension. in certain cases this
 prevents a fatal error (e.g. trying to call

Modified: perl/Apache-Test/trunk/lib/Apache/TestUtil.pm
URL: http://svn.apache.org/viewcvs/perl/Apache-Test/trunk/lib/Apache/TestUtil.pm?rev=179269&r1=179268&r2=179269&view=diff
==============================================================================
--- perl/Apache-Test/trunk/lib/Apache/TestUtil.pm (original)
+++ perl/Apache-Test/trunk/lib/Apache/TestUtil.pm Tue May 31 13:17:43 2005
@@ -45,6 +45,8 @@
 
 %CLEAN = ();
 
+$Apache::TestUtil::DEBUG_OUTPUT = \*STDOUT;
+
 # 5.005's Data::Dumper has problems to dump certain datastructures
 use constant HAS_DUMPER => eval { $] >= 5.6 && require Data::Dumper; };
 use constant INDENT     => 4;
@@ -145,7 +147,8 @@
     sub { @_ };
 
 sub t_debug {
-    print map {"# $_\n"} map {split /\n/} grep {defined} expand(@_);
+    my $out = $Apache::TestUtil::DEBUG_OUTPUT;
+    print $out map {"# $_\n"} map {split /\n/} grep {defined} expand(@_);
 }
 
 sub t_open_file {
@@ -497,6 +500,26 @@
 for debug prints, since if in the future the debug printing will
 change (e.g. redirected into a file) your tests won't need to be
 changed.
+
+the special global variable $Apache::TestUtil::DEBUG_OUTPUT can
+be used to redirect the output from t_debug() and related calls
+such as t_write_file().  for example, from a server-side test
+you would probably need to redirect it to STDERR:
+
+  sub handler {
+    plan $r, tests => 1;
+
+    local $Apache::TestUtil::DEBUG_OUTPUT = \*STDERR;
+
+    t_write_file('/tmp/foo', 'bar');
+    ...
+  }
+
+left to its own devices, t_debug() will collide with the standard
+HTTP protocol during server-side tests, resulting in a situation
+both confusing difficult to debug.  but STDOUT is left as the
+default, since you probably don't want debug output under normal
+circumstances unless running under verbose mode.
 
 This function is exported by default.