本文整理汇总了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)
}
示例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)
}
示例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)
}
示例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}
});
}
示例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{})
}
示例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{})
}
示例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)
}
示例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{})
}
示例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)
}
示例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{},
)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}