当前位置: 首页>>代码示例>>Golang>>正文


Golang testing.Main函数代码示例

本文整理汇总了Golang中testing.Main函数的典型用法代码示例。如果您正苦于以下问题:Golang Main函数的具体用法?Golang Main怎么用?Golang Main使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Main函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	flag.Parse()
	if *showVersion {
		printversion()
		return
	}
	if *help {
		printhelp()
		return
	}
	if len(*url) == 0 {
		fmt.Println("must provide -silk.url")
		printhelp()
		return
	}
	root = "."
	args := flag.Args()
	if len(args) > 0 {
		root = args[0]
	}
	info, err := os.Stat(root)
	if err != nil {
		log.Fatalln(err)
		return
	}
	if info.IsDir() {
		// add default pattern
		root = filepath.Join(root, "*.silk.md")
	}
	testing.Main(func(pat, str string) (bool, error) { return true, nil },
		[]testing.InternalTest{{Name: "silk", F: testFunc}},
		nil,
		nil)
}
开发者ID:lucmichalski,项目名称:silk,代码行数:34,代码来源:main.go

示例2: main

func main() {
	if len(os.Args) == 1 {
		cmd := exec.Command(os.Args[0], "-test.bench=.*", "-test.benchmem=true", "-test.benchtime=2s")
		cmd.Stdout = os.Stdout
		cmd.Stderr = os.Stderr
		cmd.Run()
		return
	}

	fmt.Printf("Build: %s %s-%s\n", runtime.Version(), runtime.GOOS, runtime.GOARCH)

	hashers := []struct {
		name string
		hash hash.Hash
	}{
		{"SHA256", sha256.New()},
		{"SHAKE256", shakeAdapter{sha3.NewShake256(), 64}},
	}

	benchmarks := []testing.InternalBenchmark{}
	for _, h := range hashers {
		benchmarks = append(benchmarks, testing.InternalBenchmark{
			Name: h.name,
			F:    wrap(h.hash),
		})
	}
	testing.Main(func(pat, str string) (bool, error) {
		return true, nil
	}, nil, benchmarks, nil)
}
开发者ID:calmh,项目名称:gohashcompare,代码行数:30,代码来源:main.go

示例3: main

func main() {
	flag.StringVar(&target, "target", "localhost:8080", "Test target")
	flag.StringVar(&authUser, "user", "", "Username")
	flag.StringVar(&authPass, "pass", "", "Password")
	flag.StringVar(&csrfFile, "csrf", "", "CSRF token file")
	flag.StringVar(&apiKey, "api", "", "API key")
	flag.Parse()

	if len(csrfFile) > 0 {
		fd, err := os.Open(csrfFile)
		if err != nil {
			log.Fatal(err)
		}
		s := bufio.NewScanner(fd)
		for s.Scan() {
			csrfToken = s.Text()
		}
		fd.Close()
	}

	var tests []testing.InternalTest
	tests = append(tests, testing.InternalTest{"TestGetIndex", TestGetIndex})
	tests = append(tests, testing.InternalTest{"TestGetVersion", TestGetVersion})
	tests = append(tests, testing.InternalTest{"TestGetVersionNoCSRF", TestGetVersion})
	tests = append(tests, testing.InternalTest{"TestJSONEndpoints", TestJSONEndpoints})
	if len(authUser) > 0 || len(apiKey) > 0 {
		tests = append(tests, testing.InternalTest{"TestJSONEndpointsNoAuth", TestJSONEndpointsNoAuth})
		tests = append(tests, testing.InternalTest{"TestJSONEndpointsIncorrectAuth", TestJSONEndpointsIncorrectAuth})
	}
	if len(csrfToken) > 0 {
		tests = append(tests, testing.InternalTest{"TestJSONEndpointsNoCSRF", TestJSONEndpointsNoCSRF})
	}

	testing.Main(matcher, tests, nil, nil)
}
开发者ID:hbcbh1999,项目名称:syncthing,代码行数:35,代码来源:http.go

示例4: main

func main() {
	testing.Main([]testing.Test{
		testing.Test{"String", golambda.TestString},
		testing.Test{"Parse", golambda.TestParse},
		testing.Test{"OccursFree", golambda.TestOccursFree},
		testing.Test{"Substitute", golambda.TestSubstitute},
		testing.Test{"Reduce", golambda.TestReduce}
	});
}
开发者ID:stesla,项目名称:golambda,代码行数:9,代码来源:test_main.go

