From fd08f062ae5a3c92bfc0345da7e83ab320046864 Mon Sep 17 00:00:00 2001 From: Ivan Mikheykin Date: Fri, 17 Jan 2020 22:26:35 +0300 Subject: Fix bug #78323: Code 0 is returned on invalid options Set CLI exit code to 1 when invalid parameters are passed, and print error to stderr. --- sapi/cli/tests/015.phpt | 2 +- sapi/cli/tests/bug78323.phpt | 78 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 sapi/cli/tests/bug78323.phpt (limited to 'sapi/cli/tests') diff --git a/sapi/cli/tests/015.phpt b/sapi/cli/tests/015.phpt index 01f5328e99..5a5e6c5190 100644 --- a/sapi/cli/tests/015.phpt +++ b/sapi/cli/tests/015.phpt @@ -16,7 +16,7 @@ $php = getenv('TEST_PHP_EXECUTABLE'); echo `"$php" -n --version | grep built:`; echo `echo "&1 | grep Usage:`; echo "Done\n"; ?> diff --git a/sapi/cli/tests/bug78323.phpt b/sapi/cli/tests/bug78323.phpt new file mode 100644 index 0000000000..02b18e02a2 --- /dev/null +++ b/sapi/cli/tests/bug78323.phpt @@ -0,0 +1,78 @@ +--TEST-- +Bug #78323 Test exit code and error message for invalid parameters +--SKIPIF-- + +--FILE-- +&1", $exitCode); +$output = ob_get_contents(); +ob_end_clean(); + +$lines = preg_split('/\R/', $output); +echo $lines[0], "\n", + $lines[1], "\n", + "Done: $exitCode\n\n"; + + +// option not found +ob_start(); +passthru("$php -Z 2>&1", $exitCode); +$output = ob_get_contents(); +ob_end_clean(); + +$lines = preg_split('/\R/', $output); +echo $lines[0], "\n", + $lines[1], "\n", + "Done: $exitCode\n\n"; + + +// no argument for option +ob_start(); +passthru("$php --memory-limit=1G 2>&1", $exitCode); +$output = ob_get_contents(); +ob_end_clean(); + +$lines = preg_split('/\R/', $output); +echo $lines[0], "\n", + $lines[1], "\n", + "Done: $exitCode\n\n"; + + +// Successful execution +ob_start(); +passthru("$php -dmemory-limit=1G -v", $exitCode); +$output = ob_get_contents(); +ob_end_clean(); + +$lines = preg_split('/\R/', $output); +echo $lines[0], "\n", + "Done: $exitCode\n"; + +?> +--EXPECTF-- +Error in argument %d, char %d: : in flags +Usage: %s [options] [-f] [--] [args...] +Done: 1 + +Error in argument %d, char %d: option not found %s +Usage: %s [options] [-f] [--] [args...] +Done: 1 + +Error in argument %d, char %d: no argument for option %s +Usage: %s [options] [-f] [--] [args...] +Done: 1 + +PHP %s +Done: 0 -- cgit v1.2.1