diff options
author | 2018-01-09 13:46:29 -0800 | |
---|---|---|
committer | 2018-01-09 13:50:14 -0800 | |
commit | 7f17d08d5be04d1fc393958c9895747c9dc88b30 (patch) | |
tree | 2de1b6538ea5c6d6a0e014fdff2a07d94623ad2d /src/test/java | |
parent | 457a226f69ab56109fd5ec9163ac57181d715bda (diff) |
Automated rollback of commit cb7689404ef9a69488d64bfc2e0bfb9326e664d6.
*** Reason for rollback ***
Rolling forward after the underlying issue has been fixed.
*** Original change description ***
Automated rollback of commit 6a54339bb943702bd7dffc43f85267dac98dc355.
*** Reason for rollback ***
b/71442447
*** Original change description ***
Call through to Path#createDirectoryAndParents from FileUtils.
This CL removes a method that due to its implementation causes threading difficulties for Path#createDirectory.
The tests for the method are brought across to FileSystemTests since the methods are now implemented natively by the FileSystem classes. The tests were also cleaned up.
The test revealed an edge c...
***
PiperOrigin-RevId: 181367850
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/vfs/FileSystemTest.java | 56 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java | 51 |
2 files changed, 38 insertions, 69 deletions
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 ba4b4e8c57..e8896bbc0d 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 @@ -476,35 +476,21 @@ public abstract class FileSystemTest { } @Test - public void testCreateDirectories() throws Exception { + public void testCreateDirectoryAndParents() throws Exception { Path newPath = absolutize("new-dir/sub/directory"); newPath.createDirectoryAndParents(); assertThat(newPath.isDirectory()).isTrue(); } @Test - public void testCreateDirectoriesIsNotFile() throws Exception { - Path newPath = absolutize("new-dir/sub/directory"); - newPath.createDirectoryAndParents(); - assertThat(newPath.isFile()).isFalse(); - } - - @Test - public void testCreateDirectoriesIsNotSymbolicLink() throws Exception { - Path newPath = absolutize("new-dir/sub/directory"); - newPath.createDirectoryAndParents(); - assertThat(newPath.isSymbolicLink()).isFalse(); - } - - @Test - public void testCreateDirectoriesIsEmpty() throws Exception { + public void testCreateDirectoryAndParentsCreatesEmptyDirectory() throws Exception { Path newPath = absolutize("new-dir/sub/directory"); newPath.createDirectoryAndParents(); assertThat(newPath.getDirectoryEntries()).isEmpty(); } @Test - public void testCreateDirectoriesIsOnlyChildInParent() throws Exception { + public void testCreateDirectoryAndParentsIsOnlyChildInParent() throws Exception { Path newPath = absolutize("new-dir/sub/directory"); newPath.createDirectoryAndParents(); assertThat(newPath.getParentDirectory().getDirectoryEntries()).hasSize(1); @@ -512,7 +498,7 @@ public abstract class FileSystemTest { } @Test - public void testCreateAlreadyExistingDirectorySucceeds() throws Exception { + public void testCreateDirectoryAndParentsWhenAlreadyExistsSucceeds() throws Exception { Path newPath = absolutize("new-dir"); newPath.createDirectory(); newPath.createDirectoryAndParents(); @@ -520,6 +506,40 @@ public abstract class FileSystemTest { } @Test + public void testCreateDirectoryAndParentsWhenAncestorIsFile() throws IOException { + Path path = absolutize("somewhere/deep/in"); + path.getParentDirectory().createDirectoryAndParents(); + FileSystemUtils.createEmptyFile(path); + Path theHierarchy = path.getChild("the-hierarchy"); + MoreAsserts.assertThrows(IOException.class, theHierarchy::createDirectoryAndParents); + } + + @Test + public void testCreateDirectoryAndParentsWhenSymlinkToDir() throws IOException { + Path somewhereDeepIn = absolutize("somewhere/deep/in"); + somewhereDeepIn.createDirectoryAndParents(); + Path realDir = absolutize("real/dir"); + realDir.createDirectoryAndParents(); + assertThat(realDir.isDirectory()).isTrue(); + Path theHierarchy = somewhereDeepIn.getChild("the-hierarchy"); + theHierarchy.createSymbolicLink(realDir); + assertThat(theHierarchy.isDirectory()).isTrue(); + theHierarchy.createDirectoryAndParents(); + } + + @Test + public void testCreateDirectoryAndParentsWhenSymlinkEmbedded() throws IOException { + Path somewhereDeepIn = absolutize("somewhere/deep/in"); + somewhereDeepIn.createDirectoryAndParents(); + Path realDir = absolutize("real/dir"); + realDir.createDirectoryAndParents(); + Path the = somewhereDeepIn.getChild("the"); + the.createSymbolicLink(realDir); + Path theHierarchy = somewhereDeepIn.getChild("hierarchy"); + theHierarchy.createDirectoryAndParents(); + } + + @Test public void testCreateDirectoryAtFileFails() throws Exception { Path newPath = absolutize("file"); FileSystemUtils.createEmptyFile(newPath); diff --git a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java index 0e9b74ed3b..656363333e 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/FileSystemUtilsTest.java @@ -18,7 +18,6 @@ import static com.google.devtools.build.lib.vfs.FileSystemUtils.appendWithoutExt import static com.google.devtools.build.lib.vfs.FileSystemUtils.commonAncestor; import static com.google.devtools.build.lib.vfs.FileSystemUtils.copyFile; import static com.google.devtools.build.lib.vfs.FileSystemUtils.copyTool; -import static com.google.devtools.build.lib.vfs.FileSystemUtils.createDirectoryAndParents; import static com.google.devtools.build.lib.vfs.FileSystemUtils.deleteTree; import static com.google.devtools.build.lib.vfs.FileSystemUtils.moveFile; import static com.google.devtools.build.lib.vfs.FileSystemUtils.relativePath; @@ -645,56 +644,6 @@ public class FileSystemUtilsTest { } @Test - public void testCreateDirectories() throws IOException { - Path mainPath = fileSystem.getPath("/some/where/deep/in/the/hierarchy"); - assertThat(createDirectoryAndParents(mainPath)).isTrue(); - assertThat(mainPath.exists()).isTrue(); - assertThat(createDirectoryAndParents(mainPath)).isFalse(); - } - - @Test - public void testCreateDirectoriesWhenAncestorIsFile() throws IOException { - Path somewhereDeepIn = fileSystem.getPath("/somewhere/deep/in"); - assertThat(createDirectoryAndParents(somewhereDeepIn.getParentDirectory())).isTrue(); - FileSystemUtils.createEmptyFile(somewhereDeepIn); - Path theHierarchy = somewhereDeepIn.getChild("the-hierarchy"); - try { - createDirectoryAndParents(theHierarchy); - fail(); - } catch (IOException e) { - assertThat(e).hasMessage("/somewhere/deep/in (Not a directory)"); - } - } - - @Test - public void testCreateDirectoriesWhenSymlinkToDir() throws IOException { - Path somewhereDeepIn = fileSystem.getPath("/somewhere/deep/in"); - assertThat(createDirectoryAndParents(somewhereDeepIn)).isTrue(); - Path realDir = fileSystem.getPath("/real/dir"); - assertThat(createDirectoryAndParents(realDir)).isTrue(); - - Path theHierarchy = somewhereDeepIn.getChild("the-hierarchy"); - theHierarchy.createSymbolicLink(realDir); - - assertThat(createDirectoryAndParents(theHierarchy)).isFalse(); - } - - @Test - public void testCreateDirectoriesWhenSymlinkEmbedded() throws IOException { - Path somewhereDeepIn = fileSystem.getPath("/somewhere/deep/in"); - assertThat(createDirectoryAndParents(somewhereDeepIn)).isTrue(); - Path realDir = fileSystem.getPath("/real/dir"); - assertThat(createDirectoryAndParents(realDir)).isTrue(); - - Path the = somewhereDeepIn.getChild("the"); - the.createSymbolicLink(realDir); - - Path theHierarchy = somewhereDeepIn.getChild("hierarchy"); - assertThat(createDirectoryAndParents(theHierarchy)).isTrue(); - } - - - @Test public void testWriteIsoLatin1() throws Exception { Path file = fileSystem.getPath("/does/not/exist/yet.txt"); FileSystemUtils.writeIsoLatin1(file, "Line 1", "Line 2", "Line 3"); |