本文整理汇总了Golang中github.com/attic-labs/testify/assert.Panics函数的典型用法代码示例。如果您正苦于以下问题:Golang Panics函数的具体用法?Golang Panics怎么用?Golang Panics使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Panics函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
})
}())
}
示例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)) })
}
示例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))
}
示例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") })
})
}
示例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)
})
}())
}
示例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_")
}
示例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_")
}
示例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)
}
示例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))
}
示例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 })
})
}
示例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) })
}
示例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)})})
})
}
示例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!")
}
示例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")
}
示例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) })
}