本文整理汇总了Golang中github.com/attic-labs/testify/assert.Panics函数的典型用法代码示例。如果您正苦于以下问题:Golang Panics函数的具体用法?Golang Panics怎么用?Golang Panics使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Panics函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestTry2
func TestTry2(t *testing.T) {
assert := assert.New(t)
assert.Panics(func() {
Try(func() {
panic(te)
})
})
assert.Panics(func() {
Try(func() {
PanicIfError(te)
}, te2)
})
assert.Error(func() error {
return Try(func() {
PanicIfError(te)
})
}())
assert.Error(func() error {
return Try(func() {
PanicIfError(te)
}, testError{})
}())
assert.Nil(func() error {
return Try(func() {
PanicIfError(nil)
})
}())
}
开发者ID:Richardphp,项目名称:noms,代码行数:33,代码来源:try_test.go
示例2: TestValidateRef
func TestValidateRef(t *testing.T) {
ds := createTestDataset("test")
b := types.Bool(true)
r := ds.Database().WriteValue(b)
assert.Panics(t, func() { ds.validateRefAsCommit(r) })
assert.Panics(t, func() { ds.validateRefAsCommit(types.NewRef(b)) })
}
开发者ID:willhite,项目名称:noms-old,代码行数:8,代码来源:pull_test.go
示例3: TestGenericStructSet
func TestGenericStructSet(t *testing.T) {
assert := assert.New(t)
s := NewStruct("S3", StructData{"b": Bool(true), "o": String("hi")})
s2 := s.Set("b", Bool(false))
assert.Panics(func() { s.Set("b", Number(1)) })
assert.Panics(func() { s.Set("x", Number(1)) })
s3 := s2.Set("b", Bool(true))
assert.True(s.Equals(s3))
}
开发者ID:Richardphp,项目名称:noms,代码行数:12,代码来源:struct_test.go
示例4: TestTry
func TestTry(t *testing.T) {
assert := assert.New(t)
IsUsageError(assert, func() { Exp.Fail("hey-o") })
assert.Panics(func() {
Try(func() { Chk.Fail("hey-o") })
})
assert.Panics(func() {
Try(func() { panic("hey-o") })
})
}
开发者ID:willhite,项目名称:noms-old,代码行数:13,代码来源:try_test.go
示例5: TestTryCatch
func TestTryCatch(t *testing.T) {
assert := assert.New(t)
assert.Panics(func() {
TryCatch(func() {
panic(Wrap(te))
},
func(err error) error {
if !causeInTypes(err, testError2{}) {
panic(err)
}
return Unwrap(err)
})
})
assert.Panics(func() {
TryCatch(func() {
panic(te)
},
func(err error) error {
if !causeInTypes(err, testError{}) {
panic(err)
}
return Unwrap(err)
})
})
assert.IsType(wrappedError{}, func() error {
return TryCatch(func() {
panic(Wrap(te))
},
func(err error) error {
return err
})
}())
assert.Error(func() error {
return TryCatch(func() {
panic(Wrap(te))
},
func(err error) error {
if !causeInTypes(err, testError2{}, testError{}) {
panic(err)
}
return Unwrap(err)
})
}())
}
开发者ID:Richardphp,项目名称:noms,代码行数:48,代码来源:try_test.go
示例6: TestVerifyStructName
func TestVerifyStructName(t *testing.T) {
assert := assert.New(t)
assertInvalid := func(n string) {
assert.Panics(func() {
MakeStructType(n, []string{}, []*Type{})
})
}
assertInvalid(" ")
assertInvalid(" a")
assertInvalid("a ")
assertInvalid("0")
assertInvalid("_")
assertInvalid("0a")
assertInvalid("_a")
assertInvalid("💩")
assertValid := func(n string) {
MakeStructType(n, []string{}, []*Type{})
}
assertValid("")
assertValid("a")
assertValid("A")
assertValid("a0")
assertValid("a_")
assertValid("a0_")
}
开发者ID:Richardphp,项目名称:noms,代码行数:28,代码来源:type_test.go
示例7: TestVerifyStructFieldName
func TestVerifyStructFieldName(t *testing.T) {
assert := assert.New(t)
assertInvalid := func(n string) {
assert.Panics(func() {
MakeStructType("S", TypeMap{n: StringType})
})
}
assertInvalid("")
assertInvalid(" ")
assertInvalid(" a")
assertInvalid("a ")
assertInvalid("0")
assertInvalid("_")
assertInvalid("0a")
assertInvalid("_a")
assertInvalid("💩")
assertValid := func(n string) {
MakeStructType("S", TypeMap{n: StringType})
}
assertValid("a")
assertValid("A")
assertValid("a0")
assertValid("a_")
assertValid("a0_")
}
开发者ID:willhite,项目名称:noms-old,代码行数:27,代码来源:type_test.go
示例8: TestHeadValueFunctions
func TestHeadValueFunctions(t *testing.T) {
assert := assert.New(t)
id1 := "testdataset"
id2 := "otherdataset"
cs := chunks.NewMemoryStore()
ds1 := newDS(id1, cs)
// ds1: |a|
a := types.String("a")
ds1, err := ds1.CommitValue(a)
assert.NoError(err)
hv := ds1.Head().Get(datas.ValueField)
assert.Equal(a, hv)
assert.Equal(a, ds1.HeadValue())
hv, ok := ds1.MaybeHeadValue()
assert.True(ok)
assert.Equal(a, hv)
ds2 := newDS(id2, cs)
assert.Panics(func() {
ds2.HeadValue()
})
_, ok = ds2.MaybeHeadValue()
assert.False(ok)
}
开发者ID:Richardphp,项目名称:noms,代码行数:29,代码来源:dataset_test.go
示例9: TestPanicIfTrue
func TestPanicIfTrue(t *testing.T) {
assert := assert.New(t)
arg := "arg value"
format := "could be a format: %s"
formatted := fmt.Sprintf(format, arg)
assert.Panics(func() {
PanicIfTrue(true, "Panicking!!!!")
})
assert.NotPanics(func() {
PanicIfTrue(false, "Not panicking")
})
err := Try(func() {
PanicIfTrue(true, format)
})
assert.Equal(errors.New(format), Unwrap(err))
err = Try(func() {
PanicIfTrue(true, format, arg)
})
assert.Equal(errors.New(formatted), Unwrap(err))
}
开发者ID:Richardphp,项目名称:noms,代码行数:25,代码来源:try_test.go
示例10: Test_Mock_On_WithFuncPanics
func Test_Mock_On_WithFuncPanics(t *testing.T) {
// make a test impl object
var mockedService = new(TestExampleImplementation)
assert.Panics(t, func() {
mockedService.On("TheExampleMethodFunc", func(string) error { return nil })
})
}
开发者ID:Richardphp,项目名称:noms,代码行数:8,代码来源:mock_test.go
示例11: TestDuplicateHeaderName
func TestDuplicateHeaderName(t *testing.T) {
assert := assert.New(t)
ds := datas.NewDatabase(chunks.NewMemoryStore())
dataString := "1,2\n3,4\n"
r := NewCSVReader(bytes.NewBufferString(dataString), ',')
headers := []string{"A", "A"}
kinds := KindSlice{types.StringKind, types.StringKind}
assert.Panics(func() { ReadToList(r, "test", headers, kinds, ds) })
}
开发者ID:willhite,项目名称:noms-old,代码行数:9,代码来源:read_test.go
示例12: TestInvalidCyclesAndUnions
func TestInvalidCyclesAndUnions(t *testing.T) {
assert := assert.New(t)
assert.Panics(func() {
MakeStructType("A",
[]string{"a"},
[]*Type{MakeStructType("A", []string{"a"}, []*Type{MakeCycleType(1)})})
})
}
开发者ID:Richardphp,项目名称:noms,代码行数:9,代码来源:type_cache_test.go
示例13: TestChunkChunkCloses
func TestChunkChunkCloses(t *testing.T) {
assert := assert.New(t)
input := "abc"
w := NewChunkWriter()
_, err := w.Write([]byte(input))
assert.NoError(err)
w.Chunk()
assert.Panics(func() { w.Write([]byte(input)) }, "Write() after Close() should barf!")
}
开发者ID:willhite,项目名称:noms-old,代码行数:10,代码来源:chunk_test.go
示例14: Test_Mock_Called_Unexpected
func Test_Mock_Called_Unexpected(t *testing.T) {
var mockedService = new(TestExampleImplementation)
// make sure it panics if no expectation was made
assert.Panics(t, func() {
mockedService.Called(1, 2, 3)
}, "Calling unexpected method should panic")
}
开发者ID:Richardphp,项目名称:noms,代码行数:10,代码来源:mock_test.go
示例15: TestEnsureChunksFails
func TestEnsureChunksFails(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
cvs := newLocalValueStore(cs)
b := NewEmptyBlob()
bref := NewRef(b)
assert.Panics(func() { cvs.ensureChunksInCache(bref) })
s := String("oy")
cs.Put(EncodeValue(b, nil))
cs.Put(EncodeValue(s, nil))
badRef := constructRef(MakeRefType(MakePrimitiveType(BoolKind)), s.Hash(), 1)
l := NewList(bref, badRef)
cs.Put(EncodeValue(l, nil))
assert.Panics(func() { cvs.ensureChunksInCache(l) })
}
开发者ID:willhite,项目名称:noms-old,代码行数:19,代码来源:value_store_test.go
示例16: TestCheckChunksNotInCache
func TestCheckChunksNotInCache(t *testing.T) {
assert := assert.New(t)
cs := chunks.NewTestStore()
cvs := newLocalValueStore(cs)
b := NewEmptyBlob()
cs.Put(EncodeValue(b, nil))
bref := NewRef(b)
assert.Panics(func() { cvs.chunkHintsFromCache(bref) })
}
开发者ID:willhite,项目名称:noms-old,代码行数:11,代码来源:value_store_test.go
示例17: TestWriteStructTooMuchData
func TestWriteStructTooMuchData(t *testing.T) {
s := NewStruct("S", StructData{"x": Number(42), "b": Bool(true)})
c := EncodeValue(s, nil)
data := c.Data()
buff := make([]byte, len(data)+1)
copy(buff, data)
buff[len(data)] = 5 // Add a bogus extrabyte
assert.Panics(t, func() {
DecodeFromBytes(buff, nil, staticTypeCache)
})
}
开发者ID:Richardphp,项目名称:noms,代码行数:11,代码来源:encoding_test.go
示例18: TestIdValidation
func TestIdValidation(t *testing.T) {
assert := assert.New(t)
store := datas.NewDatabase(chunks.NewMemoryStore())
invalidDatasetNames := []string{" ", "", "a ", " a", "$", "#", ":", "\n", "💩"}
for _, id := range invalidDatasetNames {
assert.Panics(func() {
NewDataset(store, id)
})
}
}
开发者ID:Richardphp,项目名称:noms,代码行数:11,代码来源:dataset_test.go
示例19: TestGenericStructNew
func TestGenericStructNew(t *testing.T) {
assert := assert.New(t)
s := NewStruct("S2", map[string]Value{"b": Bool(true), "o": String("hi")})
assert.True(s.Get("b").Equals(Bool(true)))
_, ok := s.MaybeGet("missing")
assert.False(ok)
s2 := NewStruct("S2", map[string]Value{"b": Bool(false), "o": String("hi")})
assert.True(s2.Get("b").Equals(Bool(false)))
o, ok := s2.MaybeGet("o")
assert.True(ok)
assert.True(String("hi").Equals(o))
typ := MakeStructType("S2", TypeMap{
"b": BoolType,
"o": StringType,
})
assert.Panics(func() { NewStructWithType(typ, nil) })
assert.Panics(func() { NewStructWithType(typ, map[string]Value{"o": String("hi")}) })
}
开发者ID:willhite,项目名称:noms-old,代码行数:21,代码来源:struct_test.go
示例20: TestGenericStructNew
func TestGenericStructNew(t *testing.T) {
assert := assert.New(t)
s := NewStruct("S2", StructData{"b": Bool(true), "o": String("hi")})
assert.True(s.Get("b").Equals(Bool(true)))
_, ok := s.MaybeGet("missing")
assert.False(ok)
s2 := NewStruct("S2", StructData{"b": Bool(false), "o": String("hi")})
assert.True(s2.Get("b").Equals(Bool(false)))
o, ok := s2.MaybeGet("o")
assert.True(ok)
assert.True(String("hi").Equals(o))
typ := MakeStructType("S2",
[]string{"b", "o"},
[]*Type{BoolType, StringType},
)
assert.Panics(func() { NewStructWithType(typ, nil) })
assert.Panics(func() { NewStructWithType(typ, ValueSlice{String("hi")}) })
}
开发者ID:Richardphp,项目名称:noms,代码行数:21,代码来源:struct_test.go
注:本文中的github.com/attic-labs/testify/assert.Panics函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论