[xdebug-dev] svn: /xdebug/ branches/xdebug_2_1/tests/bug00665.phpt branches/xdebug_2_1/xdebug_stack.c trunk/tests/bug00665.phpt trunk/xdebug_stack.c

From: Derick Rethans <derick[@]derickrethans.nl>
Date: Mon, 21 Feb 2011 22:13:24 +0000

derick Mon, 21 Feb 2011 22:13:24 +0000

Revision: http://svn.xdebug.org/cgi-bin/viewvc.cgi?view=rev&revision=3402&root=xdebug

Log:
- Fixed bug #665: xdebug does not respect display_errors=stderr.
  Patch by Ben Spencer <dangerous.ben[@]gmail.com>

Changed paths:
    A xdebug/branches/xdebug_2_1/tests/bug00665.phpt
    U xdebug/branches/xdebug_2_1/xdebug_stack.c
    A xdebug/trunk/tests/bug00665.phpt
    U xdebug/trunk/xdebug_stack.c

Added: xdebug/branches/xdebug_2_1/tests/bug00665.phpt
===================================================================
--- xdebug/branches/xdebug_2_1/tests/bug00665.phpt (rev 0)
+++ xdebug/branches/xdebug_2_1/tests/bug00665.phpt 2011-02-21 22:13:24 UTC (rev 3402)
@@ -0,0 +1,49 @@
+--TEST--
+Test for bug #665: xdebug does not respect display_errors=stderr
+--SKIPIF--
+<?php if (!extension_loaded("xdebug")) die("skip xdebug required"); ?>
+<?php if (version_compare(phpversion(), "5.2.4", '<')) die("skip display_errors=stderr only supported since PHP 5.2.4"); ?>
+--FILE--
+<?php
+$php = getenv('TEST_PHP_EXECUTABLE') . ' -d log_errors=Off -d xdebug.default_enable=On';
+
+$error = '-r ' . escapeshellarg('trigger_error("PASS");');
+$exception = '-r ' . escapeshellarg('throw new Exception("PASS");');
+
+$errors_stdout = '-d display_errors=On';
+$errors_stderr = '-d display_errors=stderr';
+$errors_nowhere = '-d display_errors=Off';
+
+$null = substr(PHP_OS, 0, 3) == 'WIN' ? 'NUL' : '/dev/null';
+$output_stdout = "2>$null";
+$output_stderr = "2>&1 >$null";
+
+if (`$php $error $errors_stdout $output_stdout`) echo "PASS1\n";
+if (!`$php $error $errors_stderr $output_stdout`) echo "PASS2\n";
+if (!`$php $error $errors_nowhere $output_stdout`) echo "PASS3\n";
+
+if (!`$php $error $errors_stdout $output_stderr`) echo "PASS4\n";
+if (`$php $error $errors_stderr $output_stderr`) echo "PASS5\n";
+if (!`$php $error $errors_nowhere $output_stderr`) echo "PASS6\n";
+
+if (`$php $exception $errors_stdout $output_stdout`) echo "PASS7\n";
+if (!`$php $exception $errors_stderr $output_stdout`) echo "PASS8\n";
+if (!`$php $exception $errors_nowhere $output_stdout`) echo "PASS9\n";
+
+if (!`$php $exception $errors_stdout $output_stderr`) echo "PASS10\n";
+if (`$php $exception $errors_stderr $output_stderr`) echo "PASS11\n";
+if (!`$php $exception $errors_nowhere $output_stderr`) echo "PASS12\n";
+?>
+--EXPECT--
+PASS1
+PASS2
+PASS3
+PASS4
+PASS5
+PASS6
+PASS7
+PASS8
+PASS9
+PASS10
+PASS11
+PASS12

Modified: xdebug/branches/xdebug_2_1/xdebug_stack.c
===================================================================
--- xdebug/branches/xdebug_2_1/xdebug_stack.c 2011-02-21 22:13:23 UTC (rev 3401)
+++ xdebug/branches/xdebug_2_1/xdebug_stack.c 2011-02-21 22:13:24 UTC (rev 3402)
@@ -440,6 +440,17 @@
         }
 }

+static void php_output_error(const char *error)
+{
+#ifdef PHP_DISPLAY_ERRORS_STDERR
+ if (PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR) {
+ fputs(error, stderr);
+ fflush(stderr);
+ return;
+ }
+#endif
+ php_printf("%s", error);
+}

 /* Error callback for formatting stack traces */
 void xdebug_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
@@ -540,13 +551,13 @@
                                 xdebug_append_printable_stack(&str, PG(html_errors) TSRMLS_CC);
                                 xdebug_str_add(&str, XG(last_exception_trace), 0);
                                 xdebug_append_error_footer(&str, PG(html_errors));
