1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-12-26 20:15:26 -05:00

remove dependency on assert lib

This commit is contained in:
Darien Raymond
2019-01-18 15:59:39 +01:00
parent c0fe58e4a4
commit 8e131bcd1f
5 changed files with 100 additions and 85 deletions

View File

@@ -5,25 +5,40 @@ import (
"testing"
. "v2ray.com/core/common"
. "v2ray.com/ext/assert"
)
func TestMust(t *testing.T) {
assert := With(t)
f := func() error {
return errors.New("test error")
hasPanic := func(f func()) (ret bool) {
defer func() {
if r := recover(); r != nil {
ret = true
}
}()
f()
return false
}
assert(func() { Must(f()) }, Panics)
}
func TestMust2(t *testing.T) {
assert := With(t)
f := func() (interface{}, error) {
return nil, errors.New("test error")
testCases := []struct {
Input func()
Panic bool
}{
{
Panic: true,
Input: func() { Must(func() error { return errors.New("test error") }()) },
},
{
Panic: true,
Input: func() { Must2(func() (int, error) { return 0, errors.New("test error") }()) },
},
{
Panic: false,
Input: func() { Must(func() error { return nil }()) },
},
}
assert(func() { Must2(f()) }, Panics)
for idx, test := range testCases {
if hasPanic(test.Input) != test.Panic {
t.Error("test case #", idx, " expect panic ", test.Panic, " but actually not")
}
}
}