mirror of
https://github.com/NixOS/nix
synced 2025-07-06 21:41:48 +02:00
Merge branch 'master' into overlayfs-store
This commit is contained in:
commit
cb4f85f11c
253 changed files with 5623 additions and 2830 deletions
|
@ -45,3 +45,8 @@ clearStore
|
|||
[[ "$path1" == "$path2" ]]
|
||||
path4=$(nix store add --mode flat --hash-algo sha1 ./dummy)
|
||||
)
|
||||
(
|
||||
path1=$(nix store add --mode text ./dummy)
|
||||
path2=$(nix eval --impure --raw --expr 'builtins.toFile "dummy" (builtins.readFile ./dummy)')
|
||||
[[ "$path1" == "$path2" ]]
|
||||
)
|
||||
|
|
Binary file not shown.
13
tests/functional/debugger.sh
Normal file
13
tests/functional/debugger.sh
Normal file
|
@ -0,0 +1,13 @@
|
|||
source common.sh
|
||||
|
||||
clearStore
|
||||
|
||||
# regression #9932
|
||||
echo ":env" | expect 1 nix eval --debugger --expr '(_: throw "oh snap") 42'
|
||||
echo ":env" | expect 1 nix eval --debugger --expr '
|
||||
let x.a = 1; in
|
||||
with x;
|
||||
(_: builtins.seq x.a (throw "oh snap")) x.a
|
||||
' >debugger-test-out
|
||||
grep -P 'with: .*a' debugger-test-out
|
||||
grep -P 'static: .*x' debugger-test-out
|
|
@ -31,17 +31,19 @@ source common.sh
|
|||
NIX_CONFIG='
|
||||
experimental-features = nix-command
|
||||
accept-flake-config = true
|
||||
' nix config show accept-flake-config 1>$TEST_ROOT/stdout 2>$TEST_ROOT/stderr
|
||||
grepQuiet "false" $TEST_ROOT/stdout
|
||||
' expect 1 nix config show accept-flake-config 1>$TEST_ROOT/stdout 2>$TEST_ROOT/stderr
|
||||
[[ $(cat $TEST_ROOT/stdout) = '' ]]
|
||||
grepQuiet "Ignoring setting 'accept-flake-config' because experimental feature 'flakes' is not enabled" $TEST_ROOT/stderr
|
||||
grepQuiet "error: could not find setting 'accept-flake-config'" $TEST_ROOT/stderr
|
||||
|
||||
# 'flakes' experimental-feature is disabled after, ignore and warn
|
||||
NIX_CONFIG='
|
||||
accept-flake-config = true
|
||||
experimental-features = nix-command
|
||||
' nix config show accept-flake-config 1>$TEST_ROOT/stdout 2>$TEST_ROOT/stderr
|
||||
grepQuiet "false" $TEST_ROOT/stdout
|
||||
' expect 1 nix config show accept-flake-config 1>$TEST_ROOT/stdout 2>$TEST_ROOT/stderr
|
||||
[[ $(cat $TEST_ROOT/stdout) = '' ]]
|
||||
grepQuiet "Ignoring setting 'accept-flake-config' because experimental feature 'flakes' is not enabled" $TEST_ROOT/stderr
|
||||
grepQuiet "error: could not find setting 'accept-flake-config'" $TEST_ROOT/stderr
|
||||
|
||||
# 'flakes' experimental-feature is enabled before, process
|
||||
NIX_CONFIG='
|
||||
|
|
|
@ -30,7 +30,10 @@ echo hello >> $TEST_ROOT/worktree/hello
|
|||
rev2=$(git -C $repo rev-parse HEAD)
|
||||
git -C $repo tag -a tag2 -m tag2
|
||||
|
||||
# Fetch a worktree
|
||||
# Check whether fetching in read-only mode works.
|
||||
nix-instantiate --eval -E "builtins.readFile ((builtins.fetchGit file://$TEST_ROOT/worktree) + \"/hello\") == \"utrecht\\n\""
|
||||
|
||||
# Fetch a worktree.
|
||||
unset _NIX_FORCE_HTTP
|
||||
path0=$(nix eval --impure --raw --expr "(builtins.fetchGit file://$TEST_ROOT/worktree).outPath")
|
||||
path0_=$(nix eval --impure --raw --expr "(builtins.fetchTree { type = \"git\"; url = file://$TEST_ROOT/worktree; }).outPath")
|
||||
|
@ -67,7 +70,7 @@ path2=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$repo; rev = \"
|
|||
[[ $(nix eval --raw --expr "builtins.readFile (fetchGit { url = file://$repo; rev = \"$rev2\"; } + \"/hello\")") = world ]]
|
||||
|
||||
# But without a hash, it fails
|
||||
expectStderr 1 nix eval --expr 'builtins.fetchGit "file:///foo"' | grepQuiet "'fetchGit' requires a locked input"
|
||||
expectStderr 1 nix eval --expr 'builtins.fetchGit "file:///foo"' | grepQuiet "'fetchGit' will not fetch unlocked input"
|
||||
|
||||
# Fetch again. This should be cached.
|
||||
mv $repo ${repo}-tmp
|
||||
|
@ -208,7 +211,7 @@ path6=$(nix eval --impure --raw --expr "(builtins.fetchTree { type = \"git\"; ur
|
|||
[[ $path3 = $path6 ]]
|
||||
[[ $(nix eval --impure --expr "(builtins.fetchTree { type = \"git\"; url = \"file://$TEST_ROOT/shallow\"; ref = \"dev\"; shallow = true; }).revCount or 123") == 123 ]]
|
||||
|
||||
expectStderr 1 nix eval --expr 'builtins.fetchTree { type = "git"; url = "file:///foo"; }' | grepQuiet "'fetchTree' requires a locked input"
|
||||
expectStderr 1 nix eval --expr 'builtins.fetchTree { type = "git"; url = "file:///foo"; }' | grepQuiet "'fetchTree' will not fetch unlocked input"
|
||||
|
||||
# Explicit ref = "HEAD" should work, and produce the same outPath as without ref
|
||||
path7=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = \"file://$repo\"; ref = \"HEAD\"; }).outPath")
|
||||
|
@ -268,3 +271,28 @@ git -C "$repo" add hello .gitignore
|
|||
git -C "$repo" commit -m 'Bla1'
|
||||
cd "$repo"
|
||||
path11=$(nix eval --impure --raw --expr "(builtins.fetchGit ./.).outPath")
|
||||
|
||||
# Test a workdir with no commits.
|
||||
empty="$TEST_ROOT/empty"
|
||||
git init "$empty"
|
||||
|
||||
emptyAttrs='{ lastModified = 0; lastModifiedDate = "19700101000000"; narHash = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo="; rev = "0000000000000000000000000000000000000000"; revCount = 0; shortRev = "0000000"; submodules = false; }'
|
||||
|
||||
[[ $(nix eval --impure --expr "builtins.removeAttrs (builtins.fetchGit $empty) [\"outPath\"]") = $emptyAttrs ]]
|
||||
|
||||
echo foo > "$empty/x"
|
||||
|
||||
[[ $(nix eval --impure --expr "builtins.removeAttrs (builtins.fetchGit $empty) [\"outPath\"]") = $emptyAttrs ]]
|
||||
|
||||
git -C "$empty" add x
|
||||
|
||||
[[ $(nix eval --impure --expr "builtins.removeAttrs (builtins.fetchGit $empty) [\"outPath\"]") = '{ lastModified = 0; lastModifiedDate = "19700101000000"; narHash = "sha256-wzlAGjxKxpaWdqVhlq55q5Gxo4Bf860+kLeEa/v02As="; rev = "0000000000000000000000000000000000000000"; revCount = 0; shortRev = "0000000"; submodules = false; }' ]]
|
||||
|
||||
# Test a repo with an empty commit.
|
||||
git -C "$empty" rm -f x
|
||||
|
||||
git -C "$empty" config user.email "foobar@example.com"
|
||||
git -C "$empty" config user.name "Foobar"
|
||||
git -C "$empty" commit --allow-empty --allow-empty-message --message ""
|
||||
|
||||
nix eval --impure --expr "let attrs = builtins.fetchGit $empty; in assert attrs.lastModified != 0; assert attrs.rev != \"0000000000000000000000000000000000000000\"; assert attrs.revCount == 1; true"
|
||||
|
|
|
@ -14,6 +14,7 @@ test_fetch_file () {
|
|||
tree = builtins.fetchTree { type = "file"; url = "file://$PWD/test_input"; };
|
||||
in
|
||||
assert (tree.narHash == "$input_hash");
|
||||
assert builtins.readFile tree == "foo\n";
|
||||
tree
|
||||
EOF
|
||||
}
|
||||
|
|
|
@ -78,3 +78,9 @@ outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file:
|
|||
|
||||
test -x $outPath/fetchurl.sh
|
||||
test -L $outPath/symlink
|
||||
|
||||
# Make sure that *not* passing a outputHash fails.
|
||||
requireDaemonNewerThan "2.20"
|
||||
expected=100
|
||||
if [[ -v NIX_DAEMON_PACKAGE ]]; then expected=1; fi # work around the daemon not returning a 100 status correctly
|
||||
expectStderr $expected nix-build --expr '{ url }: builtins.derivation { name = "nix-cache-info"; system = "x86_64-linux"; builder = "builtin:fetchurl"; inherit url; outputHashMode = "flat"; }' --argstr url file://$narxz 2>&1 | grep 'must be a fixed-output or impure derivation'
|
||||
|
|
11
tests/functional/git-hashing/common.sh
Normal file
11
tests/functional/git-hashing/common.sh
Normal file
|
@ -0,0 +1,11 @@
|
|||
source ../common.sh
|
||||
|
||||
clearStore
|
||||
clearCache
|
||||
|
||||
# Need backend to support git-hashing too
|
||||
requireDaemonNewerThan "2.19"
|
||||
|
||||
enableFeatures "git-hashing"
|
||||
|
||||
restartDaemon
|
7
tests/functional/git-hashing/local.mk
Normal file
7
tests/functional/git-hashing/local.mk
Normal file
|
@ -0,0 +1,7 @@
|
|||
git-hashing-tests := \
|
||||
$(d)/simple.sh
|
||||
|
||||
install-tests-groups += git-hashing
|
||||
|
||||
clean-files += \
|
||||
$(d)/config.nix
|
58
tests/functional/git-hashing/simple.sh
Normal file
58
tests/functional/git-hashing/simple.sh
Normal file
|
@ -0,0 +1,58 @@
|
|||
source common.sh
|
||||
|
||||
repo="$TEST_ROOT/scratch"
|
||||
git init "$repo"
|
||||
|
||||
git -C "$repo" config user.email "you@example.com"
|
||||
git -C "$repo" config user.name "Your Name"
|
||||
|
||||
try () {
|
||||
hash=$(nix hash path --mode git --format base16 --algo sha1 $TEST_ROOT/hash-path)
|
||||
[[ "$hash" == "$1" ]]
|
||||
|
||||
git -C "$repo" rm -rf hash-path || true
|
||||
cp -r "$TEST_ROOT/hash-path" "$TEST_ROOT/scratch/hash-path"
|
||||
git -C "$repo" add hash-path
|
||||
git -C "$repo" commit -m "x"
|
||||
git -C "$repo" status
|
||||
hash2=$(git -C "$TEST_ROOT/scratch" rev-parse HEAD:hash-path)
|
||||
[[ "$hash2" = "$1" ]]
|
||||
}
|
||||
|
||||
# blob
|
||||
rm -rf $TEST_ROOT/hash-path
|
||||
echo "Hello World" > $TEST_ROOT/hash-path
|
||||
try "557db03de997c86a4a028e1ebd3a1ceb225be238"
|
||||
|
||||
# tree with children
|
||||
rm -rf $TEST_ROOT/hash-path
|
||||
mkdir $TEST_ROOT/hash-path
|
||||
echo "Hello World" > $TEST_ROOT/hash-path/hello
|
||||
echo "Run Hello World" > $TEST_ROOT/hash-path/executable
|
||||
chmod +x $TEST_ROOT/hash-path/executable
|
||||
try "e5c0a11a556801a5c9dcf330ca9d7e2c572697f4"
|
||||
|
||||
rm -rf $TEST_ROOT/dummy1
|
||||
echo Hello World! > $TEST_ROOT/dummy1
|
||||
path1=$(nix store add --mode git --hash-algo sha1 $TEST_ROOT/dummy1)
|
||||
hash1=$(nix-store -q --hash $path1)
|
||||
test "$hash1" = "sha256:1brffhvj2c0z6x8qismd43m0iy8dsgfmy10bgg9w11szway2wp9v"
|
||||
|
||||
rm -rf $TEST_ROOT/dummy2
|
||||
mkdir -p $TEST_ROOT/dummy2
|
||||
echo Hello World! > $TEST_ROOT/dummy2/hello
|
||||
path2=$(nix store add --mode git --hash-algo sha1 $TEST_ROOT/dummy2)
|
||||
hash2=$(nix-store -q --hash $path2)
|
||||
test "$hash2" = "sha256:1vhv7zxam7x277q0y0jcypm7hwhccbzss81vkdgf0ww5sm2am4y0"
|
||||
|
||||
rm -rf $TEST_ROOT/dummy3
|
||||
mkdir -p $TEST_ROOT/dummy3
|
||||
mkdir -p $TEST_ROOT/dummy3/dir
|
||||
touch $TEST_ROOT/dummy3/dir/file
|
||||
echo Hello World! > $TEST_ROOT/dummy3/dir/file
|
||||
touch $TEST_ROOT/dummy3/dir/executable
|
||||
chmod +x $TEST_ROOT/dummy3/dir/executable
|
||||
echo Run Hello World! > $TEST_ROOT/dummy3/dir/executable
|
||||
path3=$(nix store add --mode git --hash-algo sha1 $TEST_ROOT/dummy3)
|
||||
hash3=$(nix-store -q --hash $path3)
|
||||
test "$hash3" = "sha256:08y3nm3mvn9qvskqnf13lfgax5lh73krxz4fcjd5cp202ggpw9nv"
|
105
tests/functional/hash-convert.sh
Normal file
105
tests/functional/hash-convert.sh
Normal file
|
@ -0,0 +1,105 @@
|
|||
source common.sh
|
||||
|
||||
# Conversion with `nix hash` `nix-hash` and `nix hash convert`
|
||||
try3() {
|
||||
# $1 = hash algo
|
||||
# $2 = expected hash in base16
|
||||
# $3 = expected hash in base32
|
||||
# $4 = expected hash in base64
|
||||
h64=$(nix hash convert --hash-algo "$1" --to base64 "$2")
|
||||
[ "$h64" = "$4" ]
|
||||
h64=$(nix-hash --type "$1" --to-base64 "$2")
|
||||
[ "$h64" = "$4" ]
|
||||
# Deprecated experiment
|
||||
h64=$(nix hash to-base64 --type "$1" "$2")
|
||||
[ "$h64" = "$4" ]
|
||||
|
||||
sri=$(nix hash convert --hash-algo "$1" --to sri "$2")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix-hash --type "$1" --to-sri "$2")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash to-sri --type "$1" "$2")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
h32=$(nix hash convert --hash-algo "$1" --to base32 "$2")
|
||||
[ "$h32" = "$3" ]
|
||||
h32=$(nix-hash --type "$1" --to-base32 "$2")
|
||||
[ "$h32" = "$3" ]
|
||||
h32=$(nix hash to-base32 --type "$1" "$2")
|
||||
[ "$h32" = "$3" ]
|
||||
h16=$(nix-hash --type "$1" --to-base16 "$h32")
|
||||
[ "$h16" = "$2" ]
|
||||
|
||||
h16=$(nix hash convert --hash-algo "$1" --to base16 "$h64")
|
||||
[ "$h16" = "$2" ]
|
||||
h16=$(nix hash to-base16 --type "$1" "$h64")
|
||||
[ "$h16" = "$2" ]
|
||||
h16=$(nix hash convert --to base16 "$sri")
|
||||
[ "$h16" = "$2" ]
|
||||
h16=$(nix hash to-base16 "$sri")
|
||||
[ "$h16" = "$2" ]
|
||||
|
||||
#
|
||||
# Converting from SRI
|
||||
#
|
||||
|
||||
# Input hash algo auto-detected from SRI and output defaults to SRI as well.
|
||||
sri=$(nix hash convert "$1-$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
sri=$(nix hash convert --from sri "$1-$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
sri=$(nix hash convert --to sri "$1-$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
sri=$(nix hash convert --from sri --to sri "$1-$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
sri=$(nix hash convert --to base64 "$1-$4")
|
||||
[ "$sri" = "$4" ]
|
||||
|
||||
#
|
||||
# Auto-detecting the input from algo and length.
|
||||
#
|
||||
|
||||
sri=$(nix hash convert --hash-algo "$1" "$2")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash convert --hash-algo "$1" "$3")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash convert --hash-algo "$1" "$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
sri=$(nix hash convert --hash-algo "$1" "$2")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash convert --hash-algo "$1" "$3")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash convert --hash-algo "$1" "$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
#
|
||||
# Asserting input format succeeds.
|
||||
#
|
||||
|
||||
sri=$(nix hash convert --hash-algo "$1" --from base16 "$2")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash convert --hash-algo "$1" --from nix32 "$3")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash convert --hash-algo "$1" --from base64 "$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
#
|
||||
# Asserting input format fails.
|
||||
#
|
||||
|
||||
fail=$(nix hash convert --hash-algo "$1" --from nix32 "$2" 2>&1 || echo "exit: $?")
|
||||
[[ "$fail" == *"error: input hash"*"exit: 1" ]]
|
||||
fail=$(nix hash convert --hash-algo "$1" --from base16 "$3" 2>&1 || echo "exit: $?")
|
||||
[[ "$fail" == *"error: input hash"*"exit: 1" ]]
|
||||
fail=$(nix hash convert --hash-algo "$1" --from nix32 "$4" 2>&1 || echo "exit: $?")
|
||||
[[ "$fail" == *"error: input hash"*"exit: 1" ]]
|
||||
|
||||
}
|
||||
|
||||
try3 sha1 "800d59cfcd3c05e900cb4e214be48f6b886a08df" "vw46m23bizj4n8afrc0fj19wrp7mj3c0" "gA1Zz808BekAy04hS+SPa4hqCN8="
|
||||
try3 sha256 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s" "ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0="
|
||||
try3 sha512 "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445" "12k9jiq29iyqm03swfsgiw5mlqs173qazm3n7daz43infy12pyrcdf30fkk3qwv4yl2ick8yipc2mqnlh48xsvvxl60lbx8vp38yji0" "IEqPxt2oLwoM7XvrjgikFlfBbvRosiioJ5vjMacDwzWW/RXBOxsH+aodO+pXeJygMa2Fx6cd1wNU7GMSOMo0RQ=="
|
92
tests/functional/hash-path.sh
Normal file
92
tests/functional/hash-path.sh
Normal file
|
@ -0,0 +1,92 @@
|
|||
source common.sh
|
||||
|
||||
try () {
|
||||
printf "%s" "$2" > $TEST_ROOT/vector
|
||||
hash="$(nix-hash --flat ${FORMAT+--$FORMAT} --type "$1" "$TEST_ROOT/vector")"
|
||||
if ! (( "${NO_TEST_CLASSIC-}" )) && test "$hash" != "$3"; then
|
||||
echo "try nix-hash: hash $1, expected $3, got $hash"
|
||||
exit 1
|
||||
fi
|
||||
hash="$(nix hash file ${FORMAT+--$FORMAT} --type "$1" "$TEST_ROOT/vector")"
|
||||
if ! (( "${NO_TEST_NIX_COMMAND-}" )) && test "$hash" != "$3"; then
|
||||
echo "try nix hash: hash $1, expected $3, got $hash"
|
||||
exit 1
|
||||
fi
|
||||
hash="$(nix hash path --mode flat ${FORMAT+--format $FORMAT} --algo "$1" "$TEST_ROOT/vector")"
|
||||
if ! (( "${NO_TEST_NIX_COMMAND-}" )) && test "$hash" != "$3"; then
|
||||
echo "try nix hash: hash $1, expected $3, got $hash"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
FORMAT=base16
|
||||
try md5 "" "d41d8cd98f00b204e9800998ecf8427e"
|
||||
try md5 "a" "0cc175b9c0f1b6a831c399e269772661"
|
||||
try md5 "abc" "900150983cd24fb0d6963f7d28e17f72"
|
||||
try md5 "message digest" "f96b697d7cb7938d525a2f31aaf161d0"
|
||||
try md5 "abcdefghijklmnopqrstuvwxyz" "c3fcd3d76192e4007dfb496cca67e13b"
|
||||
try md5 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" "d174ab98d277d9f5a5611c2c9f419d9f"
|
||||
try md5 "12345678901234567890123456789012345678901234567890123456789012345678901234567890" "57edf4a22be3c955ac49da2e2107b67a"
|
||||
|
||||
try sha1 "" "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
||||
try sha1 "abc" "a9993e364706816aba3e25717850c26c9cd0d89d"
|
||||
try sha1 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" "84983e441c3bd26ebaae4aa1f95129e5e54670f1"
|
||||
|
||||
try sha256 "" "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
try sha256 "abc" "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
|
||||
try sha256 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
|
||||
|
||||
try sha512 "" "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
|
||||
try sha512 "abc" "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"
|
||||
try sha512 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445"
|
||||
unset FORMAT
|
||||
|
||||
FORMAT=base32
|
||||
try sha256 "abc" "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s"
|
||||
unset FORMAT
|
||||
|
||||
FORMAT=sri
|
||||
try sha512 "" "sha512-z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg=="
|
||||
try sha512 "abc" "sha512-3a81oZNherrMQXNJriBBMRLm+k6JqX6iCp7u5ktV05ohkpkqJ0/BqDa6PCOj/uu9RU1EI2Q86A4qmslPpUyknw=="
|
||||
try sha512 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" "sha512-IEqPxt2oLwoM7XvrjgikFlfBbvRosiioJ5vjMacDwzWW/RXBOxsH+aodO+pXeJygMa2Fx6cd1wNU7GMSOMo0RQ=="
|
||||
try sha256 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" "sha256-JI1qYdIGOLjlwCaTDD5gOaM85Flk/yFn9uzt1BnbBsE="
|
||||
unset FORMAT
|
||||
|
||||
# nix-hash [--flat] defaults to the Base16 format
|
||||
NO_TEST_NIX_COMMAND=1 try sha512 "abc" "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"
|
||||
|
||||
# nix hash [file|path] defaults to the SRI format
|
||||
NO_TEST_CLASSIC=1 try sha512 "abc" "sha512-3a81oZNherrMQXNJriBBMRLm+k6JqX6iCp7u5ktV05ohkpkqJ0/BqDa6PCOj/uu9RU1EI2Q86A4qmslPpUyknw=="
|
||||
|
||||
try2 () {
|
||||
hash=$(nix-hash --type "$1" $TEST_ROOT/hash-path)
|
||||
if test "$hash" != "$2"; then
|
||||
echo "try nix-hash; hash $1, expected $2, got $hash"
|
||||
exit 1
|
||||
fi
|
||||
hash="$(nix hash path --mode nar --format base16 --algo "$1" "$TEST_ROOT/hash-path")"
|
||||
if test "$hash" != "$2"; then
|
||||
echo "try nix hash: hash $1, expected $2, got $hash"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
rm -rf $TEST_ROOT/hash-path
|
||||
mkdir $TEST_ROOT/hash-path
|
||||
echo "Hello World" > $TEST_ROOT/hash-path/hello
|
||||
|
||||
try2 md5 "ea9b55537dd4c7e104515b2ccfaf4100"
|
||||
|
||||
# Execute bit matters.
|
||||
chmod +x $TEST_ROOT/hash-path/hello
|
||||
try2 md5 "20f3ffe011d4cfa7d72bfabef7882836"
|
||||
|
||||
# Mtime and other bits don't.
|
||||
touch -r . $TEST_ROOT/hash-path/hello
|
||||
chmod 744 $TEST_ROOT/hash-path/hello
|
||||
try2 md5 "20f3ffe011d4cfa7d72bfabef7882836"
|
||||
|
||||
# File type (e.g., symlink) does.
|
||||
rm $TEST_ROOT/hash-path/hello
|
||||
ln -s x $TEST_ROOT/hash-path/hello
|
||||
try2 md5 "f78b733a68f5edbdf9413899339eaa4a"
|
|
@ -1,186 +0,0 @@
|
|||
source common.sh
|
||||
|
||||
try () {
|
||||
printf "%s" "$2" > $TEST_ROOT/vector
|
||||
hash="$(nix-hash --flat ${FORMAT_FLAG-} --type "$1" "$TEST_ROOT/vector")"
|
||||
if ! (( "${NO_TEST_CLASSIC-}" )) && test "$hash" != "$3"; then
|
||||
echo "try nix-hash: hash $1, expected $3, got $hash"
|
||||
exit 1
|
||||
fi
|
||||
hash="$(nix hash file ${FORMAT_FLAG-} --type "$1" "$TEST_ROOT/vector")"
|
||||
if ! (( "${NO_TEST_NIX_COMMAND-}" )) && test "$hash" != "$3"; then
|
||||
echo "try nix hash: hash $1, expected $3, got $hash"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
FORMAT_FLAG=--base16
|
||||
try md5 "" "d41d8cd98f00b204e9800998ecf8427e"
|
||||
try md5 "a" "0cc175b9c0f1b6a831c399e269772661"
|
||||
try md5 "abc" "900150983cd24fb0d6963f7d28e17f72"
|
||||
try md5 "message digest" "f96b697d7cb7938d525a2f31aaf161d0"
|
||||
try md5 "abcdefghijklmnopqrstuvwxyz" "c3fcd3d76192e4007dfb496cca67e13b"
|
||||
try md5 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" "d174ab98d277d9f5a5611c2c9f419d9f"
|
||||
try md5 "12345678901234567890123456789012345678901234567890123456789012345678901234567890" "57edf4a22be3c955ac49da2e2107b67a"
|
||||
|
||||
try sha1 "" "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
||||
try sha1 "abc" "a9993e364706816aba3e25717850c26c9cd0d89d"
|
||||
try sha1 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" "84983e441c3bd26ebaae4aa1f95129e5e54670f1"
|
||||
|
||||
try sha256 "" "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
try sha256 "abc" "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
|
||||
try sha256 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
|
||||
|
||||
try sha512 "" "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
|
||||
try sha512 "abc" "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"
|
||||
try sha512 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445"
|
||||
unset FORMAT_FLAG
|
||||
|
||||
FORMAT_FLAG=--base32
|
||||
try sha256 "abc" "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s"
|
||||
unset FORMAT_FLAG
|
||||
|
||||
FORMAT_FLAG=--sri
|
||||
try sha512 "" "sha512-z4PhNX7vuL3xVChQ1m2AB9Yg5AULVxXcg/SpIdNs6c5H0NE8XYXysP+DGNKHfuwvY7kxvUdBeoGlODJ6+SfaPg=="
|
||||
try sha512 "abc" "sha512-3a81oZNherrMQXNJriBBMRLm+k6JqX6iCp7u5ktV05ohkpkqJ0/BqDa6PCOj/uu9RU1EI2Q86A4qmslPpUyknw=="
|
||||
try sha512 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" "sha512-IEqPxt2oLwoM7XvrjgikFlfBbvRosiioJ5vjMacDwzWW/RXBOxsH+aodO+pXeJygMa2Fx6cd1wNU7GMSOMo0RQ=="
|
||||
try sha256 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" "sha256-JI1qYdIGOLjlwCaTDD5gOaM85Flk/yFn9uzt1BnbBsE="
|
||||
unset FORMAT_FLAG
|
||||
|
||||
# nix-hash [--flat] defaults to the Base16 format
|
||||
NO_TEST_NIX_COMMAND=1 try sha512 "abc" "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f"
|
||||
|
||||
# nix hash [file|path] defaults to the SRI format
|
||||
NO_TEST_CLASSIC=1 try sha512 "abc" "sha512-3a81oZNherrMQXNJriBBMRLm+k6JqX6iCp7u5ktV05ohkpkqJ0/BqDa6PCOj/uu9RU1EI2Q86A4qmslPpUyknw=="
|
||||
|
||||
try2 () {
|
||||
hash=$(nix-hash --type "$1" $TEST_ROOT/hash-path)
|
||||
if test "$hash" != "$2"; then
|
||||
echo "hash $1, expected $2, got $hash"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
rm -rf $TEST_ROOT/hash-path
|
||||
mkdir $TEST_ROOT/hash-path
|
||||
echo "Hello World" > $TEST_ROOT/hash-path/hello
|
||||
|
||||
try2 md5 "ea9b55537dd4c7e104515b2ccfaf4100"
|
||||
|
||||
# Execute bit matters.
|
||||
chmod +x $TEST_ROOT/hash-path/hello
|
||||
try2 md5 "20f3ffe011d4cfa7d72bfabef7882836"
|
||||
|
||||
# Mtime and other bits don't.
|
||||
touch -r . $TEST_ROOT/hash-path/hello
|
||||
chmod 744 $TEST_ROOT/hash-path/hello
|
||||
try2 md5 "20f3ffe011d4cfa7d72bfabef7882836"
|
||||
|
||||
# File type (e.g., symlink) does.
|
||||
rm $TEST_ROOT/hash-path/hello
|
||||
ln -s x $TEST_ROOT/hash-path/hello
|
||||
try2 md5 "f78b733a68f5edbdf9413899339eaa4a"
|
||||
|
||||
# Conversion with `nix hash` `nix-hash` and `nix hash convert`
|
||||
try3() {
|
||||
# $1 = hash algo
|
||||
# $2 = expected hash in base16
|
||||
# $3 = expected hash in base32
|
||||
# $4 = expected hash in base64
|
||||
h64=$(nix hash convert --hash-algo "$1" --to base64 "$2")
|
||||
[ "$h64" = "$4" ]
|
||||
h64=$(nix-hash --type "$1" --to-base64 "$2")
|
||||
[ "$h64" = "$4" ]
|
||||
# Deprecated experiment
|
||||
h64=$(nix hash to-base64 --type "$1" "$2")
|
||||
[ "$h64" = "$4" ]
|
||||
|
||||
sri=$(nix hash convert --hash-algo "$1" --to sri "$2")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix-hash --type "$1" --to-sri "$2")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash to-sri --type "$1" "$2")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
h32=$(nix hash convert --hash-algo "$1" --to base32 "$2")
|
||||
[ "$h32" = "$3" ]
|
||||
h32=$(nix-hash --type "$1" --to-base32 "$2")
|
||||
[ "$h32" = "$3" ]
|
||||
h32=$(nix hash to-base32 --type "$1" "$2")
|
||||
[ "$h32" = "$3" ]
|
||||
h16=$(nix-hash --type "$1" --to-base16 "$h32")
|
||||
[ "$h16" = "$2" ]
|
||||
|
||||
h16=$(nix hash convert --hash-algo "$1" --to base16 "$h64")
|
||||
[ "$h16" = "$2" ]
|
||||
h16=$(nix hash to-base16 --type "$1" "$h64")
|
||||
[ "$h16" = "$2" ]
|
||||
h16=$(nix hash convert --to base16 "$sri")
|
||||
[ "$h16" = "$2" ]
|
||||
h16=$(nix hash to-base16 "$sri")
|
||||
[ "$h16" = "$2" ]
|
||||
|
||||
#
|
||||
# Converting from SRI
|
||||
#
|
||||
|
||||
# Input hash algo auto-detected from SRI and output defaults to SRI as well.
|
||||
sri=$(nix hash convert "$1-$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
sri=$(nix hash convert --from sri "$1-$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
sri=$(nix hash convert --to sri "$1-$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
sri=$(nix hash convert --from sri --to sri "$1-$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
sri=$(nix hash convert --to base64 "$1-$4")
|
||||
[ "$sri" = "$4" ]
|
||||
|
||||
#
|
||||
# Auto-detecting the input from algo and length.
|
||||
#
|
||||
|
||||
sri=$(nix hash convert --hash-algo "$1" "$2")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash convert --hash-algo "$1" "$3")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash convert --hash-algo "$1" "$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
sri=$(nix hash convert --hash-algo "$1" "$2")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash convert --hash-algo "$1" "$3")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash convert --hash-algo "$1" "$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
#
|
||||
# Asserting input format succeeds.
|
||||
#
|
||||
|
||||
sri=$(nix hash convert --hash-algo "$1" --from base16 "$2")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash convert --hash-algo "$1" --from nix32 "$3")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
sri=$(nix hash convert --hash-algo "$1" --from base64 "$4")
|
||||
[ "$sri" = "$1-$4" ]
|
||||
|
||||
#
|
||||
# Asserting input format fails.
|
||||
#
|
||||
|
||||
fail=$(nix hash convert --hash-algo "$1" --from nix32 "$2" 2>&1 || echo "exit: $?")
|
||||
[[ "$fail" == *"error: input hash"*"exit: 1" ]]
|
||||
fail=$(nix hash convert --hash-algo "$1" --from base16 "$3" 2>&1 || echo "exit: $?")
|
||||
[[ "$fail" == *"error: input hash"*"exit: 1" ]]
|
||||
fail=$(nix hash convert --hash-algo "$1" --from nix32 "$4" 2>&1 || echo "exit: $?")
|
||||
[[ "$fail" == *"error: input hash"*"exit: 1" ]]
|
||||
|
||||
}
|
||||
|
||||
try3 sha1 "800d59cfcd3c05e900cb4e214be48f6b886a08df" "vw46m23bizj4n8afrc0fj19wrp7mj3c0" "gA1Zz808BekAy04hS+SPa4hqCN8="
|
||||
try3 sha256 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" "1b8m03r63zqhnjf7l5wnldhh7c134ap5vpj0850ymkq1iyzicy5s" "ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0="
|
||||
try3 sha512 "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445" "12k9jiq29iyqm03swfsgiw5mlqs173qazm3n7daz43infy12pyrcdf30fkk3qwv4yl2ick8yipc2mqnlh48xsvvxl60lbx8vp38yji0" "IEqPxt2oLwoM7XvrjgikFlfBbvRosiioJ5vjMacDwzWW/RXBOxsH+aodO+pXeJygMa2Fx6cd1wNU7GMSOMo0RQ=="
|
|
@ -63,3 +63,7 @@ path5=$(nix build -L --no-link --json --file ./impure-derivations.nix contentAdd
|
|||
path6=$(nix build -L --no-link --json --file ./impure-derivations.nix inputAddressedAfterCA | jq -r .[].outputs.out)
|
||||
[[ $(< $path6) = X ]]
|
||||
[[ $(< $TEST_ROOT/counter) = 5 ]]
|
||||
|
||||
# Test nix/fetchurl.nix.
|
||||
path7=$(nix build -L --no-link --print-out-paths --expr "import <nix/fetchurl.nix> { impure = true; url = file://$PWD/impure-derivations.sh; }")
|
||||
cmp $path7 $PWD/impure-derivations.sh
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
source common.sh
|
||||
|
||||
# Needs the config option 'impure-env' to work
|
||||
requireDaemonNewerThan "2.18.0pre20230816"
|
||||
requireDaemonNewerThan "2.19.0"
|
||||
|
||||
enableFeatures "configurable-impure-env"
|
||||
restartDaemon
|
||||
|
|
|
@ -14,3 +14,8 @@ error:
|
|||
8|
|
||||
|
||||
error: expected a string but found an integer: 1
|
||||
at /pwd/lang/eval-fail-attr-name-type.nix:7:17:
|
||||
6| in
|
||||
7| attrs.puppy.${key}
|
||||
| ^
|
||||
8|
|
||||
|
|
|
@ -6,4 +6,4 @@ error:
|
|||
| ^
|
||||
10|
|
||||
|
||||
error: cannot coerce a set to a string: { a = { a = { a = { a = "ha"; b = "ha"; c = "ha"; d = "ha"; e = "ha"; f = "ha"; g = "ha"; h = "ha"; j = "ha"; }; «4294967295 attributes elided»}; «4294967294 attributes elided»}; «4294967293 attributes elided»}
|
||||
error: cannot coerce a set to a string: { a = { a = { a = { a = "ha"; b = "ha"; c = "ha"; d = "ha"; e = "ha"; f = "ha"; g = "ha"; h = "ha"; j = "ha"; }; «4294967295 attributes elided» }; «4294967294 attributes elided» }; «4294967293 attributes elided» }
|
||||
|
|
|
@ -41,4 +41,11 @@ error:
|
|||
| ^
|
||||
5| if n > 0
|
||||
|
||||
… while calling the 'throw' builtin
|
||||
at /pwd/lang/eval-fail-duplicate-traces.nix:7:10:
|
||||
6| then throwAfter (n - 1)
|
||||
7| else throw "Uh oh!";
|
||||
| ^
|
||||
8| in
|
||||
|
||||
error: Uh oh!
|
||||
|
|
|
@ -27,4 +27,11 @@ error:
|
|||
| ^
|
||||
6|
|
||||
|
||||
… while calling the 'throw' builtin
|
||||
at /pwd/lang/eval-fail-foldlStrict-strict-op-application.nix:5:9:
|
||||
4| null
|
||||
5| [ (_: throw "Not the final value, but is still forced!") (_: 23) ]
|
||||
| ^
|
||||
6|
|
||||
|
||||
error: Not the final value, but is still forced!
|
||||
|
|
|
@ -5,4 +5,4 @@ error:
|
|||
| ^
|
||||
2| key = "value"
|
||||
|
||||
error: while parsing a TOML string: Dates and times are not supported
|
||||
error: while parsing TOML: Dates and times are not supported
|
||||
|
|
|
@ -54,4 +54,11 @@ error:
|
|||
|
||||
(21 duplicate frames omitted)
|
||||
|
||||
… while calling the 'throw' builtin
|
||||
at /pwd/lang/eval-fail-mutual-recursion.nix:34:10:
|
||||
33| then throwAfterB true 10
|
||||
34| else throw "Uh oh!";
|
||||
| ^
|
||||
35| in
|
||||
|
||||
error: Uh oh!
|
||||
|
|
|
@ -20,6 +20,11 @@ error:
|
|||
3| true
|
||||
|
||||
… while evaluating list element at index 3
|
||||
at /pwd/lang/eval-fail-toJSON.nix:2:3:
|
||||
1| builtins.toJSON {
|
||||
2| a.b = [
|
||||
| ^
|
||||
3| true
|
||||
|
||||
… while evaluating attribute 'c'
|
||||
at /pwd/lang/eval-fail-toJSON.nix:7:7:
|
||||
|
|
|
@ -7,3 +7,8 @@ error:
|
|||
6|
|
||||
|
||||
error: expected a string but found a set: { }
|
||||
at /pwd/lang/eval-fail-using-set-as-attr-name.nix:5:10:
|
||||
4| in
|
||||
5| attr.${key}
|
||||
| ^
|
||||
6|
|
||||
|
|
1
tests/functional/lang/eval-okay-inherit-from.err.exp
Normal file
1
tests/functional/lang/eval-okay-inherit-from.err.exp
Normal file
|
@ -0,0 +1 @@
|
|||
trace: used
|
1
tests/functional/lang/eval-okay-inherit-from.exp
Normal file
1
tests/functional/lang/eval-okay-inherit-from.exp
Normal file
|
@ -0,0 +1 @@
|
|||
[ 1 2 { __overrides = { y = { d = [ ]; }; }; c = [ ]; d = 4; x = { c = [ ]; }; y = «repeated»; } { inner = { c = 3; d = 4; }; } ]
|
16
tests/functional/lang/eval-okay-inherit-from.nix
Normal file
16
tests/functional/lang/eval-okay-inherit-from.nix
Normal file
|
@ -0,0 +1,16 @@
|
|||
let
|
||||
inherit (builtins.trace "used" { a = 1; b = 2; }) a b;
|
||||
x.c = 3;
|
||||
y.d = 4;
|
||||
|
||||
merged = {
|
||||
inner = {
|
||||
inherit (y) d;
|
||||
};
|
||||
|
||||
inner = {
|
||||
inherit (x) c;
|
||||
};
|
||||
};
|
||||
in
|
||||
[ a b rec { x.c = []; inherit (x) c; inherit (y) d; __overrides.y.d = []; } merged ]
|
|
@ -29,3 +29,6 @@ builtins.pathExists (./lib.nix)
|
|||
&& builtins.pathExists (builtins.toPath { outPath = builtins.toString ./lib.nix; })
|
||||
&& builtins.pathExists ./lib.nix
|
||||
&& !builtins.pathExists ./bla.nix
|
||||
&& builtins.pathExists ./symlink-resolution/foo/overlays/overlay.nix
|
||||
&& builtins.pathExists ./symlink-resolution/broken
|
||||
&& builtins.pathExists (builtins.toString ./symlink-resolution/foo/overlays + "/.")
|
||||
|
|
1
tests/functional/lang/parse-okay-inherits.exp
Normal file
1
tests/functional/lang/parse-okay-inherits.exp
Normal file
|
@ -0,0 +1 @@
|
|||
(let b = 2; c = { }; in { inherit b; inherit (c) d e; a = 1; f = 3; })
|
9
tests/functional/lang/parse-okay-inherits.nix
Normal file
9
tests/functional/lang/parse-okay-inherits.nix
Normal file
|
@ -0,0 +1,9 @@
|
|||
let
|
||||
c = {};
|
||||
b = 2;
|
||||
in {
|
||||
a = 1;
|
||||
inherit b;
|
||||
inherit (c) d e;
|
||||
f = 3;
|
||||
}
|
|
@ -1 +1 @@
|
|||
({ fetchurl, localServer ? false, httpServer ? false, sslSupport ? false, pythonBindings ? false, javaSwigBindings ? false, javahlBindings ? false, stdenv, openssl ? null, httpd ? null, db4 ? null, expat, swig ? null, j2sdk ? null }: assert (expat != null); assert (localServer -> (db4 != null)); assert (httpServer -> ((httpd != null) && ((httpd).expat == expat))); assert (sslSupport -> ((openssl != null) && (httpServer -> ((httpd).openssl == openssl)))); assert (pythonBindings -> ((swig != null) && (swig).pythonSupport)); assert (javaSwigBindings -> ((swig != null) && (swig).javaSupport)); assert (javahlBindings -> (j2sdk != null)); ((stdenv).mkDerivation { builder = /foo/bar; db4 = (if localServer then db4 else null); inherit expat ; inherit httpServer ; httpd = (if httpServer then httpd else null); j2sdk = (if javaSwigBindings then (swig).j2sdk else (if javahlBindings then j2sdk else null)); inherit javaSwigBindings ; inherit javahlBindings ; inherit localServer ; name = "subversion-1.1.1"; openssl = (if sslSupport then openssl else null); patches = (if javahlBindings then [ (/javahl.patch) ] else [ ]); python = (if pythonBindings then (swig).python else null); inherit pythonBindings ; src = (fetchurl { md5 = "a180c3fe91680389c210c99def54d9e0"; url = "http://subversion.tigris.org/tarballs/subversion-1.1.1.tar.bz2"; }); inherit sslSupport ; swig = (if (pythonBindings || javaSwigBindings) then swig else null); }))
|
||||
({ fetchurl, localServer ? false, httpServer ? false, sslSupport ? false, pythonBindings ? false, javaSwigBindings ? false, javahlBindings ? false, stdenv, openssl ? null, httpd ? null, db4 ? null, expat, swig ? null, j2sdk ? null }: assert (expat != null); assert (localServer -> (db4 != null)); assert (httpServer -> ((httpd != null) && ((httpd).expat == expat))); assert (sslSupport -> ((openssl != null) && (httpServer -> ((httpd).openssl == openssl)))); assert (pythonBindings -> ((swig != null) && (swig).pythonSupport)); assert (javaSwigBindings -> ((swig != null) && (swig).javaSupport)); assert (javahlBindings -> (j2sdk != null)); ((stdenv).mkDerivation { inherit expat httpServer javaSwigBindings javahlBindings localServer pythonBindings sslSupport; builder = /foo/bar; db4 = (if localServer then db4 else null); httpd = (if httpServer then httpd else null); j2sdk = (if javaSwigBindings then (swig).j2sdk else (if javahlBindings then j2sdk else null)); name = "subversion-1.1.1"; openssl = (if sslSupport then openssl else null); patches = (if javahlBindings then [ (/javahl.patch) ] else [ ]); python = (if pythonBindings then (swig).python else null); src = (fetchurl { md5 = "a180c3fe91680389c210c99def54d9e0"; url = "http://subversion.tigris.org/tarballs/subversion-1.1.1.tar.bz2"; }); swig = (if (pythonBindings || javaSwigBindings) then swig else null); }))
|
||||
|
|
1
tests/functional/lang/symlink-resolution/broken
Symbolic link
1
tests/functional/lang/symlink-resolution/broken
Symbolic link
|
@ -0,0 +1 @@
|
|||
nonexistent
|
|
@ -47,7 +47,8 @@ nix_tests = \
|
|||
optimise-store.sh \
|
||||
substitute-with-invalid-ca.sh \
|
||||
signing.sh \
|
||||
hash.sh \
|
||||
hash-convert.sh \
|
||||
hash-path.sh \
|
||||
gc-non-blocking.sh \
|
||||
check.sh \
|
||||
nix-shell.sh \
|
||||
|
@ -127,7 +128,8 @@ nix_tests = \
|
|||
toString-path.sh \
|
||||
read-only-store.sh \
|
||||
nested-sandboxing.sh \
|
||||
impure-env.sh
|
||||
impure-env.sh \
|
||||
debugger.sh
|
||||
|
||||
ifeq ($(HAVE_LIBCPUID), 1)
|
||||
nix_tests += compute-levels.sh
|
||||
|
|
|
@ -64,6 +64,9 @@ nix profile install $flake1Dir
|
|||
[[ $($TEST_HOME/.local/state/nix/profile/bin/hello) = "Hello World" ]]
|
||||
unset NIX_CONFIG
|
||||
|
||||
# Test conflicting package install.
|
||||
nix profile install $flake1Dir 2>&1 | grep "warning: 'flake1' is already installed"
|
||||
|
||||
# Test upgrading a package.
|
||||
printf NixOS > $flake1Dir/who
|
||||
printf 2.0 > $flake1Dir/version
|
||||
|
@ -166,7 +169,7 @@ error: An existing package already provides the following file:
|
|||
|
||||
To remove the existing package:
|
||||
|
||||
nix profile remove path:${flake1Dir}#packages.${system}.default
|
||||
nix profile remove flake1
|
||||
|
||||
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.
|
||||
|
|
|
@ -118,10 +118,10 @@ diff $TEST_ROOT/dev-env{,2}.json
|
|||
# Ensure `nix print-dev-env --json` contains variable assignments.
|
||||
[[ $(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-env)` in subshells to avoid modifying the current
|
||||
# environment.
|
||||
|
||||
set +u # FIXME: Make print-dev-env `set -u` compliant (issue #7951)
|
||||
set -u
|
||||
|
||||
# Ensure `source <(nix print-dev-env)` modifies the environment.
|
||||
(
|
||||
|
|
|
@ -146,29 +146,86 @@ echo "$replResult" | grepQuiet -s afterChange
|
|||
# Normal output should print attributes in lexicographical order non-recursively
|
||||
testReplResponseNoRegex '
|
||||
{ a = { b = 2; }; l = [ 1 2 3 ]; s = "string"; n = 1234; x = rec { y = { z = { inherit y; }; }; }; }
|
||||
' '{ a = { ... }; l = [ ... ]; n = 1234; s = "string"; x = { ... }; }'
|
||||
' \
|
||||
'{
|
||||
a = { ... };
|
||||
l = [ ... ];
|
||||
n = 1234;
|
||||
s = "string";
|
||||
x = { ... };
|
||||
}
|
||||
'
|
||||
|
||||
# Same for lists, but order is preserved
|
||||
testReplResponseNoRegex '
|
||||
[ 42 1 "thingy" ({ a = 1; }) ([ 1 2 3 ]) ]
|
||||
' '[ 42 1 "thingy" { ... } [ ... ] ]'
|
||||
' \
|
||||
'[
|
||||
42
|
||||
1
|
||||
"thingy"
|
||||
{ ... }
|
||||
[ ... ]
|
||||
]
|
||||
'
|
||||
|
||||
# Same for let expressions
|
||||
testReplResponseNoRegex '
|
||||
let x = { y = { a = 1; }; inherit x; }; in x
|
||||
' '{ x = { ... }; y = { ... }; }'
|
||||
' \
|
||||
'{
|
||||
x = { ... };
|
||||
y = { ... };
|
||||
}
|
||||
'
|
||||
|
||||
# The :p command should recursively print sets, but prevent infinite recursion
|
||||
testReplResponseNoRegex '
|
||||
:p { a = { b = 2; }; s = "string"; n = 1234; x = rec { y = { z = { inherit y; }; }; }; }
|
||||
' '{ a = { b = 2; }; n = 1234; s = "string"; x = { y = { z = { y = «repeated»; }; }; }; }'
|
||||
' \
|
||||
'{
|
||||
a = { b = 2; };
|
||||
n = 1234;
|
||||
s = "string";
|
||||
x = {
|
||||
y = {
|
||||
z = {
|
||||
y = «repeated»;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
'
|
||||
|
||||
# Same for lists
|
||||
testReplResponseNoRegex '
|
||||
:p [ 42 1 "thingy" (rec { a = 1; b = { inherit a; inherit b; }; }) ([ 1 2 3 ]) ]
|
||||
' '[ 42 1 "thingy" { a = 1; b = { a = 1; b = «repeated»; }; } [ 1 2 3 ] ]'
|
||||
' \
|
||||
'[
|
||||
42
|
||||
1
|
||||
"thingy"
|
||||
{
|
||||
a = 1;
|
||||
b = {
|
||||
a = 1;
|
||||
b = «repeated»;
|
||||
};
|
||||
}
|
||||
[
|
||||
1
|
||||
2
|
||||
3
|
||||
]
|
||||
]
|
||||
'
|
||||
|
||||
# Same for let expressions
|
||||
testReplResponseNoRegex '
|
||||
:p let x = { y = { a = 1; }; inherit x; }; in x
|
||||
' '{ x = { x = «repeated»; y = { a = 1; }; }; y = «repeated»; }'
|
||||
' \
|
||||
'{
|
||||
x = «repeated»;
|
||||
y = { a = 1 };
|
||||
}
|
||||
'
|
||||
|
|
|
@ -42,11 +42,11 @@ test_tarball() {
|
|||
nix-instantiate --strict --eval -E "!((import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })) ? submodules)" >&2
|
||||
nix-instantiate --strict --eval -E "!((import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })) ? submodules)" 2>&1 | grep 'true'
|
||||
|
||||
nix-instantiate --eval -E '1 + 2' -I fnord=file://no-such-tarball.tar$ext
|
||||
nix-instantiate --eval -E 'with <fnord/xyzzy>; 1 + 2' -I fnord=file://no-such-tarball$ext
|
||||
(! nix-instantiate --eval -E '<fnord/xyzzy> 1' -I fnord=file://no-such-tarball$ext)
|
||||
nix-instantiate --eval -E '1 + 2' -I fnord=file:///no-such-tarball.tar$ext
|
||||
nix-instantiate --eval -E 'with <fnord/xyzzy>; 1 + 2' -I fnord=file:///no-such-tarball$ext
|
||||
(! nix-instantiate --eval -E '<fnord/xyzzy> 1' -I fnord=file:///no-such-tarball$ext)
|
||||
|
||||
nix-instantiate --eval -E '<fnord/config.nix>' -I fnord=file://no-such-tarball$ext -I fnord=.
|
||||
nix-instantiate --eval -E '<fnord/config.nix>' -I fnord=file:///no-such-tarball$ext -I fnord=.
|
||||
|
||||
# Ensure that the `name` attribute isn’t accepted as that would mess
|
||||
# with the content-addressing
|
||||
|
@ -57,8 +57,3 @@ test_tarball() {
|
|||
test_tarball '' cat
|
||||
test_tarball .xz xz
|
||||
test_tarball .gz gzip
|
||||
|
||||
rm -rf $TEST_ROOT/tmp
|
||||
mkdir -p $TEST_ROOT/tmp
|
||||
(! TMPDIR=$TEST_ROOT/tmp XDG_RUNTIME_DIR=$TEST_ROOT/tmp nix-env -f file://$(pwd)/bad.tar.xz -qa --out-path)
|
||||
(! [ -e $TEST_ROOT/tmp/bad ])
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -14,6 +14,7 @@ namespace nix {
|
|||
ASSERT_EQ(getNameFromURL(parseURL("path:./repos/myflake#nonStandardAttr.mylaptop")), "mylaptop");
|
||||
ASSERT_EQ(getNameFromURL(parseURL("path:./nixpkgs#packages.x86_64-linux.complex^bin,man")), "complex");
|
||||
ASSERT_EQ(getNameFromURL(parseURL("path:./myproj#packages.x86_64-linux.default^*")), "myproj");
|
||||
ASSERT_EQ(getNameFromURL(parseURL("path:./myproj#defaultPackage.x86_64-linux")), "myproj");
|
||||
|
||||
ASSERT_EQ(getNameFromURL(parseURL("github:NixOS/nixpkgs#packages.x86_64-linux.hello")), "hello");
|
||||
ASSERT_EQ(getNameFromURL(parseURL("github:NixOS/nixpkgs#hello")), "hello");
|
||||
|
|
|
@ -460,19 +460,7 @@ TEST_F(ValuePrintingTests, ansiColorsError)
|
|||
|
||||
test(vError,
|
||||
ANSI_RED
|
||||
"«"
|
||||
ANSI_RED
|
||||
"error:"
|
||||
ANSI_NORMAL
|
||||
"\n … while calling the '"
|
||||
ANSI_MAGENTA
|
||||
"throw"
|
||||
ANSI_NORMAL
|
||||
"' builtin\n\n "
|
||||
ANSI_RED
|
||||
"error:"
|
||||
ANSI_NORMAL
|
||||
" uh oh!»"
|
||||
"«error: uh oh!»"
|
||||
ANSI_NORMAL,
|
||||
PrintOptions {
|
||||
.ansiColors = true,
|
||||
|
@ -501,19 +489,7 @@ TEST_F(ValuePrintingTests, ansiColorsDerivationError)
|
|||
test(vAttrs,
|
||||
"{ drvPath = "
|
||||
ANSI_RED
|
||||
"«"
|
||||
ANSI_RED
|
||||
"error:"
|
||||
ANSI_NORMAL
|
||||
"\n … while calling the '"
|
||||
ANSI_MAGENTA
|
||||
"throw"
|
||||
ANSI_NORMAL
|
||||
"' builtin\n\n "
|
||||
ANSI_RED
|
||||
"error:"
|
||||
ANSI_NORMAL
|
||||
" uh oh!»"
|
||||
"«error: uh oh!»"
|
||||
ANSI_NORMAL
|
||||
"; type = "
|
||||
ANSI_MAGENTA
|
||||
|
@ -527,19 +503,7 @@ TEST_F(ValuePrintingTests, ansiColorsDerivationError)
|
|||
|
||||
test(vAttrs,
|
||||
ANSI_RED
|
||||
"«"
|
||||
ANSI_RED
|
||||
"error:"
|
||||
ANSI_NORMAL
|
||||
"\n … while calling the '"
|
||||
ANSI_MAGENTA
|
||||
"throw"
|
||||
ANSI_NORMAL
|
||||
"' builtin\n\n "
|
||||
ANSI_RED
|
||||
"error:"
|
||||
ANSI_NORMAL
|
||||
" uh oh!»"
|
||||
"«error: uh oh!»"
|
||||
ANSI_NORMAL,
|
||||
PrintOptions {
|
||||
.ansiColors = true,
|
||||
|
@ -560,7 +524,7 @@ TEST_F(ValuePrintingTests, ansiColorsAssert)
|
|||
state.mkThunk_(v, &expr);
|
||||
|
||||
test(v,
|
||||
ANSI_RED "«" ANSI_RED "error:" ANSI_NORMAL " assertion '" ANSI_MAGENTA "false" ANSI_NORMAL "' failed»" ANSI_NORMAL,
|
||||
ANSI_RED "«error: assertion 'false' failed»" ANSI_NORMAL,
|
||||
PrintOptions {
|
||||
.ansiColors = true,
|
||||
.force = true
|
||||
|
@ -756,7 +720,7 @@ TEST_F(ValuePrintingTests, ansiColorsAttrsElided)
|
|||
vAttrs.mkAttrs(builder.finish());
|
||||
|
||||
test(vAttrs,
|
||||
"{ one = " ANSI_CYAN "1" ANSI_NORMAL "; " ANSI_FAINT "«1 attribute elided»" ANSI_NORMAL "}",
|
||||
"{ one = " ANSI_CYAN "1" ANSI_NORMAL "; " ANSI_FAINT "«1 attribute elided»" ANSI_NORMAL " }",
|
||||
PrintOptions {
|
||||
.ansiColors = true,
|
||||
.maxAttrs = 1
|
||||
|
@ -769,7 +733,7 @@ TEST_F(ValuePrintingTests, ansiColorsAttrsElided)
|
|||
vAttrs.mkAttrs(builder.finish());
|
||||
|
||||
test(vAttrs,
|
||||
"{ one = " ANSI_CYAN "1" ANSI_NORMAL "; " ANSI_FAINT "«2 attributes elided»" ANSI_NORMAL "}",
|
||||
"{ one = " ANSI_CYAN "1" ANSI_NORMAL "; " ANSI_FAINT "«2 attributes elided»" ANSI_NORMAL " }",
|
||||
PrintOptions {
|
||||
.ansiColors = true,
|
||||
.maxAttrs = 1
|
||||
|
@ -793,7 +757,7 @@ TEST_F(ValuePrintingTests, ansiColorsListElided)
|
|||
vList.bigList.size = 2;
|
||||
|
||||
test(vList,
|
||||
"[ " ANSI_CYAN "1" ANSI_NORMAL " " ANSI_FAINT "«1 item elided»" ANSI_NORMAL "]",
|
||||
"[ " ANSI_CYAN "1" ANSI_NORMAL " " ANSI_FAINT "«1 item elided»" ANSI_NORMAL " ]",
|
||||
PrintOptions {
|
||||
.ansiColors = true,
|
||||
.maxListItems = 1
|
||||
|
@ -806,7 +770,7 @@ TEST_F(ValuePrintingTests, ansiColorsListElided)
|
|||
vList.bigList.size = 3;
|
||||
|
||||
test(vList,
|
||||
"[ " ANSI_CYAN "1" ANSI_NORMAL " " ANSI_FAINT "«2 items elided»" ANSI_NORMAL "]",
|
||||
"[ " ANSI_CYAN "1" ANSI_NORMAL " " ANSI_FAINT "«2 items elided»" ANSI_NORMAL " ]",
|
||||
PrintOptions {
|
||||
.ansiColors = true,
|
||||
.maxListItems = 1
|
||||
|
|
37
tests/unit/libstore/content-address.cc
Normal file
37
tests/unit/libstore/content-address.cc
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include "content-address.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ContentAddressMethod::parse, ContentAddressMethod::render
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST(ContentAddressMethod, testRoundTripPrintParse_1) {
|
||||
for (const ContentAddressMethod & cam : {
|
||||
ContentAddressMethod { TextIngestionMethod {} },
|
||||
ContentAddressMethod { FileIngestionMethod::Flat },
|
||||
ContentAddressMethod { FileIngestionMethod::Recursive },
|
||||
ContentAddressMethod { FileIngestionMethod::Git },
|
||||
}) {
|
||||
EXPECT_EQ(ContentAddressMethod::parse(cam.render()), cam);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ContentAddressMethod, testRoundTripPrintParse_2) {
|
||||
for (const std::string_view camS : {
|
||||
"text",
|
||||
"flat",
|
||||
"nar",
|
||||
"git",
|
||||
}) {
|
||||
EXPECT_EQ(ContentAddressMethod::parse(camS).render(), camS);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ContentAddressMethod, testParseContentAddressMethodOptException) {
|
||||
EXPECT_THROW(ContentAddressMethod::parse("narwhal"), UsageError);
|
||||
}
|
||||
|
||||
}
|
|
@ -41,6 +41,24 @@ namespace nix {
|
|||
}
|
||||
}
|
||||
|
||||
TEST(CanonPath, from_existing) {
|
||||
CanonPath p0("foo//bar/");
|
||||
{
|
||||
CanonPath p("/baz//quux/", p0);
|
||||
ASSERT_EQ(p.abs(), "/baz/quux");
|
||||
ASSERT_EQ(p.rel(), "baz/quux");
|
||||
ASSERT_EQ(*p.baseName(), "quux");
|
||||
ASSERT_EQ(*p.dirOf(), "/baz");
|
||||
}
|
||||
{
|
||||
CanonPath p("baz//quux/", p0);
|
||||
ASSERT_EQ(p.abs(), "/foo/bar/baz/quux");
|
||||
ASSERT_EQ(p.rel(), "foo/bar/baz/quux");
|
||||
ASSERT_EQ(*p.baseName(), "quux");
|
||||
ASSERT_EQ(*p.dirOf(), "/foo/bar/baz");
|
||||
}
|
||||
}
|
||||
|
||||
TEST(CanonPath, pop) {
|
||||
CanonPath p("foo/bar/x");
|
||||
ASSERT_EQ(p.abs(), "/foo/bar/x");
|
||||
|
@ -80,29 +98,29 @@ namespace nix {
|
|||
{
|
||||
CanonPath p1("a//foo/bar//");
|
||||
CanonPath p2("xyzzy/bla");
|
||||
ASSERT_EQ((p1 + p2).abs(), "/a/foo/bar/xyzzy/bla");
|
||||
ASSERT_EQ((p1 / p2).abs(), "/a/foo/bar/xyzzy/bla");
|
||||
}
|
||||
|
||||
{
|
||||
CanonPath p1("/");
|
||||
CanonPath p2("/a/b");
|
||||
ASSERT_EQ((p1 + p2).abs(), "/a/b");
|
||||
ASSERT_EQ((p1 / p2).abs(), "/a/b");
|
||||
}
|
||||
|
||||
{
|
||||
CanonPath p1("/a/b");
|
||||
CanonPath p2("/");
|
||||
ASSERT_EQ((p1 + p2).abs(), "/a/b");
|
||||
ASSERT_EQ((p1 / p2).abs(), "/a/b");
|
||||
}
|
||||
|
||||
{
|
||||
CanonPath p("/foo/bar");
|
||||
ASSERT_EQ((p + "x").abs(), "/foo/bar/x");
|
||||
ASSERT_EQ((p / "x").abs(), "/foo/bar/x");
|
||||
}
|
||||
|
||||
{
|
||||
CanonPath p("/");
|
||||
ASSERT_EQ((p + "foo" + "bar").abs(), "/foo/bar");
|
||||
ASSERT_EQ((p / "foo" / "bar").abs(), "/foo/bar");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
61
tests/unit/libutil/file-content-address.cc
Normal file
61
tests/unit/libutil/file-content-address.cc
Normal file
|
@ -0,0 +1,61 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include "file-content-address.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* parseFileSerialisationMethod, renderFileSerialisationMethod
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST(FileSerialisationMethod, testRoundTripPrintParse_1) {
|
||||
for (const FileSerialisationMethod fim : {
|
||||
FileSerialisationMethod::Flat,
|
||||
FileSerialisationMethod::Recursive,
|
||||
}) {
|
||||
EXPECT_EQ(parseFileSerialisationMethod(renderFileSerialisationMethod(fim)), fim);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(FileSerialisationMethod, testRoundTripPrintParse_2) {
|
||||
for (const std::string_view fimS : {
|
||||
"flat",
|
||||
"nar",
|
||||
}) {
|
||||
EXPECT_EQ(renderFileSerialisationMethod(parseFileSerialisationMethod(fimS)), fimS);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(FileSerialisationMethod, testParseFileSerialisationMethodOptException) {
|
||||
EXPECT_THROW(parseFileSerialisationMethod("narwhal"), UsageError);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* parseFileIngestionMethod, renderFileIngestionMethod
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST(FileIngestionMethod, testRoundTripPrintParse_1) {
|
||||
for (const FileIngestionMethod fim : {
|
||||
FileIngestionMethod::Flat,
|
||||
FileIngestionMethod::Recursive,
|
||||
FileIngestionMethod::Git,
|
||||
}) {
|
||||
EXPECT_EQ(parseFileIngestionMethod(renderFileIngestionMethod(fim)), fim);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(FileIngestionMethod, testRoundTripPrintParse_2) {
|
||||
for (const std::string_view fimS : {
|
||||
"flat",
|
||||
"nar",
|
||||
"git",
|
||||
}) {
|
||||
EXPECT_EQ(renderFileIngestionMethod(parseFileIngestionMethod(fimS)), fimS);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(FileIngestionMethod, testParseFileIngestionMethodOptException) {
|
||||
EXPECT_THROW(parseFileIngestionMethod("narwhal"), UsageError);
|
||||
}
|
||||
|
||||
}
|
|
@ -42,7 +42,7 @@ namespace nix {
|
|||
|
||||
makeJSONLogger(*logger)->logEI({
|
||||
.name = "error name",
|
||||
.msg = hintfmt("this hint has %1% templated %2%!!",
|
||||
.msg = HintFmt("this hint has %1% templated %2%!!",
|
||||
"yellow",
|
||||
"values"),
|
||||
.errPos = Pos(foFile, problem_file, 02, 13)
|
||||
|
@ -62,7 +62,7 @@ namespace nix {
|
|||
throw TestError(e.info());
|
||||
} catch (Error &e) {
|
||||
ErrorInfo ei = e.info();
|
||||
ei.msg = hintfmt("%s; subsequent error message.", normaltxt(e.info().msg.str()));
|
||||
ei.msg = HintFmt("%s; subsequent error message.", Uncolored(e.info().msg.str()));
|
||||
|
||||
testing::internal::CaptureStderr();
|
||||
logger->logEI(ei);
|
||||
|
@ -176,7 +176,7 @@ namespace nix {
|
|||
|
||||
logError({
|
||||
.name = "error name",
|
||||
.msg = hintfmt("this hint has %1% templated %2%!!",
|
||||
.msg = HintFmt("this hint has %1% templated %2%!!",
|
||||
"yellow",
|
||||
"values"),
|
||||
.errPos = Pos(foString, problem_file, 02, 13),
|
||||
|
@ -193,7 +193,7 @@ namespace nix {
|
|||
|
||||
logError({
|
||||
.name = "error name",
|
||||
.msg = hintfmt("this hint has %1% templated %2%!!",
|
||||
.msg = HintFmt("this hint has %1% templated %2%!!",
|
||||
"yellow",
|
||||
"values"),
|
||||
.errPos = Pos(foFile, problem_file, 02, 13)
|
||||
|
@ -208,7 +208,7 @@ namespace nix {
|
|||
|
||||
logError({
|
||||
.name = "error name",
|
||||
.msg = hintfmt("hint %1%", "only"),
|
||||
.msg = HintFmt("hint %1%", "only"),
|
||||
});
|
||||
|
||||
auto str = testing::internal::GetCapturedStderr();
|
||||
|
@ -225,7 +225,7 @@ namespace nix {
|
|||
|
||||
logWarning({
|
||||
.name = "name",
|
||||
.msg = hintfmt("there was a %1%", "warning"),
|
||||
.msg = HintFmt("there was a %1%", "warning"),
|
||||
});
|
||||
|
||||
auto str = testing::internal::GetCapturedStderr();
|
||||
|
@ -241,7 +241,7 @@ namespace nix {
|
|||
|
||||
logWarning({
|
||||
.name = "warning name",
|
||||
.msg = hintfmt("this hint has %1% templated %2%!!",
|
||||
.msg = HintFmt("this hint has %1% templated %2%!!",
|
||||
"yellow",
|
||||
"values"),
|
||||
.errPos = Pos(foStdin, problem_file, 2, 13),
|
||||
|
@ -264,7 +264,7 @@ namespace nix {
|
|||
|
||||
auto e = AssertionError(ErrorInfo {
|
||||
.name = "wat",
|
||||
.msg = hintfmt("it has been %1% days since our last error", "zero"),
|
||||
.msg = HintFmt("it has been %1% days since our last error", "zero"),
|
||||
.errPos = Pos(foString, problem_file, 2, 13),
|
||||
});
|
||||
|
||||
|
@ -290,7 +290,7 @@ namespace nix {
|
|||
|
||||
auto e = AssertionError(ErrorInfo {
|
||||
.name = "wat",
|
||||
.msg = hintfmt("it has been %1% days since our last error", "zero"),
|
||||
.msg = HintFmt("it has been %1% days since our last error", "zero"),
|
||||
.errPos = Pos(foString, problem_file, 2, 13),
|
||||
});
|
||||
|
||||
|
@ -310,39 +310,39 @@ namespace nix {
|
|||
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* hintfmt
|
||||
* HintFmt
|
||||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST(hintfmt, percentStringWithoutArgs) {
|
||||
TEST(HintFmt, percentStringWithoutArgs) {
|
||||
|
||||
const char *teststr = "this is 100%s correct!";
|
||||
|
||||
ASSERT_STREQ(
|
||||
hintfmt(teststr).str().c_str(),
|
||||
HintFmt(teststr).str().c_str(),
|
||||
teststr);
|
||||
|
||||
}
|
||||
|
||||
TEST(hintfmt, fmtToHintfmt) {
|
||||
TEST(HintFmt, fmtToHintfmt) {
|
||||
|
||||
ASSERT_STREQ(
|
||||
hintfmt(fmt("the color of this this text is %1%", "not yellow")).str().c_str(),
|
||||
HintFmt(fmt("the color of this this text is %1%", "not yellow")).str().c_str(),
|
||||
"the color of this this text is not yellow");
|
||||
|
||||
}
|
||||
|
||||
TEST(hintfmt, tooFewArguments) {
|
||||
TEST(HintFmt, tooFewArguments) {
|
||||
|
||||
ASSERT_STREQ(
|
||||
hintfmt("only one arg %1% %2%", "fulfilled").str().c_str(),
|
||||
HintFmt("only one arg %1% %2%", "fulfilled").str().c_str(),
|
||||
"only one arg " ANSI_WARNING "fulfilled" ANSI_NORMAL " ");
|
||||
|
||||
}
|
||||
|
||||
TEST(hintfmt, tooManyArguments) {
|
||||
TEST(HintFmt, tooManyArguments) {
|
||||
|
||||
ASSERT_STREQ(
|
||||
hintfmt("what about this %1% %2%", "%3%", "one", "two").str().c_str(),
|
||||
HintFmt("what about this %1% %2%", "%3%", "one", "two").str().c_str(),
|
||||
"what about this " ANSI_WARNING "%3%" ANSI_NORMAL " " ANSI_YELLOW "one" ANSI_NORMAL);
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,14 @@
|
|||
|
||||
#include <numeric>
|
||||
|
||||
#ifdef _WIN32
|
||||
# define FS_SEP "\\"
|
||||
# define FS_ROOT "C:" FS_SEP // Need a mounted one, C drive is likely
|
||||
#else
|
||||
# define FS_SEP "/"
|
||||
# define FS_ROOT FS_SEP
|
||||
#endif
|
||||
|
||||
namespace nix {
|
||||
|
||||
/* ----------- tests for util.hh ------------------------------------------------*/
|
||||
|
@ -18,9 +26,9 @@ namespace nix {
|
|||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST(absPath, doesntChangeRoot) {
|
||||
auto p = absPath("/");
|
||||
auto p = absPath(FS_ROOT);
|
||||
|
||||
ASSERT_EQ(p, "/");
|
||||
ASSERT_EQ(p, FS_ROOT);
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,11 +61,11 @@ namespace nix {
|
|||
|
||||
|
||||
TEST(absPath, pathIsCanonicalised) {
|
||||
auto path = "/some/path/with/trailing/dot/.";
|
||||
auto path = FS_ROOT "some/path/with/trailing/dot/.";
|
||||
auto p1 = absPath(path);
|
||||
auto p2 = absPath(p1);
|
||||
|
||||
ASSERT_EQ(p1, "/some/path/with/trailing/dot");
|
||||
ASSERT_EQ(p1, FS_ROOT "some" FS_SEP "path" FS_SEP "with" FS_SEP "trailing" FS_SEP "dot");
|
||||
ASSERT_EQ(p1, p2);
|
||||
}
|
||||
|
||||
|
@ -66,24 +74,24 @@ namespace nix {
|
|||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST(canonPath, removesTrailingSlashes) {
|
||||
auto path = "/this/is/a/path//";
|
||||
auto path = FS_ROOT "this/is/a/path//";
|
||||
auto p = canonPath(path);
|
||||
|
||||
ASSERT_EQ(p, "/this/is/a/path");
|
||||
ASSERT_EQ(p, FS_ROOT "this" FS_SEP "is" FS_SEP "a" FS_SEP "path");
|
||||
}
|
||||
|
||||
TEST(canonPath, removesDots) {
|
||||
auto path = "/this/./is/a/path/./";
|
||||
auto path = FS_ROOT "this/./is/a/path/./";
|
||||
auto p = canonPath(path);
|
||||
|
||||
ASSERT_EQ(p, "/this/is/a/path");
|
||||
ASSERT_EQ(p, FS_ROOT "this" FS_SEP "is" FS_SEP "a" FS_SEP "path");
|
||||
}
|
||||
|
||||
TEST(canonPath, removesDots2) {
|
||||
auto path = "/this/a/../is/a////path/foo/..";
|
||||
auto path = FS_ROOT "this/a/../is/a////path/foo/..";
|
||||
auto p = canonPath(path);
|
||||
|
||||
ASSERT_EQ(p, "/this/is/a/path");
|
||||
ASSERT_EQ(p, FS_ROOT "this" FS_SEP "is" FS_SEP "a" FS_SEP "path");
|
||||
}
|
||||
|
||||
TEST(canonPath, requiresAbsolutePath) {
|
||||
|
@ -197,7 +205,7 @@ namespace nix {
|
|||
* --------------------------------------------------------------------------*/
|
||||
|
||||
TEST(pathExists, rootExists) {
|
||||
ASSERT_TRUE(pathExists("/"));
|
||||
ASSERT_TRUE(pathExists(FS_ROOT));
|
||||
}
|
||||
|
||||
TEST(pathExists, cwdExists) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue