Skip to content

Commit 6019bc1

Browse files
authored
fix: Improve report command tests and functionality (#10)
Improve report command tests and functionality
1 parent 99e0ca5 commit 6019bc1

File tree

4 files changed

+11
-15
lines changed

4 files changed

+11
-15
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.PHONY: all build test clean lint vet fmt run
22

3-
all: build lint test install
3+
all: build lint install test
44

55
grit:
66
go build -o grit ./grit

grit/cmd/report/report.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ var ReportCmd = &cobra.Command{
7979
if err != nil {
8080
return fmt.Errorf("error getting churn metrics: %w", err)
8181
}
82+
83+
if churnOpts.SortBy == git.Commits {
84+
for _, churn := range churns {
85+
churn.Churn = churn.Commits
86+
}
87+
}
88+
8289
flag.LogIfVerbose("Got %d churn files\n", len(churns))
8390

8491
flag.LogIfVerbose("Analyzing complexity data...\n")

test/gritrepo_test.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ import (
1313
// You can install it via go install.
1414
// You can download it from https://github.com/vbvictor/grit/releases and place it in your PATH.
1515

16-
func createTempRepo(t *testing.T) (tempPath, gritPath string) {
16+
func createTempRepo(t *testing.T) (string, string) { //nolint
1717
t.Helper()
1818

1919
tempDir := t.TempDir()
2020
gritDir := filepath.Join(tempDir, "grit")
2121
err := os.MkdirAll(gritDir, 0o755)
2222
require.NoError(t, err)
2323

24+
Unbundle(t, filepath.Join("..", "testdata", "bundles", "grit-test.bundle"), gritDir)
25+
2426
return tempDir, gritDir
2527
}
2628

@@ -91,13 +93,3 @@ func TestGritBasicFunctionality(t *testing.T) {
9193

9294
RunGritTests(t, tests)
9395
}
94-
95-
/*
96-
func newGritReportValidator(expectedOutputs ...string) OutputValidator {
97-
return func(t *testing.T, stdout, _ string) bool {
98-
t.Helper()
99-
100-
return false
101-
}
102-
}
103-
*/

test/runner.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func NewContainsValidator(expectedOutputs ...string) OutputValidator {
3939
}
4040
}
4141

42-
// RunGritTest runs a single grit test.
4342
func RunGritTest(t *testing.T, test GritTest) {
4443
t.Helper()
4544
t.Run(test.Name, func(t *testing.T) {
@@ -79,15 +78,13 @@ func RunGritTest(t *testing.T, test GritTest) {
7978

8079
// findGritExecutable tries to find the grit executable in common locations.
8180
func findGritExecutable() (string, error) {
82-
// Check if grit is in PATH
8381
if path, err := exec.LookPath("grit"); err == nil {
8482
return path, nil
8583
}
8684

8785
return "", errors.New("could not find grit executable")
8886
}
8987

90-
// RunGritTests runs multiple grit tests.
9188
func RunGritTests(t *testing.T, tests []GritTest) {
9289
t.Helper()
9390

0 commit comments

Comments
 (0)