Replace more uses of FsApparatus with Scratch.
--
MOS_MIGRATED_REVID=91980878
diff --git a/src/test/java/com/google/devtools/build/lib/events/EventTestTemplate.java b/src/test/java/com/google/devtools/build/lib/events/EventTestTemplate.java
index b956112..6f0f8fe 100644
--- a/src/test/java/com/google/devtools/build/lib/events/EventTestTemplate.java
+++ b/src/test/java/com/google/devtools/build/lib/events/EventTestTemplate.java
@@ -14,8 +14,8 @@
package com.google.devtools.build.lib.events;
import com.google.devtools.build.lib.events.Location.LineAndColumn;
+import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.util.FsApparatus;
import org.junit.Before;
@@ -27,12 +27,12 @@
protected Location locationNoPath;
protected Location locationNoLineInfo;
- private FsApparatus scratch = FsApparatus.newInMemory();
+ private Scratch scratch = new Scratch();
@Before
public void setUp() throws Exception {
String message = "This is not an error message.";
- path = scratch.path("/path/to/workspace/my/sample/path.txt");
+ path = scratch.resolve("/path/to/workspace/my/sample/path.txt");
location = Location.fromPathAndStartColumn(path, 21, 31, new LineAndColumn(3, 4));
@@ -42,5 +42,4 @@
locationNoLineInfo = Location.fromFileAndOffsets(path, 21, 31);
}
-
}
diff --git a/src/test/java/com/google/devtools/build/lib/events/ReporterTest.java b/src/test/java/com/google/devtools/build/lib/events/ReporterTest.java
index 0a248c6..feae83b 100644
--- a/src/test/java/com/google/devtools/build/lib/events/ReporterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/events/ReporterTest.java
@@ -33,6 +33,7 @@
private StringBuilder out;
private AbstractEventHandler outAppender;
+ @Override
@Before
public void setUp() throws Exception {
super.setUp();
diff --git a/src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java b/src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java
index deed44f..8d8adf6 100644
--- a/src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java
+++ b/src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java
@@ -34,7 +34,6 @@
public void handle(Event event) {
handlerCount++;
}
-
};
Reporter reporter = new Reporter(handler);
@@ -43,5 +42,4 @@
reporter.handle(new Event(EventKind.INFO, location, "Add to handlerCount."));
assertEquals(3, handlerCount);
}
-
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java b/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
index 5a1eaad..97d3a5f 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java
@@ -26,8 +26,8 @@
import com.google.devtools.build.lib.events.util.EventCollectionApparatus;
import com.google.devtools.build.lib.packages.CachingPackageLocator;
import com.google.devtools.build.lib.testutil.JunitTestUtils;
+import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.util.FsApparatus;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -39,14 +39,14 @@
@RunWith(JUnit4.class)
public class BuildFileASTTest {
- private FsApparatus scratch = FsApparatus.newInMemory();
+ private Scratch scratch = new Scratch();
private EventCollectionApparatus events = new EventCollectionApparatus(EventKind.ALL_EVENTS);
private class ScratchPathPackageLocator implements CachingPackageLocator {
@Override
public Path getBuildFileForPackage(String packageName) {
- return scratch.path(packageName).getRelative("BUILD");
+ return scratch.resolve(packageName).getRelative("BUILD");
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java b/src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java
index 8ec4e52..9215c9c 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java
@@ -22,8 +22,8 @@
import com.google.devtools.build.lib.events.EventKind;
import com.google.devtools.build.lib.events.Location;
import com.google.devtools.build.lib.events.Reporter;
+import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.util.FsApparatus;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -36,14 +36,13 @@
public class LexerTest {
private String lastError;
private Location lastErrorLocation;
- private FsApparatus scratch = FsApparatus.newInMemory();
/**
* Create a lexer which takes input from the specified string. Resets the
* error handler beforehand.
*/
private Lexer createLexer(String input) {
- Path somePath = scratch.path("/some/path.txt");
+ Path somePath = new Scratch().resolve("/some/path.txt");
ParserInputSource inputSource = ParserInputSource.create(input, somePath);
Reporter reporter = new Reporter();
reporter.addHandler(new EventHandler() {
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java b/src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java
index 5feb9d3..963cf25 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java
@@ -16,8 +16,8 @@
import static org.junit.Assert.assertEquals;
import com.google.devtools.build.lib.events.Location.LineAndColumn;
+import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.util.Pair;
-import com.google.devtools.build.lib.vfs.util.FsApparatus;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -28,11 +28,9 @@
*/
@RunWith(JUnit4.class)
public class LineNumberTableTest {
- private FsApparatus scratch = FsApparatus.newInMemory();
-
private LineNumberTable create(String buffer) {
return LineNumberTable.create(buffer.toCharArray(),
- scratch.path("/fake/file"));
+ new Scratch().resolve("/fake/file"));
}
@Test
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java
index 895e7fb..b1edbab 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java
@@ -18,8 +18,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
+import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.util.FsApparatus;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -28,6 +28,7 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
/**
* A test case for {@link ParserInputSource}.
@@ -35,12 +36,12 @@
@RunWith(JUnit4.class)
public class ParserInputSourceTest {
- private FsApparatus scratch = FsApparatus.newInMemory();
+ private Scratch scratch = new Scratch();
@Test
public void testCreateFromFile() throws IOException {
String content = joinLines("Line 1", "Line 2", "Line 3", "");
- Path file = scratch.file("/tmp/my/file.txt", content);
+ Path file = scratch.file("/tmp/my/file.txt", content.getBytes(StandardCharsets.UTF_8));
ParserInputSource input = ParserInputSource.create(file);
assertEquals(content, new String(input.getContent()));
assertEquals("/tmp/my/file.txt", input.getPath().toString());
@@ -50,7 +51,7 @@
public void testCreateFromString() {
String content = "Content provided as a string.";
String pathName = "/the/name/of/the/content.txt";
- Path path = scratch.path(pathName);
+ Path path = scratch.resolve(pathName);
ParserInputSource input = ParserInputSource.create(content, path);
assertEquals(content, new String(input.getContent()));
assertEquals(pathName, input.getPath().toString());
@@ -60,7 +61,7 @@
public void testCreateFromCharArray() {
String content = "Content provided as a string.";
String pathName = "/the/name/of/the/content.txt";
- Path path = scratch.path(pathName);
+ Path path = scratch.resolve(pathName);
char[] contentChars = content.toCharArray();
ParserInputSource input = ParserInputSource.create(contentChars, path);
assertEquals(content, new String(input.getContent()));
@@ -73,7 +74,7 @@
byte[] bytes = content.getBytes("ISO-8859-1");
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
String pathName = "/the/name/of/the/content.txt";
- Path path = scratch.path(pathName);
+ Path path = scratch.resolve(pathName);
ParserInputSource input = ParserInputSource.create(in, path);
assertEquals(content, new String(input.getContent()));
assertEquals(pathName, input.getPath().toString());
@@ -82,7 +83,7 @@
@Test
public void testIOExceptionIfInputFileDoesNotExistForSingleArgConstructor() {
try {
- Path path = scratch.path("/does/not/exist");
+ Path path = scratch.resolve("/does/not/exist");
ParserInputSource.create(path);
fail();
} catch (IOException e) {
@@ -93,13 +94,13 @@
@Test
public void testWillNotTryToReadInputFileIfContentProvidedAsString() {
- Path path = scratch.path("/will/not/try/to/read");
+ Path path = scratch.resolve("/will/not/try/to/read");
ParserInputSource.create("Content provided as string.", path);
}
@Test
public void testWillNotTryToReadInputFileIfContentProvidedAsChars() {
- Path path = scratch.path("/will/not/try/to/read");
+ Path path = scratch.resolve("/will/not/try/to/read");
char[] content = "Content provided as char array.".toCharArray();
ParserInputSource.create(content, path);
}
@@ -118,7 +119,7 @@
}
};
try {
- Path path = scratch.path("/will/not/try/to/read");
+ Path path = scratch.resolve("/will/not/try/to/read");
ParserInputSource.create(in, path);
fail();
} catch (IOException e) {
diff --git a/src/test/java/com/google/devtools/build/lib/util/DependencySetTest.java b/src/test/java/com/google/devtools/build/lib/util/DependencySetTest.java
index 40edf36..6bda566 100644
--- a/src/test/java/com/google/devtools/build/lib/util/DependencySetTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/DependencySetTest.java
@@ -18,10 +18,10 @@
import com.google.common.collect.Sets;
import com.google.devtools.build.lib.testutil.MoreAsserts;
+import com.google.devtools.build.lib.testutil.Scratch;
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.util.FsApparatus;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -32,10 +32,10 @@
@RunWith(JUnit4.class)
public class DependencySetTest {
- private FsApparatus scratch = FsApparatus.newInMemory();
+ private Scratch scratch = new Scratch();
private DependencySet newDependencySet() {
- return new DependencySet(scratch.fs().getRootDirectory());
+ return new DependencySet(scratch.resolve("/"));
}
@Test
@@ -190,8 +190,8 @@
depSet1.addDependency(file3);
depSet1.setOutputFileName(filename);
- Path outfile = scratch.path(filename);
- Path dotd = scratch.path("/usr/local/blah/blah/genhello/hello.d");
+ Path outfile = scratch.resolve(filename);
+ Path dotd = scratch.resolve("/usr/local/blah/blah/genhello/hello.d");
FileSystemUtils.createDirectoryAndParents(dotd.getParentDirectory());
depSet1.write(outfile, ".d");
@@ -217,7 +217,7 @@
depSet1.addDependency(file3);
depSet1.setOutputFileName(filename);
- Path dotd = scratch.path(filename);
+ Path dotd = scratch.resolve(filename);
FileSystemUtils.createDirectoryAndParents(dotd.getParentDirectory());
depSet1.write(dotd, ".d");
diff --git a/src/test/java/com/google/devtools/build/lib/util/DependencySetWindowsTest.java b/src/test/java/com/google/devtools/build/lib/util/DependencySetWindowsTest.java
index cdda6d1..97ab444 100644
--- a/src/test/java/com/google/devtools/build/lib/util/DependencySetWindowsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/DependencySetWindowsTest.java
@@ -15,9 +15,9 @@
import com.google.common.collect.Sets;
import com.google.devtools.build.lib.testutil.MoreAsserts;
+import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
-import com.google.devtools.build.lib.vfs.util.FsApparatus;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -28,10 +28,10 @@
@RunWith(JUnit4.class)
public class DependencySetWindowsTest {
- private FsApparatus scratch = FsApparatus.newInMemory();
+ private Scratch scratch = new Scratch();
private DependencySet newDependencySet() {
- return new DependencySet(scratch.fs().getRootDirectory());
+ return new DependencySet(scratch.resolve("/"));
}
@Test
@@ -86,5 +86,4 @@
MoreAsserts.assertSameContents(expected,
newDependencySet().read(dotd).getDependencies());
}
-
}
diff --git a/src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java b/src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java
index 2e246c8..675fa2a 100644
--- a/src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java
+++ b/src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java
@@ -18,8 +18,8 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
-import com.google.devtools.build.lib.vfs.util.FsApparatus;
import org.junit.Before;
import org.junit.Test;
@@ -75,7 +75,7 @@
}
}
- private FsApparatus scratch = FsApparatus.newInMemory();
+ private Scratch scratch = new Scratch();
private PersistentStringMap map;
private Path mapFile;
@@ -83,8 +83,8 @@
@Before
public void setUp() throws Exception {
- mapFile = scratch.fs().getPath("/tmp/map.txt");
- journalFile = scratch.fs().getPath("/tmp/journal.txt");
+ mapFile = scratch.resolve("/tmp/map.txt");
+ journalFile = scratch.resolve("/tmp/journal.txt");
createMap();
}