MCPcopy Index your code
hub / github.com/tinygo-org/tinygo / testErrorMessages

Function testErrorMessages

errors_test.go:60–92  ·  view source on GitHub ↗
(t *testing.T, filename string, options *compileopts.Options)

Source from the content-addressed store, hash-verified

58}
59
60func testErrorMessages(t *testing.T, filename string, options *compileopts.Options) {
61 t.Parallel()
62
63 // Parse expected error messages.
64 expected := readErrorMessages(t, filename)
65
66 // Try to build a binary (this should fail with an error).
67 tmpdir := t.TempDir()
68 config, err := builder.NewConfig(options)
69 if err != nil {
70 t.Fatal("expected to get a compiler error")
71 }
72 err = Build(filename, tmpdir+"/out", config)
73 if err == nil {
74 t.Fatal("expected to get a compiler error")
75 }
76
77 // Get the full ./testdata/errors directory.
78 wd, absErr := filepath.Abs("testdata/errors")
79 if absErr != nil {
80 t.Fatal(absErr)
81 }
82
83 // Write error message out as plain text.
84 var buf bytes.Buffer
85 diagnostics.CreateDiagnostics(err).WriteTo(&buf, wd)
86 actual := strings.TrimRight(buf.String(), "\n")
87
88 // Check whether the error is as expected.
89 if !matchErrors(t, expected, actual) {
90 t.Errorf("expected error:\n%s\ngot:\n%s", indentText(expected, "> "), indentText(actual, "> "))
91 }
92}
93
94func matchErrors(t *testing.T, pattern, actual string) bool {
95 patternLines := strings.Split(pattern, "\n")

Callers 1

TestErrorsFunction · 0.85

Calls 12

NewConfigFunction · 0.92
CreateDiagnosticsFunction · 0.92
readErrorMessagesFunction · 0.85
matchErrorsFunction · 0.85
indentTextFunction · 0.85
ParallelMethod · 0.80
BuildFunction · 0.70
TempDirMethod · 0.65
FatalMethod · 0.65
StringMethod · 0.65
ErrorfMethod · 0.65
WriteToMethod · 0.45

Tested by

no test coverage detected