[test] Cover presentation helper output#293
Conversation
|
|
||
| func TestPrintWorktreeResultCopySkipBranches(t *testing.T) { | ||
| cmd, buf := newTestCmd() | ||
|
|
There was a problem hiding this comment.
Medium — Test name TestPrintWorktreeResultCopySkipBranches is misleading.
The suffix Branches does not describe what is tested. The test covers Copied, Skipped, and SkippedSymlinks output lines — no branch-plural concept is involved. A reader scanning test names builds a wrong mental model.
Suggested fix: Rename to TestPrintWorktreeResultCopyAndSkipped or TestPrintWorktreeResultAllFields.
| if got := buf.String(); got != want { | ||
| t.Fatalf("output = %q, want %q", got, want) | ||
| } | ||
| } |
There was a problem hiding this comment.
Medium — The push=false branch of printSyncDryRun is not tested.
The guard if push { ... } (in cmd/sync.go) is the only conditional branch in the function, yet this test covers only push=true. A regression that unconditionally prints the push line would not be caught.
Suggested fix: Add a second test case, e.g.:
func TestPrintSyncDryRunRebaseNoPush(t *testing.T) {
cmd, buf := newTestCmd()
printSyncDryRun(cmd, "feature/login", "main", false, false)
got := buf.String()
if !strings.Contains(got, "would rebase") {
t.Fatalf("expected rebase verb, got: %q", got)
}
if strings.Contains(got, "would push") {
t.Fatalf("push line must be absent, got: %q", got)
}
}| func TestPrintWorktreeResultCopySkipBranches(t *testing.T) { | ||
| cmd, buf := newTestCmd() | ||
|
|
||
| printWorktreeResult(cmd, "Created worktree", operations.AddResult{ |
There was a problem hiding this comment.
Low — The empty-fields path of printWorktreeResult is not tested.
The three len > 0 guards (for Copied, Skipped, SkippedSymlinks) are untested with the current test. A complementary test would verify those lines are correctly suppressed when the slices are nil.
Suggested fix: Add TestPrintWorktreeResultMinimal with an AddResult where all slice fields are nil, and assert the output contains only the header, Branch, and Path lines (and does NOT contain "Copied:", "Skipped", or "symlinks").
Changing to comment — findings need addressing before approval.
Closes #273.
Adds direct output tests for:
printWorktreeResultcopied, missing, and symlink-skipped rowsprintSyncDryRunmerge dry-run outputChecks:
gofmt -w cmd/add_test.go cmd/sync_test.gogit diff --checkNote: I could not run
go testlocally because this host has Go 1.25.1 whilego.modrequires Go 1.26.4, and automatic toolchain switching hung in the sandbox.