-
Notifications
You must be signed in to change notification settings - Fork 424
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
Ensure ANSI is disabled in TracerTest regardless of environment (issu… #1166
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1166 +/- ##
=========================================
Coverage 94.29% 94.29%
Complexity 455 455
=========================================
Files 2 2
Lines 6661 6661
Branches 1792 1792
=========================================
Hits 6281 6281
Misses 102 102
Partials 278 278 Continue to review full report at Codecov.
|
When exactly should I expect ANSI to be turned on automatically? This is happening in some of our own code, where one person is testing it assuming no ANSI codes, and then I test it and the test fails due to ANSI codes in the output. Unfortunately, I don't know of a public API to just strip the codes. I do as you do here, more or less, and force |
Merged, thanks for the PR! ANSI will be switched on for Unix/Mac, with an interactive console, and for Windows when Jansi is on the classpath, with an interactive console. Then there are some details, which are documented here: https://picocli.info/#_heuristics_for_enabling_ansi For JUnit tests, I would expect ANSI to be off by default because there is no interactive console, but that is a bit fragile. |
@remkop Is this Windows-only or is it more of an issue of not being able to determine if the shell is interactive or not (on Windows)? I believe the default for ANSI is set to auto and it can use various variables (including perhaps As you cannot control what a developer has his environment variables set to vs. the test/CI environment, I think the only safe and stable option is to force it off. Is it possible to force it off by simply passing |
Correct, the default for ANSI is AUTO. Sorry I was unclear. When I said "I expect ANSI to be off..." I meant that I expect AUTO to be evaluated to disabled. FYI, picocli checks if
I completely agree.
That may be possible, but I would not recommend it, because then your tests may pass or fail depending on whether |
I see that I am still trying to find out why it's turned on and I'll let you know if I find anything. If I understand your explanation, it is supposed to be off when doing a build. |
Yes, it is checking a lot... When ANSI is AUTO, it could be enabled even when
static boolean ansiPossible() {
if (forceDisabled()) { return false; } // System.getenv("NO_COLOR") != null
if (forceEnabled()) { return true; } // getenv("CLICOLOR_FORCE") != null && !"0".equals(getenv("CLICOLOR_FORCE")
if (isWindows() && isJansiConsoleInstalled()) { return true; } //
if (hintDisabled()) { return false; } // "0".equals(getenv("CLICOLOR")) || "OFF".equals(getenv("ConEmuANSI"))
if (!isTTY() && !isPseudoTTY()) { return false; } // console != null ; env("TERM"), env("OSTYPE")
return hintEnabled() || !isWindows() || isXterm() || hasOsType(); //env("ANSICON"), env("CLICOLOR"), env("ConEmuANSI")
} |
…e #1103)