Skip to content

Commit

Permalink
fix: remove assertFormatted, use assertStats instead
Browse files Browse the repository at this point in the history
Signed-off-by: Brian McGee <[email protected]>
  • Loading branch information
brianmcgee committed Aug 21, 2024
1 parent d4c115e commit 1734bcf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
27 changes: 12 additions & 15 deletions cli/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,37 +274,34 @@ func TestCache(t *testing.T) {
},
}

var (
out []byte
err error
)
var err error

test.WriteConfig(t, configPath, cfg)
_, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir)
as.NoError(err)
assertStats(t, as, 32, 32, 32, 0)

out, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir)
_, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir)
as.NoError(err)
assertFormatted(t, as, out, 0)
assertStats(t, as, 32, 0, 0, 0)

// clear cache
_, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir, "-c")
as.NoError(err)
assertStats(t, as, 32, 32, 32, 0)

out, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir)
_, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir)
as.NoError(err)
assertFormatted(t, as, out, 0)
assertStats(t, as, 32, 0, 0, 0)

// clear cache
_, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir, "-c")
as.NoError(err)
assertStats(t, as, 32, 32, 32, 0)

out, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir)
_, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir)
as.NoError(err)
assertFormatted(t, as, out, 0)
assertStats(t, as, 32, 0, 0, 0)

// no cache
_, err = cmd(t, "--config-file", configPath, "--tree-root", tempDir, "--no-cache")
Expand Down Expand Up @@ -516,10 +513,10 @@ func TestGitWorktree(t *testing.T) {
wt, err := repo.Worktree()
as.NoError(err, "failed to get git worktree")

run := func(traversed int, emitted int, matched int, formatted int) {
out, err := cmd(t, "-c", "--config-file", configPath, "--tree-root", tempDir)
run := func(traversed int32, emitted int32, matched int32, formatted int32) {
_, err := cmd(t, "-c", "--config-file", configPath, "--tree-root", tempDir)
as.NoError(err)
assertFormatted(t, as, out, formatted)
assertStats(t, as, traversed, emitted, matched, formatted)
}

// run before adding anything to the worktree
Expand All @@ -532,11 +529,11 @@ func TestGitWorktree(t *testing.T) {

// remove python directory from the worktree
as.NoError(wt.RemoveGlob("python/*"))
run(28, 28, 28, 0)
run(29, 29, 29, 0)

// remove nixpkgs.toml from the filesystem but leave it in the index
as.NoError(os.Remove(filepath.Join(tempDir, "nixpkgs.toml")))
run(27, 27, 27, 0)
run(28, 28, 28, 0)

// walk with filesystem instead of git
_, err = cmd(t, "-c", "--config-file", configPath, "--tree-root", tempDir, "--walk", "filesystem")
Expand Down
5 changes: 0 additions & 5 deletions cli/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,3 @@ func assertStats(t *testing.T, as *require.Assertions, traversed int32, emitted
as.Equal(matched, stats.Value(stats.Matched), "stats.matched")
as.Equal(formatted, stats.Value(stats.Formatted), "stats.formatted")
}

func assertFormatted(t *testing.T, as *require.Assertions, output []byte, count int) {
t.Helper()
as.Contains(string(output), fmt.Sprintf("(%d changed)", count))
}

0 comments on commit 1734bcf

Please sign in to comment.