Try to fix Windows build failures

Text blocks use \n as their separator on all platforms. Update
withLineSeparatorUsesLineSeparator() to replace \n rather than
System.lineSeparator()

createPrinterWhenStandardAppliesCustomizations() limits the length of
the output. On Windows, the default \r\n line separator uses an
extra byte per separator compared to \n. Configure the printer to use
\n as a line separator so that non-whitespace output is the same on
all platforms.

See gh-43864
This commit is contained in:
Andy Wilkinson
2025-02-11 09:43:59 +00:00
parent 491a335ec7
commit 7c27cc52ee
2 changed files with 3 additions and 3 deletions

View File

@@ -263,8 +263,7 @@ class StandardStackTracePrinterTests {
void withLineSeparatorUsesLineSeparator() {
Throwable exception = TestException.create();
StandardStackTracePrinter printer = StandardStackTracePrinter.rootLast().withLineSeparator("!");
assertThatCleanedStackTraceMatches(printer, exception,
standardStackTrace().replace(System.lineSeparator(), "!"));
assertThatCleanedStackTraceMatches(printer, exception, standardStackTrace().replace("\n", "!"));
}
@Test

View File

@@ -144,7 +144,8 @@ class StructuredLoggingJsonPropertiesTests {
void createPrinterWhenStandardAppliesCustomizations() {
Exception exception = TestException.create();
StackTrace properties = new StackTrace(null, Root.FIRST, 300, 2, true, false);
StackTracePrinter printer = properties.createPrinter();
StackTracePrinter printer = ((StandardStackTracePrinter) properties.createPrinter())
.withLineSeparator("\n");
String actual = TestException.withoutLineNumbers(printer.printStackTraceToString(exception));
assertThat(actual).isEqualToNormalizingNewlines("""
java.lang.RuntimeException: exception