- php_printf("%s", str.d);
+ php_output_error(str.d);

                                 xdfree(str.d);
                                 free(tmp_buf);
                         } else {
                                 printable_stack = get_printable_stack(PG(html_errors), error_type_str, buffer, error_filename, error_lineno TSRMLS_CC);
- php_printf("%s", printable_stack);
+ php_output_error(printable_stack);
                                 xdfree(printable_stack);
                         }
                 }

Added: xdebug/trunk/tests/bug00665.phpt
===================================================================
--- xdebug/trunk/tests/bug00665.phpt (rev 0)
+++ xdebug/trunk/tests/bug00665.phpt 2011-02-21 22:13:24 UTC (rev 3402)
@@ -0,0 +1,49 @@
+--TEST--
+Test for bug #665: xdebug does not respect display_errors=stderr
+--SKIPIF--
+<?php if (!extension_loaded("xdebug")) die("skip xdebug required"); ?>
+<?php if (version_compare(phpversion(), "5.2.4", '<')) die("skip display_errors=stderr only supported since PHP 5.2.4"); ?>
+--FILE--
+<?php
+$php = getenv('TEST_PHP_EXECUTABLE') . ' -d log_errors=Off -d xdebug.default_enable=On';
+
+$error = '-r ' . escapeshellarg('trigger_error("PASS");');
+$exception = '-r ' . escapeshellarg('throw new Exception("PASS");');
+
+$errors_stdout = '-d display_errors=On';
+$errors_stderr = '-d display_errors=stderr';
+$errors_nowhere = '-d display_errors=Off';
+
+$null = substr(PHP_OS, 0, 3) == 'WIN' ? 'NUL' : '/dev/null';
+$output_stdout = "2>$null";
+$output_stderr = "2>&1 >$null";
+
+if (`$php $error $errors_stdout $output_stdout`) echo "PASS1\n";
+if (!`$php $error $errors_stderr $output_stdout`) echo "PASS2\n";
+if (!`$php $error $errors_nowhere $output_stdout`) echo "PASS3\n";
+
+if (!`$php $error $errors_stdout $output_stderr`) echo "PASS4\n";
+if (`$php $error $errors_stderr $output_stderr`) echo "PASS5\n";
+if (!`$php $error $errors_nowhere $output_stderr`) echo "PASS6\n";
+
+if (`$php $exception $errors_stdout $output_stdout`) echo "PASS7\n";
+if (!`$php $exception $errors_stderr $output_stdout`) echo "PASS8\n";
+if (!`$php $exception $errors_nowhere $output_stdout`) echo "PASS9\n";
+
+if (!`$php $exception $errors_stdout $output_stderr`) echo "PASS10\n";
+if (`$php $exception $errors_stderr $output_stderr`) echo "PASS11\n";
+if (!`$php $exception $errors_nowhere $output_stderr`) echo "PASS12\n";
+?>
+--EXPECT--
+PASS1
+PASS2
+PASS3
+PASS4
+PASS5
+PASS6
+PASS7
+PASS8
+PASS9
+PASS10
+PASS11
+PASS12

Modified: xdebug/trunk/xdebug_stack.c
===================================================================
--- xdebug/trunk/xdebug_stack.c 2011-02-21 22:13:23 UTC (rev 3401)
+++ xdebug/trunk/xdebug_stack.c 2011-02-21 22:13:24 UTC (rev 3402)
@@ -480,6 +480,17 @@
         }
 }

+static void php_output_error(const char *error)
+{
+#ifdef PHP_DISPLAY_ERRORS_STDERR
+ if (PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR) {
+ fputs(error, stderr);
+ fflush(stderr);
+ return;
+ }
+#endif
+ php_printf("%s", error);
+}

 /* Error callback for formatting stack traces */
 void xdebug_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
@@ -580,13 +591,13 @@
                                 xdebug_append_printable_stack(&str, PG(html_errors) TSRMLS_CC);
                                 xdebug_str_add(&str, XG(last_exception_trace), 0);
                                 xdebug_append_error_footer(&str, PG(html_errors) TSRMLS_CC);
- php_printf("%s", str.d);
+ php_output_error(str.d);

                                 xdfree(str.d);
                                 free(tmp_buf);
                         } else {
                                 printable_stack = get_printable_stack(PG(html_errors), error_type_str, buffer, error_filename, error_lineno TSRMLS_CC);
- php_printf("%s", printable_stack);
+ php_output_error(printable_stack);
                                 xdfree(printable_stack);
                         }
                 }
Received on Mon Feb 21 2011 - 22:13:24 GMT

This archive was generated by hypermail 2.2.0 : Sun Jun 24 2018 - 04:00:03 BST