Search in sources :

Example 86 with ProcessResult

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");
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 87 with ProcessResult

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"));
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Charset(java.nio.charset.Charset) Test(org.junit.Test)

Example 88 with ProcessResult

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");
}
Also used : ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 89 with ProcessResult

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"));
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) ArrayList(java.util.ArrayList) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Example 90 with ProcessResult

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");
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Aggregations

ProcessResult (com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult)175 Test (org.junit.Test)174 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)127 Path (java.nio.file.Path)21 Matchers.containsString (org.hamcrest.Matchers.containsString)20 BuildTarget (com.facebook.buck.model.BuildTarget)17 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 TestContext (com.facebook.buck.testutil.integration.TestContext)4 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)3 ZipInspector (com.facebook.buck.testutil.integration.ZipInspector)3 ZipFile (java.util.zip.ZipFile)3 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)2 DelegatingInputStream (com.facebook.buck.testutil.integration.DelegatingInputStream)2 CapturingPrintStream (com.facebook.buck.util.CapturingPrintStream)2 File (java.io.File)2 Charset (java.nio.charset.Charset)2 FileTime (java.nio.file.attribute.FileTime)2 ArtifactCache (com.facebook.buck.artifact_cache.ArtifactCache)1