-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testing: examples fail if output is colored #34284
Comments
I believe that example outputs are only intended for plaintext; I haven't seen anyone attempt to use non-printable or special characters with them. I'm also not sure that such an example should be supported. What should godoc.org show for it? It's not a terminal, so it won't color the words. |
Agree but if you want to show the user what the output should look like (even without colors), you'll have to fill the "Output comment". But if you do so, it will automatically compare it to the "real" output. If the colors are also displayed in the documentation, I would be ok with it, but that's not my point. |
It doesn't have to be an |
In my opinion examples should just match the output characters exactly. Anything else will just lead us into confusion. What if you want to use an example to show the difference between colorized and non-colorized output? |
If you're suggesting to make godoc.org interpret terminal escape codes, or become a terminal emulator, I doubt that's likely to happen :) Edit: to clarify, that seems like a lot of added complexity for little gain. |
@GuillaumeLescure yes, it doesn't look the same, it's obviously a workaround... My point is that there's a workaround that still somewhat allows you do what you want ("show the user what the output should look like (even without colors),") without changing godoc for everyone. It a corner case, after all. |
That would be nice to keep consistency indeed but I understand the price it cost. That's why I didn't suggest that at first and just do the check without the interpretation. But at this point we have 3 solutions :
I think all of them are bad and force a trade-off ... something I hate X) |
@ALTree agree. I just want to show the issue, if it's already known and decision is made, I can live with it. But I think it's not corner case. It can happen very often for many people. Ex : you use a package that have a dependence on a log system that colorize output but you cannot change the output (yeah a not-so-good package). So everytime you will use that package (maybe the whole project like Qt library) you will display colorized output in your shell. So after writting your app, you will not be able to write a documentation with exemple 😢 PS : and a workaround stands for "working around the issue" so there is an issue 😉 |
I think that a package that always colorizes output even when not writing to a terminal, and that has no way to disable that colorization, is, as you say, a not-so-good package. I don't see a real need to make the support for examples more complex in order to support not-so-good packages. |
Ok I understand. I think it's probably the best solution here. |
Issue :
go test
fail if the output is colored.Even if the tags are in the output (the comment line), it fails and seems to be litterally evaluated.
Exemple :
In myColored_test.go :
Expectation :
Be able to pass the test either :
I personally prefere the second solution because it allows more accurate tests.
Environment :
The text was updated successfully, but these errors were encountered: