<commit_before>package org.testory;

import static java.util.Arrays.asList;
import static java.util.concurrent.Executors.newFixedThreadPool;
import static javax.xml.bind.DatatypeConverter.printHexBinary;
import static org.junit.Assert.assertEquals;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;

import org.junit.Test;

public class TestBuilding {
  private String hashA, hashB;

  @Test
  public void build_is_deterministic() throws Exception {
    exec("./run/build");
    hashA = sha1("/tmp/testory.jar");
    exec("./run/build");
    hashB = sha1("/tmp/testory.jar");

    assertEquals(hashA, hashB);
  }

  private static void exec(String command) {
    try {
      Process process = Runtime.getRuntime().exec(command);
      ExecutorService executor = newFixedThreadPool(2);
      executor.submit(forward(process.getInputStream(), System.out));
      executor.submit(forward(process.getErrorStream(), System.err));
      int exitCode = process.waitFor();
      assume(exitCode == 0);
    } catch (IOException | InterruptedException e) {
      throw new RuntimeException(e);
    }
  }

  private static Callable<Void> forward(final InputStream input, final PrintStream output) {
    return new Callable<Void>() {
      public Void call() throws IOException {
        int data;
        while ((data = input.read()) != -1) {
          output.write(data);
        }
        return null;
      }
    };
  }

  private static String sha1(String filename) {
    try {
      MessageDigest sha1 = MessageDigest.getInstance("SHA-1");<commit_msg>redirected stdout and stderr from building test<commit_after>package org.testory;

import static java.util.Arrays.asList;
import static javax.xml.bind.DatatypeConverter.printHexBinary;
import static org.junit.Assert.assertEquals;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashSet;
import java.util.Set;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

public class TestBuilding {
  @Rule
  public TemporaryFolder folder = new TemporaryFolder();

  private String hashA, hashB;

  @Test
  public void build_is_deterministic() throws Exception {
    exec("./run/build");
    hashA = sha1("/tmp/testory.jar");
    exec("./run/build");
    hashB = sha1("/tmp/testory.jar");

    assertEquals(hashA, hashB);
  }

  private void exec(String command) throws InterruptedException, IOException {
    int exitCode = new ProcessBuilder(command)
        .redirectOutput(folder.newFile())
        .redirectError(folder.newFile())
        .start()
        .waitFor();
    assume(exitCode == 0);
  }

  private static String sha1(String filename) {
    try {
      MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
{'fraction_non_alphanumeric': 0.11278648974668275, 'fraction_numerical': 0.004221954161640531, 'mean_word_length': 4.0105740181268885, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '5903930', 'n_tokens_mistral': 970, 'n_tokens_neox': 957, 'n_words': 219}