mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-07-26 06:38:42 +00:00
loader: handle go list errors inside TinyGo
Instead of exiting with an error, handle these errors internally. This will enable a few improvements in the future.
This commit is contained in:
+17
-1
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -16,6 +17,10 @@ import (
|
||||
func TestErrors(t *testing.T) {
|
||||
for _, name := range []string{
|
||||
"cgo",
|
||||
"loader-importcycle",
|
||||
"loader-invaliddep",
|
||||
"loader-invalidpackage",
|
||||
"loader-nopackage",
|
||||
"syntax",
|
||||
"types",
|
||||
} {
|
||||
@@ -57,11 +62,22 @@ func testErrorMessages(t *testing.T, filename string) {
|
||||
actual := strings.TrimRight(buf.String(), "\n")
|
||||
|
||||
// Check whether the error is as expected.
|
||||
if actual != expected {
|
||||
if canonicalizeErrors(actual) != canonicalizeErrors(expected) {
|
||||
t.Errorf("expected error:\n%s\ngot:\n%s", indentText(expected, "> "), indentText(actual, "> "))
|
||||
}
|
||||
}
|
||||
|
||||
func canonicalizeErrors(text string) string {
|
||||
// Fix for Windows: replace all backslashes with forward slashes so that
|
||||
// paths will be the same as on POSIX systems.
|
||||
// (It may also change some other backslashes, but since this is only for
|
||||
// comparing text it should be fine).
|
||||
if runtime.GOOS == "windows" {
|
||||
text = strings.ReplaceAll(text, "\\", "/")
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
// Indent the given text with a given indentation string.
|
||||
func indentText(text, indent string) string {
|
||||
return indent + strings.ReplaceAll(text, "\n", "\n"+indent)
|
||||
|
||||
Reference in New Issue
Block a user