Skip to content

Commit 3b6e67f

Browse files
authored
gopy: fix tests to work with go modules
1 parent 6fbd665 commit 3b6e67f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

main_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,19 @@ func testPkg(t *testing.T, table pkg) {
805805
}
806806
}
807807

808+
func writeGoMod(t *testing.T, pkgDir, tstDir string) {
809+
template := `
810+
module dummy
811+
812+
require github.com/go-python/gopy v0.0.0
813+
replace github.com/go-python/gopy => %s
814+
`
815+
contents := fmt.Sprintf(template, pkgDir)
816+
if err := ioutil.WriteFile(filepath.Join(tstDir, "go.mod"), []byte(contents), 0666); err != nil {
817+
t.Fatalf("failed to write go.mod file: %v", err)
818+
}
819+
}
820+
808821
func testPkgBackend(t *testing.T, pyvm string, table pkg) {
809822
curPkgPath := reflect.TypeOf(table).PkgPath()
810823
_, pkgNm := filepath.Split(table.path)
@@ -821,6 +834,8 @@ func testPkgBackend(t *testing.T, pyvm string, table pkg) {
821834
defer os.RemoveAll(workdir)
822835
defer bind.ResetPackages()
823836

837+
writeGoMod(t, cwd, workdir)
838+
824839
// fmt.Printf("building in work dir: %s\n", workdir)
825840
fpath := "./" + table.path
826841
if table.cmd != "build" { // non-build cases end up inside the working dir -- need a global import path

0 commit comments

Comments
 (0)