aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-08 08:25:42 +0100
committereldritch horrors <pennae@lix.systems>2024-03-09 07:20:23 -0700
commit1958152d146389b00c50a149c33012a16864ef83 (patch)
tree1a6fb0cbaa147e26dc661092d88bdb6dd7adfdf1 /tests
parentb221a14f0a477db06f8ab705bd08404e431ec135 (diff)
Pretty-print values in the REPL
Pretty-print values in the REPL by printing each item in a list or attrset on a separate line. When possible, single-item lists and attrsets are printed on one line, as long as they don't contain a nested list, attrset, or thunk. Before: ``` { attrs = { a = { b = { c = { }; }; }; }; list = [ 1 ]; list' = [ 1 2 3 ]; } ``` After: ``` { attrs = { a = { b = { c = { }; }; }; }; list = [ 1 ]; list' = [ 1 2 3 ]; } ``` (cherry picked from commit c0a15fb7d03dfb8f53bc6726c414bc88aa362592) Change-Id: Ia2b41849165a5ddb63f7a8c272a2476b3e4292df
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/lang/eval-fail-bad-string-interpolation-4.err.exp2
-rw-r--r--tests/functional/repl.sh69
-rw-r--r--tests/unit/libexpr/value/print.cc8
3 files changed, 68 insertions, 11 deletions
diff --git a/tests/functional/lang/eval-fail-bad-string-interpolation-4.err.exp b/tests/functional/lang/eval-fail-bad-string-interpolation-4.err.exp
index 5119238d7..6f907106b 100644
--- a/tests/functional/lang/eval-fail-bad-string-interpolation-4.err.exp
+++ b/tests/functional/lang/eval-fail-bad-string-interpolation-4.err.exp
@@ -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» }
diff --git a/tests/functional/repl.sh b/tests/functional/repl.sh
index 0921edc0f..3765fb492 100644
--- a/tests/functional/repl.sh
+++ b/tests/functional/repl.sh
@@ -151,29 +151,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 = «repeated»; 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 = «repeated»; y = { a = 1; }; }'
+' \
+'{
+ x = «repeated»;
+ y = { a = 1 };
+}
+'
diff --git a/tests/unit/libexpr/value/print.cc b/tests/unit/libexpr/value/print.cc
index c1de3a6a9..aabf156c2 100644
--- a/tests/unit/libexpr/value/print.cc
+++ b/tests/unit/libexpr/value/print.cc
@@ -720,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
@@ -733,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
@@ -757,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
@@ -770,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