From 4ce0d8800f1aaabe82f7a61faf1d5609b69c38cf Mon Sep 17 00:00:00 2001 From: Ulf Adams Date: Fri, 24 Apr 2015 16:10:16 +0000 Subject: Inline/remove some calls to FoundationTestCase.scratchFS(). -- MOS_MIGRATED_REVID=91987064 --- .../google/devtools/build/lib/analysis/RunfilesTest.java | 10 +++++----- .../analysis/actions/TemplateExpansionActionTest.java | 16 ++++++++-------- .../lib/analysis/config/BuildConfigurationTest.java | 2 +- .../com/google/devtools/build/lib/testutil/Scratch.java | 10 ++++++++++ 4 files changed, 24 insertions(+), 14 deletions(-) (limited to 'src/test/java/com/google/devtools') diff --git a/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java b/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java index 107b6fcbca..ca521ea8d5 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java @@ -41,7 +41,7 @@ public class RunfilesTest extends FoundationTestCase { public void testFilterListForObscuringSymlinksCatchesBadObscurer() throws Exception { Map obscuringMap = new HashMap<>(); PathFragment pathA = new PathFragment("a"); - Root root = Root.asSourceRoot(scratchFS().getPath("/workspace")); + Root root = Root.asSourceRoot(scratch.resolve("/workspace")); Artifact artifactA = new Artifact(new PathFragment("a"), root); obscuringMap.put(pathA, artifactA); obscuringMap.put(new PathFragment("a/b"), new Artifact(new PathFragment("c/b"), @@ -54,7 +54,7 @@ public class RunfilesTest extends FoundationTestCase { public void testFilterListForObscuringSymlinksCatchesBadGrandParentObscurer() throws Exception { Map obscuringMap = new HashMap<>(); PathFragment pathA = new PathFragment("a"); - Root root = Root.asSourceRoot(scratchFS().getPath("/workspace")); + Root root = Root.asSourceRoot(scratch.resolve("/workspace")); Artifact artifactA = new Artifact(new PathFragment("a"), root); obscuringMap.put(pathA, artifactA); @@ -68,7 +68,7 @@ public class RunfilesTest extends FoundationTestCase { public void testFilterListForObscuringSymlinksCatchesBadObscurerNoListener() throws Exception { Map obscuringMap = new HashMap<>(); PathFragment pathA = new PathFragment("a"); - Root root = Root.asSourceRoot(scratchFS().getPath("/workspace")); + Root root = Root.asSourceRoot(scratch.resolve("/workspace")); Artifact artifactA = new Artifact(new PathFragment("a"), root); obscuringMap.put(pathA, artifactA); @@ -81,7 +81,7 @@ public class RunfilesTest extends FoundationTestCase { public void testFilterListForObscuringSymlinksIgnoresOkObscurer() throws Exception { Map obscuringMap = new HashMap<>(); PathFragment pathA = new PathFragment("a"); - Root root = Root.asSourceRoot(scratchFS().getPath("/workspace")); + Root root = Root.asSourceRoot(scratch.resolve("/workspace")); Artifact artifactA = new Artifact(new PathFragment("a"), root); obscuringMap.put(pathA, artifactA); @@ -96,7 +96,7 @@ public class RunfilesTest extends FoundationTestCase { public void testFilterListForObscuringSymlinksNoObscurers() throws Exception { Map obscuringMap = new HashMap<>(); PathFragment pathA = new PathFragment("a"); - Root root = Root.asSourceRoot(scratchFS().getPath("/workspace")); + Root root = Root.asSourceRoot(scratch.resolve("/workspace")); Artifact artifactA = new Artifact(new PathFragment("a"), root); obscuringMap.put(pathA, artifactA); diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java index 0dd7fff710..112e4b17d2 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java @@ -58,15 +58,15 @@ public class TemplateExpansionActionTest extends FoundationTestCase { outputRoot = Root.asDerivedRoot(scratch.dir("/workspace"), scratch.dir("/workspace/out")); Path input = scratchFile("/workspace/input.txt", TEMPLATE); inputArtifact = new Artifact(input, workspace); - output = scratchFS().getPath("/workspace/out/destination.txt"); + output = scratch.resolve("/workspace/out/destination.txt"); outputArtifact = new Artifact(output, outputRoot); substitutions = Lists.newArrayList(); substitutions.add(Substitution.of("%key%", "foo")); substitutions.add(Substitution.of("%value%", "bar")); directories = new BlazeDirectories( - scratchFS().getPath("/install"), - scratchFS().getPath("/base"), - scratchFS().getPath("/workspace")); + scratch.resolve("/install"), + scratch.resolve("/base"), + scratch.resolve("/workspace")); binTools = BinTools.empty(directories); } @@ -93,7 +93,7 @@ public class TemplateExpansionActionTest extends FoundationTestCase { } public void testKeySameIfSame() throws Exception { - Artifact outputArtifact2 = new Artifact(scratchFS().getPath("/workspace/out/destination.txt"), + Artifact outputArtifact2 = new Artifact(scratch.resolve("/workspace/out/destination.txt"), outputRoot); TemplateExpansionAction a = new TemplateExpansionAction(NULL_ACTION_OWNER, outputArtifact, Template.forString(TEMPLATE), @@ -105,7 +105,7 @@ public class TemplateExpansionActionTest extends FoundationTestCase { } public void testKeyDiffersForSubstitution() throws Exception { - Artifact outputArtifact2 = new Artifact(scratchFS().getPath("/workspace/out/destination.txt"), + Artifact outputArtifact2 = new Artifact(scratch.resolve("/workspace/out/destination.txt"), outputRoot); TemplateExpansionAction a = new TemplateExpansionAction(NULL_ACTION_OWNER, outputArtifact, Template.forString(TEMPLATE), @@ -117,7 +117,7 @@ public class TemplateExpansionActionTest extends FoundationTestCase { } public void testKeyDiffersForExecutable() throws Exception { - Artifact outputArtifact2 = new Artifact(scratchFS().getPath("/workspace/out/destination.txt"), + Artifact outputArtifact2 = new Artifact(scratch.resolve("/workspace/out/destination.txt"), outputRoot); TemplateExpansionAction a = new TemplateExpansionAction(NULL_ACTION_OWNER, outputArtifact, Template.forString(TEMPLATE), @@ -129,7 +129,7 @@ public class TemplateExpansionActionTest extends FoundationTestCase { } public void testKeyDiffersForTemplates() throws Exception { - Artifact outputArtifact2 = new Artifact(scratchFS().getPath("/workspace/out/destination.txt"), + Artifact outputArtifact2 = new Artifact(scratch.resolve("/workspace/out/destination.txt"), outputRoot); TemplateExpansionAction a = new TemplateExpansionAction(NULL_ACTION_OWNER, outputArtifact, Template.forString(TEMPLATE), diff --git a/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationTest.java b/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationTest.java index ebe3fa3819..46c7009b51 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationTest.java @@ -283,7 +283,7 @@ public class BuildConfigurationTest extends ConfigurationTestCase { public void testSerialization() throws Exception { FileSystem oldFileSystem = Path.getFileSystemForSerialization(); try { - Path.setFileSystemForSerialization(scratchFS()); + Path.setFileSystemForSerialization(scratch.getFileSystem()); TestUtils.serializeObject(createCollection()); } finally { Path.setFileSystemForSerialization(oldFileSystem); diff --git a/src/test/java/com/google/devtools/build/lib/testutil/Scratch.java b/src/test/java/com/google/devtools/build/lib/testutil/Scratch.java index f5785a342f..0d1f0818df 100644 --- a/src/test/java/com/google/devtools/build/lib/testutil/Scratch.java +++ b/src/test/java/com/google/devtools/build/lib/testutil/Scratch.java @@ -18,6 +18,7 @@ import com.google.devtools.build.lib.util.BlazeClock; import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; +import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import java.io.IOException; @@ -87,6 +88,15 @@ public final class Scratch { return workingDir.getRelative(pathName); } + /** + * Resolves {@code pathName} relative to the working directory. Note that this will not create any + * entity in the filesystem; i.e., the file that the object is describing may not exist in the + * filesystem. + */ + public Path resolve(PathFragment pathName) { + return workingDir.getRelative(pathName); + } + /** * Create a directory in the scratch filesystem, with the given path name. */ -- cgit v1.2.3