Search in sources :

Example 6 with Event

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

the class MoreAsserts method assertContainsEventWithFrequency.

public static List<Event> assertContainsEventWithFrequency(Iterable<Event> events, String expectedMessage, int expectedFrequency) {
    ImmutableList.Builder<Event> builder = ImmutableList.builder();
    for (Event event : events) {
        if (event.getMessage().contains(expectedMessage)) {
            builder.add(event);
        }
    }
    List<Event> foundEvents = builder.build();
    assertWithMessage(events.toString()).that(foundEvents).hasSize(expectedFrequency);
    return foundEvents;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Event(com.google.devtools.build.lib.events.Event)

Example 7 with Event

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

the class SkylarkRuleImplementationFunctionsTest method checkReportedErrorStartsWith.

/**
   * Checks whether the given (invalid) statement leads to the expected error
   */
private void checkReportedErrorStartsWith(SkylarkRuleContext ruleContext, String errorMsg, String... statements) throws Exception {
    // If the component under test relies on Reporter and EventCollector for error handling, any
    // error would lead to an asynchronous AssertionFailedError thanks to failFastHandler in
    // FoundationTestCase.
    //
    // Consequently, we disable failFastHandler and check all events for the expected error message
    reporter.removeHandler(failFastHandler);
    Object result = evalRuleContextCode(ruleContext, statements);
    String first = null;
    int count = 0;
    try {
        for (Event evt : eventCollector) {
            if (evt.getMessage().startsWith(errorMsg)) {
                return;
            }
            ++count;
            first = evt.getMessage();
        }
        if (count == 0) {
            fail(String.format("checkReportedErrorStartsWith(): There was no error; the result is '%s'", result));
        } else {
            fail(String.format("Found %d error(s), but none with the expected message '%s'. First error: '%s'", count, errorMsg, first));
        }
    } finally {
        eventCollector.clear();
    }
}
Also used : Event(com.google.devtools.build.lib.events.Event) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject)

Example 8 with Event

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

the class BuildFileASTTest method testImplicitStringConcatenationFails.

@Test
public void testImplicitStringConcatenationFails() throws Exception {
    setFailFast(false);
    BuildFileAST buildFileAST = parseBuildFile("a = 'foo' 'bar'");
    Event event = assertContainsError("Implicit string concatenation is forbidden, use the + operator");
    assertEquals("/a/build/file/BUILD", event.getLocation().getPath().toString());
    assertEquals(1, event.getLocation().getStartLineAndColumn().getLine());
    assertEquals(10, event.getLocation().getStartLineAndColumn().getColumn());
    assertTrue(buildFileAST.containsErrors());
}
Also used : Event(com.google.devtools.build.lib.events.Event) Test(org.junit.Test)

Example 9 with Event

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

the class BuildFileASTTest method testEvalException.

@Test
public void testEvalException() throws Exception {
    setFailFast(false);
    BuildFileAST buildfile = parseBuildFile("x = 1", "y = [2,3]", "", "z = x + y");
    assertFalse(buildfile.exec(env, getEventHandler()));
    Event e = assertContainsError("unsupported operand type(s) for +: 'int' and 'list'");
    assertEquals(4, e.getLocation().getStartLineAndColumn().getLine());
}
Also used : Event(com.google.devtools.build.lib.events.Event) Test(org.junit.Test)

Example 10 with Event

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

the class SkyframeActionExecutor method dumpRecordedOutErr.

/**
   * Dump the output from the action.
   *
   * @param action The action whose output is being dumped
   * @param outErrBuffer The OutErr that recorded the actions output
   */
private void dumpRecordedOutErr(Action action, FileOutErr outErrBuffer) {
    StringBuilder message = new StringBuilder("");
    message.append("From ");
    message.append(action.describe());
    message.append(":");
    Event event = Event.info(message.toString());
    dumpRecordedOutErr(event, outErrBuffer);
}
Also used : ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) ActionCompletionEvent(com.google.devtools.build.lib.actions.ActionCompletionEvent) ActionMiddlemanEvent(com.google.devtools.build.lib.actions.ActionMiddlemanEvent) CachedActionEvent(com.google.devtools.build.lib.actions.CachedActionEvent) ActionExecutedEvent(com.google.devtools.build.lib.actions.ActionExecutedEvent) Event(com.google.devtools.build.lib.events.Event)

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