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);
}
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());
}
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");
}
}
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);
}
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");
}
Aggregations