Skip to content

Commit 1dc9bb8

Browse files
committed
test: fix misleading test names and comments (PR #172 Copilot round 3)
- fix: rename TestAtomicWriteFile_RenameFailure → TargetNotWritable and TestAtomicWriteFile_TmpFileCleanedUpOnRenameFailure → NoTempFilesOnEarlyFailure; both tests exercise the preflight OpenFile check, not the rename path - crossfilereferenceintegrity: rename TestCheck_LinkWithNoTextOffset → TestCheck_BrokenLinkDiagnosticPosition to match what the test actually asserts https://claude.ai/code/session_01DvP5H17ofGpHmR7DhSU438
1 parent 5c2a5f2 commit 1dc9bb8

2 files changed

Lines changed: 16 additions & 32 deletions

File tree

internal/fix/fix_coverage_test.go

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -395,41 +395,29 @@ func TestFix_IsIgnored_Continue(t *testing.T) {
395395

396396
// --- atomicWriteFile error paths ---
397397

398-
// TestAtomicWriteFile_RenameFailure causes os.Rename to fail by making the
399-
// target path a directory. On Linux, renaming a regular file onto a directory
400-
// returns EISDIR.
401-
func TestAtomicWriteFile_RenameFailure(t *testing.T) {
398+
// TestAtomicWriteFile_TargetNotWritable verifies that atomicWriteFile returns
399+
// an error when the target exists but is not writable (directory). The
400+
// preflight OpenFile(O_WRONLY) check fails before any temp file is created.
401+
func TestAtomicWriteFile_TargetNotWritable(t *testing.T) {
402402
if runtime.GOOS == "windows" {
403-
t.Skip("rename-over-directory test not reliable on Windows")
403+
t.Skip("not reliable on Windows")
404404
}
405405

406406
dir := t.TempDir()
407-
// Create a directory at the target path.
407+
// Create a directory at the target path — OpenFile(O_WRONLY) on a
408+
// directory returns EISDIR on Linux, failing the preflight check.
408409
targetDir := filepath.Join(dir, "target")
409410
require.NoError(t, os.Mkdir(targetDir, 0o755))
410411

411-
// atomicWriteFile: the target exists, stat will succeed, OpenFile on a
412-
// directory for O_WRONLY will fail on Linux (EISDIR).
413412
err := atomicWriteFile(targetDir, []byte("data"), 0o644)
414413
require.Error(t, err, "expected error when target is a directory")
415414
}
416415

417-
// TestAtomicWriteFile_WriteFailure causes tmp.Write to fail by filling the
418-
// target directory's filesystem quota. Since we cannot easily exhaust disk
419-
// space, we instead point the temp file into a read-only directory — but that
420-
// would prevent CreateTemp too. Instead, we use a pipe trick: replace the
421-
// temp dir with a read-only mount is not portable. The most portable approach
422-
// is to write a very large file to a tmpfs of limited size. As an alternative,
423-
// we test the Rename failure path (different from read-only target) by
424-
// arranging the Chmod to fail.
425-
//
426-
// On Linux, Chmod of a temp file we own always succeeds, so the only reliably
427-
// injectable post-CreateTemp failure is Rename. TestAtomicWriteFile_RenameFailure
428-
// covers that. The write/sync/close paths are exercised implicitly by the
429-
// successful write tests; their error returns are straightforward OS wrappers
430-
// with no logic to branch on, so they do not contribute to the branch-coverage
431-
// gap targeted here.
432-
func TestAtomicWriteFile_TmpFileCleanedUpOnRenameFailure(t *testing.T) {
416+
// TestAtomicWriteFile_NoTempFilesOnEarlyFailure verifies that no temp files
417+
// are created when atomicWriteFile fails at the preflight writability check
418+
// (before reaching CreateTemp). Using a directory as the target triggers the
419+
// same early-exit path as TestAtomicWriteFile_TargetNotWritable.
420+
func TestAtomicWriteFile_NoTempFilesOnEarlyFailure(t *testing.T) {
433421
if runtime.GOOS == "windows" {
434422
t.Skip("not reliable on Windows")
435423
}
@@ -441,7 +429,7 @@ func TestAtomicWriteFile_TmpFileCleanedUpOnRenameFailure(t *testing.T) {
441429
err := atomicWriteFile(targetDir, []byte("data"), 0o644)
442430
require.Error(t, err)
443431

444-
// Verify no orphaned temp files remain in the directory after the failure.
432+
// No temp files should exist because the error occurred before CreateTemp.
445433
entries, err := os.ReadDir(dir)
446434
require.NoError(t, err)
447435
for _, e := range entries {

internal/rules/crossfilereferenceintegrity/rule_morecoverage_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,9 @@ func TestMatchesPathFilters_IncludeThenExclude(t *testing.T) {
134134
require.Len(t, diags, 0)
135135
}
136136

137-
// --- linkPosition: offset < 0 branch (no text node in link) ---
138-
139-
func TestCheck_LinkWithNoTextOffset(t *testing.T) {
140-
// A link that resolves but whose AST link node has no text children
141-
// would produce offset < 0. This is very hard to construct directly,
142-
// but we can exercise linkPosition indirectly through a normal check
143-
// that produces a diagnostic — the diagnostic's line/col is correct.
137+
// TestCheck_BrokenLinkDiagnosticPosition verifies that a broken link produces
138+
// a diagnostic with correct non-zero line and column numbers.
139+
func TestCheck_BrokenLinkDiagnosticPosition(t *testing.T) {
144140
dir := t.TempDir()
145141
sourcePath := filepath.Join(dir, "doc.md")
146142
writeFile(t, sourcePath, "# Doc\n\nSee [missing](missing.md).\n")

0 commit comments

Comments
 (0)