github.com/iotexproject/iotex-core@v1.14.1-rc1/pkg/recovery/recovery_test.go (about) 1 package recovery 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestCrashLog(t *testing.T) { 11 require := require.New(t) 12 heapdumpDir := t.TempDir() 13 require.NoError(SetCrashlogDir(heapdumpDir)) 14 15 t.Run("index out of range", func(t *testing.T) { 16 defer Recover() 17 strs := make([]string, 2) 18 strs[0] = "a" 19 strs[1] = "b" 20 strs[2] = "c" 21 }) 22 t.Run("invaled memory address or nil pointer", func(t *testing.T) { 23 defer Recover() 24 var i *int 25 *i = 1 26 }) 27 t.Run("divide by zero", func(t *testing.T) { 28 defer Recover() 29 a, b := 10, 0 30 a = a / b 31 }) 32 } 33 34 func TestPrintInfo(t *testing.T) { 35 printInfo("test", func() (interface{}, error) { 36 return nil, errors.New("make error") 37 }) 38 }