diff --git a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java index b2273a11d9a914..8006e15121d0fc 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java @@ -16,6 +16,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.TruthJUnit.assume; import static java.lang.Math.min; import static java.nio.charset.StandardCharsets.ISO_8859_1; import static java.nio.charset.StandardCharsets.UTF_8; @@ -44,6 +45,7 @@ import java.nio.channels.ReadableByteChannel; import java.nio.channels.SeekableByteChannel; import java.nio.channels.WritableByteChannel; +import java.nio.charset.Charset; import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.nio.file.attribute.PosixFilePermission; @@ -1981,6 +1983,8 @@ public void testGetNioPath_basic() { @Test public void testGetNioPath_externalUtf8() throws IOException { + assumeUtf8CompatibleEncoding(); + // Simulates a Starlark string constant, which is read from a presumably UTF-8 encoded source // file into Bazel's internal representation. Path utf8File = absolutize(StringEncoding.unicodeToInternal("some_dir/入力_A_🌱.txt")); @@ -1997,6 +2001,8 @@ public void testGetNioPath_externalUtf8() throws IOException { @Test public void testGetNioPath_internalUtf8() throws IOException { + assumeUtf8CompatibleEncoding(); + Path dirPath = absolutize("some_dir"); dirPath.createDirectoryAndParents(); @@ -2036,11 +2042,16 @@ protected java.nio.file.Path getJavaPathOrSkipIfUnsupported(Path path) { return javaPath; } - protected String unicodeToPlatform(String s) { + protected static String unicodeToPlatform(String s) { return StringEncoding.internalToPlatform(StringEncoding.unicodeToInternal(s)); } - protected String platformToUnicode(String s) { + protected static String platformToUnicode(String s) { return StringEncoding.internalToUnicode(StringEncoding.platformToInternal(s)); } + + protected static void assumeUtf8CompatibleEncoding() { + Charset sunJnuEncoding = Charset.forName(System.getProperty("sun.jnu.encoding")); + assume().that(ImmutableList.of(UTF_8, ISO_8859_1)).contains(sunJnuEncoding); + } } diff --git a/src/test/java/com/google/devtools/build/lib/vfs/SymlinkAwareFileSystemTest.java b/src/test/java/com/google/devtools/build/lib/vfs/SymlinkAwareFileSystemTest.java index bba6bc0ffe3e76..f6cf370ce8e721 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/SymlinkAwareFileSystemTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/SymlinkAwareFileSystemTest.java @@ -670,6 +670,8 @@ public void testCreatingFileInLinkedDirectory() throws Exception { @Test public void testUtf8Symlink() throws Exception { + assumeUtf8CompatibleEncoding(); + String target = StringEncoding.unicodeToInternal("入力_A_🌱.target"); Path link = absolutize(StringEncoding.unicodeToInternal("入力_A_🌱.txt")); createSymbolicLink(link, PathFragment.create(target));