Search in sources :

Example 91 with ProcessResult

use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.

the class DefaultJavaLibraryIntegrationTest method testFileChangeThatDoesNotModifyAbiOfAUsedClassAvoidsRebuild.

@Test
public void testFileChangeThatDoesNotModifyAbiOfAUsedClassAvoidsRebuild() throws IOException {
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "dep_file_rule_key", tmp);
    workspace.setUp();
    // Run `buck build` to create the dep file
    BuildTarget bizTarget = BuildTargetFactory.newInstance("//:biz");
    // Warm the used classes file
    ProcessResult buildResult = workspace.runBuckCommand("build", bizTarget.getFullyQualifiedName());
    buildResult.assertSuccess("Successful build should exit with 0.");
    workspace.getBuildLog().assertTargetBuiltLocally("//:biz");
    workspace.getBuildLog().assertTargetBuiltLocally("//:util");
    // Edit MoreUtil.java in a way that changes its ABI
    workspace.replaceFileContents("MoreUtil.java", "printHelloWorld", "printHelloWorld2");
    // Run `buck build` again.
    ProcessResult buildResult2 = workspace.runBuckCommand("build", "//:biz");
    buildResult2.assertSuccess("Successful build should exit with 0.");
    // If all goes well, we'll fetch //:biz's dep file from the cache and realize we don't need
    // to rebuild it because //:biz didn't use MoreUtil.
    workspace.getBuildLog().assertTargetBuiltLocally("//:util");
    workspace.getBuildLog().assertTargetHadMatchingDepfileRuleKey("//:biz");
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 92 with ProcessResult

use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.

the class DefaultJavaLibraryIntegrationTest method testBuildJavaLibraryWithoutSrcsAndVerifyAbi.

@Test
public void testBuildJavaLibraryWithoutSrcsAndVerifyAbi() throws IOException {
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "abi", tmp);
    workspace.setUp();
    workspace.enableDirCache();
    // Run `buck build`.
    BuildTarget target = BuildTargetFactory.newInstance("//:no_srcs");
    ProcessResult buildResult = workspace.runBuckCommand("build", target.getFullyQualifiedName());
    buildResult.assertSuccess("Successful build should exit with 0.");
    Path outputPath = BuildTargets.getGenPath(filesystem, target, "lib__%s__output/" + target.getShortName() + ".jar");
    Path outputFile = workspace.getPath(outputPath);
    assertTrue(Files.exists(outputFile));
    // TODO(bolinfest): When we produce byte-for-byte identical JAR files across builds, do:
    //
    //   HashCode hashOfOriginalJar = Files.hash(outputFile, Hashing.sha1());
    //
    // And then compare that to the output when //:no_srcs is built again with --no-cache.
    long sizeOfOriginalJar = Files.size(outputFile);
    // This verifies that the ABI key was written correctly.
    workspace.verify();
    // Verify the build cache.
    Path buildCache = workspace.getPath(filesystem.getBuckPaths().getCacheDir());
    assertTrue(Files.isDirectory(buildCache));
    ArtifactCache dirCache = TestArtifactCaches.createDirCacheForTest(workspace.getDestPath(), buildCache);
    int totalArtifactsCount = DirArtifactCacheTestUtil.getAllFilesInCache(dirCache).size();
    assertEquals("There should be two entries (a zip and metadata) in the build cache.", 2, totalArtifactsCount);
    // Run `buck clean`.
    ProcessResult cleanResult = workspace.runBuckCommand("clean");
    cleanResult.assertSuccess("Successful clean should exit with 0.");
    totalArtifactsCount = getAllFilesInPath(buildCache).size();
    assertEquals("The build cache should still exist.", 2, totalArtifactsCount);
    // Corrupt the build cache!
    File artifactZip = FluentIterable.from(ImmutableList.copyOf(DirArtifactCacheTestUtil.getAllFilesInCache(dirCache))).toSortedList(Ordering.natural()).get(0).toFile();
    FileSystem zipFs = FileSystems.newFileSystem(artifactZip.toPath(), /* loader */
    null);
    Path outputInZip = zipFs.getPath("/" + outputPath.toString());
    Files.write(outputInZip, "Hello world!".getBytes(), WRITE);
    zipFs.close();
    // Run `buck build` again.
    ProcessResult buildResult2 = workspace.runBuckCommand("build", target.getFullyQualifiedName());
    buildResult2.assertSuccess("Successful build should exit with 0.");
    assertTrue(Files.isRegularFile(outputFile));
    assertEquals("The content of the output file will be 'Hello World!' if it is read from the build cache.", "Hello world!", new String(Files.readAllBytes(outputFile), UTF_8));
    // Run `buck clean` followed by `buck build` yet again, but this time, specify `--no-cache`.
    ProcessResult cleanResult2 = workspace.runBuckCommand("clean");
    cleanResult2.assertSuccess("Successful clean should exit with 0.");
    ProcessResult buildResult3 = workspace.runBuckCommand("build", "--no-cache", target.getFullyQualifiedName());
    buildResult3.assertSuccess();
    assertNotEquals("The contents of the file should no longer be pulled from the corrupted build cache.", "Hello world!", new String(Files.readAllBytes(outputFile), UTF_8));
    assertEquals("We cannot do a byte-for-byte comparision with the original JAR because timestamps might " + "have changed, but we verify that they are the same size, as a proxy.", sizeOfOriginalJar, Files.size(outputFile));
}
Also used : Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) FileSystem(java.nio.file.FileSystem) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ZipFile(java.util.zip.ZipFile) File(java.io.File) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) Test(org.junit.Test)

