tests/functional: Enable more tests in NixOS VM

This commit is contained in:
Robert Hensing 2024-06-16 17:56:50 +02:00
parent f0abe4d8f0
commit 648302b833
38 changed files with 71 additions and 104 deletions

View file

@ -31,9 +31,7 @@ test "$hash1" = "sha256:$hash2"
#### New style commands
TODO_NixOS
clearStore
clearStoreIfPossible
(
path1=$(nix store add ./dummy)

View file

@ -4,7 +4,7 @@ source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
clearCacheCache
# Fails without remote builders

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
# https://github.com/NixOS/nix/issues/6572
issue_6572_independent_outputs() {

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
# Make sure that 'nix build' returns all outputs by default.
nix build -f multiple-outputs.nix --json a b --no-link | jq --exit-status '

View file

@ -45,13 +45,18 @@ nix-build -o "$RESULT" check-refs.nix -A test7
# test10 should succeed (no disallowed references).
nix-build -o "$RESULT" check-refs.nix -A test10
if isDaemonNewer 2.12pre20230103; then
if ! isDaemonNewer 2.16.0; then
enableFeatures discard-references
restartDaemon
if ! isTestOnNixOS; then
# If we have full control over our store, we can test some more things.
if isDaemonNewer 2.12pre20230103; then
if ! isDaemonNewer 2.16.0; then
enableFeatures discard-references
restartDaemon
fi
# test11 should succeed.
test11=$(nix-build -o "$RESULT" check-refs.nix -A test11)
[[ -z $(nix-store -q --references "$test11") ]]
fi
# test11 should succeed.
test11=$(nix-build -o "$RESULT" check-refs.nix -A test11)
[[ -z $(nix-store -q --references "$test11") ]]
fi

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
RESULT=$TEST_ROOT/result

View file

@ -82,11 +82,25 @@ clearProfiles() {
rm -rf "$profiles"
}
# Clear the store, but do not fail if we're in an environment where we can't.
# This allows the test to run in a NixOS test environment, where we use the system store.
# See doc/manual/src/contributing/testing.md / Running functional tests on NixOS.
clearStoreIfPossible() {
if isTestOnNixOS; then
echo "clearStoreIfPossible: Not clearing store, because we're on NixOS. Moving on."
else
doClearStore
fi
}
clearStore() {
if isTestOnNixOS; then
die "clearStore: not supported when testing on NixOS. Is it really needed? If so add conditionals; e.g. if ! isTestOnNixOS; then ..."
die "clearStore: not supported when testing on NixOS. If not essential, call clearStoreIfPossible. If really needed, add conditionals; e.g. if ! isTestOnNixOS; then ..."
fi
doClearStore
}
doClearStore() {
echo "clearing store..."
chmod -R +w "$NIX_STORE_DIR"
rm -rf "$NIX_STORE_DIR"

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
clearCache
outPath=$(nix-build dependencies.nix --no-out-link)

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
# regression #9932
echo ":env" | expect 1 nix eval --debugger --expr '(_: throw "oh snap") 42'

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
drvPath=$(nix-instantiate dependencies.nix)
@ -67,6 +65,8 @@ drvPath2=$(nix-instantiate dependencies.nix --argstr hashInvalidator yay)
# now --valid-derivers returns both
test "$(nix-store -q --valid-derivers "$outPath" | sort)" = "$(sort <<< "$drvPath"$'\n'"$drvPath2")"
TODO_NixOS # The following --delete fails, because it seems to be still alive. This might be caused by a different test using the same path. We should try make the derivations unique, e.g. naming after tests, and adding a timestamp that's constant for that test script run.
# check that nix-store --valid-derivers only returns existing drv
nix-store --delete "$drvPath"
test "$(nix-store -q --valid-derivers "$outPath")" = "$drvPath2"

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
testStdinHeredoc=$(nix eval -f - <<EOF
{

View file

@ -4,9 +4,7 @@ source common.sh
requireGit
TODO_NixOS
clearStore
clearStoreIfPossible
# Intentionally not in a canonical form
# See https://github.com/NixOS/nix/issues/6195

View file

@ -4,9 +4,7 @@ source common.sh
requireGit
TODO_NixOS
clearStore
clearStoreIfPossible
repo="$TEST_ROOT/git"

View file

@ -6,9 +6,7 @@ set -u
requireGit
TODO_NixOS
clearStore
clearStoreIfPossible
rootRepo=$TEST_ROOT/gitSubmodulesRoot
subRepo=$TEST_ROOT/gitSubmodulesSub

View file

@ -7,9 +7,7 @@ requireGit
enableFeatures "verified-fetches"
TODO_NixOS
clearStore
clearStoreIfPossible
repo="$TEST_ROOT/git"

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
writeSimpleFlake "$TEST_HOME"
cd "$TEST_HOME"

View file

@ -2,9 +2,9 @@
source common.sh
TODO_NixOS
TODO_NixOS # Provide a `shell` variable. Try not to `export` it, perhaps.
clearStore
clearStoreIfPossible
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
cp ./simple.nix ./simple.builder.sh ./fmt.simple.sh ./config.nix $TEST_HOME
@ -33,5 +33,3 @@ EOF
nix fmt ./file ./folder | grep 'Formatting: ./file ./folder'
nix flake check
nix flake show | grep -P "package 'formatter'"
clearStore

View file

@ -1,6 +1,6 @@
source ../common.sh
TODO_NixOS
TODO_NixOS # Need to enable git hashing feature and make sure test is ok for store we don't clear
clearStore
clearCache

View file

@ -2,10 +2,6 @@
source common.sh
TODO_NixOS
clearStore
# test help output
nix-build --help

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
if nix-instantiate --readonly-mode ./import-derivation.nix; then
echo "read-only evaluation of an imported derivation unexpectedly failed"

View file

@ -9,7 +9,7 @@ TODO_NixOS
enableFeatures "ca-derivations impure-derivations"
restartDaemon
clearStore
clearStoreIfPossible
# Basic test of impure derivations: building one a second time should not use the previous result.
printf 0 > $TEST_ROOT/counter

View file

@ -4,7 +4,7 @@ source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
rm -f $TEST_ROOT/result*

View file

@ -4,7 +4,7 @@ source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
outPath=$(nix-build dependencies.nix -o $TEST_ROOT/result)
test "$(cat $TEST_ROOT/result/foobar)" = FOOBAR

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
if [[ -n ${CONTENT_ADDRESSED:-} ]]; then
shellDotNix="$PWD/ca-shell.nix"

View file

@ -2,13 +2,14 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
outPath1=$(echo 'with import ./config.nix; mkDerivation { name = "foo1"; builder = builtins.toFile "builder" "mkdir $out; echo hello > $out/foo"; }' | nix-build - --no-out-link --auto-optimise-store)
outPath2=$(echo 'with import ./config.nix; mkDerivation { name = "foo2"; builder = builtins.toFile "builder" "mkdir $out; echo hello > $out/foo"; }' | nix-build - --no-out-link --auto-optimise-store)
TODO_NixOS # ignoring the client-specified setting 'auto-optimise-store', because it is a restricted setting and you are not a trusted user
# TODO: only continue when trusted user or root
inode1="$(stat --format=%i $outPath1/foo)"
inode2="$(stat --format=%i $outPath2/foo)"
if [ "$inode1" != "$inode2" ]; then

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
outPath=$(nix-build --no-out-link -E "
with import ./config.nix;

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
nix-build --no-out-link -E '
with import ./config.nix;

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
nix eval --expr 'assert 1 + 2 == 3; true'

View file

@ -2,7 +2,7 @@
source common.sh
TODO_NixOS
TODO_NixOS # NixOS doesn't provide $NIX_STATE_DIR (and shouldn't)
clearStore

View file

@ -2,7 +2,7 @@
source common.sh
TODO_NixOS
TODO_NixOS # can't enable a sandbox feature easily
enableFeatures 'recursive-nix'
restartDaemon

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
nix-instantiate --restrict-eval --eval -E '1 + 2'
(! nix-instantiate --eval --restrict-eval ./restricted.nix)

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
clearCache
(( $(nix search -f search.nix '' hello | wc -l) > 0 ))

View file

@ -4,9 +4,7 @@ source common.sh
requireDaemonNewerThan "2.6.0pre20211215"
TODO_NixOS
clearStore
clearStoreIfPossible
nix-build --no-out-link -E '
with import ./config.nix;

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
clearCache
nix-store --generate-binary-cache-key cache1.example.org $TEST_ROOT/sk1 $TEST_ROOT/pk1
@ -18,6 +16,7 @@ outPath=$(nix-build dependencies.nix --no-out-link --secret-key-files "$TEST_ROO
# Verify that the path got signed.
info=$(nix path-info --json $outPath)
echo $info | jq -e '.[] | .ultimate == true'
TODO_NixOS # looks like an actual bug? Following line fails on NixOS:
echo $info | jq -e '.[] | .signatures.[] | select(startswith("cache1.example.org"))'
echo $info | jq -e '.[] | .signatures.[] | select(startswith("cache2.example.org"))'

View file

@ -6,9 +6,7 @@ source common.sh
# tests for the older versions
requireDaemonNewerThan "2.4pre20210712"
TODO_NixOS
clearStore
clearStoreIfPossible
rm -f $TEST_ROOT/result
@ -23,6 +21,8 @@ env NIX_PATH=nixpkgs=shell.nix nix-shell structured-attrs-shell.nix \
nix develop -f structured-attrs-shell.nix -c bash -c 'test "3" = "$(jq ".my.list|length" < $NIX_ATTRS_JSON_FILE)"'
TODO_NixOS # following line fails.
# `nix develop` is a slightly special way of dealing with environment vars, it parses
# these from a shell-file exported from a derivation. This is to test especially `outputs`
# (which is an associative array in thsi case) being fine.

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
cd "$TEST_HOME"

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
rm -rf $TEST_HOME

View file

@ -2,9 +2,7 @@
source common.sh
TODO_NixOS
clearStore
clearStoreIfPossible
cp ./dependencies.nix ./dependencies.builder0.sh ./config.nix $TEST_HOME