@Override
  public int run(PrintWriter out, PrintWriter err, String... args) {
    try {
      return Main.main(System.in, out, err, args);
    } catch (RuntimeException e) {
      err.print(e.getMessage());
      err.flush();
      return 1; // pass non-zero value back indicating an error has happened
    }
  }
@Test
  public void testUsageOutputAfterLoadingViaToolName() {
    String name = "google-java-format";

    assertThat(
            ServiceLoader.load(ToolProvider.class).stream()
                .map(ServiceLoader.Provider::get)
                .map(ToolProvider::name))
        .contains(name);

    ToolProvider format = ToolProvider.findFirst(name).get();

    StringWriter out = new StringWriter();
    StringWriter err = new StringWriter();

    int result = format.run(new PrintWriter(out, true), new PrintWriter(err, true), "--help");

    assertThat(result).isNotEqualTo(0);

    String usage = err.toString();

    // Check that doc links are included.
    assertThat(usage).containsMatch("http.*/google-java-format");
    assertThat(usage).contains("Usage: google-java-format");
  }