Skip to content

Commit

Permalink
apidiff: fix tests in module mode
Browse files Browse the repository at this point in the history
Updates golang/go#30228

Change-Id: If138faaa001f557f82eb9d25812a0a89155f639d
Reviewed-on: https://go-review.googlesource.com/c/exp/+/167217
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
  • Loading branch information
Bryan C. Mills committed Mar 12, 2019
1 parent a1d7652 commit 41a7a02
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions apidiff/apidiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ func TestChanges(t *testing.T) {
sort.Strings(wanti)
sort.Strings(wantc)

oldpkg, err := load("old", dir)
oldpkg, err := load("apidiff/old", dir)
if err != nil {
t.Fatal(err)
}
newpkg, err := load("new", dir)
newpkg, err := load("apidiff/new", dir)
if err != nil {
t.Fatal(err)
}
Expand All @@ -56,8 +56,15 @@ func splitIntoPackages(t *testing.T, dir string) (incompatibles, compatibles []s
}
defer f.Close()

oldd := filepath.Join(dir, "src/old")
newd := filepath.Join(dir, "src/new")
if err := os.MkdirAll(filepath.Join(dir, "src", "apidiff"), 0700); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(filepath.Join(dir, "src", "apidiff", "go.mod"), []byte("module apidiff\n"), 0666); err != nil {
t.Fatal(err)
}

oldd := filepath.Join(dir, "src/apidiff/old")
newd := filepath.Join(dir, "src/apidiff/new")
if err := os.MkdirAll(oldd, 0700); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -112,6 +119,7 @@ func load(importPath, goPath string) (*packages.Package, error) {
}
if goPath != "" {
cfg.Env = append(os.Environ(), "GOPATH="+goPath)
cfg.Dir = filepath.Join(goPath, "src", filepath.FromSlash(importPath))
}
pkgs, err := packages.Load(cfg, importPath)
if err != nil {
Expand Down

0 comments on commit 41a7a02

Please sign in to comment.