diff --git a/gitfame/test/integration/gitfame_test.go b/gitfame/test/integration/gitfame_test.go new file mode 100644 index 0000000..d77ca46 --- /dev/null +++ b/gitfame/test/integration/gitfame_test.go @@ -0,0 +1,107 @@ +package integration + +import ( + "io/ioutil" + "os" + "os/exec" + "path" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" + "gopkg.in/yaml.v2" + + "gitlab.com/slon/shad-go/tools/testtool" +) + +const importPath = "gitlab.com/slon/shad-go/gitfame/cmd/gitfame" + +var binCache testtool.BinCache + +func TestMain(m *testing.M) { + os.Exit(func() int { + var teardown testtool.CloseFunc + binCache, teardown = testtool.NewBinCache() + defer teardown() + + return m.Run() + }()) +} + +func TestGitFame(t *testing.T) { + binary, err := binCache.GetBinary(importPath) + require.NoError(t, err) + + bundlesDir := path.Join("./testdata", "bundles") + testsDir := path.Join("./testdata", "good") + files, err := ioutil.ReadDir(testsDir) + require.NoError(t, err) + + for _, f := range files { + if !f.IsDir() { + continue + } + + tc := ReadTestCase(t, filepath.Join(testsDir, f.Name())) + + t.Run(f.Name()+"/"+tc.Name, func(t *testing.T) { + dir, err := ioutil.TempDir("", "gitfame-") + require.NoError(t, err) + defer func() { _ = os.RemoveAll(dir) }() + + args := []string{"--repository", dir} + args = append(args, tc.Args...) + + Unbundle(t, filepath.Join(bundlesDir, tc.Bundle), dir) + + cmd := exec.Command(binary, args...) + cmd.Stderr = ioutil.Discard + + output, err := cmd.Output() + require.NoError(t, err) + + require.Equal(t, string(tc.Expected), string(output)) + }) + } +} + +type TestCase struct { + *TestDescription + Expected []byte +} + +func ReadTestCase(t *testing.T, path string) *TestCase { + t.Helper() + + desc := ReadTestDescription(t, path) + + expected, err := ioutil.ReadFile(filepath.Join(path, "expected.out")) + require.NoError(t, err) + + return &TestCase{TestDescription: desc, Expected: expected} +} + +type TestDescription struct { + Name string `yaml:"name"` + Args []string `yaml:"args"` + Bundle string `yaml:"bundle"` +} + +func ReadTestDescription(t *testing.T, path string) *TestDescription { + t.Helper() + + data, err := ioutil.ReadFile(filepath.Join(path, "description.yaml")) + require.NoError(t, err) + + var desc TestDescription + require.NoError(t, yaml.Unmarshal(data, &desc)) + + return &desc +} + +func Unbundle(t *testing.T, src, dst string) { + t.Helper() + + cmd := exec.Command("git", "clone", src, dst) + require.NoError(t, cmd.Run()) +} diff --git a/gitfame/test/integration/testdata/bundles/breaker.bundle b/gitfame/test/integration/testdata/bundles/breaker.bundle new file mode 100644 index 0000000..f8cd749 Binary files /dev/null and b/gitfame/test/integration/testdata/bundles/breaker.bundle differ diff --git a/gitfame/test/integration/testdata/bundles/go-cmp.bundle b/gitfame/test/integration/testdata/bundles/go-cmp.bundle new file mode 100644 index 0000000..5ac735f Binary files /dev/null and b/gitfame/test/integration/testdata/bundles/go-cmp.bundle differ diff --git a/gitfame/test/integration/testdata/bundles/simple.bundle b/gitfame/test/integration/testdata/bundles/simple.bundle new file mode 100644 index 0000000..e793799 Binary files /dev/null and b/gitfame/test/integration/testdata/bundles/simple.bundle differ diff --git a/gitfame/test/integration/testdata/good/1/description.yaml b/gitfame/test/integration/testdata/good/1/description.yaml new file mode 100644 index 0000000..ecd8220 --- /dev/null +++ b/gitfame/test/integration/testdata/good/1/description.yaml @@ -0,0 +1,5 @@ +# Empty .md file, old revision + +name: empty file, old revision +args: [--format, csv, --revision, 49e9ed8b0c32adfa6b30ebe5d94d9d8811ba4d26] +bundle: simple.bundle diff --git a/gitfame/test/integration/testdata/good/1/expected.out b/gitfame/test/integration/testdata/good/1/expected.out new file mode 100644 index 0000000..2768efa --- /dev/null +++ b/gitfame/test/integration/testdata/good/1/expected.out @@ -0,0 +1,2 @@ +Name,Lines,Commits,Files +Russ Cox,0,1,1 diff --git a/gitfame/test/integration/testdata/good/10/description.yaml b/gitfame/test/integration/testdata/good/10/description.yaml new file mode 100644 index 0000000..5db90c7 --- /dev/null +++ b/gitfame/test/integration/testdata/good/10/description.yaml @@ -0,0 +1,5 @@ +# .md with space in name + +name: space in filename +args: [--format, csv, --revision, d5e9958063725c54e82b2e77427bd0dcbaf43fef] +bundle: breaker.bundle diff --git a/gitfame/test/integration/testdata/good/10/expected.out b/gitfame/test/integration/testdata/good/10/expected.out new file mode 100644 index 0000000..250a299 --- /dev/null +++ b/gitfame/test/integration/testdata/good/10/expected.out @@ -0,0 +1,2 @@ +Name,Lines,Commits,Files +Brad Fitzpatrick,4,1,1 diff --git a/gitfame/test/integration/testdata/good/11/description.yaml b/gitfame/test/integration/testdata/good/11/description.yaml new file mode 100644 index 0000000..7f877e9 --- /dev/null +++ b/gitfame/test/integration/testdata/good/11/description.yaml @@ -0,0 +1,5 @@ +# author with tabs in name + +name: tabs in author name +args: [--format, csv, --revision, 400683875aad1234a51d9fe6e8b6137556702ae6, --restrict-to, main.go] +bundle: breaker.bundle diff --git a/gitfame/test/integration/testdata/good/11/expected.out b/gitfame/test/integration/testdata/good/11/expected.out new file mode 100644 index 0000000..65b7f25 --- /dev/null +++ b/gitfame/test/integration/testdata/good/11/expected.out @@ -0,0 +1,2 @@ +Name,Lines,Commits,Files +My name is Tabby,7,1,1 diff --git a/gitfame/test/integration/testdata/good/12/description.yaml b/gitfame/test/integration/testdata/good/12/description.yaml new file mode 100644 index 0000000..3e8e8ae --- /dev/null +++ b/gitfame/test/integration/testdata/good/12/description.yaml @@ -0,0 +1,5 @@ +# author with tabs in name, empty file + +name: tabs in author name, empty file +args: [--format, csv, --revision, 17f8121d7a01af4dd79e2e9cba387f96edc64bd6, --restrict-to, empty.txt] +bundle: breaker.bundle diff --git a/gitfame/test/integration/testdata/good/12/expected.out b/gitfame/test/integration/testdata/good/12/expected.out new file mode 100644 index 0000000..9f3949e --- /dev/null +++ b/gitfame/test/integration/testdata/good/12/expected.out @@ -0,0 +1,2 @@ +Name,Lines,Commits,Files +My name is Tabby,0,1,1 diff --git a/gitfame/test/integration/testdata/good/13/description.yaml b/gitfame/test/integration/testdata/good/13/description.yaml new file mode 100644 index 0000000..454a7a2 --- /dev/null +++ b/gitfame/test/integration/testdata/good/13/description.yaml @@ -0,0 +1,5 @@ +# author with name consisting of printable characters, empty commit + +name: printable in author name, empty commit +args: [--format, csv, --revision, 861af9ed3975a7e247547331c2d1e029a8415da0] +bundle: breaker.bundle diff --git a/gitfame/test/integration/testdata/good/13/expected.out b/gitfame/test/integration/testdata/good/13/expected.out new file mode 100644 index 0000000..20f9446 --- /dev/null +++ b/gitfame/test/integration/testdata/good/13/expected.out @@ -0,0 +1,3 @@ +Name,Lines,Commits,Files +My name is Tabby,7,2,2 +Brad Fitzpatrick,4,1,1 diff --git a/gitfame/test/integration/testdata/good/14/description.yaml b/gitfame/test/integration/testdata/good/14/description.yaml new file mode 100644 index 0000000..2ed80ad --- /dev/null +++ b/gitfame/test/integration/testdata/good/14/description.yaml @@ -0,0 +1,5 @@ +# author with name consisting of printable characters, empty commit + +name: printable in author name, empty commit +args: [--format, csv, --revision, 68cc2ccd318dce0e86c86c0adc53a9d967e2192c] +bundle: breaker.bundle diff --git a/gitfame/test/integration/testdata/good/14/expected.out b/gitfame/test/integration/testdata/good/14/expected.out new file mode 100644 index 0000000..ff987af --- /dev/null +++ b/gitfame/test/integration/testdata/good/14/expected.out @@ -0,0 +1,4 @@ +Name,Lines,Commits,Files +My name is Tabby,7,2,2 +Brad Fitzpatrick,4,1,1 +"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUV WXYZ!""#$%&'()*+,-./:;=?@[\]^_`{|}~",0,1,1 diff --git a/gitfame/test/integration/testdata/good/15/description.yaml b/gitfame/test/integration/testdata/good/15/description.yaml new file mode 100644 index 0000000..9f8e1c6 --- /dev/null +++ b/gitfame/test/integration/testdata/good/15/description.yaml @@ -0,0 +1,5 @@ +# go-cmp, HEAD + +name: go-cmp HEAD +args: [--format, csv] +bundle: go-cmp.bundle diff --git a/gitfame/test/integration/testdata/good/15/expected.out b/gitfame/test/integration/testdata/good/15/expected.out new file mode 100644 index 0000000..d70d751 --- /dev/null +++ b/gitfame/test/integration/testdata/good/15/expected.out @@ -0,0 +1,17 @@ +Name,Lines,Commits,Files +Joe Tsai,13818,94,54 +colinnewell,130,1,1 +A. Ishikawa,92,1,2 +Roger Peppe,59,1,2 +Tobias Klauser,35,2,3 +178inaba,27,2,5 +Kyle Lemons,11,1,1 +Dmitri Shuralyov,8,1,2 +ferhat elmas,7,1,4 +Christian Muehlhaeuser,6,3,4 +k.nakada,5,1,3 +LMMilewski,5,1,2 +Ernest Galbrun,3,1,1 +Ross Light,2,1,1 +Chris Morrow,1,1,1 +Fiisio,1,1,1 diff --git a/gitfame/test/integration/testdata/good/16/description.yaml b/gitfame/test/integration/testdata/good/16/description.yaml new file mode 100644 index 0000000..cbf4f8c --- /dev/null +++ b/gitfame/test/integration/testdata/good/16/description.yaml @@ -0,0 +1,5 @@ +# go-cmp, HEAD, committer + +name: go-cmp HEAD committer +args: [--format, csv, --use-committer] +bundle: go-cmp.bundle diff --git a/gitfame/test/integration/testdata/good/16/expected.out b/gitfame/test/integration/testdata/good/16/expected.out new file mode 100644 index 0000000..276a7e2 --- /dev/null +++ b/gitfame/test/integration/testdata/good/16/expected.out @@ -0,0 +1,4 @@ +Name,Lines,Commits,Files +GitHub,11199,100,55 +Joe Tsai,3009,12,29 +Ross Light,2,1,1 diff --git a/gitfame/test/integration/testdata/good/17/description.yaml b/gitfame/test/integration/testdata/good/17/description.yaml new file mode 100644 index 0000000..72c713a --- /dev/null +++ b/gitfame/test/integration/testdata/good/17/description.yaml @@ -0,0 +1,5 @@ +# go-cmp, HEAD, order by commits + +name: go-cmp HEAD order-by commits +args: [--format, csv, --order-by, commits] +bundle: go-cmp.bundle diff --git a/gitfame/test/integration/testdata/good/17/expected.out b/gitfame/test/integration/testdata/good/17/expected.out new file mode 100644 index 0000000..3fbd626 --- /dev/null +++ b/gitfame/test/integration/testdata/good/17/expected.out @@ -0,0 +1,17 @@ +Name,Lines,Commits,Files +Joe Tsai,13818,94,54 +Christian Muehlhaeuser,6,3,4 +Tobias Klauser,35,2,3 +178inaba,27,2,5 +colinnewell,130,1,1 +A. Ishikawa,92,1,2 +Roger Peppe,59,1,2 +Kyle Lemons,11,1,1 +Dmitri Shuralyov,8,1,2 +ferhat elmas,7,1,4 +k.nakada,5,1,3 +LMMilewski,5,1,2 +Ernest Galbrun,3,1,1 +Ross Light,2,1,1 +Chris Morrow,1,1,1 +Fiisio,1,1,1 diff --git a/gitfame/test/integration/testdata/good/18/description.yaml b/gitfame/test/integration/testdata/good/18/description.yaml new file mode 100644 index 0000000..2515381 --- /dev/null +++ b/gitfame/test/integration/testdata/good/18/description.yaml @@ -0,0 +1,5 @@ +# go-cmp, HEAD, order by files + +name: go-cmp HEAD order-by files +args: [--format, csv, --order-by, files] +bundle: go-cmp.bundle diff --git a/gitfame/test/integration/testdata/good/18/expected.out b/gitfame/test/integration/testdata/good/18/expected.out new file mode 100644 index 0000000..af697f1 --- /dev/null +++ b/gitfame/test/integration/testdata/good/18/expected.out @@ -0,0 +1,17 @@ +Name,Lines,Commits,Files +Joe Tsai,13818,94,54 +178inaba,27,2,5 +ferhat elmas,7,1,4 +Christian Muehlhaeuser,6,3,4 +Tobias Klauser,35,2,3 +k.nakada,5,1,3 +A. Ishikawa,92,1,2 +Roger Peppe,59,1,2 +Dmitri Shuralyov,8,1,2 +LMMilewski,5,1,2 +colinnewell,130,1,1 +Kyle Lemons,11,1,1 +Ernest Galbrun,3,1,1 +Ross Light,2,1,1 +Chris Morrow,1,1,1 +Fiisio,1,1,1 diff --git a/gitfame/test/integration/testdata/good/2/description.yaml b/gitfame/test/integration/testdata/good/2/description.yaml new file mode 100644 index 0000000..aa8e605 --- /dev/null +++ b/gitfame/test/integration/testdata/good/2/description.yaml @@ -0,0 +1,5 @@ +# Empty project + +name: empty project +args: [--format, csv, --revision, dff562439f0406fb00229e3e95a8d2048f265683] +bundle: simple.bundle diff --git a/gitfame/test/integration/testdata/good/2/expected.out b/gitfame/test/integration/testdata/good/2/expected.out new file mode 100644 index 0000000..faaeb6f --- /dev/null +++ b/gitfame/test/integration/testdata/good/2/expected.out @@ -0,0 +1 @@ +Name,Lines,Commits,Files diff --git a/gitfame/test/integration/testdata/good/3/description.yaml b/gitfame/test/integration/testdata/good/3/description.yaml new file mode 100644 index 0000000..51e58ac --- /dev/null +++ b/gitfame/test/integration/testdata/good/3/description.yaml @@ -0,0 +1,5 @@ +# .md with single line + +name: single line +args: [--format, csv, --revision, a7b4f155866102b0559392440f4217bc3c19bf62] +bundle: simple.bundle diff --git a/gitfame/test/integration/testdata/good/3/expected.out b/gitfame/test/integration/testdata/good/3/expected.out new file mode 100644 index 0000000..20369b0 --- /dev/null +++ b/gitfame/test/integration/testdata/good/3/expected.out @@ -0,0 +1,2 @@ +Name,Lines,Commits,Files +Rober Griesemer,1,1,1 diff --git a/gitfame/test/integration/testdata/good/4/description.yaml b/gitfame/test/integration/testdata/good/4/description.yaml new file mode 100644 index 0000000..057db6b --- /dev/null +++ b/gitfame/test/integration/testdata/good/4/description.yaml @@ -0,0 +1,5 @@ +# .md with single line, filtered out with --extensions + +name: single file, extensions filter +args: [--format, csv, --revision, a7b4f155866102b0559392440f4217bc3c19bf62, --extensions, .go] +bundle: simple.bundle diff --git a/gitfame/test/integration/testdata/good/4/expected.out b/gitfame/test/integration/testdata/good/4/expected.out new file mode 100644 index 0000000..faaeb6f --- /dev/null +++ b/gitfame/test/integration/testdata/good/4/expected.out @@ -0,0 +1 @@ +Name,Lines,Commits,Files diff --git a/gitfame/test/integration/testdata/good/5/description.yaml b/gitfame/test/integration/testdata/good/5/description.yaml new file mode 100644 index 0000000..b5eb3f0 --- /dev/null +++ b/gitfame/test/integration/testdata/good/5/description.yaml @@ -0,0 +1,5 @@ +# .md with single line, filtered out with --languages + +name: single file, languages filter +args: [--format, csv, --revision, a7b4f155866102b0559392440f4217bc3c19bf62, --languages, c++] +bundle: simple.bundle diff --git a/gitfame/test/integration/testdata/good/5/expected.out b/gitfame/test/integration/testdata/good/5/expected.out new file mode 100644 index 0000000..faaeb6f --- /dev/null +++ b/gitfame/test/integration/testdata/good/5/expected.out @@ -0,0 +1 @@ +Name,Lines,Commits,Files diff --git a/gitfame/test/integration/testdata/good/6/description.yaml b/gitfame/test/integration/testdata/good/6/description.yaml new file mode 100644 index 0000000..b9650bd --- /dev/null +++ b/gitfame/test/integration/testdata/good/6/description.yaml @@ -0,0 +1,5 @@ +# .md with single line, excluded + +name: single file excluded +args: [--format, csv, --revision, a7b4f155866102b0559392440f4217bc3c19bf62, --exclude, read*] +bundle: simple.bundle diff --git a/gitfame/test/integration/testdata/good/6/expected.out b/gitfame/test/integration/testdata/good/6/expected.out new file mode 100644 index 0000000..faaeb6f --- /dev/null +++ b/gitfame/test/integration/testdata/good/6/expected.out @@ -0,0 +1 @@ +Name,Lines,Commits,Files diff --git a/gitfame/test/integration/testdata/good/7/description.yaml b/gitfame/test/integration/testdata/good/7/description.yaml new file mode 100644 index 0000000..f57fc8d --- /dev/null +++ b/gitfame/test/integration/testdata/good/7/description.yaml @@ -0,0 +1,5 @@ +# .md + .go x 2 + +name: HEAD^1 +args: [--format, csv, --revision, HEAD^1] +bundle: simple.bundle diff --git a/gitfame/test/integration/testdata/good/7/expected.out b/gitfame/test/integration/testdata/good/7/expected.out new file mode 100644 index 0000000..ce1452a --- /dev/null +++ b/gitfame/test/integration/testdata/good/7/expected.out @@ -0,0 +1,3 @@ +Name,Lines,Commits,Files +Rob Pike,7,3,2 +Brad Fitzpatrick,1,1,1 diff --git a/gitfame/test/integration/testdata/good/8/description.yaml b/gitfame/test/integration/testdata/good/8/description.yaml new file mode 100644 index 0000000..644bae1 --- /dev/null +++ b/gitfame/test/integration/testdata/good/8/description.yaml @@ -0,0 +1,5 @@ +# .md + .go x 2, tag, + +name: tag +args: [--format, csv, --revision, v1.0] +bundle: simple.bundle diff --git a/gitfame/test/integration/testdata/good/8/expected.out b/gitfame/test/integration/testdata/good/8/expected.out new file mode 100644 index 0000000..454a570 --- /dev/null +++ b/gitfame/test/integration/testdata/good/8/expected.out @@ -0,0 +1,3 @@ +Name,Lines,Commits,Files +Rob Pike,12,4,3 +Brad Fitzpatrick,1,1,1 diff --git a/gitfame/test/integration/testdata/good/9/description.yaml b/gitfame/test/integration/testdata/good/9/description.yaml new file mode 100644 index 0000000..ccd63fd --- /dev/null +++ b/gitfame/test/integration/testdata/good/9/description.yaml @@ -0,0 +1,5 @@ +# .md + .go x 2, tag, --use-committer + +name: tag committer +args: [--format, csv, --revision, v1.0, --use-committer] +bundle: simple.bundle diff --git a/gitfame/test/integration/testdata/good/9/expected.out b/gitfame/test/integration/testdata/good/9/expected.out new file mode 100644 index 0000000..71e76dc --- /dev/null +++ b/gitfame/test/integration/testdata/good/9/expected.out @@ -0,0 +1,4 @@ +Name,Lines,Commits,Files +Rob Pike,7,3,2 +Randall77,5,1,1 +Brad Fitzpatrick,1,1,1