From 5230f9bd31baf811b4e9e7a64c1af665c9c6e4ea Mon Sep 17 00:00:00 2001 From: cpovirk Date: Tue, 20 Jun 2023 08:07:03 -0700 Subject: [PATCH] Stop skipping tests that look for line breaks under Windows. Fixes https://github.com/google/guava/pull/6560 Progress toward https://github.com/google/guava/issues/2130 RELNOTES=n/a PiperOrigin-RevId: 541925496 --- .../test/com/google/common/base/ThrowablesTest.java | 12 ++---------- .../test/com/google/common/io/ResourcesTest.java | 10 +--------- .../test/com/google/common/base/ThrowablesTest.java | 12 ++---------- .../test/com/google/common/io/ResourcesTest.java | 10 +--------- 4 files changed, 6 insertions(+), 38 deletions(-) diff --git a/android/guava-tests/test/com/google/common/base/ThrowablesTest.java b/android/guava-tests/test/com/google/common/base/ThrowablesTest.java index 363550a16e59..eff9e50160db 100644 --- a/android/guava-tests/test/com/google/common/base/ThrowablesTest.java +++ b/android/guava-tests/test/com/google/common/base/ThrowablesTest.java @@ -17,7 +17,6 @@ package com.google.common.base; import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION; -import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.base.Throwables.getStackTraceAsString; import static com.google.common.base.Throwables.lazyStackTrace; import static com.google.common.base.Throwables.lazyStackTraceIsLazy; @@ -658,9 +657,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); @@ -671,8 +667,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 = "(?:.*\\R?)*"; + String expected = firstLine + "\\R" + secondLine + "\\R" + moreLines; assertThat(getStackTraceAsString(e)).matches(expected); } @@ -792,8 +788,4 @@ private void doTestLazyStackTraceFallback() { public void testNullPointers() { new NullPointerTester().testAllPublicStaticMethods(Throwables.class); } - - private static boolean isWindows() { - return OS_NAME.value().startsWith("Windows"); - } } diff --git a/android/guava-tests/test/com/google/common/io/ResourcesTest.java b/android/guava-tests/test/com/google/common/io/ResourcesTest.java index 23a487530a33..b1a46c698ae6 100644 --- a/android/guava-tests/test/com/google/common/io/ResourcesTest.java +++ b/android/guava-tests/test/com/google/common/io/ResourcesTest.java @@ -17,7 +17,6 @@ package com.google.common.io; import static com.google.common.base.CharMatcher.whitespace; -import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.truth.Truth.assertThat; import com.google.common.base.Charsets; @@ -160,10 +159,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); } @@ -194,8 +190,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"); - } } diff --git a/guava-tests/test/com/google/common/base/ThrowablesTest.java b/guava-tests/test/com/google/common/base/ThrowablesTest.java index 363550a16e59..eff9e50160db 100644 --- a/guava-tests/test/com/google/common/base/ThrowablesTest.java +++ b/guava-tests/test/com/google/common/base/ThrowablesTest.java @@ -17,7 +17,6 @@ package com.google.common.base; import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION; -import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.base.Throwables.getStackTraceAsString; import static com.google.common.base.Throwables.lazyStackTrace; import static com.google.common.base.Throwables.lazyStackTraceIsLazy; @@ -658,9 +657,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); @@ -671,8 +667,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 = "(?:.*\\R?)*"; + String expected = firstLine + "\\R" + secondLine + "\\R" + moreLines; assertThat(getStackTraceAsString(e)).matches(expected); } @@ -792,8 +788,4 @@ private void doTestLazyStackTraceFallback() { public void testNullPointers() { new NullPointerTester().testAllPublicStaticMethods(Throwables.class); } - - private static boolean isWindows() { - return OS_NAME.value().startsWith("Windows"); - } } diff --git a/guava-tests/test/com/google/common/io/ResourcesTest.java b/guava-tests/test/com/google/common/io/ResourcesTest.java index 23a487530a33..b1a46c698ae6 100644 --- a/guava-tests/test/com/google/common/io/ResourcesTest.java +++ b/guava-tests/test/com/google/common/io/ResourcesTest.java @@ -17,7 +17,6 @@ package com.google.common.io; import static com.google.common.base.CharMatcher.whitespace; -import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.truth.Truth.assertThat; import com.google.common.base.Charsets; @@ -160,10 +159,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); } @@ -194,8 +190,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"); - } }