Skip to content

Commit

Permalink
Test ANSI disabled in logging tests instead of integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhalbritter committed May 2, 2024
1 parent 2183b47 commit 516d3b1
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 263 deletions.
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ include "spring-boot-project:spring-boot-test"
include "spring-boot-project:spring-boot-testcontainers"
include "spring-boot-project:spring-boot-test-autoconfigure"
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-configuration-processor-tests"
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-console-tests"
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-launch-script-tests"
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-loader-tests"
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-loader-classic-tests"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import org.junit.jupiter.api.io.TempDir;
import org.slf4j.MDC;

import org.springframework.boot.ansi.AnsiOutput;
import org.springframework.boot.ansi.AnsiOutput.Enabled;
import org.springframework.util.StringUtils;

import static org.assertj.core.api.Assertions.contentOf;
Expand All @@ -44,39 +42,18 @@ public abstract class AbstractLoggingSystemTests {

private String originalTempDirectory;

private AnsiOutput.Enabled ansiOutputEnabled;

@BeforeEach
void beforeEach(@TempDir Path temp) {
disableAnsiOutput();
configureTempDir(temp);
}

private void disableAnsiOutput() {
this.ansiOutputEnabled = AnsiOutput.getEnabled();
AnsiOutput.setEnabled(Enabled.NEVER);
}

private void configureTempDir(@TempDir Path temp) {
void configureTempDir(@TempDir Path temp) {
this.originalTempDirectory = System.getProperty(JAVA_IO_TMPDIR);
System.setProperty(JAVA_IO_TMPDIR, temp.toAbsolutePath().toString());
MDC.clear();
}

@AfterEach
void afterEach() {
reinstateTempDir();
restoreAnsiOutputEnabled();
}

private void reinstateTempDir() {
void reinstateTempDir() {
System.setProperty(JAVA_IO_TMPDIR, this.originalTempDirectory);
}

private void restoreAnsiOutputEnabled() {
AnsiOutput.setEnabled(this.ansiOutputEnabled);
}

@AfterEach
void clear() {
for (LoggingSystemProperty property : LoggingSystemProperty.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,12 @@ void getLoggerConfiguration() {
.isEqualTo(new LoggerConfiguration(getClass().getName(), LogLevel.DEBUG, LogLevel.DEBUG));
}

@Test
void shouldNotContainAnsiEscapeCodes(CapturedOutput output) {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(null, null, null);
this.logger.info("Hello world");
assertThat(output).doesNotContain("\033[");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,14 @@ void applicationNameLoggingToFileWhenDisabled() {
.doesNotContain("myapp");
}

@Test
void shouldNotContainAnsiEscapeCodes(CapturedOutput output) {
this.loggingSystem.beforeInitialize();
this.loggingSystem.initialize(this.initializationContext, null, null);
this.logger.info("Hello world");
assertThat(output).doesNotContain("\033[");
}

private String getRelativeClasspathLocation(String fileName) {
String defaultPath = ClassUtils.getPackageName(getClass());
defaultPath = defaultPath.replace('.', '/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,14 @@ void applyingSystemPropertiesDoesNotCauseUnwantedStatusWarnings(CapturedOutput o
assertThat(output).doesNotContain("WARN");
}

@Test
void shouldNotContainAnsiEscapeCodes(CapturedOutput output) {
this.loggingSystem.beforeInitialize();
initialize(this.initializationContext, null, null);
this.logger.info("Hello world");
assertThat(output).doesNotContain("\033[");
}

private void initialize(LoggingInitializationContext context, String configLocation, LogFile logFile) {
this.loggingSystem.getSystemProperties((ConfigurableEnvironment) context.getEnvironment()).apply(logFile);
this.loggingSystem.beforeInitialize();
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 516d3b1

Please sign in to comment.