From d4a21a76ff144897f51e16b58e2b6fa94e2aecf9 Mon Sep 17 00:00:00 2001 From: Masaya Suzuki Date: Sun, 23 Dec 2018 16:43:54 -0800 Subject: [PATCH] Skip some tests when the runtime cannot handle Unicode file paths When executing a test with LANG environment variable set to non UTF-8 encoding, it seems that JRE cannot handle Unicode file paths. This happens when this test is executed in Bazel as it unsets LANG (https://docs.bazel.build/versions/master/test-encyclopedia.html#initial-conditions). Skip the test if the runtime cannot handle Unicode file paths. Change-Id: I16bd3cd959dbaf2335b9c5202873e2f12ed0ba21 Signed-off-by: Masaya Suzuki --- .../jgit/treewalk/FileTreeIteratorTest.java | 20 +++++++++- .../tst/org/eclipse/jgit/util/FSTest.java | 39 ++++++++++++++++--- 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java index 33e32cd813..6f61912f2b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java @@ -48,9 +48,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeNoException; import java.io.File; import java.io.IOException; +import java.nio.file.InvalidPathException; import java.security.MessageDigest; import org.eclipse.jgit.api.Git; @@ -666,9 +668,23 @@ public class FileTreeIteratorTest extends RepositoryTestCase { public void testFileModeSymLinkIsNotATree() throws IOException { org.junit.Assume.assumeTrue(FS.DETECTED.supportsSymlinks()); FS fs = db.getFS(); - // mål = target in swedish, just to get som unicode in here + // mål = target in swedish, just to get some unicode in here writeTrashFile("mål/data", "targetdata"); - fs.createSymLink(new File(trash, "länk"), "mål"); + File file = new File(trash, "länk"); + + try { + file.toPath(); + } catch (InvalidPathException e) { + // When executing a test with LANG environment variable set to non + // UTF-8 encoding, it seems that JRE cannot handle Unicode file + // paths. This happens when this test is executed in Bazel as it + // unsets LANG + // (https://docs.bazel.build/versions/master/test-encyclopedia.html#initial-conditions). + // Skip the test if the runtime cannot handle Unicode characters. + assumeNoException(e); + } + + fs.createSymLink(file, "mål"); FileTreeIterator fti = new FileTreeIterator(db); assertFalse(fti.eof()); while (!fti.getEntryPathString().equals("länk")) { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java index 2c8273d03c..5293ca466a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java @@ -47,11 +47,13 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeNoException; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; +import java.nio.file.InvalidPathException; import java.nio.file.attribute.PosixFileAttributeView; import java.nio.file.attribute.PosixFilePermission; import java.util.Set; @@ -92,16 +94,17 @@ public class FSTest { public void testSymlinkAttributes() throws IOException, InterruptedException { Assume.assumeTrue(FS.DETECTED.supportsSymlinks()); FS fs = FS.DETECTED; - File link = new File(trash, "ä"); - File target = new File(trash, "å"); - fs.createSymLink(link, "å"); + File link = new File(trash, "a"); + File target = new File(trash, "b"); + fs.createSymLink(link, "b"); assertTrue(fs.exists(link)); String targetName = fs.readSymLink(link); - assertEquals("å", targetName); + assertEquals("b", targetName); assertTrue(fs.lastModified(link) > 0); assertTrue(fs.exists(link)); assertFalse(fs.canExecute(link)); - assertEquals(2, fs.length(link)); + // The length of a symbolic link is a length of the target file path. + assertEquals(1, fs.length(link)); assertFalse(fs.exists(target)); assertFalse(fs.isFile(target)); assertFalse(fs.isDirectory(target)); @@ -120,6 +123,32 @@ public class FSTest { assertTrue(fs.canExecute(target)); } + @Test + public void testUnicodeFilePath() throws IOException { + Assume.assumeTrue(FS.DETECTED.supportsSymlinks()); + FS fs = FS.DETECTED; + File link = new File(trash, "ä"); + File target = new File(trash, "å"); + + try { + // Check if the runtime can support Unicode file paths. + link.toPath(); + target.toPath(); + } catch (InvalidPathException e) { + // When executing a test with LANG environment variable set to non + // UTF-8 encoding, it seems that JRE cannot handle Unicode file + // paths. This happens when this test is executed in Bazel as it + // unsets LANG + // (https://docs.bazel.build/versions/master/test-encyclopedia.html#initial-conditions). + // Skip the test if the runtime cannot handle Unicode characters. + assumeNoException(e); + } + + fs.createSymLink(link, "å"); + assertTrue(fs.exists(link)); + assertEquals("å", fs.readSymLink(link)); + } + @Test public void testExecutableAttributes() throws Exception { FS fs = FS.DETECTED.newInstance(); -- 2.39.5