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>
This commit is contained in:
Masaya Suzuki 2018-12-23 16:43:54 -08:00
parent 5138594c6e
commit d4a21a76ff
2 changed files with 52 additions and 7 deletions

View File

@ -48,9 +48,11 @@
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 void testCustomFileModeStrategyFromParentIterator() throws Exception {
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")) {

View File

@ -47,11 +47,13 @@
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 void tearDown() throws Exception {
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 void testSymlinkAttributes() throws IOException, InterruptedException {
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();