From ff688bf287af54049f4f6d9b060fed1d2b649380 Mon Sep 17 00:00:00 2001 From: nharmata Date: Wed, 7 Jun 2017 17:03:52 -0400 Subject: Make PackageFunction's strategy for handling unreadable BUILD files configurable. Add a test for the current behavior of treating an unreadable BUILD file as a package loading error. RELNOTES: None PiperOrigin-RevId: 158314187 --- .../build/lib/skyframe/PackageFunctionTest.java | 37 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'src/test/java/com') diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java index da738d6220..f9ff08e22d 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java @@ -26,6 +26,7 @@ import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.PackageIdentifier; import com.google.devtools.build.lib.packages.ConstantRuleVisibility; +import com.google.devtools.build.lib.packages.NoSuchPackageException; import com.google.devtools.build.lib.packages.NoSuchTargetException; import com.google.devtools.build.lib.pkgcache.PackageCacheOptions; import com.google.devtools.build.lib.pkgcache.PathPackageLocator; @@ -50,6 +51,7 @@ import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; import com.google.devtools.common.options.Options; import java.io.IOException; +import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -662,6 +664,23 @@ public class PackageFunctionTest extends BuildViewTestCase { } } + @Test + public void testPackageLoadingErrorOnIOExceptionReadingBuildFile() throws Exception { + Path fooBuildFilePath = scratch.file("foo/BUILD"); + IOException exn = new IOException("nope"); + fs.throwExceptionOnGetInputStream(fooBuildFilePath, exn); + + SkyKey skyKey = PackageValue.key(PackageIdentifier.parse("@//foo")); + EvaluationResult result = SkyframeExecutorTestUtils.evaluate( + getSkyframeExecutor(), skyKey, /*keepGoing=*/false, reporter); + assertThat(result.hasError()).isTrue(); + ErrorInfo errorInfo = result.getError(skyKey); + String errorMessage = errorInfo.getException().getMessage(); + assertThat(errorMessage).contains("nope"); + assertThat(errorInfo.getException()).isInstanceOf(NoSuchPackageException.class); + assertThat(errorInfo.getException()).hasCauseThat().isSameAs(exn); + } + private static class CustomInMemoryFs extends InMemoryFileSystem { private abstract static class FileStatusOrException { abstract FileStatus get() throws IOException; @@ -696,8 +715,9 @@ public class PackageFunctionTest extends BuildViewTestCase { } } - private Map stubbedStats = Maps.newHashMap(); - private Set makeUnreadableAfterReaddir = Sets.newHashSet(); + private final Map stubbedStats = Maps.newHashMap(); + private final Set makeUnreadableAfterReaddir = Sets.newHashSet(); + private final Map pathsToErrorOnGetInputStream = Maps.newHashMap(); public CustomInMemoryFs(ManualClock manualClock) { super(manualClock); @@ -731,5 +751,18 @@ public class PackageFunctionTest extends BuildViewTestCase { } return result; } + + public void throwExceptionOnGetInputStream(Path path, IOException exn) { + pathsToErrorOnGetInputStream.put(path, exn); + } + + @Override + protected InputStream getInputStream(Path path) throws IOException { + IOException exnToThrow = pathsToErrorOnGetInputStream.get(path); + if (exnToThrow != null) { + throw exnToThrow; + } + return super.getInputStream(path); + } } } -- cgit v1.2.3