diagnostics: move diagnostic printing to a new package

This is a refactor, which should (in theory) not change the behavior of
the compiler. But since this is a pretty large change, there is a chance
there will be some regressions. For that reason, the previous commits
added a bunch of tests to make sure most error messages will not be
changed due to this refactor.
This commit is contained in:
Ayke van Laethem
2024-07-12 18:28:53 +02:00
committed by Ron Evans
parent 3788b31ba5
commit 80269b98ba
4 changed files with 207 additions and 98 deletions
+2 -4
View File
@@ -2,7 +2,6 @@ package main
import (
"bytes"
"fmt"
"os"
"path/filepath"
"regexp"
@@ -11,6 +10,7 @@ import (
"time"
"github.com/tinygo-org/tinygo/compileopts"
"github.com/tinygo-org/tinygo/diagnostics"
)
// Test the error messages of the TinyGo compiler.
@@ -59,9 +59,7 @@ func testErrorMessages(t *testing.T, filename string) {
// Write error message out as plain text.
var buf bytes.Buffer
printCompilerError(err, func(v ...interface{}) {
fmt.Fprintln(&buf, v...)
}, wd)
diagnostics.CreateDiagnostics(err).WriteTo(&buf, wd)
actual := strings.TrimRight(buf.String(), "\n")
// Check whether the error is as expected.