use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class BaseCompileToJarStepFactoryTest method testAddPostprocessClassesCommands.
@Test
public void testAddPostprocessClassesCommands() {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
String androidBootClassPath = filesystem.resolve("android.jar").toString();
ImmutableList<String> postprocessClassesCommands = ImmutableList.of("tool arg1", "tool2");
Path outputDirectory = filesystem.getBuckPaths().getScratchDir().resolve("android/java/lib__java__classes");
ImmutableSortedSet<Path> classpathEntries = ImmutableSortedSet.<Path>naturalOrder().add(filesystem.resolve("rt.jar")).add(filesystem.resolve("dep.jar")).build();
ExecutionContext executionContext = TestExecutionContext.newInstance();
ImmutableList.Builder<Step> commands = ImmutableList.builder();
commands.addAll(BaseCompileToJarStepFactory.addPostprocessClassesCommands(new FakeProjectFilesystem(), postprocessClassesCommands, outputDirectory, classpathEntries, Optional.of(androidBootClassPath)));
ImmutableList<Step> steps = commands.build();
assertEquals(2, steps.size());
assertTrue(steps.get(0) instanceof ShellStep);
ShellStep step0 = (ShellStep) steps.get(0);
assertEquals(ImmutableList.of("bash", "-c", "tool arg1 " + outputDirectory), step0.getShellCommand(executionContext));
assertEquals(ImmutableMap.of("COMPILATION_BOOTCLASSPATH", androidBootClassPath, "COMPILATION_CLASSPATH", Joiner.on(':').join(Iterables.transform(classpathEntries, filesystem::resolve))), step0.getEnvironmentVariables(executionContext));
assertTrue(steps.get(1) instanceof ShellStep);
ShellStep step1 = (ShellStep) steps.get(1);
assertEquals(ImmutableList.of("bash", "-c", "tool2 " + outputDirectory), step1.getShellCommand(executionContext));
assertEquals(ImmutableMap.of("COMPILATION_BOOTCLASSPATH", androidBootClassPath, "COMPILATION_CLASSPATH", Joiner.on(':').join(Iterables.transform(classpathEntries, filesystem::resolve))), step1.getEnvironmentVariables(executionContext));
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class GenerateCodeCoverageReportStepTest method testJarFileIsExtracted.
@Test
public void testJarFileIsExtracted() throws Throwable {
final File[] extractedDir = new File[2];
step = new GenerateCodeCoverageReportStep(new ExternalJavaRuntimeLauncher("/baz/qux/java"), filesystem, SOURCE_DIRECTORIES, jarFiles, Paths.get(OUTPUT_DIRECTORY), CoverageReportFormat.HTML, "TitleFoo", Optional.empty(), Optional.empty()) {
@Override
StepExecutionResult executeInternal(ExecutionContext context, Set<Path> jarFiles) {
for (int i = 0; i < 2; i++) {
extractedDir[i] = new ArrayList<>(jarFiles).get(i).toFile();
assertTrue(extractedDir[i].isDirectory());
assertTrue(new File(extractedDir[i], "com/facebook/testing/coverage/Foo.class").exists());
}
return null;
}
};
step.execute(TestExecutionContext.newInstance());
assertFalse(extractedDir[0].exists());
assertFalse(extractedDir[1].exists());
}
use of com.facebook.buck.step.ExecutionContext in project buck by facebook.
the class GenerateCodeCoverageReportStepTest method testClassesDirIsUntouched.
@Test
public void testClassesDirIsUntouched() throws Throwable {
final File classesDir = tmp.newFolder("classesDir");
jarFiles.clear();
jarFiles.add(classesDir.toPath());
step = new GenerateCodeCoverageReportStep(new ExternalJavaRuntimeLauncher("/baz/qux/java"), filesystem, SOURCE_DIRECTORIES, jarFiles, Paths.get(OUTPUT_DIRECTORY), CoverageReportFormat.HTML, "TitleFoo", Optional.empty(), Optional.empty()) {
@Override
StepExecutionResult executeInternal(ExecutionContext context, Set<Path> jarFiles) {
assertEquals(1, jarFiles.size());
assertEquals(classesDir.toPath(), jarFiles.iterator().next());
return null;
}
};
step.execute(TestExecutionContext.newInstance());
assertTrue(classesDir.exists());
}
use of com.facebook.buck.step.ExecutionContext 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);
}
use of com.facebook.buck.step.ExecutionContext 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());
}
Aggregations