github.com/grailbio/bigslice@v0.0.0-20230519005545-30c4c12152ad/typecheck/error_test.go (about) 1 // Copyright 2018 GRAIL, Inc. All rights reserved. 2 // Use of this source code is governed by the Apache 2.0 3 // license that can be found in the LICENSE file. 4 5 package typecheck 6 7 import ( 8 "errors" 9 "runtime" 10 "testing" 11 ) 12 13 func errorCaller(calldepth int, err error) (e *Error, file string, line int) { 14 _, file, line, ok := runtime.Caller(calldepth + 1) 15 if !ok { 16 panic("not ok") 17 } 18 return NewError(calldepth+1, err), file, line 19 } 20 21 func TestError(t *testing.T) { 22 e := errors.New("hello world") 23 err, file, line := errorCaller(1, e) 24 if got, want := err.Err, e; got != want { 25 t.Errorf("got %v, want %v", got, want) 26 } 27 if got, want := file, err.File; got != want { 28 t.Errorf("got %v, want %v", got, want) 29 } 30 if got, want := line, err.Line; got != want { 31 t.Errorf("got %v, want %b", got, want) 32 } 33 }