@@ -40,10 +40,15 @@ function colorize ($text) {
4040 * Based on code of Fabien Potencier:
4141 * \Symfony\Component\Console\Output\StreamOutput::hasColorSupport()
4242 *
43+ * @param bool|null $set_to
44+ *
4345 * @return bool true if ANSI escape sequences are supported.
4446 */
45- function has_color_support () {
47+ function has_color_support ($ set_to = null ) {
4648 static $ result ;
49+ if ($ set_to !== null ) {
50+ $ result = $ set_to ;
51+ }
4752 if ($ result !== null ) {
4853 return $ result ;
4954 }
@@ -321,7 +326,7 @@ function find_tests ($target) {
321326 return file_exists ($ target ) ? [$ target ] : [];
322327}
323328
324- $ options = getopt ('hb: ' , []);
329+ $ options = getopt ('hb:cC ' , []);
325330$ targets = array_filter (
326331 array_slice ($ argv , 1 ),
327332 function ($ path ) {
@@ -330,15 +335,22 @@ $targets = array_filter(
330335);
331336line ("<g>PHPT Tests runner</g> \n" );
332337
338+ if (isset ($ options ['c ' ])) {
339+ has_color_support (true );
340+ } elseif (isset ($ options ['C ' ])) {
341+ has_color_support (false );
342+ }
333343if (!$ targets || isset ($ options ['h ' ])) {
334344 line (
335345 <<<HTML
336346<y>Usage:</y>
337- phpt-tests-runner [-h] [-b binary] [files] [directories]
347+ phpt-tests-runner [-h] [-c] [-C] [- b binary] [files] [directories]
338348
339349<y>Arguments:</y>
340350 <g>-h</g> Print this help message
341351 <g>-b</g> Specify custom PHP binary to be used (current is used by default)
352+ <g>-c</g> Force colored output
353+ <g>-C</g> Force no colored output
342354
343355<y>Examples:</y>
344356 Execute tests from tests directory:
0 commit comments