Turn off colors on command line #516

Closed
ghost opened this Issue Mar 2, 2012 · 25 comments

Comments

ghost commented Mar 2, 2012

Can you add --no-colors please so we can turn off colors that might have been set in the phpunit.xml.dist?

REF: Solved by installing ANSI driver with ANSICON

@sebastianbergmann

This comment has been minimized.

Show comment Hide comment
@sebastianbergmann

sebastianbergmann Mar 2, 2012

Owner

No.

Owner

sebastianbergmann commented Mar 2, 2012

No.

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Mar 2, 2012

@sebastianbergmann - would you accept a PR?

ghost commented Mar 2, 2012

@sebastianbergmann - would you accept a PR?

@sebastianbergmann

This comment has been minimized.

Show comment Hide comment
@sebastianbergmann

sebastianbergmann Mar 2, 2012

Owner

No. I want to avoid adding new arguments/options.

Owner

sebastianbergmann commented Mar 2, 2012

No. I want to avoid adding new arguments/options.

@edorian

This comment has been minimized.

Show comment Hide comment
@edorian

edorian Mar 2, 2012

Contributor

PHPUnit 3.7 will, most likel/propably, feature a --set name value switch (or something along those lines) that will allow you to do that in a more generic form.

We can't add --don't switches for every --do switch with the current parameters as it would grow out of proportions.

So your use case should be solve with 3.7 :)

I wanted to have the feature too (windows issues f.e.) myself and thats what seems to be the way to do that so everyone gets their "I don't want this to happen in that case without changing the config" case :)

Contributor

edorian commented Mar 2, 2012

PHPUnit 3.7 will, most likel/propably, feature a --set name value switch (or something along those lines) that will allow you to do that in a more generic form.

We can't add --don't switches for every --do switch with the current parameters as it would grow out of proportions.

So your use case should be solve with 3.7 :)

I wanted to have the feature too (windows issues f.e.) myself and thats what seems to be the way to do that so everyone gets their "I don't want this to happen in that case without changing the config" case :)

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Mar 2, 2012

@edorian - thanks.

ghost commented Mar 2, 2012

@edorian - thanks.

@edorian

This comment has been minimized.

Show comment Hide comment
@edorian

edorian Mar 2, 2012

Contributor

Just to restate it here:

Workaround for now is to use a phpunit.xml.dist and a local phpunit.xml file like this:

find . -print -exec cat {} \;

./phpunit.xml
<phpunit colors="false"/>
./phpunit.xml.dist
<phpunit colors="true"/>
./foo.php
<?php

class foo extends PHPUnit_Framework_TestCase {
    public function testBar() {
        $this->assertTrue(true);
    }
}

phpunit foo.php # Will not show any colors
Contributor

edorian commented Mar 2, 2012

Just to restate it here:

Workaround for now is to use a phpunit.xml.dist and a local phpunit.xml file like this:

find . -print -exec cat {} \;

./phpunit.xml
<phpunit colors="false"/>
./phpunit.xml.dist
<phpunit colors="true"/>
./foo.php
<?php

class foo extends PHPUnit_Framework_TestCase {
    public function testBar() {
        $this->assertTrue(true);
    }
}

phpunit foo.php # Will not show any colors
@andrewfenn

This comment has been minimized.

Show comment Hide comment
@andrewfenn

andrewfenn May 24, 2012

As a middle ground solution why not just change the command line option to --colors=on or --colors=off with the default being on if it doesn't have a value?

It would be backwards compatible and add the needed functionality without extending the options.

As a middle ground solution why not just change the command line option to --colors=on or --colors=off with the default being on if it doesn't have a value?

It would be backwards compatible and add the needed functionality without extending the options.

@edorian

This comment has been minimized.

Show comment Hide comment
@edorian

edorian May 26, 2012

Contributor

Good idea,

I've got to check if the way phpunit passes command line arguments really allows for a completly BC change but it should be. #429 is sheduled for phpunit 3.7 so something will be done there :)

Contributor

edorian commented May 26, 2012

Good idea,

I've got to check if the way phpunit passes command line arguments really allows for a completly BC change but it should be. #429 is sheduled for phpunit 3.7 so something will be done there :)

@Apathetic012

This comment has been minimized.

Show comment Hide comment
@Apathetic012

Apathetic012 Aug 18, 2012

what happened to the commit?

what happened to the commit?

@robsonpeixoto

This comment has been minimized.

Show comment Hide comment
@robsonpeixoto

robsonpeixoto Nov 1, 2012

maybe add --colors[=yes|=no] where 'yes' the default.

maybe add --colors[=yes|=no] where 'yes' the default.

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Dec 25, 2012

For anyone reading this ticket, please install ANSICON http://softkube.com/blog/ansi-command-line-colors-under-windows/

