<commit_before>package main

import (
	"bytes"
	"github.com/workfit/tester/assert"
	"io/ioutil"
	"log"
	"os/exec"
	"strings"
	"testing"
)

func TestOutput(t *testing.T) {
	options := &appOptions{
		PrintToConsole:   true,
		PackageDirectory: "examplepkg/",
		OutputReader:     true,
	}

	out := &bytes.Buffer{}
	errOut := &bytes.Buffer{}

	assert.For(t).ThatActual(errOut.String()).Equals("").ThenDiffOnFail()

	process(options, out, errOut)

	expectedBytes, err := ioutil.ReadFile("test/expected_auto_reader.txt")

	assert.For(t).ThatActual(err).IsNil()

	assert.For(t).ThatActual(strings.TrimSpace(out.String())).Equals(strings.TrimSpace(string(expectedBytes))).ThenDiffOnFail()

}

func TestOutputTest(t *testing.T) {
	options := &appOptions{
		PrintToConsole:   true,
		PackageDirectory: "examplepkg/",
		OutputReaderTest: true,
	}

	out := &bytes.Buffer{}
	errOut := &bytes.Buffer{}

	assert.For(t).ThatActual(errOut.String()).Equals("").ThenDiffOnFail()

	process(options, out, errOut)

	expectedBytes, err := ioutil.ReadFile("test/expected_auto_reader_test.txt")

	assert.For(t).ThatActual(err).IsNil()

	assert.For(t).ThatActual(strings.TrimSpace(out.String())).Equals(strings.TrimSpace(string(expectedBytes))).ThenDiffOnFail()

}

func TestEnumOutput(t *testing.T) {
	options := &appOptions{
		PrintToConsole:   true,
		PackageDirectory: "examplepkg/",
		OutputEnum:       true,
	}

	out := &bytes.Buffer{}
	errOut := &bytes.Buffer{}

	process(options, out, errOut)

	assert.For(t).ThatActual(errOut.String()).Equals("").ThenDiffOnFail()

	expectedBytes, err := ioutil.ReadFile("test/expected_auto_enum.txt")

	assert.For(t).ThatActual(err).IsNil()

	assert.For(t).ThatActual(strings.TrimSpace(out.String())).Equals(strings.TrimSpace(string(expectedBytes))).ThenDiffOnFail()

}

func TestBuild(t *testing.T) {

	log.Println("WARNING: running this command builds and `go install`s autoreader")

	//Make sure a recent version of us is built
	cmd := exec.Command("go", "install")

	err := cmd.Run()

	if !assert.For(t).ThatActual(err).IsNil().Passed() {
		log.Println(err)
	}

	cmd = exec.Command("go", "generate")
	cmd.Dir = "examplepkg/"

	err = cmd.Run()

	if !assert.For(t).ThatActual(err).IsNil().Passed() {
		log.Println(err)
	}

	cmd = exec.Command("go", "test")
	cmd.Dir = "./examplepkg/"

	err = cmd.Run()

	if !assert.For(t).ThatActual(err).IsNil().Passed() {
		log.Println(err)
	}

}

func TestOverrideDisplayNames(t *testing.T) {

	tests := []struct {
		input       string
		hasOverride bool
		displayName string
	}{
		{
			`display:"bam"`,
			true,
			"bam",
		},
		{
			" display:\"foo\"\n",
			true,
			"foo",
		},
		{
			`display:"hello \"john\""`,
			true,
			`hello \"john\"`,
		},
		{
			"blarg\n",
			false,
			"",
		},
		{
			`display:""`,
			true,
			"",
		},
	}

	for i, test := range tests {
		hasOverride, displayName := overrideDisplayname(test.input)

		assert.For(t, i).ThatActual(hasOverride).Equals(test.hasOverride)
		assert.For(t, i).ThatActual(displayName).Equals(test.displayName)

	}

}
<commit_msg>autoreader's main_test doesn't use `go install autoreader` or `go generate`, but rather runs the command directly. It does call `go test` on examplepkg. Cleanup as part of necessary #655.<commit_after>package main

