Skip to content

Commit

Permalink
Fixed the rest of the failing test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTrenkamp authored and remkop committed Mar 24, 2023
1 parent 5b036f0 commit 01b06bc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ public void testAnsiAutoJansiConsoleInstalledOverridesHintDisabled() {
environmentVariables.clear(ANSI_ENVIRONMENT_VARIABLES);
environmentVariables.set("CLICOLOR", "0"); // hint disabled
System.setProperty("os.name", "Windows");
// Clear the globally cached jansiConsole value that might
// have been set in a previous test to force the
// Ansi#isJansiConsoleInstalled method to recalculate
// the cached value.
Ansi.jansiConsole = null;
assertTrue(Ansi.isWindows());
assertFalse(Ansi.isPseudoTTY());
assertFalse(Ansi.forceDisabled());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package picocli;


import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import picocli.CommandLine.Help.Ansi;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -508,6 +510,15 @@ private String expectedCompletionScriptForNonDefault() {
CommandLine.VERSION);
}

@BeforeAll
static void disableAnsi() {
// Clear the globally cached jansiConsole value that might
// have been set in a previous test to force the
// Ansi#isJansiConsoleInstalled method to recalculate
// the cached value.
Ansi.jansiConsole = null;
}

@Test
@DisabledForJreRange(min = JRE.JAVA_18, max = JRE.JAVA_21, disabledReason = "UnsupportedOperationException in SystemLambda.withSecurityManager")
public void testAutoCompleteAppHelp() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,12 @@ public void testAnsiAutoJansiConsoleInstalledOverridesHintDisabled() throws Exce
assertFalse(Ansi.hintEnabled());

assertFalse(Ansi.isJansiConsoleInstalled());

// Clear the globally cached jansiConsole value that might
// have been set in a previous test to force the
// Ansi#isJansiConsoleInstalled method to recalculate
// the cached value.
Ansi.jansiConsole = null;
AnsiConsole.systemInstall();
try {
assertTrue(Ansi.isJansiConsoleInstalled());
Expand All @@ -628,6 +634,7 @@ public void testAnsiAutoHintDisabledOverridesHintEnabled() throws Exception {
restoreSystemProperties(() -> {

System.setProperty("os.name", "Windows");
Ansi.jansiConsole = null;
withEnvironmentVariable(ANSI_ENVIRONMENT_VARIABLES[0], null)
.and(ANSI_ENVIRONMENT_VARIABLES[1], null)
.and(ANSI_ENVIRONMENT_VARIABLES[2], null)
Expand Down Expand Up @@ -688,6 +695,7 @@ public void testAnsiAutoDisabledIfNoTty() throws Exception {
restoreSystemProperties(() -> {

System.setProperty("os.name", "Windows");
Ansi.jansiConsole = null;
assertTrue(Ansi.isWindows());
assertFalse(Ansi.isPseudoTTY());
assertFalse(Ansi.isJansiConsoleInstalled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemErrRule;
import picocli.CommandLine.Command;
import picocli.CommandLine.Help.Ansi;
import picocli.CommandLine.IParameterPreprocessor;
import picocli.CommandLine.Model.ArgSpec;
import picocli.CommandLine.Model.CommandSpec;
Expand Down Expand Up @@ -111,6 +112,11 @@ public void testAmbiguousOptionsDefault() {
//-x -y=123
MyCommand obj = new MyCommand();
CommandLine cmdLine = new CommandLine(obj);
// Clear the globally cached jansiConsole value that might
// have been set in a previous test to force the
// Ansi#isJansiConsoleInstalled method to recalculate
// the cached value.
Ansi.jansiConsole = null;
int exitCode = cmdLine.execute("-x", "-y=123");
assertEquals(2, exitCode);
String expected = String.format("" +
Expand Down

0 comments on commit 01b06bc

Please sign in to comment.