<commit_before>package test.integration;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertLinesMatch;

import com.github.sormuras.bach.Bach;
import com.github.sormuras.bach.Printer;
import com.github.sormuras.bach.api.Option;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Path;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

class BachTests {

  @Test
  void empty() {
    assertEquals("empty", Auxiliary.newEmptyBach().project().name());
  }

  @Test
  void chrooted(@TempDir Path temp) {
    var bach = Bach.of(Option.CHROOT.cli(), temp.toString());
    assertEquals(temp, bach.project().folders().root());
  }

  @Test
  void help() {
    var out = """
        Usage: bach [OPTIONS] [ACTIONS...]
        >> MESSAGE >>
        """;
    bach(0, out, Option.HELP);
  }

  @Test
  void helpExtra() {
    var out =
        """
        Usage: bach [OPTIONS] [ACTIONS...]
        >> MESSAGE >>
          --chroot.*
        >> MESSAGE >>
        """;
    bach(0, out, Option.HELP_EXTRA);
  }

  @Test
  void showConfiguration(@TempDir Path temp) {
    var out =
        """
        Bach .+
        >> BANNER >>
        Configuration
        --show-configuration
        >> CONFIGURATION >>
        Bach run took .+
        Logbook written to .+
        """;
    bach(0, out, Option.CHROOT, temp, Option.SHOW_CONFIGURATION);
  }

  @Test
  void listTools(@TempDir Path temp) {
    var out = """
        >> TOOLS >>
        """;
    bach(0, out, Option.CHROOT, temp, Option.LIST_TOOLS);
  }

  @Test
  void tool() {
    var out = """
        javac .+
        """;
    bach(0, out, Option.TOOL, "javac", "--version");
  }

  @Test
  void toolBach() {
    var out = """
        .+
        """;
    bach(0, out, Option.TOOL, "bach", "--version");
  }

  @Test
  void version() {
    bach(0, ".+", Option.VERSION);
  }

  private static void bach(int expectedStatus, String expectedOutput, Object... objects) {
    var out = new StringWriter();
    var args =
        Stream.of(objects)
            .map(
                object -> {
                  if (object instanceof Option option) return option.cli();
                  return object.toString();
                })
            .toArray(String[]::new);
    var bach = Bach.of(Printer.of(new PrintWriter(out)), args);
    var status = bach.run();

    assertEquals(expectedStatus, status, () -> bach.logbook().toString());
    assertLinesMatch(expectedOutput.lines(), out.toString().lines());
  }
}
<commit_msg>Run each exit command test in a temporary (and empty) directory<commit_after>package test.integration;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertLinesMatch;

import com.github.sormuras.bach.Bach;
import com.github.sormuras.bach.Printer;
import com.github.sormuras.bach.api.Option;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Path;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

class BachTests {

  @Test
  void empty() {
    assertEquals("empty", Auxiliary.newEmptyBach().project().name());
  }

  @Test
  void chrooted(@TempDir Path temp) {
    var bach = Bach.of(Option.CHROOT.cli(), temp.toString());
    assertEquals(temp, bach.project().folders().root());
  }

  @Test
  void help(@TempDir Path temp) {
    var out = """
        Usage: bach [OPTIONS] [ACTIONS...]
        >> MESSAGE >>
        """;
    bach(0, out, Option.CHROOT, temp, Option.HELP);
  }

  @Test
  void helpExtra(@TempDir Path temp) {
    var out =
        """
        Usage: bach [OPTIONS] [ACTIONS...]
        >> MESSAGE >>
          --chroot.*
        >> MESSAGE >>
        """;
    bach(0, out, Option.CHROOT, temp, Option.HELP_EXTRA);
  }

  @Test
  void showConfiguration(@TempDir Path temp) {
    var out =
        """
        Bach .+
        >> BANNER >>
        Configuration
        --show-configuration
        >> CONFIGURATION >>
        Bach run took .+
        Logbook written to .+
        """;
    bach(0, out, Option.CHROOT, temp, Option.SHOW_CONFIGURATION);
  }

  @Test
  void listTools(@TempDir Path temp) {
    var out = """
        >> TOOLS >>
        """;
    bach(0, out, Option.CHROOT, temp, Option.LIST_TOOLS);
  }

  @Test
  void tool(@TempDir Path temp) {
    var out = """
        javac .+
        """;
    bach(0, out, Option.CHROOT, temp, Option.TOOL, "javac", "--version");
  }

  @Test
  void toolBach(@TempDir Path temp) {
    var out = """
        .+
        """;
    bach(0, out, Option.CHROOT, temp, Option.TOOL, "bach", Option.CHROOT, temp, "--version");
  }

  @Test
  void version(@TempDir Path temp) {
    bach(0, ".+", Option.CHROOT, temp, Option.VERSION);
  }

  private static void bach(int expectedStatus, String expectedOutput, Object... objects) {
    var out = new StringWriter();
    var args =
        Stream.of(objects)
            .map(
                object -> {
                  if (object instanceof Option option) return option.cli();
                  return object.toString();
                })
            .toArray(String[]::new);
    var bach = Bach.of(Printer.of(new PrintWriter(out)), args);
    var status = bach.run();

    assertEquals(expectedStatus, status, () -> bach.logbook().toString());
    assertLinesMatch(expectedOutput.lines(), out.toString().lines());
  }
}

{'fraction_non_alphanumeric': 0.15302037845705968, 'fraction_numerical': 0.002547307132459971, 'mean_word_length': 2.357971899816738, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2889593', 'n_tokens_mistral': 1806, 'n_tokens_neox': 1745, 'n_words': 382}