Pest: --colors=never is not respected

Created on 30 May 2020  Â·  6Comments  Â·  Source: pestphp/pest

When I run

vendor/bin/pest --colors=never

Pest continues printing ascii chars that produces the following text:

   FAIL  PestExample\Test\PhpUnitSourceFileTest
  • it can add two integers

  ---

  • PestExample\Test\PhpUnitSourceFileTest > it can add two integers
   Error 

  Call to protected method PestExample\SourceFile::add() from context 'PestExample\Test\PhpUnitSourceFileTest'

  at tests/PhpUnitSourceFileTest.php:18
     14â–•     public function test_it_can_add_two_integers(): void
     15â–•     {
     16â–•         $source = new SourceFile();
     17â–• 
  ➜  18▕         $result = $source->add(3, 2);
     19â–• 
     20â–•         $this->assertGreaterThan(0, $result);
     21â–•     }
     22â–• }



  Tests:  1 failed
  Time:   0.03s

For example, when I use --colors=never with PHPUnit, it correctly disables and prints just raw text:

PHPUnit 9.1.5 by Sebastian Bergmann and contributors.

.                                                                   1 / 1 (100%)

Time: 00:00.046, Memory: 6.00 MB

Related to #4 (In Infection PHP, we need a "raw" output without all those colours for terminal to parse the text);

Even without Infection, it's still the issue as some CI do not support such output as well

Most helpful comment

To launch Pest with default phpunit printer, I usually do :

vendor/bin/pest --printer \\PHPUnit\\TextUI\\DefaultResultPrinter

Just try with --colors=never, work as expected :wink:

Anyway, to support in in pest, this could be done:

// src/Actions/AddsDefaults.php
        if (!array_key_exists('printer', $arguments)) {
-            $arguments['printer'] = new Printer();
+            $arguments['printer'] = new Printer(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? 'always');
        }

All 6 comments

@maks-rafalko Maybe is better just change the printer to the default phpunit printer. what do you think?

  1. is it possible right now? can't find anything related
  2. if it's possibl (or will be) - will I be able to use --colors=never with default PHPUnit printer?
  3. I still think colors=never should be supported by Pest. Why? For example, if Pest is used for Jenkins, there is no support for ascii codes (from what I see in my daily job :) ). So I see [37;41;1m FAIL insteaf of pretty raw FAIL

To launch Pest with default phpunit printer, I usually do :

vendor/bin/pest --printer \\PHPUnit\\TextUI\\DefaultResultPrinter

Just try with --colors=never, work as expected :wink:

Anyway, to support in in pest, this could be done:

// src/Actions/AddsDefaults.php
        if (!array_key_exists('printer', $arguments)) {
-            $arguments['printer'] = new Printer();
+            $arguments['printer'] = new Printer(null, $arguments['verbose'] ?? false, $arguments['colors'] ?? 'always');
        }

Thank you!

Hi, I'm facing a problem when using pest on Windows.

When I run pest --colors=never, the output is not quite right.

pest
image

pest --colors=never
image

Just to make it clear, if I run from a terminal that supports colors, it will print the colors correctly, the issue here is the fact that --colors=never still sends colors information.

@crossworth, I think this is actually an issue with Collision rather than Pest.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gulien picture gulien  Â·  3Comments

khalyomede picture khalyomede  Â·  7Comments

reed-jones picture reed-jones  Â·  6Comments

rihardssceredins picture rihardssceredins  Â·  5Comments

nunomaduro picture nunomaduro  Â·  5Comments