public int execute()

in src/com/facebook/buck/shell/RunShTestAndRecordResultStep.java [58:128]


  public int execute(ExecutionContext context) {
    TestResultSummary summary;
    if (context.getPlatform() == Platform.WINDOWS) {
      // Ignore sh_test on Windows.
      summary = new TestResultSummary(
          pathToShellScript,
          "sh_test",
          /* isSuccess */ true,
          /* duration*/ 0,
          /* message */ "sh_test ignored on Windows",
          /* stacktrace */ null,
          /* stdout */ null,
          /* stderr */ null);
    } else {
      ShellStep test = new ShellStep() {
        @Override
        public String getShortName() {
          return pathToShellScript;
        }

        @Override
        protected ImmutableList<String> getShellCommandInternal(
            ExecutionContext context) {
          return ImmutableList.of(pathToShellScript);
        }

        @Override
        protected boolean shouldPrintStderr(Verbosity verbosity) {
          // Do not stream this output because we want to capture it.
          return false;
        }

        @Override
        protected boolean shouldPrintStdout(Verbosity verbosity) {
          // Do not stream this output because we want to capture it.
          return false;
        }
      };
      int exitCode = test.execute(context);

      // Write test result.
      summary = new TestResultSummary(
          pathToShellScript,
          "sh_test",
          /* isSuccess */ exitCode == 0,
          test.getDuration(),
          /* message */ null,
          /* stacktrace */ null,
          test.getStdout(),
          test.getStderr());
    }

    ObjectMapper mapper = new ObjectMapper();
    try {
      mapper.writeValue(
          Files.newWriter(new File(pathToTestResultFile), Charsets.UTF_8),
          summary);
    } catch (JsonGenerationException e) {
      Throwables.propagate(e);
    } catch (JsonMappingException e) {
      Throwables.propagate(e);
    } catch (FileNotFoundException e) {
      Throwables.propagate(e);
    } catch (IOException e) {
      Throwables.propagate(e);
    }

    // Even though the test may have failed, this command executed successfully, so its exit code
    // should be zero.
    return 0;
  }