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"));
}
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());
}
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());
}
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));
}
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()));
}
Aggregations