Skip to content

Add unit tests for modules/textfile - #2132

Merged
Seanstoppable merged 1 commit into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-textfile-test-coverage
Jul 26, 2026
Merged

Seanstoppable merged 1 commit into
wtfutil:trunkfrom
Seanstoppable:seanstoppable-textfile-test-coverage

Conversation

@Seanstoppable

Copy link
Copy Markdown
Collaborator

Summary

Adds unit test coverage for modules/textfile, which previously had 0%.

  • settings_test.go: table-driven tests for NewSettingsFromYAML covering defaults, format/formatStyle/wrapText overrides, and filePaths vs. single filePath.
  • widget_test.go: exercises the read/parse/format pipeline using real temp files (t.TempDir()):
    • plainText() — normal/empty/multiline files, missing-file error path
    • formattedText() — valid lexer/style, unknown style fallback, unrecognized extension, empty file, missing-file error path
    • content() — plain vs. formatted mode, multi-source pagination, no-sources-configured edge case
    • NewWidget() full lifecycle — keyboard controls, file-watcher goroutine (including a live file-change event), Refresh(), with explicit Stop() cleanup

Coverage

0% → 85.2% of statements.

Remaining gaps are intentionally left uncovered:

  • openFile() shells out to the OS to launch an external program — not safe to trigger in tests.
  • Watcher error/closed branches call os.Exit(1) by design — would kill the test binary.
  • A few nil fallback checks in formattedText() for chroma's lexer/style/formatter lookups are effectively dead code, since those library functions never return nil in practice.

Testing

go test ./modules/textfile/... -v -cover — all passing, run multiple times for stability (goroutine/watcher lifecycle).

@Seanstoppable
Seanstoppable force-pushed the seanstoppable-textfile-test-coverage branch from adcec37 to 1939778 Compare July 24, 2026 14:28
Adds table-driven tests covering settings parsing (defaults, format,
formatStyle, wrapText, filePaths) and the read/parse/format pipeline
in widget.go, using real temp files for plainText/formattedText/content.
Covers empty files, missing files, multiple sources, format fallback
for unknown lexer/style, and the full NewWidget lifecycle (keyboard
controls, file watcher goroutine, Refresh, live file-change events).

Coverage: 0% -> 85.2%.
@Seanstoppable
Seanstoppable force-pushed the seanstoppable-textfile-test-coverage branch from 1939778 to 587e386 Compare July 26, 2026 03:39
@Seanstoppable
Seanstoppable merged commit 3683829 into wtfutil:trunk Jul 26, 2026
4 checks passed
@Seanstoppable
Seanstoppable deleted the seanstoppable-textfile-test-coverage branch July 26, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

⌂ 换网址