本文整理汇总了Golang中testing.T.Log方法的典型用法代码示例。如果您正苦于以下问题:Golang T.Log方法的具体用法?Golang T.Log怎么用?Golang T.Log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.T
的用法示例。
在下文中一共展示了T.Log方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCalibrateThreshold
func TestCalibrateThreshold(t *testing.T) {
if !*calibrate {
t.Log("not calibrating, use -calibrate to do so.")
return
}
lower := int(1e3) // math/big is faster at this size.
upper := int(300e3) // FFT is faster at this size.
big, fft := measureMul(lower)
lowerX := float64(big) / float64(fft)
fmt.Printf("speedup at size %d: %.2f\n", lower, lowerX)
big, fft = measureMul(upper)
upperX := float64(big) / float64(fft)
fmt.Printf("speedup at size %d: %.2f\n", upper, upperX)
for {
mid := (lower + upper) / 2
big, fft := measureMul(mid)
X := float64(big) / float64(fft)
fmt.Printf("speedup at size %d: %.2f\n", mid, X)
switch {
case X < 0.98:
lower = mid
lowerX = X
case X > 1.02:
upper = mid
upperX = X
default:
fmt.Printf("speedup at size %d: %.2f\n", lower, lowerX)
fmt.Printf("speedup at size %d: %.2f\n", upper, upperX)
return
}
}
}
示例2: TestCanManageReposIndependently
func TestCanManageReposIndependently(t *testing.T) {
t.Parallel()
pathA := testRepoPath("a", t)
pathB := testRepoPath("b", t)
t.Log("initialize two repos")
assert.Nil(Init(pathA, &config.Config{}), t, "a", "should initialize successfully")
assert.Nil(Init(pathB, &config.Config{}), t, "b", "should initialize successfully")
t.Log("ensure repos initialized")
assert.True(IsInitialized(pathA), t, "a should be initialized")
assert.True(IsInitialized(pathB), t, "b should be initialized")
t.Log("open the two repos")
repoA, err := Open(pathA)
assert.Nil(err, t, "a")
repoB, err := Open(pathB)
assert.Nil(err, t, "b")
t.Log("close and remove b while a is open")
assert.Nil(repoB.Close(), t, "close b")
assert.Nil(Remove(pathB), t, "remove b")
t.Log("close and remove a")
assert.Nil(repoA.Close(), t)
assert.Nil(Remove(pathA), t)
}
示例3: TestCacheComplete
func TestCacheComplete(t *testing.T) {
paths := DefaultPaths()
if len(paths) == 0 {
t.Skip("No default paths available")
}
tests := []string{"mscorlib.dll", "System.dll"}
t.Log(paths)
c := Cache{paths: paths}
for _, test := range tests {
if asm, err := c.Load(test); err != nil {
t.Error(err)
} else {
t.Logf("Found %s (%s)", test, asm.Name())
}
}
tests2 := []content.Type{
content.Type{Name: content.FullyQualifiedName{Absolute: "net://type/System.String"}},
}
for _, test := range tests2 {
if res, err := c.Complete(&test); err != nil {
t.Error(err)
} else {
t.Log(res)
}
}
}
示例4: Test_RemoveList
func Test_RemoveList(t *testing.T) {
FuncName := "GdLists.RemoveList()"
ssgl, _ := getGdListIns()
Pssgl := &ssgl
Pssgl.New()
// -- a == b == 0
// s, e, _ := 0, 0, 5 // 2, 3, 4, 5
// -- a == b == l - 1
// s, e = 4, 4 // 1, 2, 3, 4
// -- a == 0 && b == l - 1
// s, e = 0, 4 // nil
// -- 0 < a < b < l
// s, e = 1, 3 // 1, 5
// a = 0
// s, e = 0, 2 // 4, 5
// b = l - 1
// s, e = 2, 4 // 1, 2
// Pssgl.RemoveList(s, e)
// dd(Pssgl.Sync().Value)
t.Log(FuncName + " ... ok!")
}
示例5: Test_seCheck
func Test_seCheck(t *testing.T) {
FuncName := "GdLists.seCheck()"
// -- a == b == 0
// s, e, l := 0, 0, 5 // 0, 0
// -- a < 0 && b < 0
// s, e = -5, -10 // 0, 0
// -- a >=l && b >= l
// s, e = 5, 10 // 4, 4
// -- a < 0 && b >= l
// s, e = -5, 10 // 0, 4
// -- a < 0 && b >= 0
// s, e = -5, 2 // 0, 2
// -- a >= 0 && b >= l
// s, e = 2, 10 // 2, 4
// -- a == b == l - 1
// s, e = 4, 4 // 4, 4
// -- a == 0 && b == l - 1
// s, e = 0, 4 // 0, 4
// -- 0 < a < b < l
// s, e = 1, 3 // 1, 3
// -- a = 0
// s, e = 0, 2 // 0, 2
// -- b = l - 1
// s, e = 2, 4 // 2, 4
// a, b := seCheck(s, e, l)
// dd(a)
// dd(b)
t.Log(FuncName + " ... ok!")
}
示例6: TestWalk
func TestWalk(t *testing.T) {
ignores := ignore.New(false)
err := ignores.Load("testdata/.stignore")
if err != nil {
t.Fatal(err)
}
t.Log(ignores)
w := Walker{
Dir: "testdata",
BlockSize: 128 * 1024,
Matcher: ignores,
}
fchan, err := w.Walk()
if err != nil {
t.Fatal(err)
}
var tmp []protocol.FileInfo
for f := range fchan {
tmp = append(tmp, f)
}
sort.Sort(fileList(tmp))
files := fileList(tmp).testfiles()
if !reflect.DeepEqual(files, testdata) {
t.Errorf("Walk returned unexpected data\nExpected: %v\nActual: %v", testdata, files)
}
}
示例7: testSplitQueryPanics
func testSplitQueryPanics(t *testing.T, conn tabletconn.TabletConn) {
t.Log("testSplitQueryPanics")
ctx := context.Background()
if _, err := conn.SplitQuery(ctx, splitQueryBoundQuery, splitQuerySplitColumn, splitQuerySplitCount); err == nil || !strings.Contains(err.Error(), "caught test panic") {
t.Fatalf("unexpected panic error: %v", err)
}
}
示例8: testStreamExecute2Error
func testStreamExecute2Error(t *testing.T, conn tabletconn.TabletConn, fake *FakeQueryService) {
t.Log("testStreamExecute2Error")
ctx := context.Background()
stream, errFunc, err := conn.StreamExecute2(ctx, streamExecuteQuery, streamExecuteBindVars, streamExecuteTransactionID)
if err != nil {
t.Fatalf("StreamExecute2 failed: %v", err)
}
qr, ok := <-stream
if !ok {
t.Fatalf("StreamExecute2 failed: cannot read result1")
}
if len(qr.Rows) == 0 {
qr.Rows = nil
}
if !reflect.DeepEqual(*qr, streamExecuteQueryResult1) {
t.Errorf("Unexpected result1 from StreamExecute2: got %v wanted %v", qr, streamExecuteQueryResult1)
}
// signal to the server that the first result has been received
close(fake.errorWait)
// After 1 result, we expect to get an error (no more results).
qr, ok = <-stream
if ok {
t.Fatalf("StreamExecute2 channel wasn't closed")
}
err = errFunc()
verifyError(t, err, "StreamExecute2")
}
示例9: TestPortRange
func TestPortRange(t *testing.T) {
defer func() {
if r := recover(); r != nil {
t.Fatalf("Recovered from panic: %s", r)
return
}
}()
defer os.Remove("port_range.yml")
log.SetLogLevel(log.FATAL)
if err := ioutil.WriteFile("port_range.yml", []byte(
`
listen: '1:25565'
upstreams:
- hostname: server.local
upstream: localhost:65537
- hostname: server2.local
upstream: localhost:-1`), 0644); err != nil {
t.Fatal("Unable to write to port_range.yml")
return
}
SetConfig("port_range.yml")
confInit()
if len(config.Upstream) != 0 {
t.Fatalf("No valid upstreams provided, but %d upstreams found!", len(config.Upstream))
return
}
t.Log("Ok, no valid upstream.")
}
示例10: TestCreateDirs
func TestCreateDirs(t *testing.T) {
pwd, err := os.Getwd()
if err != nil {
t.Errorf("Unable to get current working directory: %s", err)
}
config := Conf{ListenPort: "9666", RootRepoPath: pwd + "/testing", SupportArch: []string{"cats", "dogs"}, EnableSSL: false}
// sanity check...
if config.RootRepoPath != pwd+"/testing" {
t.Errorf("RootRepoPath is %s, should be %s\n ", config.RootRepoPath, pwd+"/testing")
}
t.Log("creating temp dirs in ", config.RootRepoPath)
dirSuccess := createDirs(config)
if err := dirSuccess; err != nil {
t.Errorf("createDirs() failed ")
}
for _, archDir := range config.SupportArch {
if _, err := os.Stat(config.RootRepoPath + "/dists/stable/main/binary-" + archDir); err != nil {
if os.IsNotExist(err) {
t.Errorf("Directory for %s does not exist", archDir)
}
}
}
// cleanup
if err := os.RemoveAll(config.RootRepoPath); err != nil {
t.Errorf("error cleaning up after createDirs(): %s", err)
}
}
示例11: TestStateTimeoutWait
func TestStateTimeoutWait(t *testing.T) {
s := NewState()
started := make(chan struct{})
go func() {
s.WaitRunning(100 * time.Millisecond)
close(started)
}()
select {
case <-time.After(200 * time.Millisecond):
t.Fatal("Start callback doesn't fire in 100 milliseconds")
case <-started:
t.Log("Start callback fired")
}
s.Lock()
s.SetRunning(49, false)
s.Unlock()
stopped := make(chan struct{})
go func() {
s.WaitRunning(100 * time.Millisecond)
close(stopped)
}()
select {
case <-time.After(200 * time.Millisecond):
t.Fatal("Start callback doesn't fire in 100 milliseconds")
case <-stopped:
t.Log("Start callback fired")
}
}
示例12: TestIssue8518
func TestIssue8518(t *testing.T) {
fset := token.NewFileSet()
conf := Config{
Packages: make(map[string]*Package),
Error: func(err error) { t.Log(err) }, // don't exit after first error
Import: func(imports map[string]*Package, path string) (*Package, error) {
return imports[path], nil
},
}
makePkg := func(path, src string) {
f, err := parser.ParseFile(fset, path, src, 0)
if err != nil {
t.Fatal(err)
}
pkg, _ := conf.Check(path, fset, []*ast.File{f}, nil) // errors logged via conf.Error
conf.Packages[path] = pkg
}
const libSrc = `
package a
import "missing"
const C1 = foo
const C2 = missing.C
`
const mainSrc = `
package main
import "a"
var _ = a.C1
var _ = a.C2
`
makePkg("a", libSrc)
makePkg("main", mainSrc) // don't crash when type-checking this package
}
示例13: TestConfig
func TestConfig(t *testing.T) {
var (
c *Config
err error
file = "./test/store.yaml"
)
t.Log("NewConfig()")
if c, err = NewConfig(file); err != nil {
t.Errorf("NewConfig(\"%s\") error(%v)", file, err)
t.FailNow()
}
if c.Index != "/tmp/hijohn.idx" {
t.FailNow()
}
if c.Stat != "localhost:6061" {
t.FailNow()
}
if !c.Pprof.Enable {
t.FailNow()
}
if c.Pprof.Addr != "localhost:6060" {
t.FailNow()
}
if len(c.ZK) != 2 || c.ZK[0] != "1" || c.ZK[1] != "2" {
t.FailNow()
}
}
示例14: TestMultipleResultMerge
func TestMultipleResultMerge(t *testing.T) {
t1 := time.Date(2012, time.February, 2, 17, 59, 0, 0, time.UTC)
t2 := time.Date(2012, time.February, 2, 18, 0, 0, 0, time.UTC)
cd := &CallDescriptor{Direction: utils.OUT, Category: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
cc1, _ := cd.getCost()
if cc1.Cost != 61 {
//ils.LogFull(cc1)
t.Errorf("expected 61 was %v", cc1.Cost)
for _, ts := range cc1.Timespans {
t.Log(ts.RateInterval)
}
}
t1 = time.Date(2012, time.February, 2, 18, 00, 0, 0, time.UTC)
t2 = time.Date(2012, time.February, 2, 18, 01, 0, 0, time.UTC)
cd = &CallDescriptor{Direction: utils.OUT, Category: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
cc2, _ := cd.getCost()
if cc2.Cost != 30 {
t.Errorf("expected 30 was %v", cc2.Cost)
for _, ts := range cc1.Timespans {
t.Log(ts.RateInterval)
}
}
cc1.Merge(cc2)
if len(cc1.Timespans) != 2 || cc1.Timespans[0].GetDuration().Seconds() != 60 {
t.Error("wrong resulted timespans: ", len(cc1.Timespans))
}
if cc1.Cost != 91 {
t.Errorf("Exdpected 91 was %v", cc1.Cost)
}
}
示例15: TestPartitionLeaves
func TestPartitionLeaves(t *testing.T) {
zero, one, id := Terminal1(Constant1(0)), Terminal1(Constant1(1)), Terminal1(Identity1)
sum, abs, sub := Functional2(Sum), Functional1(Abs), Functional2(Sub)
var tZero, tOne, tId *Node = mt(zero), mt(one), mt(id) //mt(sum, mt(one), mt(abs, mt(sub, mt(zero), mt(id))))
t1 := mt(sum, mt(abs, tId), mt(sub, tZero, tOne))
nods, _, _ := t1.Enumerate()
le, nonle := partitionLeaves(nods)
t.Log("Leaves:", le)
t.Log("Non-leaves:", nonle)
for i := range le {
j := le[i]
if len(nods[j].children) != 0 {
t.Error("Leaf expected, but had child(ren)", j, nods[j], nods[j].children)
}
}
for i := range nonle {
j := nonle[i]
if len(nods[j].children) == 0 {
t.Error("Non-leaf expected, but didn't have child(ren)", i, j, nods[j])
}
}
}