gopy: fix tests to work with go modules

This commit is contained in:
Cosmos Nicolaou 2020-02-13 04:56:10 -08:00 committed by GitHub
parent 6fbd665bfb
commit 3b6e67ffd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -805,6 +805,19 @@ func testPkg(t *testing.T, table pkg) {
}
}
func writeGoMod(t *testing.T, pkgDir, tstDir string) {
template := `
module dummy
require github.com/go-python/gopy v0.0.0
replace github.com/go-python/gopy => %s
`
contents := fmt.Sprintf(template, pkgDir)
if err := ioutil.WriteFile(filepath.Join(tstDir, "go.mod"), []byte(contents), 0666); err != nil {
t.Fatalf("failed to write go.mod file: %v", err)
}
}
func testPkgBackend(t *testing.T, pyvm string, table pkg) {
curPkgPath := reflect.TypeOf(table).PkgPath()
_, pkgNm := filepath.Split(table.path)
@ -821,6 +834,8 @@ func testPkgBackend(t *testing.T, pyvm string, table pkg) {
defer os.RemoveAll(workdir)
defer bind.ResetPackages()
writeGoMod(t, cwd, workdir)
// fmt.Printf("building in work dir: %s\n", workdir)
fpath := "./" + table.path
if table.cmd != "build" { // non-build cases end up inside the working dir -- need a global import path