@Test
  public void incorrectPerFileFlagsUsedForCompilation() throws IOException {
    ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(this, "compiling_per_file_flags", tmp);
    workspace.setUp();

    ProjectWorkspace.ProcessResult result = workspace.runBuckBuild("//:broken-bin");
    result.assertFailure();
  }
  @Test
  @Ignore
  public void hasBuckCompilerErrorOccurredThenEventsCalled()
      throws IOException, InterruptedException {
    final ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(this, "buck_events/compiler_error", tmp);
    workspace.setUp();

    WebServerBuckEventListener webServerBuckEventListener =
        createMock(WebServerBuckEventListener.class);

    // Build started
    webServerBuckEventListener.buildStarted(anyObject(BuildEvent.Started.class));
    EasyMock.expectLastCall().times(1);

    // Build progress Event
    webServerBuckEventListener.buildProgressUpdated(
        anyObject(ProgressEvent.BuildProgressUpdated.class));
    EasyMock.expectLastCall().atLeastOnce();

    // Build finished
    webServerBuckEventListener.buildFinished(anyObject(BuildEvent.Finished.class));
    EasyMock.expectLastCall().times(1);

    // Parse started
    webServerBuckEventListener.parseStarted(anyObject(ParseEvent.Started.class));
    EasyMock.expectLastCall().times(1);

    // Parse progress Event
    webServerBuckEventListener.parsingProgressUpdated(
        anyObject(ProgressEvent.ParsingProgressUpdated.class));
    EasyMock.expectLastCall().atLeastOnce();

    // Parse finished
    webServerBuckEventListener.parseFinished(anyObject(ParseEvent.Finished.class));
    EasyMock.expectLastCall().times(1);

    // Compiler error
    webServerBuckEventListener.compilerErrorEvent(anyObject(CompilerErrorEvent.class));
    EasyMock.expectLastCall().times(1);

    // Console event
    webServerBuckEventListener.consoleEvent(anyObject(ConsoleEvent.class));
    EasyMock.expectLastCall().times(1);

    // Output trace
    webServerBuckEventListener.outputTrace(anyObject(BuildId.class));
    EasyMock.expectLastCall().times(1);

    EasyMock.replay(webServerBuckEventListener);

    ProjectWorkspace.ProcessResult build =
        workspace.runBuckdCommand(new TestContext(), "build", "//:broken");
    build.assertFailure();

    verify(webServerBuckEventListener);
  }
 private void platformLinkerFlags(ProjectWorkspace workspace, String target) throws IOException {
   workspace.runBuckBuild("//:binary_matches_default_exactly_" + target).assertSuccess();
   workspace.runBuckBuild("//:binary_matches_default_" + target).assertSuccess();
   ProjectWorkspace.ProcessResult result = workspace.runBuckBuild("//:binary_no_match_" + target);
   result.assertFailure();
   assertThat(result.getStderr(), Matchers.containsString("reference"));
   workspace.runBuckBuild("//:binary_with_library_matches_default_" + target).assertSuccess();
   workspace
       .runBuckBuild("//:binary_with_prebuilt_library_matches_default_" + target)
       .assertSuccess();
 }
 @Test
 public void platformPreprocessorFlags() throws IOException {
   ProjectWorkspace workspace =
       TestDataHelper.createProjectWorkspaceForScenario(this, "platform_preprocessor_flags", tmp);
   workspace.setUp();
   workspace.runBuckBuild("//:binary_matches_default_exactly").assertSuccess();
   workspace.runBuckBuild("//:binary_matches_default").assertSuccess();
   ProjectWorkspace.ProcessResult result = workspace.runBuckBuild("//:binary_no_match");
   result.assertFailure();
   assertThat(result.getStderr(), Matchers.containsString("#error"));
   workspace.runBuckBuild("//:binary_with_library_matches_default").assertSuccess();
 }
 @Test
 public void platformSources() throws IOException {
   ProjectWorkspace workspace =
       TestDataHelper.createProjectWorkspaceForScenario(this, "platform_sources", tmp);
   workspace.setUp();
   workspace.writeContentsToPath("[cxx]\n  cxxflags = -Wall -Werror", ".buckconfig");
   workspace.runBuckBuild("//:binary_matches_default_exactly").assertSuccess();
   workspace.runBuckBuild("//:binary_matches_default").assertSuccess();
   ProjectWorkspace.ProcessResult result = workspace.runBuckBuild("//:binary_no_match");
   result.assertFailure();
   assertThat(result.getStderr(), Matchers.containsString("answer()"));
   workspace.runBuckBuild("//:binary_with_library_matches_default").assertSuccess();
 }
  @Test
  public void shouldPrintNeededSymbolsFromBuild() throws IOException {
    ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(this, "symbol_finder", temporaryFolder);
    workspace.setUp();

    ProjectWorkspace.ProcessResult processResult = workspace.runBuckBuild("//java/com/example/b:b");
    processResult.assertFailure("Build with missing dependencies should fail.");

    String expectedDependencyOutput =
        String.format(
            "%s (:b) is missing deps:\n" + "    ':moreb',\n" + "    '//java/com/example/a:a',\n",
            Paths.get("java/com/example/b/BUCK"));

    assertThat(
        "Output should describe the missing dependency.",
        processResult.getStderr(),
        containsString(expectedDependencyOutput));
  }
  @Test
  public void resolveHeadersBehindSymlinkTreesInError() throws IOException {
    ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(this, "resolved", tmp);
    workspace.setUp();

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

    BuildTarget target = BuildTargetFactory.newInstance("//:bin");
    ProjectWorkspace.ProcessResult result = workspace.runBuckCommand("build", target.toString());
    result.assertFailure();

    // Verify that the preprocessed source contains no references to the symlink tree used to
    // setup the headers.
    String error = result.getStderr();
    assertThat(error, Matchers.not(Matchers.containsString(BuckConstant.SCRATCH_DIR)));
    assertThat(error, Matchers.not(Matchers.containsString(BuckConstant.GEN_DIR)));
    assertThat(error, Matchers.containsString("In file included from lib1.h:1"));
    assertThat(error, Matchers.containsString("from bin.h:1"));
    assertThat(error, Matchers.containsString("from bin.cpp:1:"));
    assertThat(error, Matchers.containsString("lib2.h:1:2: error: invalid preprocessing"));
  }