github.com/replit/upm@v0.0.0-20240423230255-9ce4fc3ea24c/test-suite/Guess_test.go (about) 1 package testSuite 2 3 import ( 4 "io" 5 "strings" 6 "testing" 7 8 "github.com/replit/upm/test-suite/templates" 9 testUtils "github.com/replit/upm/test-suite/utils" 10 ) 11 12 func TestGuess(t *testing.T) { 13 for _, bt := range languageBackends { 14 bt.Start(t) 15 16 tests := make(map[string]map[string][]string) 17 switch bt.Backend.Name { 18 case "nodejs-npm": 19 fallthrough 20 case "nodejs-pnpm": 21 fallthrough 22 case "nodejs-yarn": 23 fallthrough 24 case "bun": 25 for _, ext := range []string{"js", "jsx", "ts", "tsx"} { 26 _, ok := tests[ext] 27 if !ok { 28 tests[ext] = make(map[string][]string) 29 } 30 31 tests[ext]["js"] = []string{ 32 "basic", 33 "dedup", 34 "nested", 35 "esparse-fail", 36 "require", 37 } 38 } 39 40 for _, ext := range []string{"ts", "tsx"} { 41 tests[ext]["ts"] = []string{ 42 "typeImports", 43 } 44 } 45 46 case "python3-poetry", "python3-pip": 47 for _, ext := range []string{"py"} { 48 _, ok := tests[ext] 49 if !ok { 50 tests[ext] = make(map[string][]string) 51 } 52 53 tests[ext]["py"] = []string{ 54 "basic", 55 "dedup", 56 "replit-packages", 57 } 58 } 59 60 default: 61 t.Run(bt.Backend.Name, func(t *testing.T) { 62 t.Skip("no test") 63 }) 64 continue 65 } 66 67 for ext, guessSuites := range tests { 68 bt.Subtest(ext, func(bt testUtils.BackendT) { 69 for template, tests := range guessSuites { 70 bt.Subtest(template, func(bt testUtils.BackendT) { 71 for _, test := range tests { 72 testSrcFile := "guess/" + template + "/" + test 73 74 bt.Subtest(test, func(bt testUtils.BackendT) { 75 bt.AddTestFile(testSrcFile, test+"."+ext) 76 bt.AddTestFile(bt.Backend.Name+"/no-deps/"+bt.Backend.Specfile, bt.Backend.Specfile) 77 78 expectFile, err := templates.FS.Open(testSrcFile + ".expect") 79 if err != nil { 80 bt.Fail("No expect file found for %s: %v", testSrcFile, err) 81 } 82 83 var expectsText strings.Builder 84 _, err = io.Copy(&expectsText, expectFile) 85 if err != nil { 86 bt.Fail("Failed to read expect file for %s: %v", testSrcFile, err) 87 } 88 89 expects := strings.Split(strings.TrimSpace(expectsText.String()), "\n") 90 91 bt.UpmGuess(expects...) 92 }) 93 } 94 }) 95 } 96 }) 97 } 98 } 99 }