- commit
- 8569c7aa4cd8b5535345008750d4546ff8a7b56c
- parent
- 0cd4b9f10e38776349e0a67c80e089eeff8b0b7e
- author
- Dami <dami.etoile@gmail.com>
| M | architecture_test.go | 22 | +++++++++++++++++----- |
| M | registry/ | 23 | ++++++++++++++++++----- |
@@ -5,7 +5,6 @@ import (
55 "go/token"66 "os"77 "path/filepath"8- "runtime"98 "slices"109 "strings"1110 "testing"@@ -119,11 +118,24 @@ func concreteGameImportPaths(t testing.TB) []string {
119118 func repoRoot(t testing.TB) string {120119 t.Helper()121120 122- _, path, _, ok := runtime.Caller(0)123- if !ok {124- t.Fatal("runtime.Caller failed")121+ wd, err := os.Getwd()122+ if err != nil {123+ t.Fatalf("get working directory: %v", err)124+ }125+126+ for dir := filepath.Clean(wd); ; dir = filepath.Dir(dir) {127+ path := filepath.Join(dir, "go.mod")128+ if _, err := os.Stat(path); err == nil {129+ return dir130+ } else if !os.IsNotExist(err) {131+ t.Fatalf("stat %s: %v", path, err)132+ }133+134+ parent := filepath.Dir(dir)135+ if parent == dir {136+ t.Fatalf("find repo root from %s: go.mod not found", wd)137+ }125138 }126- return filepath.Clean(filepath.Dir(path))127139 }128140 129141 func assertFileDoesNotContain(t *testing.T, path string, forbidden []string) {@@ -4,9 +4,9 @@ import (
44 "go/ast"55 "go/parser"66 "go/token"7+ "os"78 "path/filepath"89 "reflect"9- "runtime"1010 "slices"1111 "strings"1212 "testing"@@ -207,9 +207,22 @@ func concreteGameImportPaths(t testing.TB) []string {
207207 func repoRoot(t testing.TB) string {208208 t.Helper()209209 210- _, path, _, ok := runtime.Caller(0)211- if !ok {212- t.Fatal("runtime.Caller failed")210+ wd, err := os.Getwd()211+ if err != nil {212+ t.Fatalf("get working directory: %v", err)213+ }214+215+ for dir := filepath.Clean(wd); ; dir = filepath.Dir(dir) {216+ path := filepath.Join(dir, "go.mod")217+ if _, err := os.Stat(path); err == nil {218+ return dir219+ } else if !os.IsNotExist(err) {220+ t.Fatalf("stat %s: %v", path, err)221+ }222+223+ parent := filepath.Dir(dir)224+ if parent == dir {225+ t.Fatalf("find repo root from %s: go.mod not found", wd)226+ }213227 }214- return filepath.Clean(filepath.Join(filepath.Dir(path), ".."))215228 }