<commit_before>package expect

import (
	"flag"
	"fmt"
	"github.com/wsxiaoys/terminal/color"
	"os"
	"reflect"
	"regexp"
	"runtime"
	"strings"
	"testing"
	"time"
)

var (
	showStdout = flag.Bool("vv", false, "Regular expression selecting which tests to run")
	matchFlag  = flag.String("m", "", "Regular expression selecting which tests to run")
	pattern    *regexp.Regexp
	runner     *Runner
	stdout     = os.Stdout
	silentOut  *os.File
)

func init() {
	flag.Parse()
	pattern = regexp.MustCompile("(?i)" + *matchFlag)
	if *showStdout == true {
		silentOut = stdout
	}
	os.Stdout = silentOut
}

func Expectify(suite interface{}, t *testing.T) {
	tp := reflect.TypeOf(suite)
	sv := reflect.ValueOf(suite)
	count := tp.NumMethod()

	runner = &Runner{
		results: make([]*Result, 0, 10),
	}
	announced := false
	for i := 0; i < count; i++ {
		method := tp.Method(i)
		name := method.Name
		if pattern.MatchString(name) == false || method.Type.NumIn() != 1 {
			continue
		}
		os.Stdout = stdout
		result := runner.Start(name)
		method.Func.Call([]reflect.Value{sv})
		if runner.End() == false || testing.Verbose() {
			if announced == false {
				color.Printf("\n@!%s@|\n", sv.Elem().Type().String())
				announced = true
			}
			result.Report()
		}
		os.Stdout = silentOut
	}
	if runner.Passed() == false {
		os.Stdout = stdout
		fmt.Println("")
		os.Stdout = silentOut
		t.Fail()
	}
}

type Runner struct {
	results []*Result<commit_msg>more helpful output if tested code panics<commit_after>package expect

import (
	"flag"
	"fmt"
	"github.com/wsxiaoys/terminal/color"
	"os"
	"reflect"
	"regexp"
	"runtime"
	"strings"
	"testing"
	"time"
)

var (
	showStdout = flag.Bool("vv", false, "Regular expression selecting which tests to run")
	matchFlag  = flag.String("m", "", "Regular expression selecting which tests to run")
	pattern    *regexp.Regexp
	runner     *Runner
	stdout     = os.Stdout
	silentOut  *os.File
)

func init() {
	flag.Parse()
	pattern = regexp.MustCompile("(?i)" + *matchFlag)
	if *showStdout == true {
		silentOut = stdout
	}
	os.Stdout = silentOut
}

func Expectify(suite interface{}, t *testing.T) {
	var name string
	defer func() {
		if err := recover(); err != nil {
			os.Stdout = stdout
			color.Printf("@R 💣  %-75s\n", name)
			panic(err)
		}
	}()

	tp := reflect.TypeOf(suite)
	sv := reflect.ValueOf(suite)
	count := tp.NumMethod()

	runner = &Runner{
		results: make([]*Result, 0, 10),
	}
	announced := false
	for i := 0; i < count; i++ {
		method := tp.Method(i)
		name = method.Name
		if pattern.MatchString(name) == false || method.Type.NumIn() != 1 {
			continue
		}
		os.Stdout = stdout
		result := runner.Start(name)
		method.Func.Call([]reflect.Value{sv})
		if runner.End() == false || testing.Verbose() {
			if announced == false {
				color.Printf("\n@!%s@|\n", sv.Elem().Type().String())
				announced = true
			}
			result.Report()
		}
		os.Stdout = silentOut
	}
	if runner.Passed() == false {
		os.Stdout = stdout
		fmt.Println("")
		os.Stdout = silentOut
		t.Fail()
	}
}

type Runner struct {
	results []*Result
{'fraction_non_alphanumeric': 0.16693998032141685, 'fraction_numerical': 0.003935716628402755, 'mean_word_length': 3.4267053701015966, 'pattern_counts': {'":': 0, '<': 5, '<?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': '160788', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1142, 'n_words': 266}