Search in sources :

Example 61 with ProcessResult

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

the class DefaultJavaLibraryIntegrationTest method ensureProvidedDepsAreIncludedWhenCompilingButNotWhenPackaging.

@Test
public void ensureProvidedDepsAreIncludedWhenCompilingButNotWhenPackaging() throws IOException {
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "provided_deps", tmp);
    workspace.setUp();
    // Run `buck build`.
    BuildTarget binaryTarget = BuildTargetFactory.newInstance("//:binary");
    BuildTarget binary2Target = BuildTargetFactory.newInstance("//:binary_2");
    ProcessResult buildResult = workspace.runBuckCommand("build", binaryTarget.getFullyQualifiedName(), binary2Target.getFullyQualifiedName());
    buildResult.assertSuccess("Successful build should exit with 0.");
    for (Path filename : new Path[] { BuildTargets.getGenPath(filesystem, binaryTarget, "%s.jar"), BuildTargets.getGenPath(filesystem, binary2Target, "%s.jar") }) {
        Path file = workspace.getPath(filename);
        try (Zip zip = new Zip(file, /* for writing? */
        false)) {
            Set<String> allNames = zip.getFileNames();
            // Representative file from provided_deps we don't expect to be there.
            assertFalse(allNames.contains("org/junit/Test.class"));
            // Representative file from the deps that we do expect to be there.
            assertTrue(allNames.contains("com/google/common/collect/Sets.class"));
            // The file we built.
            assertTrue(allNames.contains("com/facebook/buck/example/Example.class"));
        }
    }
}
Also used : Path(java.nio.file.Path) Zip(com.facebook.buck.testutil.Zip) BuildTarget(com.facebook.buck.model.BuildTarget) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 62 with ProcessResult

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

the class DefaultJavaLibraryIntegrationTest method testBuildJavaLibraryWithFirstOrder.

@Test
public void testBuildJavaLibraryWithFirstOrder() throws IOException {
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "warn_on_transitive", tmp);
    workspace.setUp();
    // Run `buck build`.
    ProcessResult buildResult = workspace.runBuckCommand("build", "//:raz", "-b", "FIRST_ORDER_ONLY");
    buildResult.assertFailure("Build should have failed.");
    workspace.verify();
}
Also used : ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 63 with ProcessResult

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

the class DefaultJavaLibraryIntegrationTest method testBucksClasspathNotOnBuildClasspath.

@Test
public void testBucksClasspathNotOnBuildClasspath() throws IOException {
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "guava_no_deps", tmp);
    workspace.setUp();
    // Run `buck build`.
    ProcessResult buildResult = workspace.runBuckCommand("build", "//:foo");
    buildResult.assertFailure("Build should have failed since //:foo depends on Guava and " + "Args4j but does not include it in its deps.");
    workspace.verify();
}
Also used : ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 64 with ProcessResult

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

the class DefaultJavaLibraryIntegrationTest method testAddedSourceFileInvalidatesManifest.

// Yes, we actually had the bug against which this test is guarding.
@Test
public void testAddedSourceFileInvalidatesManifest() throws IOException {
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "manifest_key", tmp);
    workspace.setUp();
    workspace.enableDirCache();
    // Run `buck build` to warm the cache.
    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");
    // 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.");
    // Add a new source file
    workspace.writeContentsToPath("package com.example; public class NewClass { }", "NewClass.java");
    // Run `buck build` again.
    ProcessResult buildResult2 = workspace.runBuckCommand("build", mainTarget.getFullyQualifiedName());
    buildResult2.assertSuccess("Successful build should exit with 0.");
    // The new source file should result in a different manifest being downloaded and thus a
    // cache miss.
    workspace.getBuildLog().assertTargetBuiltLocally("//:main");
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 65 with ProcessResult

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

the class DefaultJavaLibraryIntegrationTest method testNoDepsCompilesCleanly.

@Test
public void testNoDepsCompilesCleanly() throws IOException {
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "guava_no_deps", tmp);
    workspace.setUp();
    // Run `buck build`.
    ProcessResult buildResult = workspace.runBuckCommand("build", "//:bar");
    buildResult.assertSuccess("Build should have succeeded.");
    workspace.verify();
}
Also used : 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