(t *testing.T)
| 16 | } |
| 17 | |
| 18 | func TestValidationErrorsIncludeLocation(t *testing.T) { |
| 19 | var verr eval.ValidationErrors |
| 20 | |
| 21 | _, file, _, ok := runtime.Caller(0) |
| 22 | if !ok { |
| 23 | t.Fatal("runtime.Caller failed") |
| 24 | } |
| 25 | dsl := func() {} |
| 26 | |
| 27 | pc := reflect.ValueOf(dsl).Pointer() |
| 28 | fn := runtime.FuncForPC(pc) |
| 29 | if fn == nil { |
| 30 | t.Fatal("runtime.FuncForPC returned nil") |
| 31 | } |
| 32 | _, expectedLine := fn.FileLine(pc) |
| 33 | expectedFile := relativeToWorkdir(t, file) |
| 34 | |
| 35 | expr := &testExpr{name: "expr", dsl: dsl} |
| 36 | verr.AddError(expr, errors.New("bad")) |
| 37 | |
| 38 | expected := "[" + expectedFile + ":" + itoa(expectedLine) + "] expr: bad" |
| 39 | if got := verr.Error(); got != expected { |
| 40 | t.Fatalf("unexpected error message:\n got: %q\nwant: %q", got, expected) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | func TestValidationErrorsWithoutLocation(t *testing.T) { |
| 45 | var verr eval.ValidationErrors |
nothing calls this directly
no test coverage detected