Files
nix/tests/functional/gc-runtime.sh
Artemis Tosini 9e8cf9055a tests/gc-functional: fix running on NixOS
This test insisted on placing profiles in NIX_STATE_DIR, but all
packages were removed from the profile immediately after so they did not
act as garbage collector roots. Switch to directly calling nix-build,
allowing the test to run in VMs without NIX_STATE_DIR.
2026-01-30 11:52:34 -05:00

45 lines
875 B
Bash
Executable File

#!/usr/bin/env bash
source common.sh
case $system in
*linux*)
;;
*)
skipTest "Not running Linux";
esac
set -m # enable job control, needed for kill
programPath=$(nix-build --no-link ./gc-runtime.nix -A program)
environPath=$(nix-build --no-link ./gc-runtime.nix -A environ)
openPath=$(nix-build --no-link ./gc-runtime.nix -A open)
echo "backgrounding program..."
export environPath
"$programPath"/program "$openPath"/open &
sleep 2 # hack - wait for the program to get started
child=$!
echo PID=$child
nix-store --gc
kill -- -$child
if ! test -e "$programPath"; then
echo "running program was garbage collected!"
exit 1
fi
if ! test -e "$environPath"; then
echo "file in environment variable was garbage collected!"
exit 1
fi
if ! test -e "$openPath"; then
echo "opened file was garbage collected!"
exit 1
fi
exit 0