MCPcopy Create free account
hub / github.com/goadesign/goa / TestValidationErrorsIncludeLocation

Function TestValidationErrorsIncludeLocation

eval/error_location_test.go:18–42  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

16}
17
18func 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
44func TestValidationErrorsWithoutLocation(t *testing.T) {
45 var verr eval.ValidationErrors

Callers

nothing calls this directly

Calls 4

AddErrorMethod · 0.95
ErrorMethod · 0.95
itoaFunction · 0.85
relativeToWorkdirFunction · 0.70

Tested by

no test coverage detected