Search in sources :

Example 36 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class WatchmanTest method capabilitiesDetectedForVersion47AndLater.

@Test
public void capabilitiesDetectedForVersion47AndLater() throws InterruptedException, IOException {
    SettableFakeClock clock = new SettableFakeClock(0, 0);
    FakeListeningProcessExecutor executor = new FakeListeningProcessExecutor(ImmutableMultimap.<ProcessExecutorParams, FakeListeningProcessState>builder().putAll(ProcessExecutorParams.ofCommand(exe, "--output-encoding=bser", "get-sockname"), FakeListeningProcessState.ofStdoutBytes(bserSerialized(ImmutableMap.of("version", "4.7.0", "sockname", "/path/to/sock"))), FakeListeningProcessState.ofExit(0)).build(), clock);
    Watchman watchman = Watchman.build(executor, fakeWatchmanConnector(Paths.get("/path/to/sock"), 0, ImmutableMap.of(VERSION_QUERY, ImmutableMap.of("version", "4.7.0", "capabilities", ImmutableMap.<String, Boolean>builder().put("term-dirname", true).put("cmd-watch-project", true).put("wildmatch", true).put("wildmatch_multislash", true).put("glob_generator", true).put("clock-sync-timeout", true).build()), ImmutableList.of("watch-project", root), ImmutableMap.of("version", "4.7.0", "watch", root), ImmutableList.of("clock", root, ImmutableMap.of("sync_timeout", 100)), ImmutableMap.of("version", "4.7.0", "clock", "c:0:0:1"))), rootPaths, env, finder, new TestConsole(), clock, Optional.empty());
    assertEquals(ImmutableSet.of(Watchman.Capability.DIRNAME, Watchman.Capability.SUPPORTS_PROJECT_WATCH, Watchman.Capability.WILDMATCH_GLOB, Watchman.Capability.WILDMATCH_MULTISLASH, Watchman.Capability.GLOB_GENERATOR, Watchman.Capability.CLOCK_SYNC_TIMEOUT), watchman.getCapabilities());
    assertEquals(ImmutableMap.of(Paths.get(root), "c:0:0:1"), watchman.getClockIds());
}
Also used : FakeListeningProcessExecutor(com.facebook.buck.util.FakeListeningProcessExecutor) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 37 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class WatchmanTest method shouldFailIfWatchProjectNotAvailable.

@Test
public void shouldFailIfWatchProjectNotAvailable() throws InterruptedException, IOException {
    SettableFakeClock clock = new SettableFakeClock(0, 0);
    FakeListeningProcessExecutor executor = new FakeListeningProcessExecutor(ImmutableMultimap.<ProcessExecutorParams, FakeListeningProcessState>builder().putAll(ProcessExecutorParams.ofCommand(exe, "--output-encoding=bser", "get-sockname"), FakeListeningProcessState.ofStdoutBytes(bserSerialized(ImmutableMap.of("version", "3.8.0", "sockname", "/path/to/sock"))), FakeListeningProcessState.ofExit(0)).build(), clock);
    Watchman watchman = Watchman.build(executor, fakeWatchmanConnector(Paths.get("/path/to/sock"), 0, ImmutableMap.of(VERSION_QUERY, ImmutableMap.of("version", "3.8.0", "capabilities", ImmutableMap.of("term-dirname", true, "cmd-watch-project", false, "wildmatch", false, "wildmatch_multislash", false, "glob_generator", false), "error", "client required capabilty `cmd-watch-project` is not supported by this " + "server"))), rootPaths, env, finder, new TestConsole(), clock, Optional.empty());
    assertEquals(Watchman.NULL_WATCHMAN, watchman);
}
Also used : FakeListeningProcessExecutor(com.facebook.buck.util.FakeListeningProcessExecutor) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 38 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class WatchmanTest method capabilitiesDetectedForVersion38AndLater.

@Test
public void capabilitiesDetectedForVersion38AndLater() throws InterruptedException, IOException {
    SettableFakeClock clock = new SettableFakeClock(0, 0);
    FakeListeningProcessExecutor executor = new FakeListeningProcessExecutor(ImmutableMultimap.<ProcessExecutorParams, FakeListeningProcessState>builder().putAll(ProcessExecutorParams.ofCommand(exe, "--output-encoding=bser", "get-sockname"), FakeListeningProcessState.ofStdoutBytes(bserSerialized(ImmutableMap.of("version", "3.8.0", "sockname", "/path/to/sock"))), FakeListeningProcessState.ofExit(0)).build(), clock);
    Watchman watchman = Watchman.build(executor, fakeWatchmanConnector(Paths.get("/path/to/sock"), 0, ImmutableMap.of(VERSION_QUERY, ImmutableMap.of("version", "3.8.0", "capabilities", ImmutableMap.<String, Boolean>builder().put("term-dirname", true).put("cmd-watch-project", true).put("wildmatch", true).put("wildmatch_multislash", true).put("glob_generator", false).put("clock-sync-timeout", false).build()), ImmutableList.of("watch-project", root), ImmutableMap.of("version", "3.8.0", "watch", root), ImmutableList.of("clock", root, ImmutableMap.of()), ImmutableMap.of("version", "3.8.0", "clock", "c:0:0:1"))), rootPaths, env, finder, new TestConsole(), clock, Optional.empty());
    assertEquals(ImmutableSet.of(Watchman.Capability.DIRNAME, Watchman.Capability.SUPPORTS_PROJECT_WATCH, Watchman.Capability.WILDMATCH_GLOB, Watchman.Capability.WILDMATCH_MULTISLASH), watchman.getCapabilities());
    assertEquals(ImmutableMap.of(Paths.get(root), "c:0:0:1"), watchman.getClockIds());
}
Also used : FakeListeningProcessExecutor(com.facebook.buck.util.FakeListeningProcessExecutor) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 39 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class JUnitStepTest method testGetShellCommand.