ghost commented Dec 25, 2012

For anyone reading this ticket, please install ANSICON http://softkube.com/blog/ansi-command-line-colors-under-windows/

@andrewfenn

This comment has been minimized.

Show comment Hide comment
@andrewfenn

andrewfenn Dec 28, 2012

I can't remember exactly what I was trying to do when I hit this issue.. I think it was redirect output to grep or something however I remember it was on linux so the ANSICON solution would not work for me or others I suspect in that situation.

I can't remember exactly what I was trying to do when I hit this issue.. I think it was redirect output to grep or something however I remember it was on linux so the ANSICON solution would not work for me or others I suspect in that situation.

@sgronblo

This comment has been minimized.

Show comment Hide comment
@sgronblo

sgronblo Mar 8, 2013

For me I have a config file that has colors=true and I wanted to disable colors when using that same config file to run tests in Jenkins.

sgronblo commented Mar 8, 2013

For me I have a config file that has colors=true and I wanted to disable colors when using that same config file to run tests in Jenkins.

@fazy

This comment has been minimized.

Show comment Hide comment
@fazy

fazy Apr 2, 2013

Pull request #563 mentioned above perhaps doesn't give enough control anyway; e.g. the (admittedly, probably uncommon) use case of piping phpunit output to less -R (for a nice, colourful less display).

I'd be happy to make a PR for --colors[=yes|=no] (or true/false) as mentioned by @robsonpeixoto above if it stands a chance of being merged. Small change, big convenience.

fazy commented Apr 2, 2013

Pull request #563 mentioned above perhaps doesn't give enough control anyway; e.g. the (admittedly, probably uncommon) use case of piping phpunit output to less -R (for a nice, colourful less display).

I'd be happy to make a PR for --colors[=yes|=no] (or true/false) as mentioned by @robsonpeixoto above if it stands a chance of being merged. Small change, big convenience.

@whatthejeff

This comment has been minimized.

Show comment Hide comment
@whatthejeff

whatthejeff Apr 3, 2013

Contributor

@fazy, I don't think @sebastianbergmann is interested in accepting a PR that adds new CLI options at the moment.

Contributor

whatthejeff commented Apr 3, 2013

@fazy, I don't think @sebastianbergmann is interested in accepting a PR that adds new CLI options at the moment.

@hkdobrev

This comment has been minimized.

Show comment Hide comment
@hkdobrev

hkdobrev Jul 23, 2013

No.

@sebastianbergmann That was rude.

Could you give some arguments for:

I want to avoid adding new arguments/options.

Often you would have colors="true" in phpunit.xml, but external tool which parses the output of PHPUnit would like to run it without colors.

No.

@sebastianbergmann That was rude.

Could you give some arguments for:

I want to avoid adding new arguments/options.

Often you would have colors="true" in phpunit.xml, but external tool which parses the output of PHPUnit would like to run it without colors.

@whatthejeff

This comment has been minimized.

Show comment Hide comment
@whatthejeff

whatthejeff Jul 30, 2013

Contributor

@hkdobrev, in the mean time, you can always strip out colors with something like:

phpunit | perl -pe 's/\e\[?.*?[\@-~]//g'

Contributor

whatthejeff commented Jul 30, 2013

@hkdobrev, in the mean time, you can always strip out colors with something like:

phpunit | perl -pe 's/\e\[?.*?[\@-~]//g'

@RickWong

This comment has been minimized.

Show comment Hide comment
@RickWong

RickWong Nov 1, 2013

Another vote for --colors[=yes|=no] which isn't adding a new cli argument. It's improving one that's already there.

🍞

RickWong commented Nov 1, 2013

Another vote for --colors[=yes|=no] which isn't adding a new cli argument. It's improving one that's already there.

🍞

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Nov 1, 2013

@RickWong the problem is @sebastianbergmann is incredibly stubborn. Despite huge support for this, and really no technical reasons against, he will not budge. So sad such a talented person is so hard headed.

ghost commented Nov 1, 2013

@RickWong the problem is @sebastianbergmann is incredibly stubborn. Despite huge support for this, and really no technical reasons against, he will not budge. So sad such a talented person is so hard headed.

@RickWong

This comment has been minimized.

Show comment Hide comment
@RickWong

RickWong Nov 1, 2013

Hmm.. Please don't write such offensive remarks about the guy who brought us PHPUnit in the first place! It's not appropriate.

Anyway, we'll just have to wait patiently for a PR to be accepted in the future. In the mean time, I'm using @whatthejeff's perl workaround.

RickWong commented Nov 1, 2013

Hmm.. Please don't write such offensive remarks about the guy who brought us PHPUnit in the first place! It's not appropriate.

