mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 20:07:04 +01:00
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.
Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.
The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:
- 52 relative `source` lines for lib/common.sh and lib/android.sh. The
correct prefix differs per file: 40 were ../../ and 12 were ../../../,
so a blanket replace would have fixed one set and broken the other.
- REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
each walking up four levels from a directory now two levels shallower.
This caused a real regression -- the fixes suite went red with
"log_warn: command not found" -- caught by running it and comparing
against the pre-move baseline worktree.
- conftest.py's sys.path entries, which took the pytest gate down with
14 collection errors, and the `# shellcheck source=` directives, which
took shellcheck down with SC1091.
16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.
Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
117 lines
3.2 KiB
Bash
Executable File
117 lines
3.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# lib/tests/features_harness.sh — shared fixture for the features/lib suites.
|
|
#
|
|
# Sourced, not executed. One harness per DIRECTORY, not per file: jscpd fails
|
|
# the commit above 2% duplication, and near-identical per-file harnesses are
|
|
# exactly how that trips.
|
|
#
|
|
# Unlike the digital_wellbeing harness, this one does NOT avoid the effecting
|
|
# code. Its subjects sudo-write systemd units and add nftables rules, and
|
|
# those paths are the point. They are made safe by running under
|
|
# meta/scripts/shell_coverage_jail.sh, which puts the whole suite inside a
|
|
# user+mount namespace where the write targets are bind-mounted to a
|
|
# throwaway dir. Nothing here may assume it can reach the real /etc.
|
|
set -euo pipefail
|
|
|
|
PASS=0
|
|
FAIL=0
|
|
|
|
_t_pass() {
|
|
PASS=$((PASS + 1))
|
|
printf ' OK: %s\n' "$1"
|
|
}
|
|
|
|
_t_fail() {
|
|
FAIL=$((FAIL + 1))
|
|
printf ' FAIL: %s\n' "$1"
|
|
}
|
|
|
|
_t_eq() {
|
|
if [[ $2 == "$1" ]]; then
|
|
_t_pass "$3"
|
|
else
|
|
_t_fail "$3 (want '${1}', got '${2}')"
|
|
fi
|
|
}
|
|
|
|
_t_has() {
|
|
if [[ $1 == *"$2"* ]]; then
|
|
_t_pass "$3"
|
|
else
|
|
_t_fail "$3 (want a substring '${2}')"
|
|
fi
|
|
}
|
|
|
|
_t_file_has() {
|
|
if [[ -f $1 ]] && grep -q "$2" "$1"; then
|
|
_t_pass "$3"
|
|
else
|
|
_t_fail "$3 (file '${1}' missing or lacks '${2}')"
|
|
fi
|
|
}
|
|
|
|
# A function that calls `exit` would kill the test script if invoked directly
|
|
# in an `if` condition, so failures are asserted inside a subshell.
|
|
_t_exits_nonzero() {
|
|
if ("$1" >/dev/null 2>&1); then
|
|
_t_fail "$2 (expected a non-zero exit, got 0)"
|
|
else
|
|
_t_pass "$2"
|
|
fi
|
|
}
|
|
|
|
FEATURES_LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
export FEATURES_LIB_DIR
|
|
|
|
# The libs are sourced by their entry scripts and inherit these from above the
|
|
# source line. A missing one aborts the subject under `set -u` with no useful
|
|
# stderr, so the fixture asserts its own globals are populated rather than
|
|
# letting a typo become a silently skipped assertion.
|
|
log() { printf '[test] %s\n' "$1"; }
|
|
|
|
_t_setup_env() {
|
|
TEST_TMPDIR="$(mktemp -d)"
|
|
export TEST_TMPDIR
|
|
PATH="$TEST_TMPDIR/bin:$PATH"
|
|
export PATH
|
|
mkdir -p "$TEST_TMPDIR/bin"
|
|
}
|
|
|
|
# Record-and-succeed stubs for commands with no useful behaviour under test.
|
|
# `sudo` is deliberately NOT stubbed: inside the jail we are already uid 0, so
|
|
# stubbing it would hide the very writes these tests exist to exercise.
|
|
_t_stub() {
|
|
printf '#!/usr/bin/env bash\nprintf "%%s %%s\\n" "%s" "$*" >>"%s/calls.log"\nexit 0\n' \
|
|
"$1" "$TEST_TMPDIR" >"$TEST_TMPDIR/bin/$1"
|
|
chmod +x "$TEST_TMPDIR/bin/$1"
|
|
}
|
|
|
|
# Remove a stub AND forget it. bash caches executable locations in a hash
|
|
# table, so `command -v foo` keeps succeeding after foo is deleted until the
|
|
# table is cleared -- silently turning every "tool is missing" test into a
|
|
# "tool is present" test that asserts the opposite of its own name. Measured:
|
|
# without the `hash -r` the removed stub is STILL FOUND.
|
|
_t_unstub() {
|
|
rm -f "$TEST_TMPDIR/bin/$1"
|
|
hash -r
|
|
}
|
|
|
|
_t_called() {
|
|
if [[ -f "$TEST_TMPDIR/calls.log" ]] && grep -q "$1" "$TEST_TMPDIR/calls.log"; then
|
|
_t_pass "$2"
|
|
else
|
|
_t_fail "$2 (no '${1}' in the call log)"
|
|
fi
|
|
}
|
|
|
|
_t_teardown() {
|
|
if [[ -n ${TEST_TMPDIR:-} && -d ${TEST_TMPDIR} ]]; then
|
|
rm -rf "$TEST_TMPDIR"
|
|
fi
|
|
}
|
|
|
|
_t_report() {
|
|
printf '\n%s: %d passed, %d failed\n' "${1:-tests}" "$PASS" "$FAIL"
|
|
[[ $FAIL -eq 0 ]]
|
|
}
|