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