aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/binary-cache.sh2
-rw-r--r--tests/ca/substitute.sh10
-rw-r--r--tests/common.sh12
-rw-r--r--tests/common/vars-and-functions.sh.in (renamed from tests/common.sh.in)43
-rw-r--r--tests/db-migration.sh1
-rw-r--r--tests/fetchGit.sh14
-rw-r--r--tests/flakes/inputs.sh80
-rwxr-xr-x[-rw-r--r--]tests/init.sh7
-rw-r--r--tests/installer/default.nix2
-rw-r--r--tests/lang/eval-fail-foldlStrict-strict-op-application.nix5
-rw-r--r--tests/lang/eval-okay-foldlStrict-lazy-elements.exp1
-rw-r--r--tests/lang/eval-okay-foldlStrict-lazy-elements.nix9
-rw-r--r--tests/lang/eval-okay-foldlStrict-lazy-initial-accumulator.exp1
-rw-r--r--tests/lang/eval-okay-foldlStrict-lazy-initial-accumulator.nix6
-rw-r--r--tests/local.mk6
-rw-r--r--tests/nix-profile.sh30
-rw-r--r--tests/nix_path.sh5
-rw-r--r--tests/post-hook.sh8
-rwxr-xr-xtests/push-to-store-old.sh10
-rwxr-xr-xtests/push-to-store.sh2
-rw-r--r--tests/restricted.sh3
21 files changed, 221 insertions, 36 deletions
diff --git a/tests/binary-cache.sh b/tests/binary-cache.sh
index 0361ac6a8..b38db8a15 100644
--- a/tests/binary-cache.sh
+++ b/tests/binary-cache.sh
@@ -23,7 +23,7 @@ nix log $outPath 2>&1 | grep 'is not available'
nix log --substituters file://$cacheDir $outPath | grep FOO
# Test copying build logs from the binary cache.
-nix store copy-log --from file://$cacheDir $(nix-store -qd $outPath)
+nix store copy-log --from file://$cacheDir $(nix-store -qd $outPath)^'*'
nix log $outPath | grep FOO
basicDownloadTests() {
diff --git a/tests/ca/substitute.sh b/tests/ca/substitute.sh
index 819f3fd85..ea981adc4 100644
--- a/tests/ca/substitute.sh
+++ b/tests/ca/substitute.sh
@@ -28,6 +28,12 @@ nix realisation info --file ./content-addressed.nix transitivelyDependentCA
nix realisation info --file ./content-addressed.nix dependentCA
# nix realisation info --file ./content-addressed.nix rootCA --outputs out
+if isDaemonNewer "2.13"; then
+ pushToStore="../push-to-store.sh"
+else
+ pushToStore="../push-to-store-old.sh"
+fi
+
# Same thing, but
# 1. With non-ca derivations
# 2. Erasing the realisations on the remote store
@@ -37,7 +43,7 @@ nix realisation info --file ./content-addressed.nix dependentCA
#
# Regression test for #4725
clearStore
-nix build --file ../simple.nix -L --no-link --post-build-hook ../push-to-store.sh
+nix build --file ../simple.nix -L --no-link --post-build-hook "$pushToStore"
clearStore
rm -r "$REMOTE_STORE_DIR/realisations"
nix build --file ../simple.nix -L --no-link --substitute --substituters "$REMOTE_STORE" --no-require-sigs -j0
@@ -52,7 +58,7 @@ if [[ -z "$(ls "$REMOTE_STORE_DIR/realisations")" ]]; then
fi
# Test the local realisation disk cache
-buildDrvs --post-build-hook ../push-to-store.sh
+buildDrvs --post-build-hook "$pushToStore"
clearStore
# Add the realisations of rootCA to the cachecache
clearCacheCache
diff --git a/tests/common.sh b/tests/common.sh
new file mode 100644
index 000000000..68b90a85f
--- /dev/null
+++ b/tests/common.sh
@@ -0,0 +1,12 @@
+set -e
+
+if [[ -z "${COMMON_SH_SOURCED-}" ]]; then
+
+COMMON_SH_SOURCED=1
+
+source "$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")/common/vars-and-functions.sh"
+if [[ -n "${NIX_DAEMON_PACKAGE:-}" ]]; then
+ startDaemon
+fi
+
+fi # COMMON_SH_SOURCED
diff --git a/tests/common.sh.in b/tests/common/vars-and-functions.sh.in
index 939f2fce1..0deef4c1c 100644
--- a/tests/common.sh.in
+++ b/tests/common/vars-and-functions.sh.in
@@ -1,8 +1,8 @@
set -e
-if [[ -z "$COMMON_SH_SOURCED" ]]; then
+if [[ -z "${COMMON_VARS_AND_FUNCTIONS_SH_SOURCED-}" ]]; then
-COMMON_SH_SOURCED=1
+COMMON_VARS_AND_FUNCTIONS_SH_SOURCED=1
export PS4='+(${BASH_SOURCE[0]}:$LINENO) '
@@ -25,7 +25,7 @@ if [[ -n $NIX_STORE ]]; then
fi
export _NIX_IN_TEST=$TEST_ROOT/shared
export _NIX_TEST_NO_LSOF=1
-export NIX_REMOTE=$NIX_REMOTE_
+export NIX_REMOTE=${NIX_REMOTE_-}
unset NIX_PATH
export TEST_HOME=$TEST_ROOT/test-home
export HOME=$TEST_HOME
@@ -90,13 +90,14 @@ clearCacheCache() {
startDaemon() {
# Don’t start the daemon twice, as this would just make it loop indefinitely
- if [[ "$NIX_REMOTE" == daemon ]]; then
- return
+ if [[ "${_NIX_TEST_DAEMON_PID-}" != '' ]]; then
+ return
fi
# Start the daemon, wait for the socket to appear.
rm -f $NIX_DAEMON_SOCKET_PATH
- PATH=$DAEMON_PATH nix-daemon&
- pidDaemon=$!
+ PATH=$DAEMON_PATH nix-daemon &
+ _NIX_TEST_DAEMON_PID=$!
+ export _NIX_TEST_DAEMON_PID
for ((i = 0; i < 300; i++)); do
if [[ -S $NIX_DAEMON_SOCKET_PATH ]]; then
DAEMON_STARTED=1
@@ -108,25 +109,35 @@ startDaemon() {
fail "Didn’t manage to start the daemon"
fi
trap "killDaemon" EXIT
+ # Save for if daemon is killed
+ NIX_REMOTE_OLD=$NIX_REMOTE
export NIX_REMOTE=daemon
}
killDaemon() {
- kill $pidDaemon
+ # Don’t fail trying to stop a non-existant daemon twice
+ if [[ "${_NIX_TEST_DAEMON_PID-}" == '' ]]; then
+ return
+ fi
+ kill $_NIX_TEST_DAEMON_PID
for i in {0..100}; do
- kill -0 $pidDaemon 2> /dev/null || break
+ kill -0 $_NIX_TEST_DAEMON_PID 2> /dev/null || break
sleep 0.1
done
- kill -9 $pidDaemon 2> /dev/null || true
- wait $pidDaemon || true
+ kill -9 $_NIX_TEST_DAEMON_PID 2> /dev/null || true
+ wait $_NIX_TEST_DAEMON_PID || true
+ rm -f $NIX_DAEMON_SOCKET_PATH
+ # Indicate daemon is stopped
+ unset _NIX_TEST_DAEMON_PID
+ # Restore old nix remote
+ NIX_REMOTE=$NIX_REMOTE_OLD
trap "" EXIT
}
restartDaemon() {
- [[ -z "${pidDaemon:-}" ]] && return 0
+ [[ -z "${_NIX_TEST_DAEMON_PID:-}" ]] && return 0
killDaemon
- unset NIX_REMOTE
startDaemon
}
@@ -190,10 +201,6 @@ enableFeatures() {
set -x
-if [[ -n "${NIX_DAEMON_PACKAGE:-}" ]]; then
- startDaemon
-fi
-
onError() {
set +x
echo "$0: test failed at:" >&2
@@ -205,4 +212,4 @@ onError() {
trap onError ERR
-fi # COMMON_SH_SOURCED
+fi # COMMON_VARS_AND_FUNCTIONS_SH_SOURCED
diff --git a/tests/db-migration.sh b/tests/db-migration.sh
index 3f9dc8972..92dd4f3ba 100644
--- a/tests/db-migration.sh
+++ b/tests/db-migration.sh
@@ -9,7 +9,6 @@ fi
source common.sh
killDaemon
-unset NIX_REMOTE
# Fill the db using the older Nix
PATH_WITH_NEW_NIX="$PATH"
diff --git a/tests/fetchGit.sh b/tests/fetchGit.sh
index da09c3f37..a7a8df186 100644
--- a/tests/fetchGit.sh
+++ b/tests/fetchGit.sh
@@ -237,3 +237,17 @@ rm -rf $repo/.git
# should succeed for a repo without commits
git init $repo
path10=$(nix eval --impure --raw --expr "(builtins.fetchGit \"file://$repo\").outPath")
+
+# should succeed for a path with a space
+# regression test for #7707
+repo="$TEST_ROOT/a b"
+git init "$repo"
+git -C "$repo" config user.email "foobar@example.com"
+git -C "$repo" config user.name "Foobar"
+
+echo utrecht > "$repo/hello"
+touch "$repo/.gitignore"
+git -C "$repo" add hello .gitignore
+git -C "$repo" commit -m 'Bla1'
+cd "$repo"
+path11=$(nix eval --impure --raw --expr "(builtins.fetchGit ./.).outPath")
diff --git a/tests/flakes/inputs.sh b/tests/flakes/inputs.sh
new file mode 100644
index 000000000..80620488a
--- /dev/null
+++ b/tests/flakes/inputs.sh
@@ -0,0 +1,80 @@
+source ./common.sh
+
+requireGit
+
+
+test_subdir_self_path() {
+ baseDir=$TEST_ROOT/$RANDOM
+ flakeDir=$baseDir/b-low
+ mkdir -p $flakeDir
+ writeSimpleFlake $baseDir
+ writeSimpleFlake $flakeDir
+
+ echo all good > $flakeDir/message
+ cat > $flakeDir/flake.nix <<EOF
+{
+ outputs = inputs: rec {
+ packages.$system = rec {
+ default =
+ assert builtins.readFile ./message == "all good\n";
+ assert builtins.readFile (inputs.self + "/message") == "all good\n";
+ import ./simple.nix;
+ };
+ };
+}
+EOF
+ (
+ nix build $baseDir?dir=b-low --no-link
+ )
+}
+test_subdir_self_path
+
+
+test_git_subdir_self_path() {
+ repoDir=$TEST_ROOT/repo-$RANDOM
+ createGitRepo $repoDir
+ flakeDir=$repoDir/b-low
+ mkdir -p $flakeDir
+ writeSimpleFlake $repoDir
+ writeSimpleFlake $flakeDir
+
+ echo all good > $flakeDir/message
+ cat > $flakeDir/flake.nix <<EOF
+{
+ outputs = inputs: rec {
+ packages.$system = rec {
+ default =
+ assert builtins.readFile ./message == "all good\n";
+ assert builtins.readFile (inputs.self + "/message") == "all good\n";
+ assert inputs.self.outPath == inputs.self.sourceInfo.outPath + "/b-low";
+ import ./simple.nix;
+ };
+ };
+}
+EOF
+ (
+ cd $flakeDir
+ git add .
+ git commit -m init
+ # nix build
+ )
+
+ clientDir=$TEST_ROOT/client-$RANDOM
+ mkdir -p $clientDir
+ cat > $clientDir/flake.nix <<EOF
+{
+ inputs.inp = {
+ type = "git";
+ url = "file://$repoDir";
+ dir = "b-low";
+ };
+
+ outputs = inputs: rec {
+ packages = inputs.inp.packages;
+ };
+}
+EOF
+ nix build $clientDir --no-link
+
+}
+test_git_subdir_self_path
diff --git a/tests/init.sh b/tests/init.sh
index 3c6d5917d..fea659516 100644..100755
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -1,8 +1,13 @@
-source common.sh
+set -eu -o pipefail
+
+# Don't start the daemon
+source common/vars-and-functions.sh
test -n "$TEST_ROOT"
if test -d "$TEST_ROOT"; then
chmod -R u+w "$TEST_ROOT"
+ # We would delete any daemon socket, so let's stop the daemon first.
+ killDaemon
rm -rf "$TEST_ROOT"
fi
mkdir "$TEST_ROOT"
diff --git a/tests/installer/default.nix b/tests/installer/default.nix
index 32aa7889a..31d83699d 100644
--- a/tests/installer/default.nix
+++ b/tests/installer/default.nix
@@ -120,7 +120,7 @@ let
makeTest = imageName: testName:
let image = images.${imageName}; in
- with nixpkgsFor.${image.system};
+ with nixpkgsFor.${image.system}.native;
runCommand
"installer-test-${imageName}-${testName}"
{ buildInputs = [ qemu_kvm openssh ];
diff --git a/tests/lang/eval-fail-foldlStrict-strict-op-application.nix b/tests/lang/eval-fail-foldlStrict-strict-op-application.nix
new file mode 100644
index 000000000..1620cc76e
--- /dev/null
+++ b/tests/lang/eval-fail-foldlStrict-strict-op-application.nix
@@ -0,0 +1,5 @@
+# Tests that the result of applying op is forced even if the value is never used
+builtins.foldl'
+ (_: f: f null)
+ null
+ [ (_: throw "Not the final value, but is still forced!") (_: 23) ]
diff --git a/tests/lang/eval-okay-foldlStrict-lazy-elements.exp b/tests/lang/eval-okay-foldlStrict-lazy-elements.exp
new file mode 100644
index 000000000..d81cc0710
--- /dev/null
+++ b/tests/lang/eval-okay-foldlStrict-lazy-elements.exp
@@ -0,0 +1 @@
+42
diff --git a/tests/lang/eval-okay-foldlStrict-lazy-elements.nix b/tests/lang/eval-okay-foldlStrict-lazy-elements.nix
new file mode 100644
index 000000000..c666e07f3
--- /dev/null
+++ b/tests/lang/eval-okay-foldlStrict-lazy-elements.nix
@@ -0,0 +1,9 @@
+# Tests that the rhs argument of op is not forced unconditionally
+let
+ lst = builtins.foldl'
+ (acc: x: acc ++ [ x ])
+ [ ]
+ [ 42 (throw "this shouldn't be evaluated") ];
+in
+
+builtins.head lst
diff --git a/tests/lang/eval-okay-foldlStrict-lazy-initial-accumulator.exp b/tests/lang/eval-okay-foldlStrict-lazy-initial-accumulator.exp
new file mode 100644
index 000000000..d81cc0710
--- /dev/null
+++ b/tests/lang/eval-okay-foldlStrict-lazy-initial-accumulator.exp
@@ -0,0 +1 @@
+42
diff --git a/tests/lang/eval-okay-foldlStrict-lazy-initial-accumulator.nix b/tests/lang/eval-okay-foldlStrict-lazy-initial-accumulator.nix
new file mode 100644
index 000000000..abcd5366a
--- /dev/null
+++ b/tests/lang/eval-okay-foldlStrict-lazy-initial-accumulator.nix
@@ -0,0 +1,6 @@
+# Checks that the nul value for the accumulator is not forced unconditionally.
+# Some languages provide a foldl' that is strict in this argument, but Nix does not.
+builtins.foldl'
+ (_: x: x)
+ (throw "This is never forced")
+ [ "but the results of applying op are" 42 ]
diff --git a/tests/local.mk b/tests/local.mk
index b3135fd4d..4a620f18b 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -1,9 +1,11 @@
nix_tests = \
+ init.sh \
flakes/flakes.sh \
flakes/run.sh \
flakes/mercurial.sh \
flakes/circular.sh \
flakes/init.sh \
+ flakes/inputs.sh \
flakes/follow-paths.sh \
flakes/bundle.sh \
flakes/check.sh \
@@ -128,9 +130,9 @@ endif
install-tests += $(foreach x, $(nix_tests), tests/$(x))
-clean-files += $(d)/common.sh $(d)/config.nix $(d)/ca/config.nix
+clean-files += $(d)/tests/common/vars-and-functions.sh $(d)/config.nix $(d)/ca/config.nix
-test-deps += tests/common.sh tests/config.nix tests/ca/config.nix
+test-deps += tests/common/vars-and-functions.sh tests/config.nix tests/ca/config.nix tests/plugins/libplugintest.$(SO_EXT)
ifeq ($(BUILD_SHARED_LIBS), 1)
test-deps += tests/plugins/libplugintest.$(SO_EXT)
diff --git a/tests/nix-profile.sh b/tests/nix-profile.sh
index 266dc9e49..652e8a8f2 100644
--- a/tests/nix-profile.sh
+++ b/tests/nix-profile.sh
@@ -140,6 +140,36 @@ printf World2 > $flake2Dir/who
nix profile install $flake1Dir
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
+expect 1 nix profile install $flake2Dir
+diff -u <(
+ nix --offline profile install $flake2Dir 2>&1 1> /dev/null \
+ | grep -vE "^warning: " \
+ || true
+) <(cat << EOF
+error: An existing package already provides the following file:
+
+ $(nix build --no-link --print-out-paths ${flake1Dir}"#default.out")/bin/hello
+
+ This is the conflicting file from the new package:
+
+ $(nix build --no-link --print-out-paths ${flake2Dir}"#default.out")/bin/hello
+
+ To remove the existing package:
+
+ nix profile remove path:${flake1Dir}
+
+ The new package can also be installed next to the existing one by assigning a different priority.
+ The conflicting packages have a priority of 5.
+ To prioritise the new package:
+
+ nix profile install path:${flake2Dir} --priority 4
+
+ To prioritise the existing package:
+
+ nix profile install path:${flake2Dir} --priority 6
+EOF
+)
+[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
nix profile install $flake2Dir --priority 100
[[ $($TEST_HOME/.nix-profile/bin/hello) = "Hello World" ]]
nix profile install $flake2Dir --priority 0
diff --git a/tests/nix_path.sh b/tests/nix_path.sh
index d16fb4bb2..2b222b4a1 100644
--- a/tests/nix_path.sh
+++ b/tests/nix_path.sh
@@ -12,8 +12,3 @@ nix-instantiate --eval -E '<by-relative-path/simple.nix>' --restrict-eval
[[ $(nix-instantiate --find-file by-absolute-path/simple.nix) = $PWD/simple.nix ]]
[[ $(nix-instantiate --find-file by-relative-path/simple.nix) = $PWD/simple.nix ]]
-
-unset NIX_PATH
-
-[[ $(nix-instantiate --option nix-path by-relative-path=. --find-file by-relative-path/simple.nix) = "$PWD/simple.nix" ]]
-[[ $(NIX_PATH= nix-instantiate --option nix-path by-relative-path=. --find-file by-relative-path/simple.nix) = "$PWD/simple.nix" ]]
diff --git a/tests/post-hook.sh b/tests/post-hook.sh
index 4eff5f511..0266eb15d 100644
--- a/tests/post-hook.sh
+++ b/tests/post-hook.sh
@@ -9,8 +9,14 @@ echo 'require-sigs = false' >> $NIX_CONF_DIR/nix.conf
restartDaemon
+if isDaemonNewer "2.13"; then
+ pushToStore="$PWD/push-to-store.sh"
+else
+ pushToStore="$PWD/push-to-store-old.sh"
+fi
+
# Build the dependencies and push them to the remote store.
-nix-build -o $TEST_ROOT/result dependencies.nix --post-build-hook $PWD/push-to-store.sh
+nix-build -o $TEST_ROOT/result dependencies.nix --post-build-hook "$pushToStore"
clearStore
diff --git a/tests/push-to-store-old.sh b/tests/push-to-store-old.sh
new file mode 100755
index 000000000..b1495c9e2
--- /dev/null
+++ b/tests/push-to-store-old.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+set -x
+set -e
+
+[ -n "$OUT_PATHS" ]
+[ -n "$DRV_PATH" ]
+
+echo Pushing "$OUT_PATHS" to "$REMOTE_STORE"
+printf "%s" "$DRV_PATH" | xargs nix copy --to "$REMOTE_STORE" --no-require-sigs
diff --git a/tests/push-to-store.sh b/tests/push-to-store.sh
index b1495c9e2..0b090e1b3 100755
--- a/tests/push-to-store.sh
+++ b/tests/push-to-store.sh
@@ -7,4 +7,4 @@ set -e
[ -n "$DRV_PATH" ]
echo Pushing "$OUT_PATHS" to "$REMOTE_STORE"
-printf "%s" "$DRV_PATH" | xargs nix copy --to "$REMOTE_STORE" --no-require-sigs
+printf "%s" "$DRV_PATH"^'*' | xargs nix copy --to "$REMOTE_STORE" --no-require-sigs
diff --git a/tests/restricted.sh b/tests/restricted.sh
index 3b6ee2af1..9bd16cf51 100644
--- a/tests/restricted.sh
+++ b/tests/restricted.sh
@@ -17,9 +17,6 @@ nix-instantiate --restrict-eval --eval -E 'builtins.readDir ../src/nix-channel'
(! nix-instantiate --restrict-eval --eval -E 'let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in <foo>')
nix-instantiate --restrict-eval --eval -E 'let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in <foo>' -I src=.
-# no default NIX_PATH
-(unset NIX_PATH; ! nix-instantiate --restrict-eval --find-file .)
-
p=$(nix eval --raw --expr "builtins.fetchurl file://$(pwd)/restricted.sh" --impure --restrict-eval --allowed-uris "file://$(pwd)")
cmp $p restricted.sh