Example #1
0
func taskRun(input interface{}) interface{} {
	in := input.(*taskInput)
	buf := new(bytes.Buffer) // TODO use sync.Pool?
	l := log.New(buf, "", 0)
	start := time.Now()
	state := run(in.test, l)
	return &taskOutput{in.name, state, time.Now().Sub(start), buf}
}
Example #2
0
func main() {
	config.Flags.VisitAll(func(f *flag.Flag) {
		flag.Var(f.Value, f.Name, f.Usage)
	})
	flag.Parse()

	r := runner.New(log.New(os.Stderr, "", 0))
	r.Add("TestBasic", placehold.TestBasic, 1)

	r.Test(nil)
}
Example #3
0
func main() {
	config.Flags.VisitAll(func(f *flag.Flag) {
		flag.Var(f.Value, f.Name, f.Usage)
	})
	flag.Parse()

	r := runner.New(log.New(os.Stderr, "", 0))
	r.Add("TestBasic", placehold.TestBasic, 1)

	l, err := runner.NewStepLoader(5, 10, 1, 1*time.Second)
	if err != nil {
		panic(err)
	}

	r.Load(nil, l, runner.FailStep)
}
Example #4
0
// Test runs tests matching regexp in random order.
func (r *Runner) Test(re *regexp.Regexp) {
	var failedTests, skippedTests []string
	for _, p := range rand.Perm(len(r.tests)) {
		test := r.tests[p]
		if re != nil && !re.MatchString(test.name) {
			continue
		}

		r.l.Printf("=== TEST %s", test.name)

		start := time.Now()
		state := run(test.test, log.New(os.Stderr, "", 0))
		duration := time.Since(start)

		switch state {
		case failed, panicked:
			r.l.Printf("--- FAIL %s (%.2fs)", test.name, duration.Seconds())
			failedTests = append(failedTests, test.name)
		case skipped:
			r.l.Printf("--- SKIP %s (%.2fs)", test.name, duration.Seconds())
			skippedTests = append(skippedTests, test.name)
		case passed:
			r.l.Printf("--- PASS %s (%.2fs)", test.name, duration.Seconds())
		}
	}

	r.l.Printf("%d tests run, %d passed, %d skipped, %d failed.",
		len(r.tests), len(r.tests)-len(skippedTests)-len(failedTests), len(skippedTests), len(failedTests))
	if len(skippedTests) > 0 {
		r.l.Print("Skipped tests:")
		for _, name := range skippedTests {
			r.l.Printf("\t%s", name)
		}
	}
	if len(failedTests) > 0 {
		r.l.Print("Failed tests:")
		for _, name := range failedTests {
			r.l.Printf("\t%s", name)
		}
		os.Exit(1)
	}
}
Example #5
0
func testLogger() (*log.Logger, *bytes.Buffer) {
	buf := new(bytes.Buffer)
	return log.New(buf, "", 0), buf
}