import (
	"bytes"
	"flag"
	"github.com/workfit/tester/assert"
	"io/ioutil"
	"log"
	"os/exec"
	"strings"
	"testing"
)

func TestOutput(t *testing.T) {
	options := &appOptions{
		PrintToConsole:   true,
		PackageDirectory: "examplepkg/",
		OutputReader:     true,
	}

	out := &bytes.Buffer{}
	errOut := &bytes.Buffer{}

	assert.For(t).ThatActual(errOut.String()).Equals("").ThenDiffOnFail()

	process(options, out, errOut)

	expectedBytes, err := ioutil.ReadFile("test/expected_auto_reader.txt")

	assert.For(t).ThatActual(err).IsNil()

	assert.For(t).ThatActual(strings.TrimSpace(out.String())).Equals(strings.TrimSpace(string(expectedBytes))).ThenDiffOnFail()

}

func TestOutputTest(t *testing.T) {
	options := &appOptions{
		PrintToConsole:   true,
		PackageDirectory: "examplepkg/",
		OutputReaderTest: true,
	}

	out := &bytes.Buffer{}
	errOut := &bytes.Buffer{}

	assert.For(t).ThatActual(errOut.String()).Equals("").ThenDiffOnFail()

	process(options, out, errOut)

	expectedBytes, err := ioutil.ReadFile("test/expected_auto_reader_test.txt")

	assert.For(t).ThatActual(err).IsNil()

	assert.For(t).ThatActual(strings.TrimSpace(out.String())).Equals(strings.TrimSpace(string(expectedBytes))).ThenDiffOnFail()

}

func TestEnumOutput(t *testing.T) {
	options := &appOptions{
		PrintToConsole:   true,
		PackageDirectory: "examplepkg/",
		OutputEnum:       true,
	}

	out := &bytes.Buffer{}
	errOut := &bytes.Buffer{}

	process(options, out, errOut)

	assert.For(t).ThatActual(errOut.String()).Equals("").ThenDiffOnFail()

	expectedBytes, err := ioutil.ReadFile("test/expected_auto_enum.txt")

	assert.For(t).ThatActual(err).IsNil()

	assert.For(t).ThatActual(strings.TrimSpace(out.String())).Equals(strings.TrimSpace(string(expectedBytes))).ThenDiffOnFail()

}

func TestBuild(t *testing.T) {

	log.Println("WARNING: running this command generates auto output for examplepkg/")

	//Get default options
	options := getOptions(flag.NewFlagSet("test", 0), []string{})

	options.PackageDirectory = "examplepkg/"

	out := &bytes.Buffer{}
	errOut := &bytes.Buffer{}

	process(options, out, errOut)

	assert.For(t).ThatActual(errOut.String()).Equals("").ThenDiffOnFail()

	cmd := exec.Command("go", "test")
	cmd.Dir = "./examplepkg/"

	err := cmd.Run()

	if !assert.For(t).ThatActual(err).IsNil().Passed() {
		log.Println(err)
	}

}

func TestOverrideDisplayNames(t *testing.T) {

	tests := []struct {
		input       string
		hasOverride bool
		displayName string
	}{
		{
			`display:"bam"`,
			true,
			"bam",
		},
		{
			" display:\"foo\"\n",
			true,
			"foo",
		},
		{
			`display:"hello \"john\""`,
			true,
			`hello \"john\"`,
		},
		{
			"blarg\n",
			false,
			"",
		},
		{
			`display:""`,
			true,
			"",
		},
	}

	for i, test := range tests {
		hasOverride, displayName := overrideDisplayname(test.input)

		assert.For(t, i).ThatActual(hasOverride).Equals(test.hasOverride)
		assert.For(t, i).ThatActual(displayName).Equals(test.displayName)

	}

}

{'fraction_non_alphanumeric': 0.1783357476259456, 'fraction_numerical': 0.0006438113632705617, 'mean_word_length': 4.394097222222222, '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': '5096300', 'n_tokens_mistral': 2460, 'n_tokens_neox': 2253, 'n_words': 357}