Skip to content

test: add ptyunit test suite (CLI + PTY/TUI)#1

Open
fissible wants to merge 1 commit intoflathead:masterfrom
fissible:add-ptyunit-tests
Open

test: add ptyunit test suite (CLI + PTY/TUI)#1
fissible wants to merge 1 commit intoflathead:masterfrom
fissible:add-ptyunit-tests

Conversation

@fissible
Copy link
Copy Markdown

@fissible fissible commented Apr 6, 2026

Summary

Adds a test suite using ptyunit, a bash test framework that can drive interactive terminal UIs via a real pseudoterminal — making it possible to test both the CLI flags and the interactive TUI.

ptyunit is added as a git submodule at tests/ptyunit. To run the tests:

git submodule update --init
bash tests/run.sh

What's covered

Unit tests (tests/unit/test-cli.sh) — CLI flag mode:

  • Password output: length, quiet mode, -n no-newline
  • Character sets: default, --simple, --db-safe
  • First-character invariant: password never starts with - or .
  • Flag conflict between -d and -s
  • Error handling: missing -l value, out-of-range lengths, unknown flags
  • Verbose output structure (Password/Base64/SHA-256 labels)

Integration tests (tests/integration/test-tui.sh) — interactive TUI:

  • TUI renders all expected labels and hotkey hints
  • Key handling: r, Enter, Space, +, -, numeric presets (1–8)
  • DB-safe mode toggle (R key)
  • History navigation (</> keys, position counter)
  • Help screen (? key, dismiss and return)

Bugs the tests catch

A few bugs surface when the tests run — leaving them for discussion rather than fixing here, since the fixes are straightforward but warrant a separate commit:

  • -l without a value causes a shift 2 crash under set -euo pipefail instead of a clean error message
  • -d -s flag ordering — the last flag wins, so passgen -d -s produces an alphanumeric-only password labeled "DB-safe"
  • HISTORY[-1] requires bash 4.3+ (negative array indices); fails silently on 4.0–4.2

Tests written with ptyunit — a bash testing framework with built-in PTY/TUI support, mocking, and parameterized tests.

Adds tests/ptyunit as a git submodule (fissible/ptyunit) and a test
suite covering both the CLI and interactive TUI.

Unit tests (tests/unit/test-cli.sh):
- Password length, character set, and quiet/verbose output
- DB-safe charset constraints
- First-character invariant (never - or .)
- Flag conflict: -d vs -s ordering bug
- Error handling: missing -l value, out-of-range lengths, unknown flags

Integration/PTY tests (tests/integration/test-tui.sh):
- TUI renders all expected labels and hotkeys
- Key handling: r, Enter, Space, +, -, numeric presets
- DB-safe mode toggle (R key)
- History navigation (< and > keys, position display)
- Help screen (? key, dismiss and return)

Run with: bash tests/run.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant