Search in sources :

Example 11 with EventBus

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());
}
Also used : EventBus(com.google.common.eventbus.EventBus) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 12 with EventBus

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();
}
Also used : EventBus(com.google.common.eventbus.EventBus) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 13 with EventBus

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")));
}
Also used : EventBus(com.google.common.eventbus.EventBus) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 14 with EventBus

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());
}
Also used : EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Example 15 with EventBus

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());
}
Also used : EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Aggregations

EventBus (com.google.common.eventbus.EventBus)84 Test (org.junit.Test)56 BuckEventBus (com.facebook.buck.event.BuckEventBus)21 FakeClock (com.facebook.buck.timing.FakeClock)19 EasyMock.anyObject (org.easymock.EasyMock.anyObject)18 Reporter (com.google.devtools.build.lib.events.Reporter)15 WatchEvent (java.nio.file.WatchEvent)12 Subscribe (com.google.common.eventbus.Subscribe)11 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)8 Before (org.junit.Before)8 Path (com.google.devtools.build.lib.vfs.Path)7 FakeWatchmanClient (com.facebook.buck.io.FakeWatchmanClient)6 ActionExecutionMetadata (com.google.devtools.build.lib.actions.ActionExecutionMetadata)4 ResourceHandle (com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle)4 BuildLangTypedAttributeValuesMap (com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap)4 HashMap (java.util.HashMap)4 Executor (com.google.devtools.build.lib.actions.Executor)3 Event (com.google.devtools.build.lib.events.Event)3 SuiteHint (com.carrotsearch.ant.tasks.junit4.balancers.SuiteHint)2 AggregatedQuitEvent (com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedQuitEvent)2