Search in sources :

Example 31 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class HttpArtifactCacheUploadListenerTest method setUp.

@Before
public void setUp() {
    buildId = new BuildId();
    clock = new FakeClock(0);
    events = Lists.newArrayList();
    eventBus = new BuckEventBus(clock, buildId);
    eventBus = new BuckEventBus(clock, /* async */
    false, buildId, 1000);
    eventBus.register(this);
    lastStartedEvent = null;
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) FakeClock(com.facebook.buck.timing.FakeClock) Before(org.junit.Before)

Example 32 with FakeClock

use of com.facebook.buck.timing.FakeClock in project buck by facebook.

the class ProjectBuildFileParserTest method whenSubprocessReturnsSyntaxErrorInFileBeingParsedThenExceptionContainsFileNameOnce.

@Test
public void whenSubprocessReturnsSyntaxErrorInFileBeingParsedThenExceptionContainsFileNameOnce() 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, column 16:\n" + "java_test(name=*@!&#(!@&*()\n" + "               ^");
    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("offset", 16).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)

Example 33 with FakeClock

use of com.facebook.buck.timing.FakeClock 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 34 with FakeClock

use of com.facebook.buck.timing.FakeClock 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 35 with FakeClock

use of com.facebook.buck.timing.FakeClock 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

FakeClock (com.facebook.buck.timing.FakeClock)54 Test (org.junit.Test)48 BuckEventBus (com.facebook.buck.event.BuckEventBus)36 EventBus (com.google.common.eventbus.EventBus)19 EasyMock.anyObject (org.easymock.EasyMock.anyObject)17 WatchEvent (java.nio.file.WatchEvent)13 BuildId (com.facebook.buck.model.BuildId)12 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)9 ProjectBuildFileParser (com.facebook.buck.json.ProjectBuildFileParser)8 Path (java.nio.file.Path)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)7 FakeWatchmanClient (com.facebook.buck.io.FakeWatchmanClient)6 Subscribe (com.google.common.eventbus.Subscribe)6 ArrayList (java.util.ArrayList)6 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)5 SettableFakeClock (com.facebook.buck.timing.SettableFakeClock)5 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)4 FakeExecutor (com.facebook.buck.testutil.FakeExecutor)4 BuckEvent (com.facebook.buck.event.BuckEvent)3 WatchmanStatusEvent (com.facebook.buck.event.WatchmanStatusEvent)2