forked from lix-project/lix
tests: Add simple tests for nix-shell
nix-shell -A, -p and -i are lightly tested.
This commit is contained in:
parent
018f884ffd
commit
b501bea25f
|
@ -11,7 +11,7 @@ nix_tests = \
|
||||||
multiple-outputs.sh import-derivation.sh fetchurl.sh optimise-store.sh \
|
multiple-outputs.sh import-derivation.sh fetchurl.sh optimise-store.sh \
|
||||||
binary-cache.sh nix-profile.sh repair.sh dump-db.sh case-hack.sh \
|
binary-cache.sh nix-profile.sh repair.sh dump-db.sh case-hack.sh \
|
||||||
check-reqs.sh pass-as-file.sh tarball.sh restricted.sh \
|
check-reqs.sh pass-as-file.sh tarball.sh restricted.sh \
|
||||||
placeholders.sh
|
placeholders.sh nix-shell.sh
|
||||||
# parallel.sh
|
# parallel.sh
|
||||||
|
|
||||||
install-tests += $(foreach x, $(nix_tests), tests/$(x))
|
install-tests += $(foreach x, $(nix_tests), tests/$(x))
|
||||||
|
|
21
tests/nix-shell.sh
Normal file
21
tests/nix-shell.sh
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
source common.sh
|
||||||
|
|
||||||
|
clearStore
|
||||||
|
|
||||||
|
# Test nix-shell -A
|
||||||
|
export IMPURE_VAR=foo
|
||||||
|
output=$(nix-shell --pure shell.nix -A shellDrv --run \
|
||||||
|
'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX"')
|
||||||
|
|
||||||
|
[ "$output" = " - foo - bar" ]
|
||||||
|
|
||||||
|
# Test nix-shell -p
|
||||||
|
output=$(NIX_PATH=nixpkgs=shell.nix nix-shell --pure -p foo bar --run 'echo "$(foo) $(bar)"')
|
||||||
|
[ "$output" = "foo bar" ]
|
||||||
|
|
||||||
|
# Test nix-shell shebang mode
|
||||||
|
sed -e "s|@ENV_PROG@|$(type -p env)|" shell.shebang.sh > $TEST_ROOT/shell.shebang.sh
|
||||||
|
chmod a+rx $TEST_ROOT/shell.shebang.sh
|
||||||
|
|
||||||
|
output=$($TEST_ROOT/shell.shebang.sh)
|
||||||
|
[ "$output" = "foo bar" ]
|
46
tests/shell.nix
Normal file
46
tests/shell.nix
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
{ }:
|
||||||
|
|
||||||
|
with import ./config.nix;
|
||||||
|
|
||||||
|
rec {
|
||||||
|
setupSh = builtins.toFile "setup" ''
|
||||||
|
export VAR_FROM_STDENV_SETUP=foo
|
||||||
|
for pkg in $buildInputs; do
|
||||||
|
export PATH=$PATH:$pkg/bin
|
||||||
|
done
|
||||||
|
'';
|
||||||
|
|
||||||
|
stdenv = mkDerivation {
|
||||||
|
name = "stdenv";
|
||||||
|
buildCommand = ''
|
||||||
|
mkdir -p $out
|
||||||
|
ln -s ${setupSh} $out/setup
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
shellDrv = mkDerivation {
|
||||||
|
name = "shellDrv";
|
||||||
|
builder = "/does/not/exist";
|
||||||
|
VAR_FROM_NIX = "bar";
|
||||||
|
inherit stdenv;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Used by nix-shell -p
|
||||||
|
runCommand = name: args: buildCommand: mkDerivation (args // {
|
||||||
|
inherit name buildCommand stdenv;
|
||||||
|
});
|
||||||
|
|
||||||
|
foo = runCommand "foo" {} ''
|
||||||
|
mkdir -p $out/bin
|
||||||
|
echo 'echo foo' > $out/bin/foo
|
||||||
|
chmod a+rx $out/bin/foo
|
||||||
|
'';
|
||||||
|
|
||||||
|
bar = runCommand "bar" {} ''
|
||||||
|
mkdir -p $out/bin
|
||||||
|
echo 'echo bar' > $out/bin/bar
|
||||||
|
chmod a+rx $out/bin/bar
|
||||||
|
'';
|
||||||
|
|
||||||
|
bash = shell;
|
||||||
|
}
|
4
tests/shell.shebang.sh
Executable file
4
tests/shell.shebang.sh
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#! @ENV_PROG@ nix-shell
|
||||||
|
#! nix-shell -I nixpkgs=shell.nix --option use-binary-caches false
|
||||||
|
#! nix-shell --pure -i bash -p foo bar
|
||||||
|
echo "$(foo) $(bar)"
|
Loading…
Reference in a new issue