示例5: main

func main() {
	flag.Set("test.bench", "Large")
	flag.Set("test.v", "true")

	testing.Main(func(pat, str string) (bool, error) { return true, nil },
		[]testing.InternalTest{{"TestLargeMapGC", TestLargeMapGC}},
		[]testing.InternalBenchmark{{"BenchmarkLargeMapGC", BenchmarkLargeMapGC}},
		[]testing.InternalExample{})
}
开发者ID:Kane-Sendgrid,项目名称:gopher-meetup-talk,代码行数:9,代码来源:big_map.go

示例6: main

func main() {
	log.Println(runtime.Version())
	flag.Set("test.bench", "foo")
	flag.Set("test.v", "true")

	testing.Main(func(pat, str string) (bool, error) { return true, nil },
		[]testing.InternalTest{{"TestSlice", TestSlice}, {"TestSliceByte", TestSliceByte}},
		[]testing.InternalBenchmark{},
		[]testing.InternalExample{})
}
开发者ID:Kane-Sendgrid,项目名称:gopher-meetup-talk,代码行数:10,代码来源:slice_nogc.go

示例7: TestCustomSuite

func TestCustomSuite(path string) {
	test := func(t *testing.T) {
		RunTestSuite(path, t)
	}

	tests := []testing.InternalTest{testing.InternalTest{Name: "CustomTest(" + path + ")", F: test}}
	_, benches, examples := initialize()

	testing.Main(matchString, tests, benches, examples)
}
开发者ID:nmakiya,项目名称:tritium,代码行数:10,代码来源:custom_tests.go

示例8: main

func main() {
	log.Println(runtime.Version())
	flag.Set("test.bench", "foo")
	flag.Set("test.v", "true")

	testing.Main(func(pat, str string) (bool, error) { return true, nil },
		[]testing.InternalTest{},
		[]testing.InternalBenchmark{{"BenchmarkFreelist", BenchmarkFreelist}, {"BenchmarkFreelist2", BenchmarkFreelist2}},
		[]testing.InternalExample{})
}
开发者ID:Kane-Sendgrid,项目名称:gopher-meetup-talk,代码行数:10,代码来源:freelist.go

示例9: main

func main() {
	testsuite := komoku.Testsuite()
	numTests := len(testsuite)
	if numTests > 1 || numTests == 0 {
		fmt.Printf("Running %d tests in SUBSTITUTE_THIS...\n", numTests)
	} else {
		fmt.Printf("Running %d test in SUBSTITUTE_THIS...\n", numTests)
	}
	matchAlways := func(pat, str string) (bool, os.Error) {
		return true, nil
	}
	testing.Main(matchAlways, testsuite)
}
开发者ID:Sh4pe,项目名称:komoku,代码行数:13,代码来源:skeleton.go

示例10: main

func main() {
	flag.Parse()

	if *g_keyId == "" {
		fmt.Println("You must set the -key_id flag.")
		fmt.Println("Find a key ID here:")
		fmt.Println("    https://portal.aws.amazon.com/gp/aws/securityCredentials")
		os.Exit(1)
	}

	if *g_bucketName == "" {
		fmt.Println("You must set the -bucket flag.")
		fmt.Println("Manage your buckets here:")
		fmt.Println("    https://console.aws.amazon.com/s3/")
		os.Exit(1)
	}

	if *g_region == "" {
		fmt.Println("You must set the -region flag. See region.go.")
		os.Exit(1)
	}

	// Read in the access key.
	g_accessKey.Id = *g_keyId
	g_accessKey.Secret = readPassword("Access key secret: ")

	// Run the tests.
	matchString := func(pat, str string) (bool, error) {
		re, err := regexp.Compile(pat)
		if err != nil {
			return false, err
		}

		return re.MatchString(str), nil
	}

	testing.Main(
		matchString,
		[]testing.InternalTest{
			testing.InternalTest{
				Name: "IntegrationTest",
				F:    func(t *testing.T) { ogletest.RunTests(t) },
			},
		},
		[]testing.InternalBenchmark{},
		[]testing.InternalExample{},
	)
}
开发者ID:jacobsa,项目名称:aws,代码行数:48,代码来源:main.go

示例11: main

