<commit_before>package gps

import (
	"fmt"
	"os"
	"os/exec"
	"testing"
	"time"
)

func mkTestCmd(iterations int) *monitoredCmd {
	return newMonitoredCmd(
		exec.Command("./echosleep", "-n", fmt.Sprint(iterations)),
		200*time.Millisecond,
	)
}

func TestMonitoredCmd(t *testing.T) {
	err := exec.Command("go", "build", "./_testdata/cmd/echosleep.go").Run()
	if err != nil {
		t.Errorf("Unable to build echosleep binary: %s", err)
	}
	defer os.Remove("./echosleep")

	cmd := mkTestCmd(2)
	err = cmd.run()
	if err != nil {
		t.Errorf("Expected command not to fail: %s", err)
	}

	expectedOutput := "foo\nfoo\n"
	if cmd.stdout.buf.String() != expectedOutput {
		t.Errorf("Unexpected output:\n\t(GOT): %s\n\t(WNT): %s", cmd.stdout.buf.String(), expectedOutput)
	}

	cmd = mkTestCmd(10)
	err = cmd.run()
	if err == nil {
		t.Error("Expected command to fail")
	}

	_, ok := err.(*timeoutError)
	if !ok {
		t.Errorf("Expected a timeout error, but got: %s", err)
	}

	expectedOutput = "foo\nfoo\nfoo\nfoo\n"
	if cmd.stdout.buf.String() != expectedOutput {
		t.Errorf("Unexpected output:\n\t(GOT): %s\n\t(WNT): %s", cmd.stdout.buf.String(), expectedOutput)
	}
}<commit_msg>Separate cmd vars to minimize overwrite chance<commit_after>package gps

import (
	"fmt"
	"os"
	"os/exec"
	"testing"
	"time"
)

func mkTestCmd(iterations int) *monitoredCmd {
	return newMonitoredCmd(
		exec.Command("./echosleep", "-n", fmt.Sprint(iterations)),
		200*time.Millisecond,
	)
}

func TestMonitoredCmd(t *testing.T) {
	err := exec.Command("go", "build", "./_testdata/cmd/echosleep.go").Run()
	if err != nil {
		t.Errorf("Unable to build echosleep binary: %s", err)
	}
	defer os.Remove("./echosleep")

	cmd := mkTestCmd(2)
	err = cmd.run()
	if err != nil {
		t.Errorf("Expected command not to fail: %s", err)
	}

	expectedOutput := "foo\nfoo\n"
	if cmd.stdout.buf.String() != expectedOutput {
		t.Errorf("Unexpected output:\n\t(GOT): %s\n\t(WNT): %s", cmd.stdout.buf.String(), expectedOutput)
	}

	cmd2 := mkTestCmd(10)
	err = cmd2.run()
	if err == nil {
		t.Error("Expected command to fail")
	}

	_, ok := err.(*timeoutError)
	if !ok {
		t.Errorf("Expected a timeout error, but got: %s", err)
	}

	expectedOutput = "foo\nfoo\nfoo\nfoo\n"
	if cmd2.stdout.buf.String() != expectedOutput {
		t.Errorf("Unexpected output:\n\t(GOT): %s\n\t(WNT): %s", cmd2.stdout.buf.String(), expectedOutput)
	}
}
{'fraction_non_alphanumeric': 0.18961148648648649, 'fraction_numerical': 0.006756756756756757, 'mean_word_length': 4.00845665961945, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7406144', 'n_tokens_mistral': 974, 'n_tokens_neox': 932, 'n_words': 198}