Test ANSI disabled in logging tests instead of integration tests
See gh-40172
This commit is contained in:
@@ -25,8 +25,6 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
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;
|
||||
@@ -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()) {
|
||||
|
||||
@@ -185,4 +185,12 @@ class JavaLoggingSystemTests extends AbstractLoggingSystemTests {
|
||||
.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[");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -651,6 +651,14 @@ class Log4J2LoggingSystemTests extends AbstractLoggingSystemTests {
|
||||
.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('.', '/');
|
||||
|
||||
@@ -877,6 +877,14 @@ class LogbackLoggingSystemTests extends AbstractLoggingSystemTests {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user