func main() {
	flag.Parse()

	test := []testing.InternalTest{
		{"Get", add.Get},
		{"PostEmpty", add.PostEmpty},
		{"PostFile", add.PostFile},
		{"GetCat", cat.Get},
	}

	bench := []testing.InternalBenchmark{}

	examples := []testing.InternalExample{}

	testing.Main(strmatch, test, bench, examples)
}
开发者ID:travisperson,项目名称:ipfs-api-test,代码行数:16,代码来源:main.go

示例12: BenchmarkCustomSuite

func BenchmarkCustomSuite(path string) {
	benchmark := func(b *testing.B) {
		RunBenchmarkSuite(path, b)
	}

	benches := []testing.InternalBenchmark{testing.InternalBenchmark{Name: "CustomBenchmark(" + path + ")", F: benchmark}}

	test := func(t *testing.T) {
		RunTestSuite(path, t)
	}

	tests := []testing.InternalTest{testing.InternalTest{Name: "CustomTest(" + path + ")", F: test}}

	_, _, examples := initialize()

	flag.Set("test.bench", ".*") // IMPORTANT : The testing internals check that this flag is set

	testing.Main(matchString, tests, benches, examples)
}
开发者ID:nmakiya,项目名称:tritium,代码行数:19,代码来源:custom_tests.go

示例13: main

func main() {
	flag.Parse()
	if *showVersion {
		printversion()
		return
	}
	if *help {
		printhelp()
		return
	}
	if *url == "" {
		fmt.Println("silk.url argument is required")
		return
	}
	paths = flag.Args()
	testing.Main(func(pat, str string) (bool, error) { return true, nil },
		[]testing.InternalTest{{Name: "silk", F: testFunc}},
		nil,
		nil)
}
开发者ID:matryer,项目名称:silk,代码行数:20,代码来源:main.go

示例14: main

func main() {
	flag.StringVar(&target, "target", "localhost:8080", "Test target")
	flag.StringVar(&authUser, "user", "", "Username")
	flag.StringVar(&authPass, "pass", "", "Password")
	flag.StringVar(&csrfFile, "csrf", "", "CSRF token file")
	flag.StringVar(&apiKey, "api", "", "API key")
	flag.Parse()

	if len(csrfFile) > 0 {
		fd, err := os.Open(csrfFile)
		if err != nil {
			log.Fatal(err)
		}
		s := bufio.NewScanner(fd)
		for s.Scan() {
			csrfToken = s.Text()
		}
		fd.Close()
	}

	var tests []testing.InternalTest
	tests = append(tests, testing.InternalTest{"TestGetIndex", TestGetIndex})
	tests = append(tests, testing.InternalTest{"TestJSONEndpoints", TestJSONEndpoints})
	tests = append(tests, testing.InternalTest{"TestPOSTNoCSRF", TestPOSTNoCSRF})

	if len(authUser) > 0 {
		// If we expect authentication, verify that it fails with the wrong password and wrong API key
		tests = append(tests, testing.InternalTest{"TestJSONEndpointsNoAuth", TestJSONEndpointsNoAuth})
		tests = append(tests, testing.InternalTest{"TestJSONEndpointsIncorrectAuth", TestJSONEndpointsIncorrectAuth})
	}

	if len(csrfToken) > 0 {
		// If we have a CSRF token, verify that POST succeeds with it
		tests = append(tests, testing.InternalTest{"TestPostWitchCSRF", TestPostWitchCSRF})
		tests = append(tests, testing.InternalTest{"TestGetPostConfigOK", TestGetPostConfigOK})
		tests = append(tests, testing.InternalTest{"TestGetPostConfigFail", TestGetPostConfigFail})
	}

	fmt.Printf("Testing HTTP: CSRF=%v, API=%v, Auth=%v\n", len(csrfToken) > 0, len(apiKey) > 0, len(authUser) > 0)
	testing.Main(matcher, tests, nil, nil)
}
开发者ID:GDXN,项目名称:syncthing,代码行数:41,代码来源:http.go

示例15: main

func main() {
	var tests []testing.InternalTest
	tests = append(tests, testing.InternalTest{Name: "TestAll", F: TestAll})
	testing.Main(func(pat, str string) (bool, error) { return true, nil }, tests, nil, nil)
}
开发者ID:matryer,项目名称:tdd-in-go,代码行数:5,代码来源:isolated_example.go


注:本文中的testing.Main函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。