Example #1
0
  @Test
  public void testJsonOutputWithDirectDependencies() throws IOException {
    // Run Buck targets command on a case where the deps and direct_dependencies differ
    ProcessResult result = workspace.runBuckCommand("targets", "--json", "//:B");

    // Parse the observed JSON.
    JsonNode observed =
        objectMapper.readTree(
            objectMapper
                .getJsonFactory()
                .createJsonParser(result.getStdout())
                .enable(Feature.ALLOW_COMMENTS));

    // Parse the expected JSON.
    String expectedJson = workspace.getFileContents("TargetsCommandTestBuckJson2.js");
    JsonNode expected =
        objectMapper.readTree(
            objectMapper
                .getJsonFactory()
                .createJsonParser(expectedJson)
                .enable(Feature.ALLOW_COMMENTS));

    assertThat(
        "Output from targets command should match expected JSON.", observed, is(equalTo(expected)));
    assertThat(
        "Nothing should be printed to stderr.", console.getTextWrittenToStdErr(), is(equalTo("")));
  }
Example #2
0
  @Test
  public void testBuckPyIgnorePaths() throws IOException {
    ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(
            this, "buck_py_ignore_paths", temporaryFolder);
    workspace.setUp();

    ProcessResult result = workspace.runBuckCommand("test", "--all");
    result.assertExitCode("buck test --all should exit cleanly", 0);
  }
  @Test
  public void testKeepGoingWithMultipleSuccessfulTargets() throws IOException {
    ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(this, "keep_going", tmp).setUp();

    ProcessResult result = buildTwoGoodRulesAndAssertSuccess(workspace);
    String expectedReport =
        "OK   //:rule_with_output BUILT_LOCALLY "
            + GENRULE_OUTPUT
            + "\n"
            + "OK   //:rule_without_output BUILT_LOCALLY\n";
    assertThat(result.getStderr(), containsString(expectedReport));
  }
  @Test
  public void testIfCommandExitsZeroThenGenruleFails() throws IOException {
    assumeTrue(
        "This genrule uses the 'bash' argument, which is not supported on Windows. ",
        Platform.detect() != Platform.WINDOWS);
    ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(
            this, "genrule_failing_command", temporaryFolder);
    workspace.setUp();

    ProcessResult buildResult = workspace.runBuckCommand("build", "//:fail");
    buildResult.assertExitCode(1);

    // We make sure that we failed for the right reason.
    assertThat(
        buildResult.getStderr(),
        containsString("BUILD FAILED: //:fail failed on step \"genrule\" with exit code 1"));
  }
  @Test
  public void testKeepGoingWithOneFailingTarget() throws IOException {
    ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(this, "keep_going", tmp).setUp();

    ProcessResult result =
        workspace
            .runBuckBuild("--keep-going", "//:rule_with_output", "//:failing_rule")
            .assertFailure();
    String expectedReport =
        "OK   //:rule_with_output BUILT_LOCALLY "
            + GENRULE_OUTPUT
            + "\n"
            + "FAIL //:failing_rule\n";
    assertThat(result.getStderr(), containsString(expectedReport));
    Path outputFile = workspace.getPath(GENRULE_OUTPUT);
    assertTrue(Files.exists(outputFile));
  }
  @Test
  public void testVariousSuccessTypesInReport() throws IOException {
    ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(this, "keep_going", tmp).setUp();

    ProcessResult result1 = buildTwoGoodRulesAndAssertSuccess(workspace);
    String expectedReport1 =
        "OK   //:rule_with_output BUILT_LOCALLY "
            + GENRULE_OUTPUT
            + "\n"
            + "OK   //:rule_without_output BUILT_LOCALLY\n";
    assertThat(result1.getStderr(), containsString(expectedReport1));

    ProcessResult result2 = buildTwoGoodRulesAndAssertSuccess(workspace);
    String expectedReport2 =
        "OK   //:rule_with_output MATCHING_RULE_KEY "
            + GENRULE_OUTPUT
            + "\n"
            + "OK   //:rule_without_output MATCHING_RULE_KEY\n";
    assertThat(result2.getStderr(), containsString(expectedReport2));

    workspace.runBuckCommand("clean").assertSuccess();

    ProcessResult result3 = buildTwoGoodRulesAndAssertSuccess(workspace);
    String expectedReport3 =
        "OK   //:rule_with_output FETCHED_FROM_CACHE "
            + GENRULE_OUTPUT
            + "\n"
            + "OK   //:rule_without_output FETCHED_FROM_CACHE\n";
    assertThat(result3.getStderr(), containsString(expectedReport3));
  }