mirror of
https://github.com/NixOS/nix
synced 2024-10-18 00:16:11 -04:00
test(functional): add tests for new environment operation flags
Refs: nixos/nix#10795
This commit is contained in:
parent
d68b2a7c1b
commit
a3aaa573c4
|
@ -552,7 +552,6 @@
|
|||
''^tests/functional/flakes/check\.sh$''
|
||||
''^tests/functional/flakes/common\.sh$''
|
||||
''^tests/functional/flakes/config\.sh$''
|
||||
''^tests/functional/flakes/develop\.sh$''
|
||||
''^tests/functional/flakes/flakes\.sh$''
|
||||
''^tests/functional/flakes/follow-paths\.sh$''
|
||||
''^tests/functional/flakes/prefetch\.sh$''
|
||||
|
|
|
@ -5,11 +5,11 @@ source ../common.sh
|
|||
TODO_NixOS
|
||||
|
||||
clearStore
|
||||
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
|
||||
rm -rf "$TEST_HOME/.cache" "$TEST_HOME/.config" "$TEST_HOME/.local"
|
||||
|
||||
# Create flake under test.
|
||||
cp ../shell-hello.nix ../config.nix $TEST_HOME/
|
||||
cat <<EOF >$TEST_HOME/flake.nix
|
||||
cp ../shell-hello.nix ../config.nix "$TEST_HOME/"
|
||||
cat <<EOF >"$TEST_HOME/flake.nix"
|
||||
{
|
||||
inputs.nixpkgs.url = "$TEST_HOME/nixpkgs";
|
||||
outputs = {self, nixpkgs}: {
|
||||
|
@ -24,9 +24,9 @@ cat <<EOF >$TEST_HOME/flake.nix
|
|||
EOF
|
||||
|
||||
# Create fake nixpkgs flake.
|
||||
mkdir -p $TEST_HOME/nixpkgs
|
||||
cp ../config.nix ../shell.nix $TEST_HOME/nixpkgs
|
||||
cat <<EOF >$TEST_HOME/nixpkgs/flake.nix
|
||||
mkdir -p "$TEST_HOME/nixpkgs"
|
||||
cp ../config.nix ../shell.nix "$TEST_HOME/nixpkgs"
|
||||
cat <<EOF >"$TEST_HOME/nixpkgs/flake.nix"
|
||||
{
|
||||
outputs = {self}: {
|
||||
legacyPackages.$system.bashInteractive = (import ./shell.nix {}).bashInteractive;
|
||||
|
@ -34,7 +34,7 @@ cat <<EOF >$TEST_HOME/nixpkgs/flake.nix
|
|||
}
|
||||
EOF
|
||||
|
||||
cd $TEST_HOME
|
||||
cd "$TEST_HOME"
|
||||
|
||||
# Test whether `nix develop` passes through environment variables.
|
||||
[[ "$(
|
||||
|
@ -50,6 +50,85 @@ echo "\$ENVVAR"
|
|||
EOF
|
||||
)" ]]
|
||||
|
||||
# Test wether `--keep-env-var` keeps the environment variable.
|
||||
(
|
||||
expect='BAR'
|
||||
got="$(FOO='BAR' nix develop --ignore-env --keep-env-var FOO --no-write-lock-file .#hello <<EOF
|
||||
echo "\$FOO"
|
||||
EOF
|
||||
)"
|
||||
[[ "$got" == "$expect" ]]
|
||||
)
|
||||
|
||||
# Test wether `--set-env-var` sets the environment variable.
|
||||
(
|
||||
expect='BAR'
|
||||
got="$(nix develop --ignore-env --set-env-var FOO 'BAR' --no-write-lock-file .#hello <<EOF
|
||||
echo "\$FOO"
|
||||
EOF
|
||||
)"
|
||||
[[ "$got" == "$expect" ]]
|
||||
)
|
||||
|
||||
# Test wether multiple `--unset-env-var` and `--set-env-var` cancle out
|
||||
(
|
||||
expect=''
|
||||
got="$(nix develop --set-env-var FOO 'BAR' --unset-env-var FOO --no-write-lock-file .#hello <<EOF
|
||||
echo "\$FOO"
|
||||
EOF
|
||||
)"
|
||||
[[ "$got" == "$expect" ]]
|
||||
)
|
||||
|
||||
# Test that `--unset-env-var` unsets the variable, regardless of where in the command it is.
|
||||
(
|
||||
expect=''
|
||||
got="$(nix develop --set-env-var FOO 'BAR' --unset-env-var FOO --set-env-var FOO 'BLA' --no-write-lock-file .#hello <<EOF
|
||||
echo "\$FOO"
|
||||
EOF
|
||||
)"
|
||||
[[ "$got" == "$expect" ]]
|
||||
)
|
||||
|
||||
# Test that `--set-env-var` overwrites previously set variables.
|
||||
(
|
||||
expect='BLA'
|
||||
got="$(nix develop --set-env-var FOO 'BAR' --set-env-var FOO 'BLA' --no-write-lock-file .#hello <<EOF
|
||||
echo "\$FOO"
|
||||
EOF
|
||||
)"
|
||||
[[ "$got" == "$expect" ]]
|
||||
)
|
||||
|
||||
# Test that `--set-env-var` overwrites previously set variables.
|
||||
(
|
||||
expect='BLA'
|
||||
got="$(FOO='BAR' nix develop --set-env-var FOO 'BLA' --no-write-lock-file .#hello <<EOF
|
||||
echo "\$FOO"
|
||||
EOF
|
||||
)"
|
||||
[[ "$got" == "$expect" ]]
|
||||
)
|
||||
|
||||
# Test that multiple `--set-env-var` work.
|
||||
(
|
||||
expect='BARFOO'
|
||||
got="$(nix develop --set-env-var FOO 'BAR' --set-env-var BAR 'FOO' --no-write-lock-file .#hello <<EOF | tr -d '\n'
|
||||
echo "\$FOO"
|
||||
echo "\$BAR"
|
||||
EOF
|
||||
)"
|
||||
[[ "$got" == "$expect" ]]
|
||||
)
|
||||
|
||||
# Check that we throw an error when `--keep-env-var` is used without `--ignore-env`.
|
||||
expectStderr 1 nix develop --keep-env-var FOO .#hello |
|
||||
grepQuiet "error: --keep-env-var does not make sense without --ignore-env"
|
||||
|
||||
# Check that we throw an error when `--unset-env-var` is used with `--ignore-env`.
|
||||
expectStderr 1 nix develop --ignore-env --unset-env-var FOO .#hello |
|
||||
grepQuiet "error: --unset-env-var does not make sense with --ignore-env"
|
||||
|
||||
# Determine the bashInteractive executable.
|
||||
nix build --no-write-lock-file './nixpkgs#bashInteractive' --out-link ./bash-interactive
|
||||
BASH_INTERACTIVE_EXECUTABLE="$PWD/bash-interactive/bin/bash"
|
||||
|
|
Loading…
Reference in a new issue