Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: listing tests with tags #20

Merged
merged 2 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gotesplit.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ Options:
}

func getTestListsFromPkgs(pkgs []string, tags string) ([]testList, error) {
args := []string{"test", "-list"}
args := []string{"test", "-list", "."}
if tags != "" {
args = append(args, tags)
}
args = append(append(args, "."), pkgs...)
args = append(args, pkgs...)
buf := &bytes.Buffer{}
c := exec.Command("go", args...)
c.Stdout = buf
Expand Down
25 changes: 25 additions & 0 deletions gotesplit_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gotesplit

import (
"os"
"reflect"
"testing"
)
Expand Down Expand Up @@ -123,3 +124,27 @@ func TestDetectTags(t *testing.T) {
})
}
}

func TestGetTestListFromPkgs(t *testing.T) {
if err := os.Chdir("testdata/withtags"); err != nil {
wd, _ := os.Getwd()
t.Fatalf("unexpected error: %v, cwd: %s", err, wd)
}

expect := []testList{{
pkg: "github.com/Songmu/gotesplit/testdata/withtags",
list: []string{
"TestNoTag",
"TestTagA",
},
}}

got, err := getTestListsFromPkgs([]string{"."}, "-tags=a")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

if !reflect.DeepEqual(expect, got) {
t.Errorf("expect: %#v\ngot: %#v", expect, got)
}
}
3 changes: 3 additions & 0 deletions testdata/withtags/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/Songmu/gotesplit/testdata/withtags

go 1.18
5 changes: 5 additions & 0 deletions testdata/withtags/notag_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package withtags

import "testing"

func TestNoTag(t *testing.T) {}
7 changes: 7 additions & 0 deletions testdata/withtags/tag_a_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build a

package withtags

import "testing"

func TestTagA(t *testing.T) {}