Search in sources :

Example 11 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class EventCollectorTest method usesPassedInCollection.

@Test
public void usesPassedInCollection() {
    Collection<Event> events = new ArrayList<>();
    EventCollector collector = new EventCollector(EventKind.ALL_EVENTS, events);
    collector.handle(event);
    Event onlyEvent = events.iterator().next();
    assertEquals(event.getMessage(), onlyEvent.getMessage());
    assertSame(location, onlyEvent.getLocation());
    assertEquals(event.getKind(), onlyEvent.getKind());
    assertEquals(event.getLocation().getStartOffset(), onlyEvent.getLocation().getStartOffset());
    assertEquals(collector.count(), 1);
    assertEquals(events.size(), 1);
}
Also used : ArrayList(java.util.ArrayList) Event(com.google.devtools.build.lib.events.Event) Test(org.junit.Test)

Example 12 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class BlazeExecutorTest method testDebugPrintActionContexts.

@Test
public void testDebugPrintActionContexts() throws Exception {
    TestExecutorBuilder builder = new TestExecutorBuilder(directories, binTools);
    OptionsParser parser = OptionsParser.newOptionsParser(TestExecutorBuilder.DEFAULT_OPTIONS);
    parser.parse("--debug_print_action_contexts");
    Reporter reporter = new Reporter(new EventBus());
    StoredEventHandler storedEventHandler = new StoredEventHandler();
    reporter.addHandler(storedEventHandler);
    SpawnActionContext mockStrategy = Mockito.mock(SpawnActionContext.class);
    builder.setReporter(reporter).setOptionsParser(parser).setExecution("mock", mockStrategy);
    builder.build();
    Event event = Iterables.find(storedEventHandler.getEvents(), new Predicate<Event>() {

        @Override
        public boolean apply(@Nullable Event event) {
            return event.getMessage().contains("SpawnActionContextMap: \"mock\" = ");
        }
    });
    assertThat(event).isNotNull();
    assertThat(event.getMessage()).contains("\"mock\" = " + mockStrategy.getClass().getSimpleName());
}
Also used : TestExecutorBuilder(com.google.devtools.build.lib.exec.util.TestExecutorBuilder) StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) Reporter(com.google.devtools.build.lib.events.Reporter) Event(com.google.devtools.build.lib.events.Event) EventBus(com.google.common.eventbus.EventBus) OptionsParser(com.google.devtools.common.options.OptionsParser) SpawnActionContext(com.google.devtools.build.lib.actions.SpawnActionContext) Test(org.junit.Test)

Example 13 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class RuleClassTest method testCreateRule.

@Test
public void testCreateRule() throws Exception {
    RuleClass ruleClassA = createRuleClassA();
    // LinkedHashMap -> predictable iteration order for testing
    Map<String, Object> attributeValues = new LinkedHashMap<>();
    // wrong type
    attributeValues.put("my-labellist-attr", "foobar");
    // no such attr
    attributeValues.put("bogus-attr", "foobar");
    attributeValues.put("my-stringlist-attr", Arrays.asList("foo", "bar"));
    reporter.removeHandler(failFastHandler);
    EventCollector collector = new EventCollector(EventKind.ERRORS);
    reporter.addHandler(collector);
    Rule rule = createRule(ruleClassA, TEST_RULE_NAME, attributeValues, testRuleLocation);
    // TODO(blaze-team): (2009) refactor to use assertContainsEvent
    Iterator<String> expectedMessages = Arrays.asList("expected value of type 'list(label)' for attribute 'my-labellist-attr' " + "in 'ruleA' rule, but got \"foobar\" (string)", "no such attribute 'bogus-attr' in 'ruleA' rule", "missing value for mandatory " + "attribute 'my-string-attr' in 'ruleA' rule", "missing value for mandatory attribute 'my-label-attr' in 'ruleA' rule", "missing value for mandatory " + "attribute 'my-labellist-attr' in 'ruleA' rule", "missing value for mandatory " + "attribute 'my-string-attr2' in 'ruleA' rule").iterator();
    for (Event event : collector) {
        assertEquals(TEST_RULE_DEFINED_AT_LINE, event.getLocation().getStartLineAndColumn().getLine());
        assertEquals(testBuildfilePath.asFragment(), event.getLocation().getPath());
        assertEquals(TEST_RULE_LABEL.toString().substring(1) + ": " + expectedMessages.next(), event.getMessage());
    }
    // Test basic rule properties:
    assertEquals("ruleA", rule.getRuleClass());
    assertEquals(TEST_RULE_NAME, rule.getName());
    assertEquals(TEST_RULE_LABEL.substring(1), rule.getLabel().toString());
    // Test attribute access:
    AttributeMap attributes = RawAttributeMapper.of(rule);
    assertEquals("//default:label", attributes.get("my-label-attr", BuildType.LABEL).toString());
    assertEquals(42, attributes.get("my-integer-attr", Type.INTEGER).intValue());
    assertEquals(// missing attribute -> default chosen based on type
    "", attributes.get("my-string-attr", Type.STRING));
    assertThat(attributes.get("my-labellist-attr", BuildType.LABEL_LIST)).isEmpty();
    assertEquals(Arrays.asList("foo", "bar"), attributes.get("my-stringlist-attr", Type.STRING_LIST));
    try {
        // wrong type
        attributes.get("my-labellist-attr", Type.STRING);
        fail();
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessage("Attribute my-labellist-attr is of type list(label) " + "and not of type string in ruleA rule //testpackage:my-rule-A");
    }
}
Also used : EventCollector(com.google.devtools.build.lib.events.EventCollector) Event(com.google.devtools.build.lib.events.Event) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 14 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class PackageFactoryTestBase method assertGlobProducesError.

