func (delegate *TestClientDelegate) Initialize(ctx application.Context) { log.Printf("TestClientDelegate.Initialize...") // Set the necessary flags using the mojo args. args := ctx.Args() mojoFlag = flag.NewFlagSet(args[0], flag.ExitOnError) mojoRun := mojoFlag.String("test.run", "", "") mojoBench := mojoFlag.String("test.bench", "", "") endpointFlag = mojoFlag.String("endpoint", "", "") v23TcpAddr := mojoFlag.String("v23.tcp.address", "", "") mojoFlag.Parse(args[1:]) flag.Set("test.run", *mojoRun) flag.Set("test.bench", *mojoBench) flag.Set("v23.tcp.address", *v23TcpAddr) tests := []func(*testing.T, application.Context){ TestSimple, TestMultiArgs, TestReuseProxy, TestNoOutArgs, } benchmarks := []func(*testing.B, application.Context){ BenchmarkSimpleRpc, } matchAllTests := func(pat, str string) (bool, error) { return true, nil } exitCode := testing.MainStart(matchAllTests, convertTests(tests, ctx), convertBenchmarks(benchmarks, ctx), nil).Run() if exitCode == 0 { fmt.Printf("%s\n", expected.SuccessMessage) } else { fmt.Printf("%s\n", expected.FailureMessage) } ctx.Close() os.Exit(exitCode) }
func main() { // fmt.Println(testing.Benchmark(func(b *testing.B) { // for i := 0; i < b.N; i++ { // TestGetString(nil) // } // })) match := func(pat, str string) (bool, error) { return true, nil } m := testing.MainStart(match, tests, nil, nil) os.Exit(m.Run()) }
func RunAppTests(mctx application.Context) int { apptests := []func(*testing.T, application.Context){ AppTestDiscoveryBasic, AppTestGlobalDiscoveryBasic, } var tests []testing.InternalTest for _, apptest := range apptests { qname := runtime.FuncForPC(reflect.ValueOf(apptest).Pointer()).Name() name := qname[strings.LastIndex(qname, ".")+1:] f := apptest // To bind the current value of apptest to each closure. tests = append(tests, testing.InternalTest{name, func(t *testing.T) { f(t, mctx) }}) } // MainStart is not supposed to be called directly, but there is no other way // to run tests programatically at run time. return testing.MainStart(regexp.MatchString, tests, nil, nil).Run() }