aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2015-04-24 14:30:01 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-04-27 18:46:42 +0000
commitbdd9c1f4c634302b85915856a961ae5975d81ec0 (patch)
treee6fbd5f1cc4af0491238397c237925f7a24f568c /src/test/java/com/google
parent8f17429a60e37db8d93fffa700a64574f4b72687 (diff)
Replace more uses of FsApparatus with Scratch.
-- MOS_MIGRATED_REVID=91980878
Diffstat (limited to 'src/test/java/com/google')
-rw-r--r--src/test/java/com/google/devtools/build/lib/events/EventTestTemplate.java7
-rw-r--r--src/test/java/com/google/devtools/build/lib/events/ReporterTest.java1
-rw-r--r--src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java2
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/BuildFileASTTest.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/LexerTest.java5
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/LineNumberTableTest.java6
-rw-r--r--src/test/java/com/google/devtools/build/lib/syntax/ParserInputSourceTest.java21
-rw-r--r--src/test/java/com/google/devtools/build/lib/util/DependencySetTest.java12
-rw-r--r--src/test/java/com/google/devtools/build/lib/util/DependencySetWindowsTest.java7
-rw-r--r--src/test/java/com/google/devtools/build/lib/util/PersistentMapTest.java8
10 files changed, 35 insertions, 40 deletions
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 b9561125fa..6f0f8fef7c 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 @@ public abstract class EventTestTemplate {
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 @@ public abstract class EventTestTemplate {
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 0a248c6659..feae83b15d 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 @@ public class ReporterTest extends EventTestTemplate {
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 deed44f652..8d8adf6a84 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 class SimpleReportersTest extends EventTestTemplate {
public void handle(Event event) {
handlerCount++;
}
-
};
Reporter reporter = new Reporter(handler);
@@ -43,5 +42,4 @@ public class SimpleReportersTest extends EventTestTemplate {
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 5a1eaad14b..97d3a5f1fd 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.Reporter;
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 @@ import java.util.Arrays;
@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 8ec4e52fb3..9215c9cc79 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.EventHandler;
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 @@ import org.junit.runners.JUnit4;
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 5feb9d335a..963cf25672 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 @@ package com.google.devtools.build.lib.syntax;
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 @@ import org.junit.runners.JUnit4;
*/
@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 895e7fbbc8..b1edbab426 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 com.google.devtools.build.lib.util.StringUtilities.joinLines;
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 org.junit.runners.JUnit4;
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 @@ import java.io.InputStream;
@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 class ParserInputSourceTest {
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 class ParserInputSourceTest {
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 @@ public class ParserInputSourceTest {
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 @@ public class ParserInputSourceTest {
@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 @@ public class ParserInputSourceTest {
@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 @@ public class ParserInputSourceTest {
}
};
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 40edf36b03..6bda56635d 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 static org.junit.Assert.fail;
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 @@ import java.util.Collection;
@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 @@ public class DependencySetTest {
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 @@ public class DependencySetTest {
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 cdda6d182b..97ab444d08 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 @@ package com.google.devtools.build.lib.util;
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 @@ import java.util.Set;
@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 @@ public class DependencySetWindowsTest {
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 2e246c89b0..675fa2af0d 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.assertEquals;
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 @@ public class PersistentMapTest {
}
}
- private FsApparatus scratch = FsApparatus.newInMemory();
+ private Scratch scratch = new Scratch();
private PersistentStringMap map;
private Path mapFile;
@@ -83,8 +83,8 @@ public class PersistentMapTest {
@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();
}