diff options
author | alois31 <alois1@gmx-topmail.de> | 2024-07-19 06:40:13 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@localhost> | 2024-07-19 06:40:13 +0000 |
commit | aba5f19680b2f4c29d7ce2ff5e2a89128c1cb26d (patch) | |
tree | c1c3ce68cd7aab98167a394e11934ebcaed27ade /tests | |
parent | 5ee1e6ea9887a54f0af3a66528abc04b17611516 (diff) | |
parent | 768d1f29a2dcd9ed9552fafb4ab836ea2e400738 (diff) |
Merge changes I829581a3,I0016970d,I5dac8e77,Ib7560fe5 into main
* changes:
doc/release-notes: add for pretty printing improvements
libexpr/print: do not show elided nested items when there are none
libexpr/print: never show empty attrsets or derivations as «repeated»
libexpr/print: pretty-print idempotently
Diffstat (limited to 'tests')
-rw-r--r-- | tests/functional/repl_characterization/data/idempotent.test | 13 | ||||
-rw-r--r-- | tests/functional/repl_characterization/repl_characterization.cc | 1 | ||||
-rw-r--r-- | tests/unit/libexpr/value/print.cc | 67 |
3 files changed, 58 insertions, 23 deletions
diff --git a/tests/functional/repl_characterization/data/idempotent.test b/tests/functional/repl_characterization/data/idempotent.test new file mode 100644 index 000000000..4ab087d45 --- /dev/null +++ b/tests/functional/repl_characterization/data/idempotent.test @@ -0,0 +1,13 @@ +A previously unforced thunk in an attribute set does not lead to indentation when it won't evaluate to a nested structure: + nix-repl> :p let x = 1 + 2; in [ { inherit x; } { inherit x; } ] + [ + { x = 3; } + { x = 3; } + ] + +Same for a list: + nix-repl> :p let x = 1 + 2; in [ [ x ] [ x ] ] + [ + [ 3 ] + [ 3 ] + ] diff --git a/tests/functional/repl_characterization/repl_characterization.cc b/tests/functional/repl_characterization/repl_characterization.cc index c91d6c1e3..f2cf0ca3d 100644 --- a/tests/functional/repl_characterization/repl_characterization.cc +++ b/tests/functional/repl_characterization/repl_characterization.cc @@ -185,5 +185,6 @@ REPL_TEST(repl_overlays_error); REPL_TEST(repl_printing); REPL_TEST(stack_vars); REPL_TEST(errors); +REPL_TEST(idempotent); }; // namespace nix diff --git a/tests/unit/libexpr/value/print.cc b/tests/unit/libexpr/value/print.cc index cdbc8f8f9..ddf8b8b99 100644 --- a/tests/unit/libexpr/value/print.cc +++ b/tests/unit/libexpr/value/print.cc @@ -193,6 +193,9 @@ TEST_F(ValuePrintingTests, vBlackhole) TEST_F(ValuePrintingTests, depthAttrs) { + Value vZero; + vZero.mkInt(0); + Value vOne; vOne.mkInt(1); @@ -203,10 +206,16 @@ TEST_F(ValuePrintingTests, depthAttrs) Value vAttrsEmpty; vAttrsEmpty.mkAttrs(builderEmpty.finish()); + BindingsBuilder builderNested(state, state.allocBindings(1)); + builderNested.insert(state.symbols.create("zero"), &vZero); + Value vAttrsNested; + vAttrsNested.mkAttrs(builderNested.finish()); + BindingsBuilder builder(state, state.allocBindings(10)); builder.insert(state.symbols.create("one"), &vOne); builder.insert(state.symbols.create("two"), &vTwo); - builder.insert(state.symbols.create("nested"), &vAttrsEmpty); + builder.insert(state.symbols.create("empty"), &vAttrsEmpty); + builder.insert(state.symbols.create("nested"), &vAttrsNested); Value vAttrs; vAttrs.mkAttrs(builder.finish()); @@ -220,9 +229,9 @@ TEST_F(ValuePrintingTests, depthAttrs) vNested.mkAttrs(builder2.finish()); test(vNested, "{ nested = { ... }; one = 1; two = 2; }", PrintOptions { .maxDepth = 1 }); - test(vNested, "{ nested = { nested = { ... }; one = 1; two = 2; }; one = 1; two = 2; }", PrintOptions { .maxDepth = 2 }); - test(vNested, "{ nested = { nested = { }; one = 1; two = 2; }; one = 1; two = 2; }", PrintOptions { .maxDepth = 3 }); - test(vNested, "{ nested = { nested = { }; one = 1; two = 2; }; one = 1; two = 2; }", PrintOptions { .maxDepth = 4 }); + test(vNested, "{ nested = { empty = { }; nested = { ... }; one = 1; two = 2; }; one = 1; two = 2; }", PrintOptions { .maxDepth = 2 }); + test(vNested, "{ nested = { empty = { }; nested = { zero = 0; }; one = 1; two = 2; }; one = 1; two = 2; }", PrintOptions { .maxDepth = 3 }); + test(vNested, "{ nested = { empty = { }; nested = { zero = 0; }; one = 1; two = 2; }; one = 1; two = 2; }", PrintOptions { .maxDepth = 4 }); } TEST_F(ValuePrintingTests, depthList) @@ -641,20 +650,24 @@ TEST_F(ValuePrintingTests, ansiColorsBlackhole) TEST_F(ValuePrintingTests, ansiColorsAttrsRepeated) { - BindingsBuilder emptyBuilder(state, state.allocBindings(1)); + Value vZero; + vZero.mkInt(0); + + BindingsBuilder innerBuilder(state, state.allocBindings(1)); + innerBuilder.insert(state.symbols.create("x"), &vZero); - Value vEmpty; - vEmpty.mkAttrs(emptyBuilder.finish()); + Value vInner; + vInner.mkAttrs(innerBuilder.finish()); BindingsBuilder builder(state, state.allocBindings(10)); - builder.insert(state.symbols.create("a"), &vEmpty); - builder.insert(state.symbols.create("b"), &vEmpty); + builder.insert(state.symbols.create("a"), &vInner); + builder.insert(state.symbols.create("b"), &vInner); Value vAttrs; vAttrs.mkAttrs(builder.finish()); test(vAttrs, - "{ a = { }; b = " ANSI_MAGENTA "«repeated»" ANSI_NORMAL "; }", + "{ a = { x = " ANSI_CYAN "0" ANSI_NORMAL "; }; b = " ANSI_MAGENTA "«repeated»" ANSI_NORMAL "; }", PrintOptions { .ansiColors = true }); @@ -662,19 +675,23 @@ TEST_F(ValuePrintingTests, ansiColorsAttrsRepeated) TEST_F(ValuePrintingTests, ansiColorsListRepeated) { - BindingsBuilder emptyBuilder(state, state.allocBindings(1)); + Value vZero; + vZero.mkInt(0); + + BindingsBuilder innerBuilder(state, state.allocBindings(1)); + innerBuilder.insert(state.symbols.create("x"), &vZero); - Value vEmpty; - vEmpty.mkAttrs(emptyBuilder.finish()); + Value vInner; + vInner.mkAttrs(innerBuilder.finish()); Value vList; state.mkList(vList, 3); - vList.bigList.elems[0] = &vEmpty; - vList.bigList.elems[1] = &vEmpty; + vList.bigList.elems[0] = &vInner; + vList.bigList.elems[1] = &vInner; vList.bigList.size = 2; test(vList, - "[ { } " ANSI_MAGENTA "«repeated»" ANSI_NORMAL " ]", + "[ { x = " ANSI_CYAN "0" ANSI_NORMAL "; } " ANSI_MAGENTA "«repeated»" ANSI_NORMAL " ]", PrintOptions { .ansiColors = true }); @@ -682,20 +699,24 @@ TEST_F(ValuePrintingTests, ansiColorsListRepeated) TEST_F(ValuePrintingTests, listRepeated) { - BindingsBuilder emptyBuilder(state, state.allocBindings(1)); + Value vZero; + vZero.mkInt(0); + + BindingsBuilder innerBuilder(state, state.allocBindings(1)); + innerBuilder.insert(state.symbols.create("x"), &vZero); - Value vEmpty; - vEmpty.mkAttrs(emptyBuilder.finish()); + Value vInner; + vInner.mkAttrs(innerBuilder.finish()); Value vList; state.mkList(vList, 3); - vList.bigList.elems[0] = &vEmpty; - vList.bigList.elems[1] = &vEmpty; + vList.bigList.elems[0] = &vInner; + vList.bigList.elems[1] = &vInner; vList.bigList.size = 2; - test(vList, "[ { } «repeated» ]", PrintOptions { }); + test(vList, "[ { x = 0; } «repeated» ]", PrintOptions { }); test(vList, - "[ { } { } ]", + "[ { x = 0; } { x = 0; } ]", PrintOptions { .trackRepeated = false }); |