Search in sources :

Example 11 with ProjectBuildFileParser

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"))));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeClock(com.facebook.buck.timing.FakeClock) WatchmanDiagnosticEvent(com.facebook.buck.io.WatchmanDiagnosticEvent) ProjectBuildFileParser(com.facebook.buck.json.ProjectBuildFileParser) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with ProjectBuildFileParser

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"));
    }
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeClock(com.facebook.buck.timing.FakeClock) ProjectBuildFileParser(com.facebook.buck.json.ProjectBuildFileParser) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with ProjectBuildFileParser

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"));
    }
}
Also used : ProjectBuildFileParser(com.facebook.buck.json.ProjectBuildFileParser) FakeClock(com.facebook.buck.timing.FakeClock) Test(org.junit.Test)

Aggregations

ProjectBuildFileParser (com.facebook.buck.json.ProjectBuildFileParser)13 Test (org.junit.Test)9 FakeClock (com.facebook.buck.timing.FakeClock)8 BuckEventBus (com.facebook.buck.event.BuckEventBus)5 ArrayList (java.util.ArrayList)5 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)4 WatchmanDiagnosticEvent (com.facebook.buck.io.WatchmanDiagnosticEvent)2 BuildFileParseException (com.facebook.buck.json.BuildFileParseException)2 Path (java.nio.file.Path)2 List (java.util.List)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 BuckPyFunction (com.facebook.buck.rules.BuckPyFunction)1 Cell (com.facebook.buck.rules.Cell)1 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)1 DefaultTypeCoercerFactory (com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory)1 Escaper (com.facebook.buck.util.Escaper)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1