protected void assertGlobProducesError(String pattern, boolean errorExpected) throws Exception {
    events.setFailFast(false);
    Package pkg = evaluateGlob(ImmutableList.of(pattern), Collections.<String>emptyList(), false, "").first;
    assertEquals(errorExpected, pkg.containsErrors());
    boolean foundError = false;
    for (Event event : events.collector()) {
        if (event.getMessage().contains("glob")) {
            if (!errorExpected) {
                fail("error not expected for glob pattern " + pattern + ", but got: " + event);
                return;
            }
            foundError = errorExpected;
            break;
        }
    }
    assertEquals(errorExpected, foundError);
}
Also used : Event(com.google.devtools.build.lib.events.Event) Package(com.google.devtools.build.lib.packages.Package)

Example 15 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class ParallelEvaluatorTest method storedEventFilter.

@Test
public void storedEventFilter() throws Exception {
    graph = new InMemoryGraphImpl();
    SkyKey a = GraphTester.toSkyKey("a");
    final AtomicBoolean evaluated = new AtomicBoolean(false);
    tester.getOrCreate(a).setBuilder(new SkyFunction() {

        @Nullable
        @Override
        public SkyValue compute(SkyKey skyKey, Environment env) {
            evaluated.set(true);
            env.getListener().handle(Event.error(null, "boop"));
            env.getListener().handle(Event.warn(null, "beep"));
            return new StringValue("a");
        }

        @Nullable
        @Override
        public String extractTag(SkyKey skyKey) {
            return null;
        }
    });
    ParallelEvaluator evaluator = makeEvaluator(graph, tester.getSkyFunctionMap(), /*keepGoing=*/
    false, new EventFilter() {

        @Override
        public boolean apply(Event event) {
            return event.getKind() == EventKind.ERROR;
        }

        @Override
        public boolean storeEvents() {
            return true;
        }
    });
    evaluator.eval(ImmutableList.of(a));
    assertTrue(evaluated.get());
    assertEventCount(2, eventCollector);
    assertContainsEvent(eventCollector, "boop");
    assertContainsEvent(eventCollector, "beep");
    eventCollector.clear();
    evaluator = makeEvaluator(graph, tester.getSkyFunctionMap(), /*keepGoing=*/
    false);
    evaluated.set(false);
    evaluator.eval(ImmutableList.of(a));
    assertFalse(evaluated.get());
    assertEventCount(1, eventCollector);
    assertContainsEvent(eventCollector, "boop");
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MoreAsserts.assertContainsEvent(com.google.devtools.build.lib.testutil.MoreAsserts.assertContainsEvent) Event(com.google.devtools.build.lib.events.Event) StringValue(com.google.devtools.build.skyframe.GraphTester.StringValue) Nullable(javax.annotation.Nullable) Test(org.junit.Test)

Aggregations

Event (com.google.devtools.build.lib.events.Event)28 Test (org.junit.Test)15 EventHandler (com.google.devtools.build.lib.events.EventHandler)4 EventBus (com.google.common.eventbus.EventBus)3 ActionExecutedEvent (com.google.devtools.build.lib.actions.ActionExecutedEvent)3 Reporter (com.google.devtools.build.lib.events.Reporter)3 MoreAsserts.assertContainsEvent (com.google.devtools.build.lib.testutil.MoreAsserts.assertContainsEvent)3 StringValue (com.google.devtools.build.skyframe.GraphTester.StringValue)3 ArrayList (java.util.ArrayList)3 ActionCompletionEvent (com.google.devtools.build.lib.actions.ActionCompletionEvent)2 ActionMiddlemanEvent (com.google.devtools.build.lib.actions.ActionMiddlemanEvent)2 ActionStartedEvent (com.google.devtools.build.lib.actions.ActionStartedEvent)2 CachedActionEvent (com.google.devtools.build.lib.actions.CachedActionEvent)2 SpawnActionContext (com.google.devtools.build.lib.actions.SpawnActionContext)2 EventCollector (com.google.devtools.build.lib.events.EventCollector)2 StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Supplier (com.google.common.base.Supplier)1 ImmutableList (com.google.common.collect.ImmutableList)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1