From 3b6e67ffd298eb64b680d640b0ac6839e2a52cac Mon Sep 17 00:00:00 2001 From: Cosmos Nicolaou Date: Thu, 13 Feb 2020 04:56:10 -0800 Subject: [PATCH] gopy: fix tests to work with go modules --- main_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main_test.go b/main_test.go index a71d8fd..7e93e5a 100644 --- a/main_test.go +++ b/main_test.go @@ -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