From 2646b61c153ba22b33ad864e55c7ca107aa615ea Mon Sep 17 00:00:00 2001 From: cpovirk Date: Thu, 8 Jun 2023 11:23:05 -0700 Subject: [PATCH] Run CI under Windows, suppressing existing failures. - Fixes https://github.com/google/guava/issues/2686 - In some sense addresses https://github.com/google/guava/issues/2130, but I'm going to leave that open to track removing the suppressions. - Provides better testing for the fix for https://github.com/google/guava/issues/6535 RELNOTES=n/a PiperOrigin-RevId: 538841996 --- .github/workflows/ci.yml | 9 +++-- .../google/common/base/ThrowablesTest.java | 8 +++++ ...edOutputStreamAndroidIncompatibleTest.java | 8 +++++ .../common/io/FileBackedOutputStreamTest.java | 14 ++++++++ .../common/io/FilesCreateTempDirTest.java | 8 +++++ .../com/google/common/io/ResourcesTest.java | 8 +++++ .../google/common/reflect/ClassPathTest.java | 27 +++++++++++++++ .../util/concurrent/AbstractFutureTest.java | 29 ++++++++++++++++ .../google/common/base/ThrowablesTest.java | 8 +++++ ...edOutputStreamAndroidIncompatibleTest.java | 8 +++++ .../common/io/FileBackedOutputStreamTest.java | 14 ++++++++ .../common/io/FilesCreateTempDirTest.java | 8 +++++ .../com/google/common/io/MoreFilesTest.java | 8 +++++ .../com/google/common/io/ResourcesTest.java | 8 +++++ .../google/common/reflect/ClassPathTest.java | 33 +++++++++++++++++++ .../util/concurrent/AbstractFutureTest.java | 29 ++++++++++++++++ 16 files changed, 225 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f754437caf7..485a3d403e14 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,12 +16,17 @@ jobs: permissions: actions: write # for styfle/cancel-workflow-action to cancel/stop running workflows contents: read # for actions/checkout to fetch code - name: "${{ matrix.root-pom }} on JDK ${{ matrix.java }}" + name: "${{ matrix.root-pom }} on JDK ${{ matrix.java }} on ${{ matrix.os }}" strategy: matrix: + os: [ ubuntu-latest ] java: [ 8, 11, 17 ] root-pom: [ 'pom.xml', 'android/pom.xml' ] - runs-on: ubuntu-latest + include: + - os: windows-latest + java: 17 + root-pom: pom.xml + runs-on: ${{ matrix.os }} env: ROOT_POM: ${{ matrix.root-pom }} steps: 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 d04c358be8d8..363550a16e59 100644 --- a/android/guava-tests/test/com/google/common/base/ThrowablesTest.java +++ b/android/guava-tests/test/com/google/common/base/ThrowablesTest.java @@ -17,6 +17,7 @@ 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; @@ -657,6 +658,9 @@ 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); @@ -788,4 +792,8 @@ 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/FileBackedOutputStreamAndroidIncompatibleTest.java b/android/guava-tests/test/com/google/common/io/FileBackedOutputStreamAndroidIncompatibleTest.java index 4ecdcf8d5688..9d25e42affb3 100644 --- a/android/guava-tests/test/com/google/common/io/FileBackedOutputStreamAndroidIncompatibleTest.java +++ b/android/guava-tests/test/com/google/common/io/FileBackedOutputStreamAndroidIncompatibleTest.java @@ -16,6 +16,7 @@ package com.google.common.io; +import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.io.FileBackedOutputStreamTest.write; import com.google.common.testing.GcFinalization; @@ -30,6 +31,9 @@ public class FileBackedOutputStreamAndroidIncompatibleTest extends IoTestCase { public void testFinalizeDeletesFile() throws Exception { + if (isWindows()) { + return; // TODO: b/285742623 - Fix FileBackedOutputStream under Windows. + } byte[] data = newPreFilledByteArray(100); FileBackedOutputStream out = new FileBackedOutputStream(0, true); @@ -51,4 +55,8 @@ public boolean isDone() { } }); } + + private static boolean isWindows() { + return OS_NAME.value().startsWith("Windows"); + } } diff --git a/android/guava-tests/test/com/google/common/io/FileBackedOutputStreamTest.java b/android/guava-tests/test/com/google/common/io/FileBackedOutputStreamTest.java index 87247e1ed4d5..2924cc081909 100644 --- a/android/guava-tests/test/com/google/common/io/FileBackedOutputStreamTest.java +++ b/android/guava-tests/test/com/google/common/io/FileBackedOutputStreamTest.java @@ -17,6 +17,7 @@ package com.google.common.io; import static com.google.common.base.StandardSystemProperty.JAVA_IO_TMPDIR; +import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.truth.Truth.assertThat; import static java.nio.file.attribute.PosixFilePermission.OWNER_READ; import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE; @@ -40,6 +41,9 @@ public class FileBackedOutputStreamTest extends IoTestCase { public void testThreshold() throws Exception { + if (isWindows()) { + return; // TODO: b/285742623 - Fix FileBackedOutputStream under Windows. + } testThreshold(0, 100, true, false); testThreshold(10, 100, true, false); testThreshold(100, 100, true, false); @@ -99,6 +103,9 @@ private void testThreshold( public void testThreshold_resetOnFinalize() throws Exception { + if (isWindows()) { + return; // TODO: b/285742623 - Fix FileBackedOutputStream under Windows. + } testThreshold(0, 100, true, true); testThreshold(10, 100, true, true); testThreshold(100, 100, true, true); @@ -124,6 +131,9 @@ static void write(OutputStream out, byte[] b, int off, int len, boolean singleBy // TODO(chrisn): only works if we ensure we have crossed file threshold public void testWriteErrorAfterClose() throws Exception { + if (isWindows()) { + return; // TODO: b/285742623 - Fix FileBackedOutputStream under Windows. + } byte[] data = newPreFilledByteArray(100); FileBackedOutputStream out = new FileBackedOutputStream(50); ByteSource source = out.asByteSource(); @@ -167,4 +177,8 @@ public void testReset() throws Exception { private static boolean isAndroid() { return System.getProperty("java.runtime.name", "").contains("Android"); } + + private static boolean isWindows() { + return OS_NAME.value().startsWith("Windows"); + } } diff --git a/android/guava-tests/test/com/google/common/io/FilesCreateTempDirTest.java b/android/guava-tests/test/com/google/common/io/FilesCreateTempDirTest.java index 62098ef0288a..228891d27255 100644 --- a/android/guava-tests/test/com/google/common/io/FilesCreateTempDirTest.java +++ b/android/guava-tests/test/com/google/common/io/FilesCreateTempDirTest.java @@ -17,6 +17,7 @@ package com.google.common.io; import static com.google.common.base.StandardSystemProperty.JAVA_IO_TMPDIR; +import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.truth.Truth.assertThat; import static java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE; import static java.nio.file.attribute.PosixFilePermission.OWNER_READ; @@ -38,6 +39,9 @@ @SuppressWarnings("deprecation") // tests of a deprecated method public class FilesCreateTempDirTest extends TestCase { public void testCreateTempDir() throws IOException { + if (isWindows()) { + return; // TODO: b/285742623 - Fix Files.createTempDir under Windows. + } if (JAVA_IO_TMPDIR.value().equals("/sdcard")) { assertThrows(IllegalStateException.class, Files::createTempDir); return; @@ -63,4 +67,8 @@ public void testCreateTempDir() throws IOException { private static boolean isAndroid() { return System.getProperty("java.runtime.name", "").contains("Android"); } + + 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 0b51c9986f88..23a487530a33 100644 --- a/android/guava-tests/test/com/google/common/io/ResourcesTest.java +++ b/android/guava-tests/test/com/google/common/io/ResourcesTest.java @@ -17,6 +17,7 @@ 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; @@ -159,6 +160,9 @@ 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); } finally { Thread.currentThread().setContextClassLoader(oldContextLoader); @@ -190,4 +194,8 @@ 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/android/guava-tests/test/com/google/common/reflect/ClassPathTest.java b/android/guava-tests/test/com/google/common/reflect/ClassPathTest.java index 0184ed89135d..f2de67c19b28 100644 --- a/android/guava-tests/test/com/google/common/reflect/ClassPathTest.java +++ b/android/guava-tests/test/com/google/common/reflect/ClassPathTest.java @@ -17,6 +17,7 @@ import static com.google.common.base.Charsets.US_ASCII; import static com.google.common.base.StandardSystemProperty.JAVA_CLASS_PATH; +import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.base.StandardSystemProperty.PATH_SEPARATOR; import static com.google.common.truth.Truth.assertThat; @@ -173,6 +174,13 @@ public void testToFile_AndroidIncompatible() throws Exception { @AndroidIncompatible // Android forbids null parent ClassLoader // https://github.com/google/guava/issues/2152 public void testJarFileWithSpaces() throws Exception { + if (isWindows()) { + /* + * TODO: b/285742623 - Fix c.g.c.io.Files.createTempDir under Windows. Or use java.nio.files + * instead? + */ + return; + } URL url = makeJarUrlWithName("To test unescaped spaces in jar file name.jar"); URLClassLoader classloader = new URLClassLoader(new URL[] {url}, null); assertThat(ClassPath.from(classloader).getTopLevelClasses()).isNotEmpty(); @@ -215,6 +223,9 @@ public void testScanFromFile_notJarFile() throws IOException { } public void testGetClassPathEntry() throws MalformedURLException, URISyntaxException { + if (isWindows()) { + return; // TODO: b/136041958 - We need to account for drive letters in the path. + } assertEquals( new File("/usr/test/dep.jar").toURI(), ClassPath.getClassPathEntry(new File("/home/build/outer.jar"), "file:/usr/test/dep.jar") @@ -285,6 +296,9 @@ public void testGetClassPathFromManifest_jarInCurrentDirectory() throws IOExcept } public void testGetClassPathFromManifest_absoluteDirectory() throws IOException { + if (isWindows()) { + return; // TODO: b/136041958 - We need to account for drive letters in the path. + } File jarFile = new File("base/some.jar"); Manifest manifest = manifestClasspath("file:/with/absolute/dir"); assertThat(ClassPath.getClassPathFromManifest(jarFile, manifest)) @@ -292,6 +306,9 @@ public void testGetClassPathFromManifest_absoluteDirectory() throws IOException } public void testGetClassPathFromManifest_absoluteJar() throws IOException { + if (isWindows()) { + return; // TODO: b/136041958 - We need to account for drive letters in the path. + } File jarFile = new File("base/some.jar"); Manifest manifest = manifestClasspath("file:/with/absolute.jar"); assertThat(ClassPath.getClassPathFromManifest(jarFile, manifest)) @@ -299,6 +316,9 @@ public void testGetClassPathFromManifest_absoluteJar() throws IOException { } public void testGetClassPathFromManifest_multiplePaths() throws IOException { + if (isWindows()) { + return; // TODO: b/136041958 - We need to account for drive letters in the path. + } File jarFile = new File("base/some.jar"); Manifest manifest = manifestClasspath("file:/with/absolute.jar relative.jar relative/dir"); assertThat(ClassPath.getClassPathFromManifest(jarFile, manifest)) @@ -355,6 +375,9 @@ public void testGetPackageName() { public void testGetClassPathUrls() throws Exception { + if (isWindows()) { + return; // TODO: b/136041958 - We need to account for drive letters in the path. + } String oldPathSeparator = PATH_SEPARATOR.value(); String oldClassPath = JAVA_CLASS_PATH.value(); System.setProperty(PATH_SEPARATOR.key(), ":"); @@ -572,4 +595,8 @@ private static ImmutableSet scanResourceNames(ClassLoader loader) throws } return builder.build(); } + + private static boolean isWindows() { + return OS_NAME.value().startsWith("Windows"); + } } diff --git a/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java b/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java index 0ed399b726ad..5a28ff1f9724 100644 --- a/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java +++ b/android/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java @@ -17,6 +17,7 @@ package com.google.common.util.concurrent; import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION; +import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; @@ -217,6 +218,9 @@ public void testToString_allUnique() throws Exception { } public void testToString_oom() throws Exception { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } SettableFuture future = SettableFuture.create(); future.set( new Object() { @@ -296,6 +300,9 @@ public String pendingToString() { @SuppressWarnings({"DeprecatedThreadMethods", "ThreadPriorityCheck"}) @AndroidIncompatible // Thread.suspend public void testToString_delayedTimeout() throws Exception { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } Integer javaVersion = Ints.tryParse(JAVA_SPECIFICATION_VERSION.value()); // Parsing to an integer might fail because Java 8 returns "1.8" instead of "8." // We can continue if it's 1.8, and we can continue if it's an integer in [9, 20). @@ -385,6 +392,9 @@ public String pendingToString() { } public void testCompletionFinishesWithDone() { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } ExecutorService executor = Executors.newFixedThreadPool(10); for (int i = 0; i < 50000; i++) { final AbstractFuture future = new AbstractFuture() {}; @@ -436,6 +446,9 @@ public void run() { */ public void testFutureBash() { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } final CyclicBarrier barrier = new CyclicBarrier( 6 // for the setter threads @@ -617,6 +630,9 @@ public void run() { // setFuture and cancel() interact in more complicated ways than the other setters. public void testSetFutureCancelBash() { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } final int size = 50; final CyclicBarrier barrier = new CyclicBarrier( @@ -752,6 +768,9 @@ public void run() { // Test to ensure that when calling setFuture with a done future only setFuture or cancel can // return true. public void testSetFutureCancelBash_withDoneFuture() { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } final CyclicBarrier barrier = new CyclicBarrier( 2 // for the setter threads @@ -835,6 +854,9 @@ public void run() { // In a previous implementation this would cause a stack overflow after ~2000 futures chained // together. Now it should only be limited by available memory (and time) public void testSetFuture_stackOverflow() { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } SettableFuture orig = SettableFuture.create(); SettableFuture prev = orig; for (int i = 0; i < 100000; i++) { @@ -852,6 +874,9 @@ public void testSetFuture_stackOverflow() { @GwtIncompatible @AndroidIncompatible public void testSetFutureToString_stackOverflow() { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } SettableFuture orig = SettableFuture.create(); SettableFuture prev = orig; for (int i = 0; i < 100000; i++) { @@ -1325,4 +1350,8 @@ protected void interruptTask() { interruptTaskWasCalled = true; } } + + 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 d04c358be8d8..363550a16e59 100644 --- a/guava-tests/test/com/google/common/base/ThrowablesTest.java +++ b/guava-tests/test/com/google/common/base/ThrowablesTest.java @@ -17,6 +17,7 @@ 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; @@ -657,6 +658,9 @@ 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); @@ -788,4 +792,8 @@ 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/FileBackedOutputStreamAndroidIncompatibleTest.java b/guava-tests/test/com/google/common/io/FileBackedOutputStreamAndroidIncompatibleTest.java index 4ecdcf8d5688..9d25e42affb3 100644 --- a/guava-tests/test/com/google/common/io/FileBackedOutputStreamAndroidIncompatibleTest.java +++ b/guava-tests/test/com/google/common/io/FileBackedOutputStreamAndroidIncompatibleTest.java @@ -16,6 +16,7 @@ package com.google.common.io; +import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.io.FileBackedOutputStreamTest.write; import com.google.common.testing.GcFinalization; @@ -30,6 +31,9 @@ public class FileBackedOutputStreamAndroidIncompatibleTest extends IoTestCase { public void testFinalizeDeletesFile() throws Exception { + if (isWindows()) { + return; // TODO: b/285742623 - Fix FileBackedOutputStream under Windows. + } byte[] data = newPreFilledByteArray(100); FileBackedOutputStream out = new FileBackedOutputStream(0, true); @@ -51,4 +55,8 @@ public boolean isDone() { } }); } + + private static boolean isWindows() { + return OS_NAME.value().startsWith("Windows"); + } } diff --git a/guava-tests/test/com/google/common/io/FileBackedOutputStreamTest.java b/guava-tests/test/com/google/common/io/FileBackedOutputStreamTest.java index 87247e1ed4d5..2924cc081909 100644 --- a/guava-tests/test/com/google/common/io/FileBackedOutputStreamTest.java +++ b/guava-tests/test/com/google/common/io/FileBackedOutputStreamTest.java @@ -17,6 +17,7 @@ package com.google.common.io; import static com.google.common.base.StandardSystemProperty.JAVA_IO_TMPDIR; +import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.truth.Truth.assertThat; import static java.nio.file.attribute.PosixFilePermission.OWNER_READ; import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE; @@ -40,6 +41,9 @@ public class FileBackedOutputStreamTest extends IoTestCase { public void testThreshold() throws Exception { + if (isWindows()) { + return; // TODO: b/285742623 - Fix FileBackedOutputStream under Windows. + } testThreshold(0, 100, true, false); testThreshold(10, 100, true, false); testThreshold(100, 100, true, false); @@ -99,6 +103,9 @@ private void testThreshold( public void testThreshold_resetOnFinalize() throws Exception { + if (isWindows()) { + return; // TODO: b/285742623 - Fix FileBackedOutputStream under Windows. + } testThreshold(0, 100, true, true); testThreshold(10, 100, true, true); testThreshold(100, 100, true, true); @@ -124,6 +131,9 @@ static void write(OutputStream out, byte[] b, int off, int len, boolean singleBy // TODO(chrisn): only works if we ensure we have crossed file threshold public void testWriteErrorAfterClose() throws Exception { + if (isWindows()) { + return; // TODO: b/285742623 - Fix FileBackedOutputStream under Windows. + } byte[] data = newPreFilledByteArray(100); FileBackedOutputStream out = new FileBackedOutputStream(50); ByteSource source = out.asByteSource(); @@ -167,4 +177,8 @@ public void testReset() throws Exception { private static boolean isAndroid() { return System.getProperty("java.runtime.name", "").contains("Android"); } + + private static boolean isWindows() { + return OS_NAME.value().startsWith("Windows"); + } } diff --git a/guava-tests/test/com/google/common/io/FilesCreateTempDirTest.java b/guava-tests/test/com/google/common/io/FilesCreateTempDirTest.java index 62098ef0288a..228891d27255 100644 --- a/guava-tests/test/com/google/common/io/FilesCreateTempDirTest.java +++ b/guava-tests/test/com/google/common/io/FilesCreateTempDirTest.java @@ -17,6 +17,7 @@ package com.google.common.io; import static com.google.common.base.StandardSystemProperty.JAVA_IO_TMPDIR; +import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.truth.Truth.assertThat; import static java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE; import static java.nio.file.attribute.PosixFilePermission.OWNER_READ; @@ -38,6 +39,9 @@ @SuppressWarnings("deprecation") // tests of a deprecated method public class FilesCreateTempDirTest extends TestCase { public void testCreateTempDir() throws IOException { + if (isWindows()) { + return; // TODO: b/285742623 - Fix Files.createTempDir under Windows. + } if (JAVA_IO_TMPDIR.value().equals("/sdcard")) { assertThrows(IllegalStateException.class, Files::createTempDir); return; @@ -63,4 +67,8 @@ public void testCreateTempDir() throws IOException { private static boolean isAndroid() { return System.getProperty("java.runtime.name", "").contains("Android"); } + + private static boolean isWindows() { + return OS_NAME.value().startsWith("Windows"); + } } diff --git a/guava-tests/test/com/google/common/io/MoreFilesTest.java b/guava-tests/test/com/google/common/io/MoreFilesTest.java index 005cf531da54..e669bf7ddfc4 100644 --- a/guava-tests/test/com/google/common/io/MoreFilesTest.java +++ b/guava-tests/test/com/google/common/io/MoreFilesTest.java @@ -16,6 +16,7 @@ package com.google.common.io; +import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.io.RecursiveDeleteOption.ALLOW_INSECURE; import static com.google.common.jimfs.Feature.SECURE_DIRECTORY_STREAM; import static com.google.common.jimfs.Feature.SYMBOLIC_LINKS; @@ -301,6 +302,9 @@ public void testCreateParentDirectories_multipleParentsNeeded() throws IOExcepti } public void testCreateParentDirectories_noPermission() { + if (isWindows()) { + return; // TODO: b/136041958 - Create/find a directory that we don't have permissions on? + } Path file = root().resolve("parent/nonexistent.file"); Path parent = file.getParent(); assertFalse(Files.exists(parent)); @@ -721,4 +725,8 @@ public void assertDeleteSucceeded(Path path) throws IOException { public abstract void assertDeleteSucceeded(Path path) throws IOException; } + + 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 0b51c9986f88..23a487530a33 100644 --- a/guava-tests/test/com/google/common/io/ResourcesTest.java +++ b/guava-tests/test/com/google/common/io/ResourcesTest.java @@ -17,6 +17,7 @@ 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; @@ -159,6 +160,9 @@ 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); } finally { Thread.currentThread().setContextClassLoader(oldContextLoader); @@ -190,4 +194,8 @@ 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/reflect/ClassPathTest.java b/guava-tests/test/com/google/common/reflect/ClassPathTest.java index 3d78e7b24a06..587419576b72 100644 --- a/guava-tests/test/com/google/common/reflect/ClassPathTest.java +++ b/guava-tests/test/com/google/common/reflect/ClassPathTest.java @@ -17,6 +17,7 @@ import static com.google.common.base.Charsets.US_ASCII; import static com.google.common.base.StandardSystemProperty.JAVA_CLASS_PATH; +import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.base.StandardSystemProperty.PATH_SEPARATOR; import static com.google.common.io.MoreFiles.deleteRecursively; import static com.google.common.truth.Truth.assertThat; @@ -179,6 +180,13 @@ public void testToFile_AndroidIncompatible() throws Exception { @AndroidIncompatible // Android forbids null parent ClassLoader // https://github.com/google/guava/issues/2152 public void testJarFileWithSpaces() throws Exception { + if (isWindows()) { + /* + * TODO: b/285742623 - Fix c.g.c.io.Files.createTempDir under Windows. Or use java.nio.files + * instead? + */ + return; + } URL url = makeJarUrlWithName("To test unescaped spaces in jar file name.jar"); URLClassLoader classloader = new URLClassLoader(new URL[] {url}, null); assertThat(ClassPath.from(classloader).getTopLevelClasses()).isNotEmpty(); @@ -202,6 +210,9 @@ public void testScan_classPathCycle() throws IOException { @AndroidIncompatible // Path (for symlink creation) public void testScanDirectory_symlinkCycle() throws IOException { + if (isWindows()) { + return; // TODO: b/136041958 - Can we detect cycles under Windows? + } ClassLoader loader = ClassPathTest.class.getClassLoader(); // directory with a cycle, // /root @@ -234,6 +245,9 @@ public void testScanDirectory_symlinkCycle() throws IOException { @AndroidIncompatible // Path (for symlink creation) public void testScanDirectory_symlinkToRootCycle() throws IOException { + if (isWindows()) { + return; // TODO: b/136041958 - Can we detect cycles under Windows? + } ClassLoader loader = ClassPathTest.class.getClassLoader(); // directory with a cycle, // /root @@ -274,6 +288,9 @@ public void testScanFromFile_notJarFile() throws IOException { } public void testGetClassPathEntry() throws MalformedURLException, URISyntaxException { + if (isWindows()) { + return; // TODO: b/136041958 - We need to account for drive letters in the path. + } assertEquals( new File("/usr/test/dep.jar").toURI(), ClassPath.getClassPathEntry(new File("/home/build/outer.jar"), "file:/usr/test/dep.jar") @@ -344,6 +361,9 @@ public void testGetClassPathFromManifest_jarInCurrentDirectory() throws IOExcept } public void testGetClassPathFromManifest_absoluteDirectory() throws IOException { + if (isWindows()) { + return; // TODO: b/136041958 - We need to account for drive letters in the path. + } File jarFile = new File("base/some.jar"); Manifest manifest = manifestClasspath("file:/with/absolute/dir"); assertThat(ClassPath.getClassPathFromManifest(jarFile, manifest)) @@ -351,6 +371,9 @@ public void testGetClassPathFromManifest_absoluteDirectory() throws IOException } public void testGetClassPathFromManifest_absoluteJar() throws IOException { + if (isWindows()) { + return; // TODO: b/136041958 - We need to account for drive letters in the path. + } File jarFile = new File("base/some.jar"); Manifest manifest = manifestClasspath("file:/with/absolute.jar"); assertThat(ClassPath.getClassPathFromManifest(jarFile, manifest)) @@ -358,6 +381,9 @@ public void testGetClassPathFromManifest_absoluteJar() throws IOException { } public void testGetClassPathFromManifest_multiplePaths() throws IOException { + if (isWindows()) { + return; // TODO: b/136041958 - We need to account for drive letters in the path. + } File jarFile = new File("base/some.jar"); Manifest manifest = manifestClasspath("file:/with/absolute.jar relative.jar relative/dir"); assertThat(ClassPath.getClassPathFromManifest(jarFile, manifest)) @@ -414,6 +440,9 @@ public void testGetPackageName() { public void testGetClassPathUrls() throws Exception { + if (isWindows()) { + return; // TODO: b/136041958 - We need to account for drive letters in the path. + } String oldPathSeparator = PATH_SEPARATOR.value(); String oldClassPath = JAVA_CLASS_PATH.value(); System.setProperty(PATH_SEPARATOR.key(), ":"); @@ -640,4 +669,8 @@ private static ImmutableSet scanResourceNames(ClassLoader loader) throws } return builder.build(); } + + private static boolean isWindows() { + return OS_NAME.value().startsWith("Windows"); + } } diff --git a/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java b/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java index 0ed399b726ad..5a28ff1f9724 100644 --- a/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java +++ b/guava-tests/test/com/google/common/util/concurrent/AbstractFutureTest.java @@ -17,6 +17,7 @@ package com.google.common.util.concurrent; import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION; +import static com.google.common.base.StandardSystemProperty.OS_NAME; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; @@ -217,6 +218,9 @@ public void testToString_allUnique() throws Exception { } public void testToString_oom() throws Exception { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } SettableFuture future = SettableFuture.create(); future.set( new Object() { @@ -296,6 +300,9 @@ public String pendingToString() { @SuppressWarnings({"DeprecatedThreadMethods", "ThreadPriorityCheck"}) @AndroidIncompatible // Thread.suspend public void testToString_delayedTimeout() throws Exception { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } Integer javaVersion = Ints.tryParse(JAVA_SPECIFICATION_VERSION.value()); // Parsing to an integer might fail because Java 8 returns "1.8" instead of "8." // We can continue if it's 1.8, and we can continue if it's an integer in [9, 20). @@ -385,6 +392,9 @@ public String pendingToString() { } public void testCompletionFinishesWithDone() { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } ExecutorService executor = Executors.newFixedThreadPool(10); for (int i = 0; i < 50000; i++) { final AbstractFuture future = new AbstractFuture() {}; @@ -436,6 +446,9 @@ public void run() { */ public void testFutureBash() { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } final CyclicBarrier barrier = new CyclicBarrier( 6 // for the setter threads @@ -617,6 +630,9 @@ public void run() { // setFuture and cancel() interact in more complicated ways than the other setters. public void testSetFutureCancelBash() { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } final int size = 50; final CyclicBarrier barrier = new CyclicBarrier( @@ -752,6 +768,9 @@ public void run() { // Test to ensure that when calling setFuture with a done future only setFuture or cancel can // return true. public void testSetFutureCancelBash_withDoneFuture() { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } final CyclicBarrier barrier = new CyclicBarrier( 2 // for the setter threads @@ -835,6 +854,9 @@ public void run() { // In a previous implementation this would cause a stack overflow after ~2000 futures chained // together. Now it should only be limited by available memory (and time) public void testSetFuture_stackOverflow() { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } SettableFuture orig = SettableFuture.create(); SettableFuture prev = orig; for (int i = 0; i < 100000; i++) { @@ -852,6 +874,9 @@ public void testSetFuture_stackOverflow() { @GwtIncompatible @AndroidIncompatible public void testSetFutureToString_stackOverflow() { + if (isWindows()) { + return; // TODO: b/136041958 - Some tests in this file are slow, but I'm not sure which. + } SettableFuture orig = SettableFuture.create(); SettableFuture prev = orig; for (int i = 0; i < 100000; i++) { @@ -1325,4 +1350,8 @@ protected void interruptTask() { interruptTaskWasCalled = true; } } + + private static boolean isWindows() { + return OS_NAME.value().startsWith("Windows"); + } }