github.com/searKing/golang/go@v1.2.74/error/exception/throwable_test.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package exception_test 6 7 import ( 8 "bytes" 9 "strings" 10 "testing" 11 12 "github.com/searKing/golang/go/error/exception" 13 ) 14 15 type ThrowableTests struct { 16 input exception.Throwable 17 output []string 18 } 19 20 var ( 21 throwableTests = []ThrowableTests{ 22 { 23 exception.NewThrowable(), 24 []string{"runtime/debug.Stack"}, 25 }, 26 { 27 exception.NewThrowable1("throwable exception"), 28 []string{"throwable exception"}, 29 }, 30 { 31 exception.NewThrowable2("throwable exception2", exception.NewThrowable1("throwable exception1")), 32 []string{"throwable exception1", "throwable exception2"}, 33 }, 34 } 35 ) 36 37 func TestThrowable(t *testing.T) { 38 for m, test := range throwableTests { 39 runs := bytes.Buffer{} 40 test.input.PrintStackTrace1(&runs) 41 output := runs.String() 42 for n, outputExpect := range test.output { 43 if !strings.Contains(runs.String(), output) { 44 t.Errorf("#%d[%d]: %v: got %s runs; expected %s", m, n, test.input, output, outputExpect) 45 continue 46 } 47 } 48 } 49 50 }