Search in sources :

Example 56 with ProcessResult

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");
}
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 57 with ProcessResult

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

Example 58 with ProcessResult

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

Example 59 with ProcessResult

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

Example 60 with ProcessResult

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();
}
Also used : Path(java.nio.file.Path) ImmutableSet(com.google.common.collect.ImmutableSet) ZipFile(java.util.zip.ZipFile) BuildTarget(com.facebook.buck.model.BuildTarget) ZipEntry(java.util.zip.ZipEntry) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) 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