func cleanOutput(o []byte, testPkg string) []byte {
	o = []byte(strings.Replace(string(o), path.Base(testPkg), "somepkg", -1))
	stackFrameRe := regexp.MustCompile(`\t\S+\.(c|go):\d+`)
	o = stackFrameRe.ReplaceAll(o, []byte("\tsome_file.txt:0"))
	pathRe := regexp.MustCompile(`/\S+/(\w+\.go:\d+)`)
	o = pathRe.ReplaceAll(o, []byte("/some/path/$1"))
	timingRe1 := regexp.MustCompile(`--- FAIL: .* \(\d\.\d{2}s\)`)
	o = timingRe1.ReplaceAll(o, []byte("--- FAIL: TestSomething (1.23s)"))
	timingRe2 := regexp.MustCompile(`FAIL.*somepkg\s*\d\.\d{2,}s`)
	o = timingRe2.ReplaceAll(o, []byte("FAIL somepkg 1.234s"))
	timingRe3 := regexp.MustCompile(`ok.*somepkg\s*\d\.\d{2,}s`)
	o = timingRe3.ReplaceAll(o, []byte("ok somepkg 1.234s"))
	timingRe4 := regexp.MustCompile(`SlowTest \([0-9.]+ms\)`)
	o = timingRe4.ReplaceAll(o, []byte("SlowTest (1234ms)"))
	return o
}
cleanOutput transforms the supplied output so that it no longer contains
information that changes from run to run, making the golden tests less
flaky.
package ogletest_test
import (
	"errors"
	"flag"
	"fmt"
	"go/build"
	"io/ioutil"
	"os"
	"os/exec"
	"path"
	"regexp"
	"strings"
	"syscall"
	"testing"
)
const ogletestPkg = "github.com/smartystreets/assertions/internal/ogletest"
var dumpNew = flag.Bool("dump_new", false, "Dump new golden files.")
var objDir string
func installLocalPackages() error {
	cmd := exec.Command(
		"go",
		"install",
		ogletestPkg,
		"github.com/smartystreets/assertions/internal/oglemock",
		"github.com/smartystreets/assertions/internal/ogletest/test_cases/mock_image")
	output, err := cmd.CombinedOutput()
	if err != nil {
		return errors.New(fmt.Sprintf("%v:\n%s", err, output))
	}
	return nil
}
func getCaseNames() ([]string, error) {
	dir, err := os.Open("test_cases")
	if err != nil {
		return nil, errors.New(fmt.Sprintf("Opening dir: %v", err))
	}
	names, err := dir.Readdirnames(0)
	if err != nil {
		return nil, errors.New(fmt.Sprintf("Readdirnames: %v", err))
	}
	result := make([]string, len(names))
	resultLen := 0
	for _, name := range names {
		if strings.HasPrefix(name, "golden.") || strings.HasPrefix(name, ".") {
			continue
		}
		if !strings.HasSuffix(name, ".test.go") {
			continue
		}
		result[resultLen] = name[:len(name)-8]
		resultLen++
	}
	return result[:resultLen], nil
}
func writeContentsToFileOrDie(contents []byte, path string) {
	if err := ioutil.WriteFile(path, contents, 0600); err != nil {
		panic("ioutil.WriteFile: " + err.Error())
	}
}
func readFileOrDie(path string) []byte {
	contents, err := ioutil.ReadFile(path)
	if err != nil {
		panic("ioutil.ReadFile: " + err.Error())
	}
	return contents
}