mirror of
https://github.com/NixOS/nix
synced 2025-06-25 02:21:16 +02:00
nix-cli: Add --json --pretty / --no-pretty
Default: istty(stdout) This refactors `nix develop` internals a bit to use the `json` type more. The assertion now operates in the in-memory json instead of re-parsing it. While this is technically a weaker guarantee, we should be able to rely on the library to get this right. It's its most essential purpose.
This commit is contained in:
parent
e9af7a0749
commit
fe00dfbd56
17 changed files with 151 additions and 29 deletions
44
tests/functional/json.sh
Normal file
44
tests/functional/json.sh
Normal file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
source common.sh
|
||||
|
||||
# Meson would split the output into two buffers, ruining the coherence of the log.
|
||||
exec 1>&2
|
||||
|
||||
cat > "$TEST_HOME/expected-machine.json" <<EOF
|
||||
{"a":{"b":{"c":true}}}
|
||||
EOF
|
||||
|
||||
cat > "$TEST_HOME/expected-pretty.json" <<EOF
|
||||
{
|
||||
"a": {
|
||||
"b": {
|
||||
"c": true
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
nix eval --json --expr '{ a.b.c = true; }' > "$TEST_HOME/actual.json"
|
||||
diff -U3 "$TEST_HOME/expected-machine.json" "$TEST_HOME/actual.json"
|
||||
|
||||
nix eval --json --pretty --expr \
|
||||
'{ a.b.c = true; }' > "$TEST_HOME/actual.json"
|
||||
diff -U3 "$TEST_HOME/expected-pretty.json" "$TEST_HOME/actual.json"
|
||||
|
||||
if type script &>/dev/null; then
|
||||
script --return --quiet --command 'nix eval --json --expr "{ a.b.c = true; }"' > "$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.
|
||||
# diff -U3 "$TEST_HOME/expected-pretty.json" "$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"
|
||||
cat "$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"
|
||||
cat "$TEST_HOME/actual.json"
|
||||
grep -F '"a":{' "$TEST_HOME/actual.json"
|
||||
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue