use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.
the class TimestampBuilderTest method testMissingSourceFileIsAnError.
@Test
public void testMissingSourceFileIsAnError() throws Exception {
// A missing input to an action must be treated as an error because there's
// a risk that the action that consumes it will succeed, but with a
// different behavior (imagine that it globs over the directory, for
// example). It's not ok to simply try the action and let the action
// report "input file not found".
//
// (However, there are exceptions to this principle: C++ compilation
// actions may depend on non-existent headers from stale .d files. We need
// to allow the action to proceed to execution in this case.)
reporter.removeHandler(failFastHandler);
// doesn't exist
Artifact in = createSourceArtifact("in");
Artifact out = createDerivedArtifact("out");
registerAction(new TestAction(TestAction.NO_EFFECT, Collections.singleton(in), Collections.singleton(out)));
try {
// fails with ActionExecutionException
buildArtifacts(amnesiacBuilder(), out);
fail();
} catch (BuildFailedException e) {
assertThat(e.getMessage()).contains("1 input file(s) do not exist");
}
}
use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.
the class TimestampBuilderTestCase method createActionButton.
/**
* Creates a TestAction from 'inputs' to 'outputs', and a new button, such
* that executing the action causes the button to be pressed. The button is
* returned.
*/
protected Button createActionButton(Collection<Artifact> inputs, Collection<Artifact> outputs) {
Button button = new Button();
registerAction(new TestAction(button, inputs, outputs));
return button;
}
use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.
the class FilesystemValueCheckerTest method checkDirtyActions.
public void checkDirtyActions(BatchStat batchStatter, boolean forceDigests) throws Exception {
Artifact out1 = createDerivedArtifact("fiz");
Artifact out2 = createDerivedArtifact("pop");
FileSystemUtils.writeContentAsLatin1(out1.getPath(), "hello");
FileSystemUtils.writeContentAsLatin1(out2.getPath(), "fizzlepop");
Action action1 = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(out1));
Action action2 = new TestAction(Runnables.doNothing(), ImmutableSet.<Artifact>of(), ImmutableSet.of(out2));
differencer.inject(ImmutableMap.<SkyKey, SkyValue>of(ActionExecutionValue.key(action1), actionValue(action1, forceDigests), ActionExecutionValue.key(action2), actionValue(action2, forceDigests)));
assertFalse(driver.evaluate(ImmutableList.<SkyKey>of(), false, 1, NullEventHandler.INSTANCE).hasError());
assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).isEmpty();
FileSystemUtils.writeContentAsLatin1(out1.getPath(), "goodbye");
assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.EVERYTHING_MODIFIED)).containsExactly(ActionExecutionValue.key(action1));
assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(out1.getExecPath()).build())).containsExactly(ActionExecutionValue.key(action1));
assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, new ModifiedFileSet.Builder().modify(out1.getExecPath().getParentDirectory()).build())).isEmpty();
assertThat(new FilesystemValueChecker(null, null).getDirtyActionValues(evaluator.getValues(), batchStatter, ModifiedFileSet.NOTHING_MODIFIED)).isEmpty();
}
use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.
the class ParallelBuilderTest method testFailureRecovery.
/**
* Test that we can recover properly after a failed build.
*/
@Test
public void testFailureRecovery() throws Exception {
// [action] -> foo
Artifact foo = createDerivedArtifact("foo");
Callable<Void> makeFoo = new Callable<Void>() {
@Override
public Void call() throws IOException {
throw new IOException("building 'foo' is supposed to fail");
}
};
registerAction(new TestAction(makeFoo, Artifact.NO_ARTIFACTS, ImmutableList.of(foo)));
// [action] -> bar
Artifact bar = createDerivedArtifact("bar");
registerAction(new TestAction(TestAction.NO_EFFECT, emptySet, ImmutableList.of(bar)));
// Don't fail fast when we encounter the error
reporter.removeHandler(failFastHandler);
// test that building 'foo' fails
try {
buildArtifacts(foo);
fail("building 'foo' was supposed to fail!");
} catch (BuildFailedException e) {
if (!e.getMessage().contains("building 'foo' is supposed to fail")) {
throw e;
}
// Make sure the reporter reported the error message.
assertContainsEvent("building 'foo' is supposed to fail");
}
// test that a subsequent build of 'bar' succeeds
buildArtifacts(bar);
}
use of com.google.devtools.build.lib.actions.util.TestAction in project bazel by bazelbuild.
the class ParallelBuilderTest method testCyclicActionGraphWithTail.
@Test
public void testCyclicActionGraphWithTail() throws Exception {
// bar -> [action] -> foo
// baz -> [action] -> bar
// bat, foo -> [action] -> baz
Artifact foo = createDerivedArtifact("foo");
Artifact bar = createDerivedArtifact("bar");
Artifact baz = createDerivedArtifact("baz");
Artifact bat = createDerivedArtifact("bat");
try {
registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bar), asSet(foo)));
registerAction(new TestAction(TestAction.NO_EFFECT, asSet(baz), asSet(bar)));
registerAction(new TestAction(TestAction.NO_EFFECT, asSet(bat, foo), asSet(baz)));
registerAction(new TestAction(TestAction.NO_EFFECT, ImmutableSet.<Artifact>of(), asSet(bat)));
buildArtifacts(foo);
fail("Builder failed to detect cyclic action graph");
} catch (BuildFailedException e) {
assertEquals(e.getMessage(), CYCLE_MSG);
}
}
Aggregations