MCPcopy Create free account
hub / github.com/github/gh-aw / TestIsFormattedCompilerError

Function TestIsFormattedCompilerError

pkg/workflow/compiler_error_formatter_test.go:16–77  ·  view source on GitHub ↗

TestIsFormattedCompilerError verifies that the helper correctly identifies errors produced by formatCompilerError / formatCompilerErrorWithPosition and returns false for other error types.

(t *testing.T)

Source from the content-addressed store, hash-verified

14// errors produced by formatCompilerError / formatCompilerErrorWithPosition and
15// returns false for other error types.
16func TestIsFormattedCompilerError(t *testing.T) {
17 tests := []struct {
18 name string
19 err error
20 expected bool
21 }{
22 {
23 name: "error from formatCompilerError with nil cause",
24 err: formatCompilerError("file.md", "error", "something went wrong", nil),
25 expected: true,
26 },
27 {
28 name: "error from formatCompilerError with non-nil cause",
29 err: formatCompilerError("file.md", "error", "something went wrong", errors.New("root cause")),
30 expected: true,
31 },
32 {
33 name: "error from formatCompilerErrorWithPosition",
34 err: formatCompilerErrorWithPosition("file.md", 5, 3, "error", "bad value", nil),
35 expected: true,
36 },
37 {
38 name: "error from parser.FormatImportError is detected as formatted",
39 err: parser.FormatImportError(&parser.ImportError{
40 ImportPath: "missing.md",
41 FilePath: "workflow.md",
42 Line: 10,
43 Column: 5,
44 Cause: errors.New("file not found: missing.md"),
45 }, "imports:\n - missing.md"),
46 expected: true,
47 },
48 {
49 name: "error from parser.NewFormattedParserError is detected as formatted",
50 err: parser.NewFormattedParserError("workflow.md:5:3: error: bad value"),
51 expected: true,
52 },
53 {
54 name: "plain error is not formatted",
55 err: errors.New("plain error"),
56 expected: false,
57 },
58 {
59 name: "fmt.Errorf error is not formatted",
60 err: errors.New("wrapped: plain error"),
61 expected: false,
62 },
63 {
64 name: "nil error",
65 err: nil,
66 expected: false,
67 },
68 }
69
70 for _, tt := range tests {
71 t.Run(tt.name, func(t *testing.T) {
72 got := isFormattedCompilerError(tt.err)
73 assert.Equal(t, tt.expected, got,

Callers

nothing calls this directly

Calls 6

FormatImportErrorFunction · 0.92
NewFormattedParserErrorFunction · 0.92
formatCompilerErrorFunction · 0.85
isFormattedCompilerErrorFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected