Skip to content

Testing

Nakanomk edited this page Aug 9, 2026 · 6 revisions

Testing

Language: English · 简体中文

Run the tests

make check

This builds build/test_runner and runs it. The test build deliberately uses different flags than the main build:

  • -DSEEKEY_TEST — gates out the ncurses rendering code in src/tui.c so the pure helpers can be tested without a terminal.
  • -DG_DISABLE_ASSERT — disables g_assert side effects in production paths.
  • Links only glib / gobject / gio / json-glib / gtk4 + the vendored Unity framework — no ncurses, no libevdev, no layer-shell, no display needed.

So the whole suite runs headless in CI.

What's covered

123 unit tests using the vendored Unity framework (MIT; under tests/vendor/unity/).

File Covers
test_config.c defaults, search order, strict validation, non-regular path rejection, migration/preservation, themes, Matugen resolution and fallback
test_tui.c field value formatting, adjust/reset pure logic, theme choices, bool string_target regression
test_keynames.c key name / icon / shift-pair / modifier-order lookups
test_runtime_lock.c cross-process-style lock exclusion and handoff
test_preview_session.c overlay-state discovery and semantic preview-config comparison
test_style.c generated CSS font escaping and minimum bubble width
test_window_state.c path resolution, save/load roundtrip, malformed/non-regular-file tolerance, clear
test_main.c test runner entry; registers all suites
test_helpers.c / .h shared test helpers

Why pure helpers?

TUI rendering (ncurses) and the GTK event loop can't be exercised in a headless unit test. So the testable logic in src/tui.c is split into pure functions (tui_field_value, tui_adjust_field, tui_reset_field, tui_nearest_color_index, tui_current_choice_index) that operate on a TuiField/SeekeyConfig with no I/O. The ncurses code path is wrapped in #ifdef SEEKEY_TEST. The same pattern is used in config.c, keynames.c, and window_state.c, which is why they compile into the test binary directly.

Adding a test

  1. Add a TEST(<group>, <name>) { ... } function in the relevant tests/test_<area>.c.
  2. Register it in that file's RUN_<GROUP>_TESTS() (or equivalent RUN_TEST block).
  3. Call the group runner from test_main.c.
  4. make check.

Other Makefile targets

Target Purpose
make check run unit tests, shell syntax, translation checks, and desktop-entry validation when available
make format clang-format src/ and tests/ (if installed)
make clean remove seekey, objects, build/test_runner, locale/

Clone this wiki locally