Skip to content

Commit

Permalink
google#2130 - Stop skipping certain tests under Windows
Browse files Browse the repository at this point in the history
Some tests depended on Unix line ending, changing those to use `System.lineSeparator()` instead. Now they can run on Windows too.
  • Loading branch information
ineuwirth committed Jun 17, 2023
1 parent efede00 commit c74303d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,6 @@ static void methodThatThrowsUndeclaredChecked() throws SomeUndeclaredCheckedExce
@J2ktIncompatible
@GwtIncompatible // getStackTraceAsString(Throwable)
public void testGetStackTraceAsString() {
if (isWindows()) {
return; // TODO: b/136041958 - We probably just need to accept \r\n line delimiters.
}
class StackTraceException extends Exception {
StackTraceException(String message) {
super(message);
Expand All @@ -671,8 +668,8 @@ class StackTraceException extends Exception {

String firstLine = quote(e.getClass().getName() + ": " + e.getMessage());
String secondLine = "\\s*at " + ThrowablesTest.class.getName() + "\\..*";
String moreLines = "(?:.*\n?)*";
String expected = firstLine + "\n" + secondLine + "\n" + moreLines;
String moreLines = "(?:.*" + System.lineSeparator() + "?)*";
String expected = String.join(System.lineSeparator(), firstLine, secondLine, moreLines);
assertThat(getStackTraceAsString(e)).matches(expected);
}

Expand Down Expand Up @@ -792,8 +789,4 @@ private void doTestLazyStackTraceFallback() {
public void testNullPointers() {
new NullPointerTester().testAllPublicStaticMethods(Throwables.class);
}

private static boolean isWindows() {
return OS_NAME.value().startsWith("Windows");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ public void testGetResource_contextClassLoader() throws IOException {
Thread.currentThread().setContextClassLoader(loader);
URL url = Resources.getResource(tempFile.getName());
String text = Resources.toString(url, Charsets.UTF_8);
if (isWindows()) {
return; // TODO: b/136041958 - We probably just need to accept \r\n line delimiters.
}
assertEquals("rud a chur ar an méar fhada\n", text);
assertEquals("rud a chur ar an méar fhada" + System.lineSeparator(), text);
} finally {
Thread.currentThread().setContextClassLoader(oldContextLoader);
}
Expand Down Expand Up @@ -194,8 +191,4 @@ public void testNulls() {
private static URL classfile(Class<?> c) {
return c.getResource(c.getSimpleName() + ".class");
}

private static boolean isWindows() {
return OS_NAME.value().startsWith("Windows");
}
}
11 changes: 2 additions & 9 deletions guava-tests/test/com/google/common/base/ThrowablesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,6 @@ static void methodThatThrowsUndeclaredChecked() throws SomeUndeclaredCheckedExce
@J2ktIncompatible
@GwtIncompatible // getStackTraceAsString(Throwable)
public void testGetStackTraceAsString() {
if (isWindows()) {
return; // TODO: b/136041958 - We probably just need to accept \r\n line delimiters.
}
class StackTraceException extends Exception {
StackTraceException(String message) {
super(message);
Expand All @@ -671,8 +668,8 @@ class StackTraceException extends Exception {

String firstLine = quote(e.getClass().getName() + ": " + e.getMessage());
String secondLine = "\\s*at " + ThrowablesTest.class.getName() + "\\..*";
String moreLines = "(?:.*\n?)*";
String expected = firstLine + "\n" + secondLine + "\n" + moreLines;
String moreLines = "(?:.*" + System.lineSeparator() + "?)*";
String expected = String.join(System.lineSeparator(), firstLine, secondLine, moreLines);
assertThat(getStackTraceAsString(e)).matches(expected);
}

Expand Down Expand Up @@ -792,8 +789,4 @@ private void doTestLazyStackTraceFallback() {
public void testNullPointers() {
new NullPointerTester().testAllPublicStaticMethods(Throwables.class);
}

private static boolean isWindows() {
return OS_NAME.value().startsWith("Windows");
}
}
9 changes: 1 addition & 8 deletions guava-tests/test/com/google/common/io/ResourcesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ public void testGetResource_contextClassLoader() throws IOException {
Thread.currentThread().setContextClassLoader(loader);
URL url = Resources.getResource(tempFile.getName());
String text = Resources.toString(url, Charsets.UTF_8);
if (isWindows()) {
return; // TODO: b/136041958 - We probably just need to accept \r\n line delimiters.
}
assertEquals("rud a chur ar an méar fhada\n", text);
assertEquals("rud a chur ar an méar fhada" + System.lineSeparator(), text);
} finally {
Thread.currentThread().setContextClassLoader(oldContextLoader);
}
Expand Down Expand Up @@ -194,8 +191,4 @@ public void testNulls() {
private static URL classfile(Class<?> c) {
return c.getResource(c.getSimpleName() + ".class");
}

private static boolean isWindows() {
return OS_NAME.value().startsWith("Windows");
}
}

0 comments on commit c74303d

Please sign in to comment.