Skip to content

Commit e48c060

Browse files
committed
Added options -c and -C for explicit control over output color
1 parent a0276ee commit e48c060

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

bin/phpt-tests-runner

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
);
331336
line("<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+
}
333343
if (!$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:

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
PHPT Tests runner
55
66
Usage:
7-
phpt-tests-runner [-h] [-b binary] [files] [directories]
7+
phpt-tests-runner [-h] [-c] [-C] [-b binary] [files] [directories]
88
99
Arguments:
1010
-h Print this help message
1111
-b Specify custom PHP binary to be used (current is used by default)
12+
-c Force colored output
13+
-C Force no colored output
1214
1315
Examples:
1416
Execute tests from tests directory:

0 commit comments

Comments
 (0)