Skip to content

Commit

Permalink
fix: use go/build to check build tags for or_e2e (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
vk-outreach authored Jul 30, 2021
1 parent 2717e90 commit 7dbe428
Showing 1 changed file with 6 additions and 31 deletions.
37 changes: 6 additions & 31 deletions e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package main

import (
"context"
"go/ast"
"go/parser"
"go/token"
"go/build"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -222,38 +220,15 @@ func main() {
return nil
}

f, err := os.Open(path)
pkg, err := build.Default.Import(path, filepath.Base(path), build.ImportComment)
if err != nil {
return errors.Wrap(err, "open file")
return errors.Wrap(err, "import")
}
defer f.Close()

fset := token.NewFileSet()

root, err := parser.ParseFile(fset, filepath.Base(path), f, parser.ParseComments)
if err != nil {
return errors.Wrap(err, "parse file")
for _, tag := range pkg.AllTags {
runEndToEndTests = runEndToEndTests || tag == "or_e2e"
}

ast.Inspect(root, func(n ast.Node) bool {
if runEndToEndTests {
// No need to keep traversing.
return false
}

if c, ok := n.(*ast.Comment); ok {
text := strings.TrimSpace(strings.TrimPrefix(c.Text, "//"))
if strings.HasPrefix(text, "+build") && strings.Contains(text, "or_e2e") {
runEndToEndTests = true

// Stop descending into this node.
return false
}
}

return true
})


return nil
})

Expand Down

0 comments on commit 7dbe428

Please sign in to comment.