Search in sources :

Example 46 with ProcessResult

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

the class TargetsCommandIntegrationTest method testTargetHashChangesAfterModifyingSourceFile.

@Test
public void testTargetHashChangesAfterModifyingSourceFile() 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();
    String hash = parseAndVerifyTargetAndHash(result.getStdout(), "//workspace:workspace");
    String fileName = "test/Test.m";
    Files.write(workspace.getPath(fileName), "// This is not a test\n".getBytes(UTF_8));
    ProcessResult result2 = workspace.runBuckCommand("targets", "--show-target-hash", "--detect-test-changes", "//workspace:workspace");
    result2.assertSuccess();
    String hash2 = parseAndVerifyTargetAndHash(result2.getStdout(), "//workspace:workspace");
    assertNotEquals(hash, hash2);
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 47 with ProcessResult

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

the class TargetsCommandIntegrationTest method testValidateBuildTargetForNonAliasTarget.

@Test
public void testValidateBuildTargetForNonAliasTarget() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "target_validation", tmp);
    workspace.setUp();
    ProcessResult result = workspace.runBuckCommand("targets", "--resolve-alias", "//:test-library");
    assertTrue(result.getStdout(), result.getStdout().contains("//:test-library"));
    try {
        workspace.runBuckCommand("targets", "--resolve-alias", "//:");
    } catch (HumanReadableException e) {
        assertEquals("//: cannot end with a colon", e.getMessage());
    }
    try {
        workspace.runBuckCommand("targets", "--resolve-alias", "//:test-libarry");
    } catch (HumanReadableException e) {
        assertEquals("//:test-libarry is not a valid target.", e.getMessage());
    }
    try {
        workspace.runBuckCommand("targets", "--resolve-alias", "//blah/foo");
    } catch (HumanReadableException e) {
        assertEquals("//blah/foo must contain exactly one colon (found 0)", e.getMessage());
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) HumanReadableException(com.facebook.buck.util.HumanReadableException) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 48 with ProcessResult

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

the class TargetsCommandIntegrationTest method testJsonOutputWithShowOptions.

@Test
public void testJsonOutputWithShowOptions() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "output_path", tmp);
    workspace.setUp();
    ProcessResult result = workspace.runBuckCommand("targets", "--json", "--show-output", "//:test");
    ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
    // Parse the observed JSON.
    JsonNode observed = objectMapper.readTree(objectMapper.getFactory().createParser(result.getStdout()));
    System.out.println(observed.toString());
    String expectedJson = workspace.getFileContents("output_path_json.js");
    JsonNode expected = objectMapper.readTree(objectMapper.getFactory().createParser(normalizeNewlines(expectedJson)));
    MatcherAssert.assertThat("Output from targets command should match expected JSON.", observed, equalTo(expected));
}
Also used : 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 49 with ProcessResult

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

the class TargetsCommandIntegrationTest method testShowAllTargets.

@Test
public void testShowAllTargets() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "xcode_workspace_with_tests", tmp);
    workspace.setUp();
    ProcessResult result = workspace.runBuckCommand("targets");
    result.assertSuccess();
    assertEquals(ImmutableSet.of("//bin:bin", "//bin:genrule", "//lib:lib", "//test:test", "//workspace:workspace"), ImmutableSet.copyOf(Splitter.on('\n').omitEmptyStrings().split(result.getStdout())));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessResult(com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult) Test(org.junit.Test)

Example 50 with ProcessResult

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

the class TargetsCommandIntegrationTest method testBuckTargetsReferencedFileWithNonExistentFile.

@Test
public void testBuckTargetsReferencedFileWithNonExistentFile() throws IOException {
    // The contents of the project are not relevant for this test. We just want a non-empty project
    // to prevent against a regression where all of the build rules are printed.
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "project_slice", tmp);
    workspace.setUp();
    String pathToNonExistentFile = "modules/dep1/dep2/hello.txt";
    assertFalse(Files.exists(workspace.getPath(pathToNonExistentFile)));
    ProcessResult result = workspace.runBuckCommand("targets", "--referenced-file", pathToNonExistentFile);
    result.assertSuccess("Even though the file does not exist, buck targets` should succeed.");
    assertEquals("Because no targets match, stdout should be empty.", "", result.getStdout());
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) 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