aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/pkgcache
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2017-12-14 12:51:10 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-14 12:53:23 -0800
commit82e68b75304438c96ff878a0c2b8d18b42002486 (patch)
tree0984b21536f07a5ab3a8ae62235201c58afb431b /src/test/java/com/google/devtools/build/lib/pkgcache
parentb5fd7611017f95e1303aa1f2c4a0a2962f2cc4eb (diff)
Make FileSystem operate on LocalPath instead of Path.
PiperOrigin-RevId: 179082062
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/pkgcache')
-rw-r--r--src/test/java/com/google/devtools/build/lib/pkgcache/IOExceptionsTest.java77
-rw-r--r--src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java12
-rw-r--r--src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorIOTest.java19
3 files changed, 59 insertions, 49 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/IOExceptionsTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/IOExceptionsTest.java
index 184f22201b..9f84f73a57 100644
--- a/src/test/java/com/google/devtools/build/lib/pkgcache/IOExceptionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/pkgcache/IOExceptionsTest.java
@@ -25,6 +25,7 @@ import com.google.devtools.build.lib.skyframe.TransitiveTargetKey;
import com.google.devtools.build.lib.skyframe.TransitiveTargetValue;
import com.google.devtools.build.lib.vfs.FileStatus;
import com.google.devtools.build.lib.vfs.FileSystem;
+import com.google.devtools.build.lib.vfs.LocalPath;
import com.google.devtools.build.lib.vfs.ModifiedFileSet;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -48,15 +49,16 @@ public class IOExceptionsTest extends PackageLoadingTestCase {
private static final String FS_ROOT = "/fsg";
- private static final Function<Path, String> NULL_FUNCTION = new Function<Path, String>() {
- @Override
- @Nullable
- public String apply(Path path) {
- return null;
- }
- };
+ private static final Function<LocalPath, String> NULL_FUNCTION =
+ new Function<LocalPath, String>() {
+ @Override
+ @Nullable
+ public String apply(LocalPath path) {
+ return null;
+ }
+ };
- private Function<Path, String> crashMessage = NULL_FUNCTION;
+ private Function<LocalPath, String> crashMessage = NULL_FUNCTION;
@Before
public final void initializeVisitor() throws Exception {
@@ -82,7 +84,7 @@ public class IOExceptionsTest extends PackageLoadingTestCase {
protected FileSystem createFileSystem() {
return new InMemoryFileSystem(BlazeClock.instance(), PathFragment.create(FS_ROOT)) {
@Override
- public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
+ public FileStatus stat(LocalPath path, boolean followSymlinks) throws IOException {
String crash = crashMessage.apply(path);
if (crash != null) {
throw new IOException(crash);
@@ -97,15 +99,16 @@ public class IOExceptionsTest extends PackageLoadingTestCase {
reporter.removeHandler(failFastHandler); // expect errors
final Path buildPath = scratch.file("pkg/BUILD",
"sh_library(name = 'x')");
- crashMessage = new Function<Path, String>() {
- @Override
- public String apply(Path path) {
- if (buildPath.equals(path)) {
- return "custom crash: " + buildPath;
- }
- return null;
- }
- };
+ crashMessage =
+ new Function<LocalPath, String>() {
+ @Override
+ public String apply(LocalPath path) {
+ if (buildPath.getLocalPath().equals(path)) {
+ return "custom crash: " + buildPath;
+ }
+ return null;
+ }
+ };
assertThat(visitTransitively(Label.parseAbsolute("//pkg:x"))).isFalse();
scratch.overwriteFile("pkg/BUILD",
"# another comment to force reload",
@@ -126,15 +129,16 @@ public class IOExceptionsTest extends PackageLoadingTestCase {
"sh_library(name = 'top', deps = ['//pkg:x'])");
final Path buildPath = scratch.file("pkg/BUILD",
"sh_library(name = 'x')");
- crashMessage = new Function<Path, String>() {
- @Override
- public String apply(Path path) {
- if (buildPath.equals(path)) {
- return "custom crash: " + buildPath;
- }
- return null;
- }
- };
+ crashMessage =
+ new Function<LocalPath, String>() {
+ @Override
+ public String apply(LocalPath path) {
+ if (buildPath.getLocalPath().equals(path)) {
+ return "custom crash: " + buildPath;
+ }
+ return null;
+ }
+ };
assertThat(visitTransitively(Label.parseAbsolute("//top:top"))).isFalse();
assertContainsEvent("no such package 'pkg'");
// The traditional label visitor does not propagate the original IOException message.
@@ -159,15 +163,16 @@ public class IOExceptionsTest extends PackageLoadingTestCase {
final Path buildPath = scratch.file("top/BUILD",
"sh_library(name = 'x')");
buildPath.getParentDirectory().getRelative("pkg").createDirectory();
- crashMessage = new Function<Path, String>() {
- @Override
- public String apply(Path path) {
- if (buildPath.equals(path)) {
- return "custom crash: " + buildPath;
- }
- return null;
- }
- };
+ crashMessage =
+ new Function<LocalPath, String>() {
+ @Override
+ public String apply(LocalPath path) {
+ if (buildPath.getLocalPath().equals(path)) {
+ return "custom crash: " + buildPath;
+ }
+ return null;
+ }
+ };
assertThat(visitTransitively(Label.parseAbsolute("//top/pkg:x"))).isFalse();
}
}
diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java
index 6e83bbedca..04e41a3c79 100644
--- a/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java
+++ b/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java
@@ -48,6 +48,7 @@ import com.google.devtools.build.lib.vfs.Dirent;
import com.google.devtools.build.lib.vfs.FileStatus;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
+import com.google.devtools.build.lib.vfs.LocalPath;
import com.google.devtools.build.lib.vfs.ModifiedFileSet;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -76,8 +77,8 @@ import org.junit.runners.JUnit4;
public class IncrementalLoadingTest {
protected PackageCacheTester tester;
- private Path throwOnReaddir = null;
- private Path throwOnStat = null;
+ private LocalPath throwOnReaddir = null;
+ private LocalPath throwOnStat = null;
@Before
public final void createTester() throws Exception {
@@ -85,7 +86,8 @@ public class IncrementalLoadingTest {
FileSystem fs =
new InMemoryFileSystem(clock) {
@Override
- public Collection<Dirent> readdir(Path path, boolean followSymlinks) throws IOException {
+ public Collection<Dirent> readdir(LocalPath path, boolean followSymlinks)
+ throws IOException {
if (path.equals(throwOnReaddir)) {
throw new FileNotFoundException(path.getPathString());
}
@@ -94,7 +96,7 @@ public class IncrementalLoadingTest {
@Nullable
@Override
- public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
+ public FileStatus stat(LocalPath path, boolean followSymlinks) throws IOException {
if (path.equals(throwOnStat)) {
throw new IOException("bork " + path.getPathString());
}
@@ -337,7 +339,7 @@ public class IncrementalLoadingTest {
Path buildFile = tester.addFile("e/BUILD", "sh_library(name = 'e', data = glob(['*.txt']))");
Path parentDir = buildFile.getParentDirectory();
tester.addFile("e/data.txt");
- throwOnReaddir = parentDir;
+ throwOnReaddir = parentDir.getLocalPath();
tester.sync();
try {
tester.getTarget("//e:e");
diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorIOTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorIOTest.java
index 37a992d405..1eb87496a4 100644
--- a/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorIOTest.java
+++ b/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorIOTest.java
@@ -21,6 +21,7 @@ import com.google.devtools.build.lib.vfs.Dirent;
import com.google.devtools.build.lib.vfs.FileStatus;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
+import com.google.devtools.build.lib.vfs.LocalPath;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryContentInfo;
@@ -41,14 +42,15 @@ public class TargetPatternEvaluatorIOTest extends AbstractTargetPatternEvaluator
private static class Transformer {
@SuppressWarnings("unused")
@Nullable
- public FileStatus stat(FileStatus stat, Path path, boolean followSymlinks) throws IOException {
+ public FileStatus stat(FileStatus stat, LocalPath path, boolean followSymlinks)
+ throws IOException {
return stat;
}
@SuppressWarnings("unused")
@Nullable
- public Collection<Dirent> readdir(Collection<Dirent> readdir, Path path, boolean followSymlinks)
- throws IOException {
+ public Collection<Dirent> readdir(
+ Collection<Dirent> readdir, LocalPath path, boolean followSymlinks) throws IOException {
return readdir;
}
}
@@ -59,13 +61,14 @@ public class TargetPatternEvaluatorIOTest extends AbstractTargetPatternEvaluator
protected FileSystem createFileSystem() {
return new InMemoryFileSystem(BlazeClock.instance(), PathFragment.create(FS_ROOT)) {
@Override
- public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
+ public FileStatus stat(LocalPath path, boolean followSymlinks) throws IOException {
FileStatus defaultResult = super.stat(path, followSymlinks);
return transformer.stat(defaultResult, path, followSymlinks);
}
@Override
- protected Collection<Dirent> readdir(Path path, boolean followSymlinks) throws IOException {
+ protected Collection<Dirent> readdir(LocalPath path, boolean followSymlinks)
+ throws IOException {
Collection<Dirent> defaultResult = super.readdir(path, followSymlinks);
return transformer.readdir(defaultResult, path, followSymlinks);
}
@@ -133,7 +136,7 @@ public class TargetPatternEvaluatorIOTest extends AbstractTargetPatternEvaluator
return new Transformer() {
@Nullable
@Override
- public FileStatus stat(final FileStatus stat, Path path, boolean followSymlinks)
+ public FileStatus stat(FileStatus stat, LocalPath path, boolean followSymlinks)
throws IOException {
if (path.getPathString().endsWith(badPathSuffix)) {
return new InMemoryContentInfo(BlazeClock.instance()) {
@@ -200,8 +203,8 @@ public class TargetPatternEvaluatorIOTest extends AbstractTargetPatternEvaluator
return new Transformer() {
@Nullable
@Override
- public Collection<Dirent> readdir(Collection<Dirent> readdir, Path path,
- boolean followSymlinks) throws IOException {
+ public Collection<Dirent> readdir(
+ Collection<Dirent> readdir, LocalPath path, boolean followSymlinks) throws IOException {
if (path.getPathString().endsWith(badPathSuffix)) {
throw new IOException("Path ended in " + badPathSuffix + ", so readdir failed.");
}