(perl #127380) default PERLIO_DEBUG/-Di to use STDERR
authorTony Cook <[email protected]>
Thu, 7 Apr 2016 05:35:42 +0000 (15:35 +1000)
committerTony Cook <[email protected]>
Wed, 8 Jun 2016 03:48:46 +0000 (13:48 +1000)
This includes under taint, just as other -D switches write to stderr
when taint is on.

perlio.c
t/run/switchDx.t

index 20c2fa3..27710e3 100644 (file)
--- a/perlio.c
+++ b/perlio.c
@@ -364,11 +364,11 @@ PerlIO_debug(const char *fmt, ...)
                PL_perlio_debug_fd
                    = PerlLIO_open3(s, O_WRONLY | O_CREAT | O_APPEND, 0666);
            else
-               PL_perlio_debug_fd = -1;
+               PL_perlio_debug_fd = PerlLIO_dup(2); /* stderr */
        } else {
-           /* tainting or set*id, so ignore the environment, and ensure we
-              skip these tests next time through.  */
-           PL_perlio_debug_fd = -1;
+           /* tainting or set*id, so ignore the environment and send the
+               debug output to stderr, like other -D switches.  */
+           PL_perlio_debug_fd = PerlLIO_dup(2); /* stderr */
        }
     }
     if (PL_perlio_debug_fd > 0) {
index d9d8a4c..acb2995 100644 (file)
@@ -14,7 +14,7 @@ skip_all "DEBUGGING build required"
   unless $::Config{ccflags} =~ /DEBUGGING/
          or $^O eq 'VMS' && $::Config{usedebugging_perl} eq 'Y';
 
-plan tests => 6;
+plan tests => 8;
 
 END {
     unlink $perlio_log;
@@ -32,8 +32,19 @@ END {
     ok(-e $perlio_log, "... perlio debugging file found with -Di and PERLIO_DEBUG");
 
     unlink $perlio_log;
-    fresh_perl_is("print qq(hello\n)", "\nEXECUTING...\n\nhello\n",
+    fresh_perl_like("print qq(hello\n)", qr/define raw/,
                   { stderr => 1, switches => [ "-TDi" ] },
-                  "No perlio debug file with -T..");
+                  "Perlio debug output to stderr with -TDi (with PERLIO_DEBUG)...");
     ok(!-e $perlio_log, "...no perlio debugging file found");
 }
+
+{
+    local $ENV{PERLIO_DEBUG};
+    fresh_perl_like("print qq(hello)", qr/define raw/,
+                    { stderr => 1, switches => [ '-Di' ] },
+                   "-Di defaults to stderr");
+    fresh_perl_like("print qq(hello)", qr/define raw/,
+                    { stderr => 1, switches => [ '-TDi' ] },
+                   "Perlio debug output to STDERR with -TDi (no PERLIO_DEBUG)");
+}
+