Search in sources :

Example 1 with EventCollector

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

the class MemoizingEvaluatorTest method initializeReporter.

private void initializeReporter() {
    eventCollector = new EventCollector();
    reporter = new Reporter(new EventBus(), eventCollector);
    tester.resetPlayedEvents();
}
Also used : EventCollector(com.google.devtools.build.lib.events.EventCollector) Reporter(com.google.devtools.build.lib.events.Reporter) EventBus(com.google.common.eventbus.EventBus)

Example 2 with EventCollector

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

the class SkyframeLabelVisitorTestCase method assertNewBuildFileConflict.

protected Collection<Event> assertNewBuildFileConflict() throws Exception {
    // expect errors
    reporter.removeHandler(failFastHandler);
    scratch.file("pkg/BUILD", "sh_library(name = 'x', deps = ['//pkg2:q/sub'])");
    scratch.file("pkg2/BUILD", "sh_library(name = 'q/sub')");
    assertLabelsVisited(ImmutableSet.of("//pkg:x", "//pkg2:q/sub"), ImmutableSet.of("//pkg:x"), !EXPECT_ERROR, !KEEP_GOING);
    scratch.file("pkg2/q/BUILD");
    syncPackages();
    EventCollector warningCollector = new EventCollector(EventKind.WARNING);
    reporter.addHandler(warningCollector);
    assertLabelsVisitedWithErrors(ImmutableSet.of("//pkg:x"), ImmutableSet.of("//pkg:x"));
    assertContainsEvent("Label '//pkg2:q/sub' crosses boundary of subpackage 'pkg2/q'");
    assertContainsEvent("no such target '//pkg2:q/sub'");
    Collection<Event> warnings = Lists.newArrayList(warningCollector);
    // Check stability (not redundant).
    assertLabelsVisitedWithErrors(ImmutableSet.of("//pkg:x"), ImmutableSet.of("//pkg:x"));
    assertContainsEvent("Label '//pkg2:q/sub' crosses boundary of subpackage 'pkg2/q'");
    return warnings;
}
Also used : EventCollector(com.google.devtools.build.lib.events.EventCollector) Event(com.google.devtools.build.lib.events.Event)

Example 3 with EventCollector

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

the class FoundationTestCase method initializeLogging.

@Before
public final void initializeLogging() throws Exception {
    eventCollector = new EventCollector(EventKind.ERRORS_AND_WARNINGS);
    reporter = new Reporter(new EventBus(), eventCollector);
    reporter.addHandler(failFastHandler);
}
Also used : EventCollector(com.google.devtools.build.lib.events.EventCollector) Reporter(com.google.devtools.build.lib.events.Reporter) EventBus(com.google.common.eventbus.EventBus) Before(org.junit.Before)

Example 4 with EventCollector

use of com.google.devtools.build.lib.events.EventCollector 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 5 with EventCollector

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

the class RuleClassTest method testCreateRuleWithLegacyPublicVisibility.

@Test
public void testCreateRuleWithLegacyPublicVisibility() throws Exception {
    RuleClass ruleClass = newRuleClass("ruleVis", false, false, false, false, false, false, ImplicitOutputsFunction.NONE, RuleClass.NO_CHANGE, null, DUMMY_CONFIGURED_TARGET_FACTORY, PredicatesWithMessage.<Rule>alwaysTrue(), PREFERRED_DEPENDENCY_PREDICATE, AdvertisedProviderSet.EMPTY, null, NO_EXTERNAL_BINDINGS, null, ImmutableSet.<Class<?>>of(), MissingFragmentPolicy.FAIL_ANALYSIS, true, attr("visibility", LABEL_LIST).legacyAllowAnyFileType().build());
    Map<String, Object> attributeValues = new HashMap<>();
    attributeValues.put("visibility", Arrays.asList("//visibility:legacy_public"));
    reporter.removeHandler(failFastHandler);
    EventCollector collector = new EventCollector(EventKind.ERRORS);
    reporter.addHandler(collector);
    createRule(ruleClass, TEST_RULE_NAME, attributeValues, testRuleLocation);
    assertContainsEvent("//visibility:legacy_public only allowed in package declaration");
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) EventCollector(com.google.devtools.build.lib.events.EventCollector) Test(org.junit.Test)

Aggregations

EventCollector (com.google.devtools.build.lib.events.EventCollector)5 EventBus (com.google.common.eventbus.EventBus)2 Event (com.google.devtools.build.lib.events.Event)2 Reporter (com.google.devtools.build.lib.events.Reporter)2 LinkedHashMap (java.util.LinkedHashMap)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Before (org.junit.Before)1