use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method testSaveClassFilesToDiskWithRemoveClasses.
@Test
public void testSaveClassFilesToDiskWithRemoveClasses() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "spool_class_files_to_disk_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));
Path jarPath = workspace.getPath(BuildTargets.getGenPath(filesystem, target, "lib__%s__output/a.jar"));
assertTrue("Jar should exist.", 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.assertFileDoesNotExist("test/pkg/RemovableC.class");
zipInspector.assertFileDoesNotExist("test/pkg/B$MemberD.class");
zipInspector.assertFileDoesNotExist("DeletableB.class");
}
use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class GenruleDepsIntegrationTest method testUpdatingJarBuildByGenruleAffectDependentRebuild.
@Test
public void testUpdatingJarBuildByGenruleAffectDependentRebuild() throws IOException {
final Charset charsetForTest = StandardCharsets.UTF_8;
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "genrule_test", tmp);
workspace.setUp();
// The test should pass out of the box.
ProcessResult result = workspace.runBuckCommand("test", "//:test");
result.assertSuccess();
// Edit the test so it should fail and then make sure that it fails.
Path testFile = workspace.getPath("resource.base.txt");
Files.write(testFile, "Different text".getBytes(charsetForTest));
ProcessResult result2 = workspace.runBuckCommand("test", "//:test");
result2.assertTestFailure();
assertThat("`buck test` should fail because testBasicAssertion() failed.", result2.getStderr(), containsString("FAILURE com.example.LameTest testBasicAssertion"));
}
use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method testResourceFileChangeCanTakeAdvantageOfDepBasedKeys.
@Test
public void testResourceFileChangeCanTakeAdvantageOfDepBasedKeys() throws IOException {
workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "resource_in_dep_file", tmp);
workspace.setUp();
// Warm the used classes file
ProcessResult buildResult = workspace.runBuckCommand("build", ":main");
buildResult.assertSuccess("Successful build should exit with 0.");
workspace.getBuildLog().assertTargetBuiltLocally("//:main");
workspace.getBuildLog().assertTargetBuiltLocally("//:util");
// Edit the unread_file.txt resource
workspace.replaceFileContents("unread_file.txt", "hello", "goodbye");
// Run `buck build` again.
ProcessResult buildResult2 = workspace.runBuckCommand("build", "//:main");
buildResult2.assertSuccess("Successful build should exit with 0.");
// If all goes well, we'll fetch //:main's dep file from the cache and realize we don't need
// to rebuild it because //:main didn't use unread_file.
workspace.getBuildLog().assertTargetBuiltLocally("//:util");
workspace.getBuildLog().assertTargetHadMatchingDepfileRuleKey("//:main");
// Edit read_file.txt resource
workspace.replaceFileContents("read_file.txt", "me", "you");
workspace.runBuckCommand("build", ":main").assertSuccess();
// Since that file was used during the compilation, we must rebuild
workspace.getBuildLog().assertTargetBuiltLocally("//:util");
workspace.getBuildLog().assertTargetBuiltLocally("//:main");
}
use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method testSaveClassFilesToDisk.
@Test
public void testSaveClassFilesToDisk() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "spool_class_files_to_disk", 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"));
assertTrue(Files.exists(classesDir));
assertTrue(Files.isDirectory(classesDir));
ArrayList<String> classFiles = new ArrayList<>();
for (File file : classesDir.toFile().listFiles()) {
classFiles.add(file.getName());
}
assertThat("There should be 2 class files saved to disk from the compiler", classFiles, hasSize(2));
assertThat(classFiles, hasItem("A.class"));
assertThat(classFiles, hasItem("B.class"));
}
use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method testAnnotationProcessorFileChangeThatDoesNotModifyAbiCausesRebuild.
@Test
public void testAnnotationProcessorFileChangeThatDoesNotModifyAbiCausesRebuild() throws IOException {
workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "annotation_processors", tmp);
workspace.setUp();
// Run `buck build` to create the dep file
BuildTarget mainTarget = BuildTargetFactory.newInstance("//:main");
// Warm the used classes file
ProcessResult buildResult = workspace.runBuckCommand("build", mainTarget.getFullyQualifiedName());
buildResult.assertSuccess("Successful build should exit with 0.");
workspace.getBuildLog().assertTargetBuiltLocally("//:main");
workspace.getBuildLog().assertTargetBuiltLocally("//:annotation_processor");
workspace.getBuildLog().assertTargetBuiltLocally("//:util");
// Edit a source file in the annotation processor in a way that doesn't change the ABI
workspace.replaceFileContents("AnnotationProcessor.java", "false", "true");
// Run `buck build` again.
ProcessResult buildResult2 = workspace.runBuckCommand("build", "//:main");
buildResult2.assertSuccess("Successful build should exit with 0.");
// If all goes well, we'll rebuild //:annotation_processor because of the source change,
// and then rebuild //:main because the code of the annotation processor has changed
workspace.getBuildLog().assertTargetHadMatchingRuleKey("//:util");
workspace.getBuildLog().assertTargetBuiltLocally("//:main");
workspace.getBuildLog().assertTargetBuiltLocally("//:annotation_processor");
}
Aggregations