aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2015-04-09 17:02:08 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2015-04-09 17:26:42 +0000
commitf5845bd11b8f4e13802cd74793939eb530d005b6 (patch)
tree9e047ff728a86ff341365f04b2ca98a4302e5415 /src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java
parentc2b7b8db59676d3666b6bd95a22d72eaa73d4262 (diff)
Allow relative paths for the scratch* methods; resolve relative to workspace.
This allows removing most /[]/ prefixes from all output file names in all tests that inherit from FoundationTestCase; that, in turn, allows us to switch the workspace root to a neutral name, such as /workspace/. -- MOS_MIGRATED_REVID=90720852
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java')
-rw-r--r--src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java b/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java
index 15d4c43f94..56773d4dac 100644
--- a/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/testutil/FoundationTestCase.java
@@ -140,14 +140,20 @@ public abstract class FoundationTestCase extends TestCase {
return scratch.getFileSystem();
}
+ private String workspaceRelative(String pathName) {
+ if (!pathName.startsWith("/")) {
+ return "/" + TestConstants.TEST_WORKSPACE_DIRECTORY + "/" + pathName;
+ }
+ return pathName;
+ }
+
/**
* Create a scratch file in the scratch filesystem, with the given pathName,
* consisting of a set of lines. The method returns a Path instance for the
* scratch file.
*/
- protected Path scratchFile(String pathName, String... lines)
- throws IOException {
- return scratch.file(pathName, lines);
+ protected Path scratchFile(String pathName, String... lines) throws IOException {
+ return scratch.file(workspaceRelative(pathName), lines);
}
/**
@@ -155,7 +161,7 @@ public abstract class FoundationTestCase extends TestCase {
* exists.
*/
protected Path overwriteScratchFile(String pathName, String... lines) throws IOException {
- return scratch.overwriteFile(pathName, lines);
+ return scratch.overwriteFile(workspaceRelative(pathName), lines);
}
/**
@@ -165,7 +171,7 @@ public abstract class FoundationTestCase extends TestCase {
*/
protected Path scratchFile(FileSystem fs, String pathName, String... lines)
throws IOException {
- return scratch.file(fs, pathName, lines);
+ return scratch.file(fs, workspaceRelative(pathName), lines);
}
/**
@@ -175,7 +181,16 @@ public abstract class FoundationTestCase extends TestCase {
*/
protected Path scratchFile(FileSystem fs, String pathName, byte[] content)
throws IOException {
- return scratch.file(fs, pathName, content);
+ return scratch.file(fs, workspaceRelative(pathName), content);
+ }
+
+ /**
+ * Create a scratch file in the scratch filesystem, with the given pathName,
+ * consisting of a set of lines. The method returns a Path instance for the
+ * scratch file.
+ */
+ protected void deleteFile(String pathName) throws IOException {
+ scratch.deleteFile(workspaceRelative(pathName));
}
// Mix-in assertions: