tstCheckScriptError ensures the type of the two passed errors are of the same type (either both nil or both of type Error) and their error codes match when not nil.
(gotErr, wantErr error)
| 16 | // same type (either both nil or both of type Error) and their error codes |
| 17 | // match when not nil. |
| 18 | func tstCheckScriptError(gotErr, wantErr error) error { |
| 19 | // Ensure the error code is of the expected type and the error |
| 20 | // code matches the value specified in the test instance. |
| 21 | if reflect.TypeOf(gotErr) != reflect.TypeOf(wantErr) { |
| 22 | return fmt.Errorf("wrong error - got %T (%[1]v), want %T", |
| 23 | gotErr, wantErr) |
| 24 | } |
| 25 | if gotErr == nil { |
| 26 | return nil |
| 27 | } |
| 28 | |
| 29 | // Ensure the want error type is a script error. |
| 30 | werr, ok := wantErr.(Error) |
| 31 | if !ok { |
| 32 | return fmt.Errorf("unexpected test error type %T", wantErr) |
| 33 | } |
| 34 | |
| 35 | // Ensure the error codes match. It's safe to use a raw type assert |
| 36 | // here since the code above already proved they are the same type and |
| 37 | // the want error is a script error. |
| 38 | gotErrorCode := gotErr.(Error).ErrorCode |
| 39 | if gotErrorCode != werr.ErrorCode { |
| 40 | return fmt.Errorf("mismatched error code - got %v (%v), want %v", |
| 41 | gotErrorCode, gotErr, werr.ErrorCode) |
| 42 | } |
| 43 | |
| 44 | return nil |
| 45 | } |
| 46 | |
| 47 | // TestStack tests that all of the stack operations work as expected. |
| 48 | func TestStack(t *testing.T) { |
no outgoing calls
no test coverage detected
searching dependent graphs…