Search in sources :

Example 56 with TestConsole

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

the class XctoolRunTestsStepTest method xctoolCommandWhichFailsPrintsStderrToConsole.

@Test
public void xctoolCommandWhichFailsPrintsStderrToConsole() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    XctoolRunTestsStep step = new XctoolRunTestsStep(projectFilesystem, Paths.get("/path/to/xctool"), ImmutableMap.of(), Optional.empty(), "iphonesimulator", Optional.empty(), ImmutableSet.of(Paths.get("/path/to/Foo.xctest")), ImmutableMap.of(), Paths.get("/path/to/output.json"), Optional.empty(), Suppliers.ofInstance(Optional.of(Paths.get("/path/to/developer/dir"))), TestSelectorList.EMPTY, false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
    ProcessExecutorParams xctoolParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("/path/to/xctool", "-reporter", "json-stream", "-sdk", "iphonesimulator", "run-tests", "-logicTest", "/path/to/Foo.xctest")).setEnvironment(ImmutableMap.of("DEVELOPER_DIR", "/path/to/developer/dir")).setDirectory(projectFilesystem.getRootPath().toAbsolutePath()).setRedirectOutput(ProcessBuilder.Redirect.PIPE).build();
    FakeProcess fakeXctoolFailure = new FakeProcess(42, "", "Something went terribly wrong\n");
    FakeProcessExecutor processExecutor = new FakeProcessExecutor(ImmutableMap.of(xctoolParams, fakeXctoolFailure));
    TestConsole testConsole = new TestConsole();
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(processExecutor).setEnvironment(ImmutableMap.of()).setConsole(testConsole).build();
    assertThat(step.execute(executionContext).getExitCode(), equalTo(42));
    assertThat(testConsole.getTextWrittenToStdErr(), equalTo("xctool failed with exit code 42: Something went terribly wrong\n"));
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProcess(com.facebook.buck.util.FakeProcess) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 57 with TestConsole

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

the class JUnitStepTest method ensureThatDebugFlagCausesJavaDebugCommandFlagToBeAdded.

@Test
public void ensureThatDebugFlagCausesJavaDebugCommandFlagToBeAdded() {
    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().setClasspathFile(classpathFile).setBuildId(pretendBuildId).setBuckModuleBaseSourceCodePath(modulePath).setTestRunnerClasspath(testRunnerClasspath).setDebugEnabled(true).setExtraJvmArgs(vmArgs).setTestType(TestType.JUNIT).setDirectoryForTestResults(directoryForTestResults).addAllTestClasses(testClassNames).build();
    JUnitStep junit = new JUnitStep(filesystem, ImmutableMap.of(), /* testRuleTimeoutMs */
    Optional.empty(), /* testCaseTimeoutMs */
    Optional.empty(), ImmutableMap.of(), new ExternalJavaRuntimeLauncher("/foo/bar/custom/java"), args);
    TestConsole console = new TestConsole(Verbosity.ALL);
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setConsole(console).setDebugEnabled(true).build();
    List<String> observedArgs = junit.getShellCommand(executionContext);
    MoreAsserts.assertListEquals(ImmutableList.of("/foo/bar/custom/java", "-Dbuck.testrunner_classes=" + testRunnerClasspath, buildIdArg, modulePathArg, "-Dapple.awt.UIElement=true", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005", 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", "0", testClass1, testClass2), observedArgs);
    // TODO(shs96c): Why does the CapturingPrintStream append spaces?
    assertEquals("Debugging. Suspending JVM. Connect a JDWP debugger to port 5005 to proceed.", console.getTextWrittenToStdErr().trim());
}
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 58 with TestConsole

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

the class ProjectWorkspace method asCell.

public Cell asCell() throws IOException, InterruptedException {
    ProjectFilesystemAndConfig filesystemAndConfig = projectFilesystemAndConfig.get();
    ProjectFilesystem filesystem = filesystemAndConfig.projectFilesystem;
    Config config = filesystemAndConfig.config;
    TestConsole console = new TestConsole();
    ImmutableMap<String, String> env = ImmutableMap.copyOf(System.getenv());
    DefaultAndroidDirectoryResolver directoryResolver = new DefaultAndroidDirectoryResolver(filesystem.getRootPath().getFileSystem(), env, Optional.empty(), Optional.empty());
    return CellProvider.createForLocalBuild(filesystem, Watchman.NULL_WATCHMAN, new BuckConfig(config, filesystem, Architecture.detect(), Platform.detect(), env, new DefaultCellPathResolver(filesystem.getRootPath(), config)), CellConfig.of(), new KnownBuildRuleTypesFactory(new DefaultProcessExecutor(console), directoryResolver)).getCellByPath(filesystem.getRootPath());
}
Also used : DefaultCellPathResolver(com.facebook.buck.rules.DefaultCellPathResolver) DefaultAndroidDirectoryResolver(com.facebook.buck.android.DefaultAndroidDirectoryResolver) BuckConfig(com.facebook.buck.cli.BuckConfig) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) BuckConfig(com.facebook.buck.cli.BuckConfig) Config(com.facebook.buck.config.Config) CellConfig(com.facebook.buck.config.CellConfig) KnownBuildRuleTypesFactory(com.facebook.buck.rules.KnownBuildRuleTypesFactory) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole)

Example 59 with TestConsole

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

the class ProcessExecutorSerializerTest method testSerializingDefaultType.

@Test
public void testSerializingDefaultType() throws Exception {
    Console console = new TestConsole();
    DefaultProcessExecutor instance = new DefaultProcessExecutor(console);
    Map<String, Object> data = ProcessExecutorSerializer.serialize(instance);
    ProcessExecutor outstance = ProcessExecutorSerializer.deserialize(data, console);
    assertThat(outstance, Matchers.instanceOf(DefaultProcessExecutor.class));
}
Also used : TestConsole(com.facebook.buck.testutil.TestConsole) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 60 with TestConsole

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

the class ProcessExecutorSerializerTest method testSerializingContextualType.

@Test
public void testSerializingContextualType() throws Exception {
    Console console = new TestConsole();
    DefaultProcessExecutor delegate = new DefaultProcessExecutor(console);
    ImmutableMap<String, String> context = ImmutableMap.of("k1", "v1", "k2", "v2");
    ContextualProcessExecutor instance = new ContextualProcessExecutor(delegate, context);
    Map<String, Object> data = ProcessExecutorSerializer.serialize(instance);
    ProcessExecutor outstance = ProcessExecutorSerializer.deserialize(data, console);
    assertThat(outstance, Matchers.instanceOf(ContextualProcessExecutor.class));
    ContextualProcessExecutor contextualProcessExecutor = (ContextualProcessExecutor) outstance;
    assertThat(contextualProcessExecutor.getContext(), Matchers.equalToObject(context));
    assertThat(contextualProcessExecutor.getDelegate(), Matchers.instanceOf(delegate.getClass()));
}
Also used : TestConsole(com.facebook.buck.testutil.TestConsole) 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