Problem
A fork census of ./bashunit --version (PATH shims over the usual binaries):
2 uname
1 tput
1 perl
1 dirname
Two of those five are avoidable, and every invocation pays them — including the
~258 nested runs the acceptance suite spawns.
uname twice.bashunit::check_os::init caches its result in
_BASHUNIT_UNAME, but it runs twice: once when src/system/check_os.sh is
sourced (its last line) and again from the entrypoint. On Linux the second run
also re-runs is_nixos, which greps /etc/os-release, so it is up to two
extra forks there.
dirname once.declare -r BASHUNIT_ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")"
is a command substitution plus a dirname. ${BASH_SOURCE[0]%/*} does the same
thing, with a guard for the no-slash case (invoked as a bare name), which is
the only case where the two differ.
Fix
Make check_os::init idempotent — cheaper than deciding which of the two call
sites is the right one to delete, and it keeps any future caller honest — and
replace the dirname with parameter expansion.
tput and perl stay: tput cols decides snapshot width and perl is the
clock on Bash < 5, both already documented as irreducible.
Problem
A fork census of
./bashunit --version(PATH shims over the usual binaries):Two of those five are avoidable, and every invocation pays them — including the
~258 nested runs the acceptance suite spawns.
unametwice.bashunit::check_os::initcaches its result in_BASHUNIT_UNAME, but it runs twice: once whensrc/system/check_os.shissourced (its last line) and again from the entrypoint. On Linux the second run
also re-runs
is_nixos, which greps/etc/os-release, so it is up to twoextra forks there.
dirnameonce.declare -r BASHUNIT_ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")"is a command substitution plus a
dirname.${BASH_SOURCE[0]%/*}does the samething, with a guard for the no-slash case (invoked as a bare name), which is
the only case where the two differ.
Fix
Make
check_os::initidempotent — cheaper than deciding which of the two callsites is the right one to delete, and it keeps any future caller honest — and
replace the
dirnamewith parameter expansion.tputandperlstay:tput colsdecides snapshot width andperlis theclock on Bash < 5, both already documented as irreducible.