Search in sources :

Example 51 with ProcessResult

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

the class TargetsCommandIntegrationTest method testRuleKeyWithoutTarget.

@Test
public void testRuleKeyWithoutTarget() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "output_path", tmp);
    workspace.setUp();
    ProcessResult result = workspace.runBuckCommand("targets", "--show-rulekey");
    result.assertSuccess();
    assertThat(result.getStdout().trim(), Matchers.matchesPattern("//:another-test [a-f0-9]{40}\n//:test [a-f0-9]{40}"));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 52 with ProcessResult

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

the class TargetsCommandIntegrationTest method testTargetHashXcodeWorkspaceWithTests.

@Test
public void testTargetHashXcodeWorkspaceWithTests() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "xcode_workspace_with_tests", tmp);
    workspace.setUp();
    ProcessResult result = workspace.runBuckCommand("targets", "--show-target-hash", "--detect-test-changes", "//workspace:workspace");
    result.assertSuccess();
    parseAndVerifyTargetAndHash(result.getStdout(), "//workspace:workspace");
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 53 with ProcessResult

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

the class TargetsCommandIntegrationTest method testJsonOutputWithShowFullOutput.

@Test
public void testJsonOutputWithShowFullOutput() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "output_path", tmp);
    workspace.setUp();
    ProcessResult result = workspace.runBuckCommand("targets", "--json", "--show-full-output", "//:test");
    ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
    // Parse the observed JSON.
    JsonNode observed = objectMapper.readTree(objectMapper.getFactory().createParser(result.getStdout()));
    assertTrue(observed.isArray());
    JsonNode targetNode = observed.get(0);
    assertTrue(targetNode.isObject());
    JsonNode cellPath = targetNode.get("buck.outputPath");
    assertNotNull(cellPath);
    Path expectedPath = tmp.getRoot().resolve("buck-out/gen/test/test-output");
    String expectedRootPath = MorePaths.pathWithPlatformSeparators(expectedPath);
    assertEquals(expectedRootPath, cellPath.asText());
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 54 with ProcessResult

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

the class CachedTestIntegrationTest method testRunningTestAfterBuildingWithCacheHitDoesNotReportStaleTests.

/**
   * This is similar to {@link #testPullingJarFromCacheDoesNotResultInReportingStaleTestResults()}
   * but this first builds the test and then runs it. It catches the corner case where the test run
   * may have the jar read from disk, but the test results are still stale.
   */
@Test
public void testRunningTestAfterBuildingWithCacheHitDoesNotReportStaleTests() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "cached_test", tmp);
    workspace.setUp();
    CachedTestUtil testUtil = new CachedTestUtil(workspace);
    // 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.
    testUtil.makeTestFail();
    workspace.runBuckCommand("build", "//:test").assertSuccess("The test should build successfully, but will fail when executed.");
    ProcessResult result2 = workspace.runBuckCommand("test", "//:test");
    result2.assertTestFailure();
    assertThat("`buck test` should fail because testBasicAssertion() failed.", result2.getStderr(), containsString("FAILURE com.example.LameTest testBasicAssertion"));
    // Restore the file to its previous state.
    testUtil.makeTestSucceed();
    workspace.runBuckCommand("build", "//:test").assertSuccess("The test should build successfully.");
    ProcessResult result3 = workspace.runBuckCommand("test", "//:test");
    result3.assertSuccess();
    // Put the file back in the broken state and make sure the test fails.
    testUtil.makeTestFail();
    workspace.runBuckCommand("build", "//:test").assertSuccess("The test should build successfully, but will fail when executed.");
    ProcessResult result4 = workspace.runBuckCommand("test", "//:test");
    result4.assertTestFailure();
    assertThat("`buck test` should fail because testBasicAssertion() failed.", result4.getStderr(), containsString("FAILURE com.example.LameTest testBasicAssertion"));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 55 with ProcessResult

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

the class DefaultJavaLibraryIntegrationTest method updatingAResourceWhichIsJavaLibraryCausesAJavaLibraryToBeRepacked.

@Test
public void updatingAResourceWhichIsJavaLibraryCausesAJavaLibraryToBeRepacked() throws IOException {
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "resource_change_causes_repack", tmp);
    workspace.setUp();
    // Run `buck build`.
    ProcessResult buildResult = workspace.runBuckCommand("build", "//:lib");
    buildResult.assertSuccess("Successful build should exit with 0.");
    workspace.copyFile("ResClass.java.new", "ResClass.java");
    workspace.resetBuildLogFile();
    // The copied file changed the contents but not the ABI of :lib. Because :lib is included as a
    // resource of :res, it's expected that both :lib and :res are rebuilt (:lib because of a code
    // change, :res in order to repack the resource)
    buildResult = workspace.runBuckCommand("build", "//:lib");
    buildResult.assertSuccess("Successful build should exit with 0.");
    workspace.getBuildLog().assertTargetBuiltLocally("//:res");
    workspace.getBuildLog().assertTargetBuiltLocally("//:lib");
}
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