Example 93 with ProcessResult

use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.

the class DefaultJavaLibraryIntegrationTest method ensureThatSourcePathIsSetSensibly.

@Test
public void ensureThatSourcePathIsSetSensibly() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "sourcepath", tmp);
    workspace.setUp();
    ProcessResult result = workspace.runBuckBuild("//:b");
    // This should fail, since we expect the symbol for A not to be found.
    result.assertFailure();
    String stderr = result.getStderr();
    assertTrue(stderr, stderr.contains("cannot find symbol"));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 94 with ProcessResult

use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.

the class DefaultJavaLibraryIntegrationTest method testFileChangeThatDoesNotModifyAbiOfAUsedClassAvoidsRebuildEvenWithBuckClean.

@Test
public void testFileChangeThatDoesNotModifyAbiOfAUsedClassAvoidsRebuildEvenWithBuckClean() throws IOException {
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "dep_file_rule_key", tmp);
    workspace.setUp();
    workspace.enableDirCache();
    // Run `buck build` to warm the cache.
    BuildTarget bizTarget = BuildTargetFactory.newInstance("//:biz");
    // Warm the used classes file
    ProcessResult buildResult = workspace.runBuckCommand("build", bizTarget.getFullyQualifiedName());
    buildResult.assertSuccess("Successful build should exit with 0.");
    workspace.getBuildLog().assertTargetBuiltLocally("//:biz");
    workspace.getBuildLog().assertTargetBuiltLocally("//:util");
    // Run `buck clean` so that we're forced to fetch the dep file from the cache.
    ProcessResult cleanResult = workspace.runBuckCommand("clean");
    cleanResult.assertSuccess("Successful clean should exit with 0.");
    // Edit MoreUtil.java in a way that changes its ABI
    workspace.replaceFileContents("MoreUtil.java", "printHelloWorld", "printHelloWorld2");
    // Run `buck build` again.
    ProcessResult buildResult2 = workspace.runBuckCommand("build", "//:biz");
    buildResult2.assertSuccess("Successful build should exit with 0.");
    // If all goes well, we'll fetch //:biz's dep file from the cache and realize we don't need
    // to rebuild it because //:biz didn't use MoreUtil.
    workspace.getBuildLog().assertTargetBuiltLocally("//:util");
    workspace.getBuildLog().assertTargetWasFetchedFromCacheByManifestMatch("//:biz");
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 95 with ProcessResult

use of com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult in project buck by facebook.

the class DefaultJavaLibraryIntegrationTest method testSpoolClassFilesDirectlyToJar.

@Test
public void testSpoolClassFilesDirectlyToJar() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "spool_class_files_directly_to_jar", 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(Files.exists(classesDir), is(Boolean.TRUE));
    assertThat("There should be no class files in 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));
    ZipInputStream zip = new ZipInputStream(new FileInputStream(jarPath.toFile()));
    assertThat(zip.getNextEntry().getName(), is("A.class"));
    assertThat(zip.getNextEntry().getName(), is("B.class"));
    zip.close();
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ZipInputStream(java.util.zip.ZipInputStream) BuildTarget(com.facebook.buck.model.BuildTarget) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) FileInputStream(java.io.FileInputStream) 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