Anyway, we'll just have to wait patiently for a PR to be accepted in the future. In the mean time, I'm using @whatthejeff's perl workaround.

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Nov 1, 2013

Well flame me back, but I'm not being offensive but just stating the fact that Sebastian is stubborn about this issue. I said he is very talented but hard headed, maybe you are not a native English speaker but there is zero malice there. Lots of people ask for this feature, all the time, and there are no technical reasons not to give it. It's simple.

ghost commented Nov 1, 2013

Well flame me back, but I'm not being offensive but just stating the fact that Sebastian is stubborn about this issue. I said he is very talented but hard headed, maybe you are not a native English speaker but there is zero malice there. Lots of people ask for this feature, all the time, and there are no technical reasons not to give it. It's simple.

@andrewfenn

This comment has been minimized.

Show comment Hide comment
@andrewfenn

andrewfenn Nov 1, 2013

@sebastianbergmann could you comment on what you think about my earlier solution for improving the --colors command line option.

#516 (comment)

@sebastianbergmann could you comment on what you think about my earlier solution for improving the --colors command line option.

#516 (comment)

@unfunco

This comment has been minimized.

Show comment Hide comment
@unfunco

unfunco Nov 5, 2013

👍 for @andrewfenn's suggestion. I tried this before reading the documentation only to be informed option --colors doesn't allow an argument – I wanted to turn off colours so that the output in Codeship was formatted better. My workaround was to remove colors="true" from the phpunit.xml file, and add <arg value="--colors"> to my build.xml file (since I only use Ant locally, this works fine until I decide to move to Ant on Codeship.)

unfunco commented Nov 5, 2013

👍 for @andrewfenn's suggestion. I tried this before reading the documentation only to be informed option --colors doesn't allow an argument – I wanted to turn off colours so that the output in Codeship was formatted better. My workaround was to remove colors="true" from the phpunit.xml file, and add <arg value="--colors"> to my build.xml file (since I only use Ant locally, this works fine until I decide to move to Ant on Codeship.)

@whatthejeff

This comment has been minimized.

Show comment Hide comment
@whatthejeff

whatthejeff Nov 10, 2013

Contributor

@RickWong the problem is @sebastianbergmann is incredibly stubborn. Despite huge support for this, and really no technical reasons against, he will not budge. So sad such a talented person is so hard headed.

Maybe @sebastianbergmann just disagrees with a handful of people about a relatively low-priority feature request. If that makes him hardheaded, then I guess we're all hardheaded :P

I really wouldn't mind seeing --colors[=on|=off] or something similar. But, for the time being, this probably is not going to happen. @sebastianbergmann is currently refactoring how configurations are handled (see #913 and https://github.com/sebastianbergmann/phpunit/tree/configuration) and it's unlikely we will change too much until his changes land in the master branch. Once he's done, I'm sure we can re-evaluate this issue and see what our options are. Until then, there are a number of reasonable workarounds posted in this ticket.

Contributor

whatthejeff commented Nov 10, 2013

@RickWong the problem is @sebastianbergmann is incredibly stubborn. Despite huge support for this, and really no technical reasons against, he will not budge. So sad such a talented person is so hard headed.

Maybe @sebastianbergmann just disagrees with a handful of people about a relatively low-priority feature request. If that makes him hardheaded, then I guess we're all hardheaded :P

I really wouldn't mind seeing --colors[=on|=off] or something similar. But, for the time being, this probably is not going to happen. @sebastianbergmann is currently refactoring how configurations are handled (see #913 and https://github.com/sebastianbergmann/phpunit/tree/configuration) and it's unlikely we will change too much until his changes land in the master branch. Once he's done, I'm sure we can re-evaluate this issue and see what our options are. Until then, there are a number of reasonable workarounds posted in this ticket.

patrickallaert added a commit to ezsystems/ezpublish-api that referenced this issue Jan 17, 2014

Changed: turning colors off by default for unit tests
There is no way to turn them off on command line and that won't happen
soon according to Sebastian:
sebastianbergmann/phpunit#516

To have the colors, use the --colors switch

mauris added a commit to mauris/SparseApp that referenced this issue Mar 16, 2014

mauris added a commit to mauris/SparseApp that referenced this issue Apr 28, 2014

@Jean85 Jean85 referenced this issue in sebastianbergmann/phpunit-documentation Aug 25, 2015

Closed

CLI --colors options [never|auto|always] are undocumented #319

@olleharstedt

This comment has been minimized.

Show comment Hide comment
@olleharstedt

olleharstedt Nov 25, 2016

Would be nice if colors=never would also turn off colours in exceptions. Right now, the line number is yellow, which is impossible to read with white background.

Would be nice if colors=never would also turn off colours in exceptions. Right now, the line number is yellow, which is impossible to read with white background.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment