diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-18 12:42:02 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-18 12:42:02 +0300 |
| commit | 42036d5ec36160a9caa6de64f9476726a5386a69 (patch) | |
| tree | cea966e9683dc5adc967912341b9847abd40dfed /tests | |
| parent | 3c35381b71f992eb7a86552697ea647bb76b68b1 (diff) | |
Support FreeBSD and macOS via resolved GNU tool variables
shuriken relied on GNU-only extensions (find -printf, stat -c, cp -a,
sort -R) and hard-refused to run outside Linux. Resolve each of the four
tools once at startup to a FIND/STAT/CP/SORT variable, preferring a
g-prefixed sibling (gfind, gstat, gcp, gsort) when present on PATH -
mirroring the $SED/$GREP/$DATE tool-selection pattern in the sibling
gemtexter project - so the same source runs unmodified on Linux, macOS,
and FreeBSD once GNU coreutils/findutils are installed there.
- src/lib/compat.source.sh: add resolve_gnu_tool + FIND/STAT/CP/SORT;
add a fast verify_gnu_tool_versions preflight (--version contains
"GNU") ahead of the existing behavioral probes, which now run against
the resolved variables instead of hardcoded tool names; split the
probes and error reporting into their own ~30-line functions.
- Replace the GNU-only find -printf / stat -c / cp -a / sort -R call
sites in photo-list, image, album-photo-select, metadata-cache,
config.staging, and random source files with the resolved variables.
POSIX-portable find/sort calls elsewhere are untouched.
- README.md: drop the "Linux-only" claim; document brew/pkg GNU
coreutils+findutils install steps for macOS and FreeBSD.
- tests/cli.sh: add coverage for the g-prefixed-sibling preference and
for the new --version-string preflight's error message, alongside the
existing behavioral-probe guard tests.
just build / just check-generated / just shellcheck / just test /
git diff --check all pass.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/cli.sh | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/cli.sh b/tests/cli.sh index 52952d5..c248b4c 100755 --- a/tests/cli.sh +++ b/tests/cli.sh @@ -6782,6 +6782,93 @@ FAKE test::teardown } +# resolve_gnu_tool (src/lib/compat.source.sh) must prefer a "g"-prefixed +# sibling over a broken plain-named tool, the macOS/FreeBSD layout produced by +# `brew install coreutils findutils` / `pkg install coreutils findutils` +# (see README.md's "Platform compatibility" section): the GNU tool is +# installed as "gfind" alongside the system's own (non-GNU) "find" rather than +# replacing it. Here "find" is replaced with a fake that rejects -printf (as +# BSD/macOS find would), but a real, working find is also installed as +# "gfind" -- shuriken must resolve FIND to "gfind" and succeed, proving the +# preference is applied rather than the guard merely tolerating a fluke. +test_gnu_tool_guard_prefers_g_prefixed_sibling() { + local path_bin + local real_find + local output + + test::setup + path_bin="$TEST_TMPDIR/bin" + real_find=$(command -v find) + test::install_coreutils_without_imagemagick "$path_bin" + rm -f "$path_bin/find" + cat > "$path_bin/find" <<FAKE +#!/usr/bin/env bash +set -euo pipefail +for arg in "\$@"; do + if [ "\$arg" = -printf ]; then + printf 'find: unknown predicate -printf\n' >&2 + exit 2 + fi +done +exec "$real_find" "\$@" +FAKE + chmod 0755 "$path_bin/find" + ln -s "$real_find" "$path_bin/gfind" + + output=$( + cd "$TEST_TMPDIR" + PATH="$path_bin" "$TEST_SHURIKEN" --version + ) + + test::assert_contains 'This is Shuriken Version' "$output" + test::assert_not_contains 'shuriken requires the GNU versions' "$output" + test::teardown +} + +# verify_gnu_tool_versions (src/lib/compat.source.sh) is the fast preflight +# check that runs before the (slower) behavioral probes: it rejects a resolved +# tool outright when its own --version output does not claim to be GNU, naming +# the tool and pointing at the README install instructions. This is distinct +# from (and runs before) the "GNU-tool guard rejects non-GNU find" case above, +# which covers a tool that claims GNU but lacks the specific behavior. +test_gnu_tool_guard_rejects_non_gnu_version_string() { + local path_bin + local real_find + local output + + test::setup + path_bin="$TEST_TMPDIR/bin" + real_find=$(command -v find) + test::install_coreutils_without_imagemagick "$path_bin" + rm -f "$path_bin/find" + cat > "$path_bin/find" <<FAKE +#!/usr/bin/env bash +set -euo pipefail +if [ "\${1:-}" = --version ]; then + printf 'find (BSD)\n' + exit 0 +fi +for arg in "\$@"; do + if [ "\$arg" = -printf ]; then + printf 'find: unknown predicate -printf\n' >&2 + exit 2 + fi +done +exec "$real_find" "\$@" +FAKE + chmod 0755 "$path_bin/find" + + output=$( + cd "$TEST_TMPDIR" + PATH="$path_bin" test::capture_failure_output \ + "$TEST_SHURIKEN" --version + ) + + test::assert_contains 'does not report itself as GNU' "$output" + test::assert_contains 'Platform compatibility' "$output" + test::teardown +} + test_extra_args_fail() { test::assert_failure 'extra operand is rejected' "$TEST_SHURIKEN" --version extra test::assert_failure \ @@ -7747,6 +7834,12 @@ main() { 'GNU-tool guard rejects non-GNU stat' \ test_gnu_tool_guard_rejects_non_gnu_stat test::run_case \ + 'GNU-tool guard prefers a g-prefixed sibling tool' \ + test_gnu_tool_guard_prefers_g_prefixed_sibling + test::run_case \ + 'GNU-tool guard rejects a tool with a non-GNU version string' \ + test_gnu_tool_guard_rejects_non_gnu_version_string + test::run_case \ 'src/shuriken.sh lib source list matches Justfile LIB_SOURCES' \ test_lib_sources_match_justfile_lib_sources } |
