aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/analysis
diff options
context:
space:
mode:
authorGravatar janakr <janakr@google.com>2017-07-13 19:55:32 +0200
committerGravatar László Csomor <laszlocsomor@google.com>2017-07-14 10:52:09 +0200
commit28adce590d95cb9aa826fcd9f939efbb8e1eab7e (patch)
tree4df40b5eebecd4f237a6343d5f3577c480600e24 /src/test/java/com/google/devtools/build/lib/analysis
parent5abf4ed4dc9fc134e47f9b56e3b65ba26d0ba9f0 (diff)
If globbing throws an IOException, fail to construct the package instead of constructing the package with an error.
Prior to this change, if a Package.Builder object was constructed, it was guaranteed that a Package (possibly with errors) would be created. This is no longer true: if an IOException is set on the Package.Builder object, it will throw a NoSuchPackageException during #build(). PiperOrigin-RevId: 161832111
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/analysis')
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/AnalysisWithIOExceptionsTest.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AnalysisWithIOExceptionsTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AnalysisWithIOExceptionsTest.java
new file mode 100644
index 0000000000..7610f637cb
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/analysis/AnalysisWithIOExceptionsTest.java
@@ -0,0 +1,66 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.analysis;
+
+import static org.junit.Assert.fail;
+
+import com.google.devtools.build.lib.analysis.util.AnalysisTestCase;
+import com.google.devtools.build.lib.util.BlazeClock;
+import com.google.devtools.build.lib.vfs.FileStatus;
+import com.google.devtools.build.lib.vfs.FileSystem;
+import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.PathFragment;
+import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
+import java.io.IOException;
+import java.util.function.Function;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** {@link AnalysisTestCase} with custom filesystem that can throw on stat if desired. */
+@RunWith(JUnit4.class)
+public class AnalysisWithIOExceptionsTest extends AnalysisTestCase {
+ private static final String FS_ROOT = "/fsg";
+
+ private static final Function<Path, String> NULL_FUNCTION = (path) -> null;
+
+ private Function<Path, String> crashMessage = NULL_FUNCTION;
+
+ @Override
+ protected FileSystem createFileSystem() {
+ return new InMemoryFileSystem(BlazeClock.instance(), PathFragment.create(FS_ROOT)) {
+ @Override
+ public FileStatus stat(Path path, boolean followSymlinks) throws IOException {
+ String crash = crashMessage.apply(path);
+ if (crash != null) {
+ throw new IOException(crash);
+ }
+ return super.stat(path, followSymlinks);
+ }
+ };
+ }
+
+ @Test
+ public void testGlobIOException() throws Exception {
+ scratch.file("b/BUILD", "sh_library(name = 'b', deps= ['//a:a'])");
+ scratch.file("a/BUILD", "sh_library(name = 'a', srcs = glob(['a.sh']))");
+ crashMessage = path -> path.toString().contains("a.sh") ? "bork" : null;
+ reporter.removeHandler(failFastHandler);
+ try {
+ update("//b:b");
+ fail("Expected failure");
+ } catch (ViewCreationFailedException expected) {
+ }
+ }
+}