aboutsummaryrefslogtreecommitdiffhomepage
path: root/errors_test.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-07-09 18:08:51 +0200
committerAyke <[email protected]>2024-07-13 13:26:26 +0200
commitd7773d3e86e82a64c79a04fa70f740daf333a3be (patch)
tree99361d45c7872f8da2d2c2e6fea55090942a9570 /errors_test.go
parentb04b690842f837aedc6d8187bb4a4200b0cc6acc (diff)
downloadtinygo-d7773d3e86e82a64c79a04fa70f740daf333a3be.tar.gz
tinygo-d7773d3e86e82a64c79a04fa70f740daf333a3be.zip
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.
Diffstat (limited to 'errors_test.go')
-rw-r--r--errors_test.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/errors_test.go b/errors_test.go
index 69c29148d..1ee9a0e18 100644
--- a/errors_test.go
+++ b/errors_test.go
@@ -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)