Exemplo n.º 1
0
  @Test
  public void resolveHeadersBehindSymlinkTreesInPreprocessedOutput() throws IOException {
    BuckConfig buckConfig = new FakeBuckConfig();
    CxxPlatform cxxPlatform = DefaultCxxPlatforms.build(new CxxBuckConfig(buckConfig));

    ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(this, "resolved", tmp);
    workspace.setUp();

    workspace.writeContentsToPath("", "lib2.h");

    BuildTarget target = BuildTargetFactory.newInstance("//:bin");
    CxxSourceRuleFactory cxxSourceRuleFactory = CxxSourceRuleFactoryHelper.of(target, cxxPlatform);
    workspace.runBuckCommand("build", target.toString()).assertSuccess();

    // Verify that the preprocessed source contains no references to the symlink tree used to
    // setup the headers.
    BuildTarget ppTarget =
        cxxSourceRuleFactory.createPreprocessBuildTarget(
            "bin.cpp", CxxSource.Type.CXX, CxxSourceRuleFactory.PicType.PDC);
    Path output =
        cxxSourceRuleFactory.getPreprocessOutputPath(ppTarget, CxxSource.Type.CXX, "bin.cpp");
    String contents = workspace.getFileContents(output.toString());
    assertThat(contents, Matchers.not(Matchers.containsString(BuckConstant.SCRATCH_DIR)));
    assertThat(contents, Matchers.not(Matchers.containsString(BuckConstant.GEN_DIR)));
    assertThat(contents, Matchers.containsString("# 1 \"bin.h"));
    assertThat(contents, Matchers.containsString("# 1 \"lib1.h"));
    assertThat(contents, Matchers.containsString("# 1 \"lib2.h"));
  }
Exemplo n.º 2
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("")));
  }
 private void invokeBuckCommand(ProjectWorkspace workspace, String logOut) throws IOException {
   ProjectWorkspace.ProcessResult buckCommandResult =
       workspace.runBuckCommand("targets", "--show-rulekey", "//:java_lib_2");
   buckCommandResult.assertSuccess();
   String fullLogContents = workspace.getFileContents(LOG_FILE_PATH.toString());
   String logContentsForThisInvocation = fullLogContents.substring(lastPositionInLog);
   lastPositionInLog += logContentsForThisInvocation.length();
   workspace.writeContentsToPath(logContentsForThisInvocation, logOut);
 }
Exemplo n.º 4
0
  @Test
  public void testJsonOutputForBuildTarget()
      throws IOException, BuildFileParseException, InterruptedException {
    // run `buck targets` on the build file and parse the observed JSON.
    SortedMap<String, TargetNode<?>> nodes = buildTargetNodes(filesystem, "//:test-library");

    targetsCommand.printJsonForTargets(
        params, executor, nodes, ImmutableMap.<String, ShowOptions>of());
    String observedOutput = console.getTextWrittenToStdOut();
    JsonNode observed =
        objectMapper.readTree(objectMapper.getJsonFactory().createJsonParser(observedOutput));

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

    assertEquals("Output from targets command should match expected JSON.", expected, observed);
    assertEquals("Nothing should be printed to stderr.", "", console.getTextWrittenToStdErr());
  }