| 1 | package mapatest |
| 2 | |
| 3 | import ( |
| 4 | "go/parser" |
| 5 | "go/token" |
| 6 | "io/fs" |
| 7 | "path/filepath" |
| 8 | "strconv" |
| 9 | "strings" |
| 10 | "testing" |
| 11 | ) |
| 12 | |
| 13 | // frozenRastrillo is rastrillo's path before it moved. Nothing after |
| 14 | // v0.23.0 was released under it, so code importing it gets no fix, and |
| 15 | // its own checks cannot tell (Fichas zoomed iOS on every tap that way). |
| 16 | const frozenRastrillo = "github.com/carlosframework/rastrillo" |
| 17 | |
| 18 | func TestNoFrozenRastrilloImport(t *testing.T) { |
| 19 | root, _ := filepath.Abs(filepath.Join("..", "..")) |
| 20 | files := token.NewFileSet() |
| 21 | checked := 0 |
| 22 | err := filepath.WalkDir(root, func(path string, entry fs.DirEntry, |
| 23 | err error) error { |
| 24 | if err != nil || entry.IsDir() || !strings.HasSuffix(path, ".go") { |
| 25 | return err |
| 26 | } |
| 27 | parsed, err := parser.ParseFile(files, path, nil, |
| 28 | parser.ImportsOnly) |
| 29 | if err != nil { |
| 30 | return err |
| 31 | } |
| 32 | checked++ |
| 33 | for _, spec := range parsed.Imports { |
| 34 | imported, _ := strconv.Unquote(spec.Path.Value) |
| 35 | if strings.HasPrefix(imported, frozenRastrillo) { |
| 36 | t.Errorf("%s imports the frozen %s", path, imported) |
| 37 | } |
| 38 | } |
| 39 | return nil |
| 40 | }) |
| 41 | if err != nil || checked == 0 { |
| 42 | t.Fatalf("walked %d files: %v", checked, err) |
| 43 | } |
| 44 | } |
| 45 | |