mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
tests/functional: use script flags compatible with macOS
Co-authored-by: John Ericson <git@JohnEricson.me>
This commit is contained in:
parent
2172c17b5e
commit
f02c57dbfa
2 changed files with 33 additions and 4 deletions
|
@ -19,6 +19,20 @@ cat > "$TEST_HOME/expected-pretty.json" <<EOF
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
shellEscapeArray() {
|
||||||
|
local result=""
|
||||||
|
local separator=""
|
||||||
|
|
||||||
|
for item in "$@"; do
|
||||||
|
local escaped
|
||||||
|
printf -v escaped "%q" "$item"
|
||||||
|
result="${result}${separator}${escaped}"
|
||||||
|
separator=" "
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$result"
|
||||||
|
}
|
||||||
|
|
||||||
nix eval --json --expr '{ a.b.c = true; }' > "$TEST_HOME/actual.json"
|
nix eval --json --expr '{ a.b.c = true; }' > "$TEST_HOME/actual.json"
|
||||||
diff -U3 "$TEST_HOME/expected-machine.json" "$TEST_HOME/actual.json"
|
diff -U3 "$TEST_HOME/expected-machine.json" "$TEST_HOME/actual.json"
|
||||||
|
|
||||||
|
@ -27,18 +41,31 @@ nix eval --json --pretty --expr \
|
||||||
diff -U3 "$TEST_HOME/expected-pretty.json" "$TEST_HOME/actual.json"
|
diff -U3 "$TEST_HOME/expected-pretty.json" "$TEST_HOME/actual.json"
|
||||||
|
|
||||||
if type script &>/dev/null; then
|
if type script &>/dev/null; then
|
||||||
script --return --quiet --command 'nix eval --json --expr "{ a.b.c = true; }"' > "$TEST_HOME/actual.json"
|
acceptsCommandFlag=0
|
||||||
|
# The macOS version just accepts multiple arguments, but util-linux and its `-c` flag only accept a single argument, which is then split on whitespace. We thus have to quote in that case.
|
||||||
|
if script -c true /dev/null 2>/dev/null; then
|
||||||
|
acceptsCommandFlag=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
runScript() {
|
||||||
|
if [[ $acceptsCommandFlag -eq 0 ]]; then
|
||||||
|
script -e -q /dev/null "$@"
|
||||||
|
else
|
||||||
|
script -e -q /dev/null -c "$(shellEscapeArray "$@")"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
runScript nix eval --json --expr "{ a.b.c = true; }" > "$TEST_HOME/actual.json"
|
||||||
cat "$TEST_HOME/actual.json"
|
cat "$TEST_HOME/actual.json"
|
||||||
# script isn't perfectly accurate? Let's grep for a pretty good indication, as the pretty output has a space between the key and the value.
|
# script isn't perfectly accurate? Let's grep for a pretty good indication, as the pretty output has a space between the key and the value.
|
||||||
# diff -U3 "$TEST_HOME/expected-pretty.json" "$TEST_HOME/actual.json"
|
# diff -U3 "$TEST_HOME/expected-pretty.json" "$TEST_HOME/actual.json"
|
||||||
grep -F '"a": {' "$TEST_HOME/actual.json"
|
grep -F '"a": {' "$TEST_HOME/actual.json"
|
||||||
|
|
||||||
script --return --quiet --command 'nix eval --json --pretty --expr "{ a.b.c = true; }"' > "$TEST_HOME/actual.json"
|
runScript nix eval --json --pretty --expr "{ a.b.c = true; }" > "$TEST_HOME/actual.json"
|
||||||
cat "$TEST_HOME/actual.json"
|
cat "$TEST_HOME/actual.json"
|
||||||
grep -F '"a": {' "$TEST_HOME/actual.json"
|
grep -F '"a": {' "$TEST_HOME/actual.json"
|
||||||
|
|
||||||
script --return --quiet --command 'nix eval --json --no-pretty --expr "{ a.b.c = true; }"' > "$TEST_HOME/actual.json"
|
runScript nix eval --json --no-pretty --expr "{ a.b.c = true; }" > "$TEST_HOME/actual.json"
|
||||||
cat "$TEST_HOME/actual.json"
|
cat "$TEST_HOME/actual.json"
|
||||||
grep -F '"a":{' "$TEST_HOME/actual.json"
|
grep -F '"a":{' "$TEST_HOME/actual.json"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
git,
|
git,
|
||||||
mercurial,
|
mercurial,
|
||||||
util-linux,
|
util-linux,
|
||||||
|
unixtools,
|
||||||
|
|
||||||
nix-store,
|
nix-store,
|
||||||
nix-expr,
|
nix-expr,
|
||||||
|
@ -54,6 +55,7 @@ mkMesonDerivation (
|
||||||
jq
|
jq
|
||||||
git
|
git
|
||||||
mercurial
|
mercurial
|
||||||
|
unixtools.script
|
||||||
]
|
]
|
||||||
++ lib.optionals stdenv.hostPlatform.isLinux [
|
++ lib.optionals stdenv.hostPlatform.isLinux [
|
||||||
# For various sandboxing tests that needs a statically-linked shell,
|
# For various sandboxing tests that needs a statically-linked shell,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue