Skip to content

Commit

Permalink
Add test for build tags
Browse files Browse the repository at this point in the history
  • Loading branch information
nmiyake authored and coopernurse committed Jan 1, 2019
1 parent b41a7d8 commit 6bfc115
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions internal/errcheck/errcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,17 @@ package custom
`
)

testBuildTagsDir, err := ioutil.TempDir(".", "testbuildtags")
tmpGopath, err := ioutil.TempDir("", "testbuildtags")
if err != nil {
t.Fatalf("unable to create testbuildtags directory: %v", err)
}
defer os.RemoveAll(testBuildTagsDir)
testBuildTagsDir := path.Join(tmpGopath, "src", "github.com/testbuildtags")
if err := os.MkdirAll(testBuildTagsDir, 0755); err != nil {
t.Fatalf("MkdirAll failed: %v", err)
}
defer func() {
os.RemoveAll(tmpGopath)
}()

if err := ioutil.WriteFile(path.Join(testBuildTagsDir, "custom1.go"), []byte(testBuildCustom1Tag), 0644); err != nil {
t.Fatalf("Failed to write testbuildtags custom1: %v", err)
Expand Down Expand Up @@ -161,7 +167,14 @@ package custom
for i, currCase := range cases {
checker := NewChecker()
checker.Tags = currCase.tags
err := checker.CheckPackages(path.Join("github.com/kisielk/errcheck/internal/errcheck", testBuildTagsDir))

loadPackages = func(cfg *packages.Config, paths ...string) ([]*packages.Package, error) {
cfg.Env = append(os.Environ(), "GOPATH="+tmpGopath)
cfg.Dir = testBuildTagsDir
pkgs, err := packages.Load(cfg, paths...)
return pkgs, err
}
err := checker.CheckPackages("github.com/testbuildtags")

if currCase.numExpectedErrs == 0 {
if err != nil {
Expand Down

0 comments on commit 6bfc115

Please sign in to comment.