use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method testSpoolClassFilesDirectlyToJarWithRemoveClasses.
@Test
public void testSpoolClassFilesDirectlyToJarWithRemoveClasses() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "spool_class_files_directly_to_jar_with_remove_classes", tmp);
workspace.setUp();
BuildTarget target = BuildTargetFactory.newInstance("//:a");
ProcessResult result = workspace.runBuckBuild(target.getFullyQualifiedName());
result.assertSuccess();
Path classesDir = workspace.getPath(BuildTargets.getScratchPath(filesystem, target, "lib__%s__classes"));
assertThat("Classes directory should exist.", Files.exists(classesDir), is(Boolean.TRUE));
assertThat("No class files should be stored on disk.", ImmutableList.copyOf(classesDir.toFile().listFiles()), hasSize(0));
Path jarPath = workspace.getPath(BuildTargets.getGenPath(filesystem, target, "lib__%s__output/a.jar"));
assertTrue(Files.exists(jarPath));
// Check that normal and member classes were removed as expected.
ZipInspector zipInspector = new ZipInspector(jarPath);
zipInspector.assertFileExists("test/pkg/A.class");
zipInspector.assertFileExists("test/pkg/B.class");
zipInspector.assertFileExists("test/pkg/C.class");
zipInspector.assertFileDoesNotExist("test/pkg/RemovableZ.class");
zipInspector.assertFileDoesNotExist("B$removableB.class");
zipInspector.assertFileDoesNotExist("C$deletableD.class");
}
use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class CompileSrcZipIntegrationTest method testJavaLibraryRuleAcceptsZipFileOfJavaSourceCodeAsInput.
@Test
public void testJavaLibraryRuleAcceptsZipFileOfJavaSourceCodeAsInput() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "src_zip", tmp);
workspace.setUp();
ProcessResult buildResult = workspace.runBuckCommand("build", "//:lib", "-v", "2");
buildResult.assertSuccess("Successful build should exit with 0.");
}
use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method testBuildJavaLibraryShouldSuggestTransitiveImportsToInclude.
@Test
public void testBuildJavaLibraryShouldSuggestTransitiveImportsToInclude() throws IOException {
workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "warn_on_transitive", tmp);
workspace.setUp();
// Run `buck build`.
ProcessResult buildResult = workspace.runBuckCommand("build", "//:raz");
String expectedWarning = Joiner.on("\n").join("Rule //:raz has failed to build.", "Blargh", "Meh", "Try adding the following deps:", "//:blargh", "//:foo");
buildResult.assertFailure("Build should have failed with warnings.");
assertThat(buildResult.getStderr(), containsString(expectedWarning));
workspace.verify();
}
use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method testFileChangeThatDoesNotModifyAbiAvoidsRebuild.
@Test
public void testFileChangeThatDoesNotModifyAbiAvoidsRebuild() throws IOException {
workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "rulekey_changed_while_abi_stable", tmp);
workspace.setUp();
// Run `buck build`.
BuildTarget bizTarget = BuildTargetFactory.newInstance("//:biz");
BuildTarget utilTarget = BuildTargetFactory.newInstance("//:util");
ProcessResult buildResult = workspace.runBuckCommand("build", bizTarget.getFullyQualifiedName());
buildResult.assertSuccess("Successful build should exit with 0.");
Path utilRuleKeyPath = BuildTargets.getScratchPath(filesystem, utilTarget, ".%s/metadata/RULE_KEY");
String utilRuleKey = getContents(utilRuleKeyPath);
Path utilAbiRuleKeyPath = BuildTargets.getScratchPath(filesystem, utilTarget, ".%s/metadata/INPUT_BASED_RULE_KEY");
String utilAbiRuleKey = getContents(utilAbiRuleKeyPath);
Path bizRuleKeyPath = BuildTargets.getScratchPath(filesystem, bizTarget, ".%s/metadata/RULE_KEY");
String bizRuleKey = getContents(bizRuleKeyPath);
Path bizAbiRuleKeyPath = BuildTargets.getScratchPath(filesystem, bizTarget, ".%s/metadata/INPUT_BASED_RULE_KEY");
String bizAbiRuleKey = getContents(bizAbiRuleKeyPath);
Path utilOutputPath = BuildTargets.getGenPath(filesystem, utilTarget, "lib__%s__output/" + utilTarget.getShortName() + ".jar");
long utilJarSize = Files.size(workspace.getPath(utilOutputPath));
Path bizOutputPath = BuildTargets.getGenPath(filesystem, bizTarget, "lib__%s__output/" + bizTarget.getShortName() + ".jar");
FileTime bizJarLastModified = Files.getLastModifiedTime(workspace.getPath(bizOutputPath));
// TODO(bolinfest): Run uber-biz.jar and verify it prints "Hello World!\n".
// Edit Util.java in a way that does not affect its ABI.
workspace.replaceFileContents("Util.java", "Hello World", "Hola Mundo");
// Run `buck build` again.
ProcessResult buildResult2 = workspace.runBuckCommand("build", "//:biz");
buildResult2.assertSuccess("Successful build should exit with 0.");
assertThat(utilRuleKey, not(equalTo(getContents(utilRuleKeyPath))));
assertThat(utilAbiRuleKey, not(equalTo(getContents(utilAbiRuleKeyPath))));
workspace.getBuildLog().assertTargetBuiltLocally(utilTarget.toString());
assertThat(bizRuleKey, not(equalTo(getContents(bizRuleKeyPath))));
assertEquals(bizAbiRuleKey, getContents(bizAbiRuleKeyPath));
workspace.getBuildLog().assertTargetHadMatchingInputRuleKey(bizTarget.toString());
assertThat("util.jar should have been rewritten, so its file size should have changed.", utilJarSize, not(equalTo(Files.size(workspace.getPath(utilOutputPath)))));
assertEquals("biz.jar should not have been rewritten, so its last-modified time should be the same.", bizJarLastModified, Files.getLastModifiedTime(workspace.getPath(bizOutputPath)));
// TODO(bolinfest): Run uber-biz.jar and verify it prints "Hola Mundo!\n".
// TODO(bolinfest): This last scenario that is being tested would be better as a unit test.
// Run `buck build` one last time. This ensures that a dependency java_library() rule (:util)
// that is built via BuildRuleSuccess.Type.MATCHING_INPUT_BASED_RULE_KEY does not
// explode when its dependent rule (:biz) invokes the dependency's getAbiKey() method as part of
// its own getAbiKeyForDeps().
ProcessResult buildResult3 = workspace.runBuckCommand("build", "//:biz");
buildResult3.assertSuccess("Successful build should exit with 0.");
}
use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method testBuildJavaLibraryExportsDirectoryEntries.
@Test
public void testBuildJavaLibraryExportsDirectoryEntries() throws IOException {
workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "export_directory_entries", tmp);
workspace.setUp();
// Run `buck build`.
BuildTarget target = BuildTargetFactory.newInstance("//:empty_directory_entries");
ProcessResult buildResult = workspace.runBuckBuild(target.getFullyQualifiedName());
buildResult.assertSuccess();
Path outputFile = workspace.getPath(BuildTargets.getGenPath(filesystem, target, "lib__%s__output/" + target.getShortName() + ".jar"));
assertTrue(Files.exists(outputFile));
ImmutableSet.Builder<String> jarContents = ImmutableSet.builder();
try (ZipFile zipFile = new ZipFile(outputFile.toFile())) {
for (ZipEntry zipEntry : Collections.list(zipFile.entries())) {
jarContents.add(zipEntry.getName());
}
}
// TODO(mread): Change the output to the intended output.
assertEquals(jarContents.build(), ImmutableSet.of("META-INF/", "META-INF/MANIFEST.MF", "swag.txt", "yolo.txt"));
workspace.verify();
}
Aggregations