use of com.facebook.buck.json.ProjectBuildFileParser in project buck by facebook.
the class ProjectBuildFileParserTest method whenSubprocessReturnsNewWatchmanWarningThenDiagnosticEventPublished.
@Test
public void whenSubprocessReturnsNewWatchmanWarningThenDiagnosticEventPublished() throws IOException, BuildFileParseException, InterruptedException {
// This test depends on unix utilities that don't exist on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
TestProjectBuildFileParserFactory buildFileParserFactory = new TestProjectBuildFileParserFactory(cell.getRoot(), cell.getKnownBuildRuleTypes());
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance(new FakeClock(0));
final List<WatchmanDiagnosticEvent> watchmanDiagnosticEvents = new ArrayList<>();
class EventListener {
@Subscribe
public void on(WatchmanDiagnosticEvent consoleEvent) {
watchmanDiagnosticEvents.add(consoleEvent);
}
}
EventListener eventListener = new EventListener();
buckEventBus.register(eventListener);
try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsSuccessWithWarning(buckEventBus, "This is a watchman warning", "watchman")) {
buildFileParser.initIfNeeded();
buildFileParser.getAllRulesAndMetaRules(Paths.get("foo"));
}
assertThat(watchmanDiagnosticEvents, Matchers.contains(Matchers.hasToString(Matchers.containsString("This is a watchman warning"))));
}
use of com.facebook.buck.json.ProjectBuildFileParser in project buck by facebook.
the class ProjectBuildFileParserTest method whenSubprocessReturnsSyntaxErrorInDifferentFileThenExceptionContainsTwoFileNames.
@Test
public void whenSubprocessReturnsSyntaxErrorInDifferentFileThenExceptionContainsTwoFileNames() throws IOException, BuildFileParseException, InterruptedException {
// This test depends on unix utilities that don't exist on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
TestProjectBuildFileParserFactory buildFileParserFactory = new TestProjectBuildFileParserFactory(cell.getRoot(), cell.getKnownBuildRuleTypes());
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance(new FakeClock(0));
final List<ConsoleEvent> consoleEvents = new ArrayList<>();
class EventListener {
@Subscribe
public void onConsoleEvent(ConsoleEvent consoleEvent) {
consoleEvents.add(consoleEvent);
}
}
EventListener eventListener = new EventListener();
buckEventBus.register(eventListener);
thrown.expect(BuildFileParseException.class);
thrown.expectMessage("Parse error for build file foo/BUCK:\n" + "Syntax error in bar/BUCK\n" + "Line 42, column 24:\n" + "def some_helper_method(!@87*@!#\n" + " ^");
try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsErrorWithException(buckEventBus, "This is an error", "parser", ImmutableMap.<String, Object>builder().put("type", "SyntaxError").put("value", "You messed up").put("filename", "bar/BUCK").put("lineno", 42).put("offset", 24).put("text", "def some_helper_method(!@87*@!#\n").put("traceback", ImmutableList.of(ImmutableMap.of("filename", "bar/BUCK", "line_number", 42, "function_name", "<module>", "text", "def some_helper_method(!@87*@!#\n"), ImmutableMap.of("filename", "foo/BUCK", "line_number", 23, "function_name", "<module>", "text", "some_helper_method(name=*@!&#(!@&*()\n"))).build())) {
buildFileParser.initIfNeeded();
buildFileParser.getAllRulesAndMetaRules(Paths.get("foo/BUCK"));
}
}
use of com.facebook.buck.json.ProjectBuildFileParser in project buck by facebook.
the class ProjectBuildFileParserTest method whenSubprocessReturnsSyntaxErrorWithoutOffsetThenExceptionIsFormattedWithoutColumn.
@Test
public void whenSubprocessReturnsSyntaxErrorWithoutOffsetThenExceptionIsFormattedWithoutColumn() throws IOException, BuildFileParseException, InterruptedException {
// This test depends on unix utilities that don't exist on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
TestProjectBuildFileParserFactory buildFileParserFactory = new TestProjectBuildFileParserFactory(cell.getRoot(), cell.getKnownBuildRuleTypes());
thrown.expect(BuildFileParseException.class);
thrown.expectMessage("Parse error for build file foo/BUCK:\n" + "Syntax error on line 23:\n" + "java_test(name=*@!&#(!@&*()");
try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsErrorWithException(BuckEventBusFactory.newInstance(new FakeClock(0)), "This is an error", "parser", ImmutableMap.<String, Object>builder().put("type", "SyntaxError").put("value", "You messed up").put("filename", "foo/BUCK").put("lineno", 23).put("text", "java_test(name=*@!&#(!@&*()\n").put("traceback", ImmutableList.of(ImmutableMap.of("filename", "foo/BUCK", "line_number", 23, "function_name", "<module>", "text", "java_test(name=*@!&#(!@&*()\n"))).build())) {
buildFileParser.initIfNeeded();
buildFileParser.getAllRulesAndMetaRules(Paths.get("foo/BUCK"));
}
}
Aggregations