The section rule was `/^[[:space:]]*\/\/[[:space:]]*─+ (.+) ─+…$/`, a quantifier on a multibyte character. Under LC_ALL=C — which is what cron, systemd user units and agent shells get, regardless of LANG — gawk matches byte-wise, so `─+` means "the last byte of U+2500, repeated" and never matches. Measured on the live keybinds.kdl: the old script emitted 0 section headers instead of 12, all 120 binding rows intact, exit status 0. A silent one-third-of-the-page loss, invisible to any caller that only checks the status. The dash is now matched and stripped as a literal (`gsub(/─/, "")`), which is byte-safe in every locale, and a comment must be dash-decorated on both sides to open a section, so plain comments are still ignored. A test pins the C-locale case explicitly, because the box's own terminal has always been UTF-8 and could never have caught this. The committed artifact omp-docs/tools/niri/keybindings.md is unaffected (12 headers, 120 rows — it was generated from a UTF-8 shell); output is now identical either way.
88 lines
2.9 KiB
Bash
Executable File
88 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bats
|
|
# tests/gen-keybinds.bats — black-box tests for scripts/gen-keybinds.sh
|
|
#
|
|
# Contract: parse a keybinds.kdl into a markdown cheat sheet on stdout,
|
|
# or into a file with --write OUT. Observable surface: markdown rows,
|
|
# section headers, exit status, written file.
|
|
|
|
setup() {
|
|
GEN="$BATS_TEST_DIRNAME/../scripts/gen-keybinds.sh"
|
|
TMP="$(mktemp -d)"
|
|
cat > "$TMP/keybinds.kdl" <<'EOF'
|
|
binds {
|
|
// ─── Applications ───
|
|
Mod+Return hotkey-overlay-title="Open Terminal: Ghostty" { spawn "ghostty"; }
|
|
Mod+D hotkey-overlay-title="Open App Launcher: noctalia launcher" { spawn-sh "noctalia msg panel-toggle launcher"; }
|
|
Mod+E { spawn "nautilus"; }
|
|
|
|
// ─── Screenshots ───
|
|
Print hotkey-overlay-title="Fullscreen screenshot" { spawn-sh "noctalia msg screenshot-fullscreen"; }
|
|
|
|
// a plain comment, not a section
|
|
Mod+Shift+ESCAPE { show-hotkey-overlay; }
|
|
}
|
|
EOF
|
|
}
|
|
|
|
teardown() {
|
|
rm -rf "$TMP"
|
|
}
|
|
|
|
@test "renders a row per bind with title preferred over action" {
|
|
run "$GEN" "$TMP/keybinds.kdl"
|
|
[ "$status" -eq 0 ]
|
|
[[ "$output" == *'| `Mod+D` | Open App Launcher: noctalia launcher |'* ]]
|
|
[[ "$output" == *'| `Mod+Return` | Open Terminal: Ghostty |'* ]]
|
|
}
|
|
|
|
@test "binds without a title render their action" {
|
|
run "$GEN" "$TMP/keybinds.kdl"
|
|
[[ "$output" == *'| `Mod+E` | spawn "nautilus" |'* ]]
|
|
[[ "$output" == *'| `Mod+Shift+ESCAPE` | show-hotkey-overlay |'* ]]
|
|
}
|
|
|
|
@test "section comments become headers; plain comments are ignored" {
|
|
run "$GEN" "$TMP/keybinds.kdl"
|
|
[[ "$output" == *"## Applications"* ]]
|
|
[[ "$output" == *"## Screenshots"* ]]
|
|
[[ "$output" != *"a plain comment"* ]]
|
|
}
|
|
|
|
@test "section headers survive a C locale, where awk reads bytes instead of characters" {
|
|
# Cron, systemd units and agent shells get LC_ALL=C while Frank's terminal does not.
|
|
# A matcher that puts a quantifier on a multibyte character then loses EVERY section
|
|
# header and prints a sheet with no sections at all — silently, exit status 0.
|
|
run env LC_ALL=C "$GEN" "$TMP/keybinds.kdl"
|
|
[[ "$output" == *"## Applications"* ]]
|
|
[[ "$output" == *"## Screenshots"* ]]
|
|
[[ "$output" != *"a plain comment"* ]]
|
|
}
|
|
|
|
@test "row count matches bind count" {
|
|
run "$GEN" "$TMP/keybinds.kdl"
|
|
local rows
|
|
rows="$(grep -c '^| `' <<<"$output")"
|
|
[ "$rows" -eq 5 ]
|
|
}
|
|
|
|
@test "--write writes the markdown to the given path" {
|
|
run "$GEN" "$TMP/keybinds.kdl" --write "$TMP/out/keybindings.md"
|
|
[ "$status" -eq 0 ]
|
|
[ -f "$TMP/out/keybindings.md" ]
|
|
grep -q '| `Mod+D` | Open App Launcher: noctalia launcher |' "$TMP/out/keybindings.md"
|
|
grep -q 'GENERATED' "$TMP/out/keybindings.md"
|
|
}
|
|
|
|
@test "output begins with OKF frontmatter so the artifact passes kb-lint" {
|
|
run "$GEN" "$TMP/keybinds.kdl"
|
|
[ "${lines[0]}" = '---' ]
|
|
[[ "${lines[1]}" == 'type: reference' ]]
|
|
grep -q '^generated:' <<<"$output"
|
|
}
|
|
|
|
@test "missing input file fails loudly" {
|
|
run "$GEN" "$TMP/nope.kdl"
|
|
[ "$status" -ne 0 ]
|
|
[[ "$output" == *"no such file"* ]]
|
|
}
|