Skip to content

Commit 54705af

Browse files
authored
Merge pull request #3 from minoritea/ci
add CI testing
2 parents 924a8f9 + af159f5 commit 54705af

File tree

5 files changed

+86
-1
lines changed

5 files changed

+86
-1
lines changed

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: main
6+
pull_request:
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/setup-go@v2
12+
- uses: actions/checkout@v2
13+
- run: |
14+
go version
15+
go mod download
16+
go test

parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func GetPackages(out string) Packages {
104104
sort.Slice(packages, func(i, j int) bool {
105105
cmp := len(packages[i].Tests) - len(packages[j].Tests)
106106
if cmp != 0 {
107-
return cmp < 0
107+
return cmp > 0
108108
}
109109
return strings.Compare(packages[i].Name, packages[j].Name) < 0
110110
})

run_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package splittestgen_test
2+
3+
import (
4+
"fmt"
5+
"os/exec"
6+
"strings"
7+
"testing"
8+
)
9+
10+
func TestRun(t *testing.T) {
11+
const total = 3
12+
for _, c := range []struct {
13+
index int
14+
expected string
15+
}{
16+
{
17+
index: 0,
18+
expected: "go test github.com/minoritea/go-splittestgen/testdata/group1 -run '^(?:Test1|Test2)$'",
19+
},
20+
{
21+
index: 1,
22+
expected: "go test github.com/minoritea/go-splittestgen/testdata/group1 -run '^(?:Test3|Test4)$'",
23+
},
24+
{
25+
index: 2,
26+
expected: "go test github.com/minoritea/go-splittestgen/testdata/group2 -run '^(?:TestCases)$'",
27+
},
28+
} {
29+
index, expected := c.index, c.expected
30+
t.Run(fmt.Sprintf("case-of-index-%d", index), func(t *testing.T) {
31+
t.Parallel()
32+
output, err := exec.Command(
33+
"sh", "-c", fmt.Sprintf(` \
34+
(cd testdata && go test ./... -list .) | \
35+
go run ./cmd/go-splittestgen -index %d -total %d \
36+
`, index, total),
37+
).CombinedOutput()
38+
39+
if err != nil {
40+
t.Fatal(err)
41+
}
42+
43+
if strings.TrimSpace(string(output)) != expected {
44+
t.Log("The actual output is\n", string(output))
45+
t.Log("The expected output is\n", expected)
46+
t.Fatal("The command output is not equal to the expected value")
47+
}
48+
})
49+
}
50+
}

testdata/group1/group1_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package group1_test
2+
3+
import "testing"
4+
5+
func Test1(t *testing.T) { t.Log("OK") }
6+
func Test2(t *testing.T) { t.Log("Also OK") }
7+
func Test3(t *testing.T) { t.Log("Also OK") }
8+
func Test4(t *testing.T) { t.Log("Also OK") }

testdata/group2/group2_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package group2_test
2+
3+
import "testing"
4+
5+
func TestMain(m *testing.M) { m.Run() }
6+
func TestCases(t *testing.T) {
7+
cases := []string{"A", "B"}
8+
for _, name := range cases {
9+
t.Run("case-"+name, func(t *testing.T) { t.Logf("Case %s is OK", name) })
10+
}
11+
}

0 commit comments

Comments
 (0)