@Test
public void testGetShellCommand() throws IOException {
    String testClass1 = "com.facebook.buck.shell.JUnitCommandTest";
    String testClass2 = "com.facebook.buck.shell.InstrumentCommandTest";
    Set<String> testClassNames = ImmutableSet.of(testClass1, testClass2);
    String vmArg1 = "-Dname1=value1";
    String vmArg2 = "-Dname1=value2";
    ImmutableList<String> vmArgs = ImmutableList.of(vmArg1, vmArg2);
    BuildId pretendBuildId = new BuildId("pretend-build-id");
    String buildIdArg = String.format("-Dcom.facebook.buck.buildId=%s", pretendBuildId);
    Path modulePath = Paths.get("module/submodule");
    String modulePathArg = String.format("-Dcom.facebook.buck.moduleBasePath=%s", modulePath);
    Path directoryForTestResults = Paths.get("buck-out/gen/theresults/");
    Path testRunnerClasspath = Paths.get("build/classes/junit");
    ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
    Path classpathFile = filesystem.resolve("foo");
    JUnitJvmArgs args = JUnitJvmArgs.builder().setBuildId(pretendBuildId).setBuckModuleBaseSourceCodePath(modulePath).setClasspathFile(classpathFile).setTestRunnerClasspath(testRunnerClasspath).setExtraJvmArgs(vmArgs).setTestType(TestType.JUNIT).setDirectoryForTestResults(directoryForTestResults).addAllTestClasses(testClassNames).build();
    JUnitStep junit = new JUnitStep(filesystem, /* nativeLibsEnvironment */
    ImmutableMap.of(), /* testRuleTimeoutMs */
    Optional.empty(), /* testCaseTimeoutMs */
    Optional.empty(), ImmutableMap.of(), new ExternalJavaRuntimeLauncher("/foo/bar/custom/java"), args);
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setConsole(new TestConsole(Verbosity.ALL)).setDefaultTestTimeoutMillis(5000L).build();
    assertEquals(executionContext.getVerbosity(), Verbosity.ALL);
    assertEquals(executionContext.getDefaultTestTimeoutMillis(), 5000L);
    List<String> observedArgs = junit.getShellCommand(executionContext);
    MoreAsserts.assertListEquals(ImmutableList.of("/foo/bar/custom/java", "-Dbuck.testrunner_classes=" + testRunnerClasspath, buildIdArg, modulePathArg, "-Dapple.awt.UIElement=true", vmArg1, vmArg2, "-verbose", "-classpath", "@" + classpathFile + File.pathSeparator + MorePaths.pathWithPlatformSeparators("build/classes/junit"), FileClassPathRunner.class.getName(), "com.facebook.buck.testrunner.JUnitMain", "--output", directoryForTestResults.toString(), "--default-test-timeout", "5000", testClass1, testClass2), observedArgs);
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildId(com.facebook.buck.model.BuildId) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 40 with TestConsole

use of com.facebook.buck.testutil.TestConsole in project buck by facebook.

the class JarDirectoryStepTest method shouldFailIfMainClassMissing.

@Test
public void shouldFailIfMainClassMissing() throws IOException {
    Path zipup = folder.newFolder("zipup");
    Path zip = createZip(zipup.resolve("a.zip"), "com/example/Main.class");
    JarDirectoryStep step = new JarDirectoryStep(new ProjectFilesystem(zipup), Paths.get("output.jar"), ImmutableSortedSet.of(zip.getFileName()), "com.example.MissingMain", /* manifest file */
    null);
    TestConsole console = new TestConsole();
    ExecutionContext context = TestExecutionContext.newBuilder().setConsole(console).build();
    int returnCode = step.execute(context).getExitCode();
    assertEquals(1, returnCode);
    assertEquals("ERROR: Main class com.example.MissingMain does not exist.\n", console.getTextWrittenToStdErr());
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Aggregations

TestConsole (com.facebook.buck.testutil.TestConsole)100 Test (org.junit.Test)74 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)27 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)27 ExecutionContext (com.facebook.buck.step.ExecutionContext)25 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)25 Path (java.nio.file.Path)21 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)16 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)16 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)16 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)16 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)16 BuckEventBus (com.facebook.buck.event.BuckEventBus)15 FakeProcess (com.facebook.buck.util.FakeProcess)14 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)13 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)12 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)11 Clock (com.facebook.buck.timing.Clock)10 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)9 BuildTarget (com.facebook.buck.model.BuildTarget)8