Skip to content

Commit 516d3b1

Browse files
committed
Test ANSI disabled in logging tests instead of integration tests
See gh-40172
1 parent 2183b47 commit 516d3b1

File tree

11 files changed

+26
-263
lines changed

11 files changed

+26
-263
lines changed

settings.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ include "spring-boot-project:spring-boot-test"
7575
include "spring-boot-project:spring-boot-testcontainers"
7676
include "spring-boot-project:spring-boot-test-autoconfigure"
7777
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-configuration-processor-tests"
78-
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-console-tests"
7978
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-launch-script-tests"
8079
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-loader-tests"
8180
include "spring-boot-tests:spring-boot-integration-tests:spring-boot-loader-classic-tests"

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/AbstractLoggingSystemTests.java

+2-25
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import org.junit.jupiter.api.io.TempDir;
2626
import org.slf4j.MDC;
2727

28-
import org.springframework.boot.ansi.AnsiOutput;
29-
import org.springframework.boot.ansi.AnsiOutput.Enabled;
3028
import org.springframework.util.StringUtils;
3129

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

4543
private String originalTempDirectory;
4644

47-
private AnsiOutput.Enabled ansiOutputEnabled;
48-
4945
@BeforeEach
50-
void beforeEach(@TempDir Path temp) {
51-
disableAnsiOutput();
52-
configureTempDir(temp);
53-
}
54-
55-
private void disableAnsiOutput() {
56-
this.ansiOutputEnabled = AnsiOutput.getEnabled();
57-
AnsiOutput.setEnabled(Enabled.NEVER);
58-
}
59-
60-
private void configureTempDir(@TempDir Path temp) {
46+
void configureTempDir(@TempDir Path temp) {
6147
this.originalTempDirectory = System.getProperty(JAVA_IO_TMPDIR);
6248
System.setProperty(JAVA_IO_TMPDIR, temp.toAbsolutePath().toString());
6349
MDC.clear();
6450
}
6551

6652
@AfterEach
67-
void afterEach() {
68-
reinstateTempDir();
69-
restoreAnsiOutputEnabled();
70-
}
71-
72-
private void reinstateTempDir() {
53+
void reinstateTempDir() {
7354
System.setProperty(JAVA_IO_TMPDIR, this.originalTempDirectory);
7455
}
7556

76-
private void restoreAnsiOutputEnabled() {
77-
AnsiOutput.setEnabled(this.ansiOutputEnabled);
78-
}
79-
8057
@AfterEach
8158
void clear() {
8259
for (LoggingSystemProperty property : LoggingSystemProperty.values()) {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/java/JavaLoggingSystemTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,12 @@ void getLoggerConfiguration() {
185185
.isEqualTo(new LoggerConfiguration(getClass().getName(), LogLevel.DEBUG, LogLevel.DEBUG));
186186
}
187187

188+
@Test
189+
void shouldNotContainAnsiEscapeCodes(CapturedOutput output) {
190+
this.loggingSystem.beforeInitialize();
191+
this.loggingSystem.initialize(null, null, null);
192+
this.logger.info("Hello world");
193+
assertThat(output).doesNotContain("\033[");
194+
}
195+
188196
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/log4j2/Log4J2LoggingSystemTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,14 @@ void applicationNameLoggingToFileWhenDisabled() {
651651
.doesNotContain("myapp");
652652
}
653653

654+
@Test
655+
void shouldNotContainAnsiEscapeCodes(CapturedOutput output) {
656+
this.loggingSystem.beforeInitialize();
657+
this.loggingSystem.initialize(this.initializationContext, null, null);
658+
this.logger.info("Hello world");
659+
assertThat(output).doesNotContain("\033[");
660+
}
661+
654662
private String getRelativeClasspathLocation(String fileName) {
655663
String defaultPath = ClassUtils.getPackageName(getClass());
656664
defaultPath = defaultPath.replace('.', '/');

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/logging/logback/LogbackLoggingSystemTests.java

+8
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,14 @@ void applyingSystemPropertiesDoesNotCauseUnwantedStatusWarnings(CapturedOutput o
877877
assertThat(output).doesNotContain("WARN");
878878
}
879879

880+
@Test
881+
void shouldNotContainAnsiEscapeCodes(CapturedOutput output) {
882+
this.loggingSystem.beforeInitialize();
883+
initialize(this.initializationContext, null, null);
884+
this.logger.info("Hello world");
885+
assertThat(output).doesNotContain("\033[");
886+
}
887+
880888
private void initialize(LoggingInitializationContext context, String configLocation, LogFile logFile) {
881889
this.loggingSystem.getSystemProperties((ConfigurableEnvironment) context.getEnvironment()).apply(logFile);
882890
this.loggingSystem.beforeInitialize();

spring-boot-tests/spring-boot-integration-tests/spring-boot-console-tests/build.gradle

-44
This file was deleted.

spring-boot-tests/spring-boot-integration-tests/spring-boot-console-tests/spring-boot-console-tests-app/build.gradle

-17
This file was deleted.

spring-boot-tests/spring-boot-integration-tests/spring-boot-console-tests/spring-boot-console-tests-app/settings.gradle

-15
This file was deleted.

spring-boot-tests/spring-boot-integration-tests/spring-boot-console-tests/spring-boot-console-tests-app/src/main/java/org/springframework/boot/consoleapp/ConsoleTestApplication.java

-32
This file was deleted.

spring-boot-tests/spring-boot-integration-tests/spring-boot-console-tests/src/intTest/java/org/springframework/boot/console/ConsoleIntegrationTests.java

-125
This file was deleted.

spring-boot-tests/spring-boot-integration-tests/spring-boot-console-tests/src/intTest/resources/logback.xml

-4
This file was deleted.

0 commit comments

Comments
 (0)