aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasaya Suzuki <masayasuzuki@google.com>2018-12-23 16:43:54 -0800
committerMasaya Suzuki <masayasuzuki@google.com>2018-12-23 22:37:14 -0800
commitd4a21a76ff144897f51e16b58e2b6fa94e2aecf9 (patch)
treeb7b485d6af045b3d458b4e992d6d64b5778e71cb
parent5138594c6ed2231788d58949875aa7b4e5140eea (diff)
downloadjgit-d4a21a76ff144897f51e16b58e2b6fa94e2aecf9.tar.gz
jgit-d4a21a76ff144897f51e16b58e2b6fa94e2aecf9.zip
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 <masayasuzuki@google.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java20
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java39
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));
@@ -121,6 +124,32 @@ public class FSTest {
}
@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();
// If this assumption fails the test is halted and ignored.