use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class BuildViewTest method testReportsAnalysisRootCauses.
@Test
public void testReportsAnalysisRootCauses() throws Exception {
scratch.file("private/BUILD", "genrule(", " name='private',", " outs=['private.out'],", " cmd='',", " visibility=['//visibility:private'])");
scratch.file("foo/BUILD", "genrule(", " name='foo',", " tools=[':bar'],", " outs=['foo.out'],", " cmd='')", "genrule(", " name='bar',", " tools=['//private'],", " outs=['bar.out'],", " cmd='')");
reporter.removeHandler(failFastHandler);
EventBus eventBus = new EventBus();
AnalysisFailureRecorder recorder = new AnalysisFailureRecorder();
eventBus.register(recorder);
AnalysisResult result = update(eventBus, defaultFlags().with(Flag.KEEP_GOING), "//foo");
assertThat(result.hasError()).isTrue();
assertThat(recorder.events).hasSize(1);
AnalysisFailureEvent event = recorder.events.get(0);
assertEquals("//foo:bar", event.getFailureReason().toString());
assertEquals("//foo:foo", event.getFailedTarget().getLabel().toString());
}
use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class BuildViewTest method testSyntaxErrorInDepPackage.
@Test
public void testSyntaxErrorInDepPackage() throws Exception {
// Check that a loading error in a dependency is properly reported.
scratch.file("a/BUILD", "genrule(name='x',", " srcs = ['file.txt'],", " outs = ['foo'],", " cmd = 'echo')", // syntax error
"@");
scratch.file("b/BUILD", "genrule(name= 'cc',", " tools = ['//a:x'],", " outs = ['bar'],", " cmd = 'echo')");
reporter.removeHandler(failFastHandler);
EventBus eventBus = new EventBus();
AnalysisResult result = update(eventBus, defaultFlags().with(Flag.KEEP_GOING), "//b:cc");
assertContainsEvent("invalid character: '@'");
assertThat(result.hasError()).isTrue();
}
use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class BuildViewTest method testReportsLoadingRootCauses.
@Test
public void testReportsLoadingRootCauses() throws Exception {
// This test checks that two simultaneous errors are both reported:
// - missing outs attribute,
// - package referenced in tools does not exist
scratch.file("pkg/BUILD", "genrule(name='foo',", " tools=['//nopackage:missing'],", " cmd='')");
reporter.removeHandler(failFastHandler);
EventBus eventBus = new EventBus();
LoadingFailureRecorder recorder = new LoadingFailureRecorder();
eventBus.register(recorder);
// Note: no need to run analysis for a loading failure.
AnalysisResult result = update(eventBus, defaultFlags().with(Flag.KEEP_GOING), "//pkg:foo");
assertThat(result.hasError()).isTrue();
assertThat(recorder.events).contains(Pair.of(Label.parseAbsolute("//pkg:foo"), Label.parseAbsolute("//nopackage:missing")));
assertContainsEvent("missing value for mandatory attribute 'outs'");
assertContainsEvent("no such package 'nopackage'");
// Skyframe correctly reports the other root cause as the genrule itself (since it is
// missing attributes).
assertThat(recorder.events).hasSize(2);
assertThat(recorder.events).contains(Pair.of(Label.parseAbsolute("//pkg:foo"), Label.parseAbsolute("//pkg:foo")));
}
use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class EventSensorTest method sensorCanCount.
@Test
public void sensorCanCount() {
EventSensor sensor = new EventSensor(EventKind.ERRORS_AND_WARNINGS);
Reporter reporter = new Reporter(new EventBus(), sensor);
reporter.handle(Event.error(location, "An ERROR event."));
reporter.handle(Event.error(location, "Another ERROR event."));
reporter.handle(Event.warn(location, "A warning event."));
// not in mask
reporter.handle(Event.info(location, "An info event."));
assertEquals(3, sensor.getTriggerCount());
assertTrue(sensor.wasTriggered());
}
use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.
the class EventSensorTest method sensorIgnoresEventsNotInItsMask.
@Test
public void sensorIgnoresEventsNotInItsMask() {
EventSensor sensor = new EventSensor(EventKind.ERRORS_AND_WARNINGS);
Reporter reporter = new Reporter(new EventBus(), sensor);
reporter.handle(Event.info(location, "An INFO event."));
assertFalse(sensor.wasTriggered());
}
Aggregations