Skip to content

Commit

Permalink
Add support for passing in Go Build Tags to generated feature go files.
Browse files Browse the repository at this point in the history
Adds support to the build and runner to pass along go build tags to the
go run command. This allows Go build tags to be triggered. Such as
`testing` build tags used for filtering in a Go project.
  • Loading branch information
jasdel committed Jun 27, 2016
1 parent 5692705 commit ae56594
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 21 additions & 1 deletion builder.go 100755 → 100644
Expand Up @@ -15,7 +15,22 @@ const (
testFile = "gucumbertest__.go"
)

// BuildAndRunDir builds the given director's features into Go Code.
// Using the filters provided. An error is returned if the build fails.
func BuildAndRunDir(dir string, filters []string) error {
return buildAndRunDir(dir, filters, "")
}

// BuildAndRunDirWithGoBuildTags builds the given director's features into Go
// Code using the filters provided. Also takes a string for the build tags to
// be passed to the go command. An error is returned if the build fails.
//
// If goBuildTags is empty, the param will be ignored.
func BuildAndRunDirWithGoBuildTags(dir string, filters []string, goBuildTags string) error {
return buildAndRunDir(dir, filters, goBuildTags)
}

func buildAndRunDir(dir string, filters []string, goBuildTags string) error {
defer buildCleanup(dir)

info := buildInfo{
Expand Down Expand Up @@ -63,7 +78,12 @@ func BuildAndRunDir(dir string, filters []string) error {

// now run the command
tfile := "./" + filepath.ToSlash(dir) + "/_test/" + testFile
cmd := exec.Command("go", "run", tfile)
var cmd *exec.Cmd
if len(goBuildTags) > 0 {
cmd = exec.Command("go", "run", "-tags", goBuildTags, tfile)
} else {
cmd = exec.Command("go", "run", tfile)
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
Expand Down
4 changes: 3 additions & 1 deletion run_main.go 100755 → 100644
Expand Up @@ -17,9 +17,11 @@ func (f *filters) Set(value string) error {
}

var filterFlag filters
var goBuildTags string

func init() {
flag.Var(&filterFlag, "tags", "comma-separated list of tags to filter scenarios by")
flag.StringVar(&goBuildTags, "go-tags", "", "space seperated list of tags, wrap in quotes to specify multiple tags")
}

func RunMain() {
Expand All @@ -36,7 +38,7 @@ func RunMain() {
for _, f := range filterFlag {
filt = append(filt, string(f))
}
if err := BuildAndRunDir(dir, filt); err != nil {
if err := BuildAndRunDirWithGoBuildTags(dir, filt, goBuildTags); err != nil {
panic(err)
}
}

0 comments on commit ae56594

Please sign in to comment.