Use $TEST_ROOT

This commit is contained in:
Lazar Bodor 2023-03-14 01:48:12 +11:00
parent e210de4799
commit a3a6909bc8

View file

@ -95,17 +95,11 @@ nix develop -f "$shellDotNix" shellDrv -c echo foo |& grepQuiet foo
# Test 'nix print-dev-env'. # Test 'nix print-dev-env'.
scratch=$(mktemp -d -t tmp.XXXXXXXXXX) nix print-dev-env -f "$shellDotNix" shellDrv > $TEST_ROOT/dev-env.sh
function finish { nix print-dev-env -f "$shellDotNix" shellDrv --json > $TEST_ROOT/dev-env.json
rm -rf "$scratch"
}
trap finish EXIT
nix print-dev-env -f "$shellDotNix" shellDrv > "$scratch/dev-env.sh"
nix print-dev-env -f "$shellDotNix" shellDrv --json > "$scratch/dev-env.json"
# Ensure `nix print-dev-env --json` contains variable assignments. # Ensure `nix print-dev-env --json` contains variable assignments.
[[ $(jq -r .variables.arr1.value[2] "$scratch/dev-env.json") = '3 4' ]] [[ $(jq -r .variables.arr1.value[2] $TEST_ROOT/dev-env.json) = '3 4' ]]
# Run tests involving `source <(nix print-dev-inv)` in subshells to avoid modifying the current # Run tests involving `source <(nix print-dev-inv)` in subshells to avoid modifying the current
# environment. # environment.
@ -115,21 +109,21 @@ set +u # FIXME: Make print-dev-env `set -u` compliant (issue #7951)
# Ensure `source <(nix print-dev-env)` modifies the environment. # Ensure `source <(nix print-dev-env)` modifies the environment.
( (
path=$PATH path=$PATH
source "$scratch/dev-env.sh" source $TEST_ROOT/dev-env.sh
[[ -n $stdenv ]] [[ -n $stdenv ]]
[[ ${arr1[2]} = "3 4" ]] [[ ${arr1[2]} = "3 4" ]]
[[ ${arr2[1]} = $'\n' ]] [[ ${arr2[1]} = $'\n' ]]
[[ ${arr2[2]} = $'x\ny' ]] [[ ${arr2[2]} = $'x\ny' ]]
[[ $(fun) = blabla ]] [[ $(fun) = blabla ]]
[[ $PATH = $(jq -r .variables.PATH.value "$scratch/dev-env.json"):$path ]] [[ $PATH = $(jq -r .variables.PATH.value $TEST_ROOT/dev-env.json):$path ]]
) )
# Ensure `source <(nix print-dev-env)` handles the case when PATH is empty. # Ensure `source <(nix print-dev-env)` handles the case when PATH is empty.
( (
path=$PATH path=$PATH
PATH= PATH=
source "$scratch/dev-env.sh" source $TEST_ROOT/dev-env.sh
[[ $PATH = $(PATH=$path jq -r .variables.PATH.value "$scratch/dev-env.json") ]] [[ $PATH = $(PATH=$path jq -r .variables.PATH.value $TEST_ROOT/dev-env.json) ]]
) )
# Test nix-shell with ellipsis and no `inNixShell` argument (for backwards compat with old nixpkgs) # Test nix-shell with ellipsis and no `inNixShell` argument (for backwards compat with old nixpkgs)