Files
lix/tests/functional/repl_characterization/data/repl_printing.test
T
blokyk 68834b7841 tests/f1/repl-characterization: match golden text correctly
it seems like the repl_characterization tests have not been actually
running correctly for a while, since tests from more than 2 years ago
that should have failed have been in the test suite and OK'd thus far.

the reason why some tests passed when they shouldn't have is because
the AST nodes used by the characterization parser didn't have a correct
comparison operator, so the tests would only fail when one of the output
line was of the wrong *kind*, but not if it had the wrong *value*. this
was fixed by simply adding a default comparator to the TextNode type as
well as every derived class.

i've taken the occasion to fix the tests that were failing now that we
are actually being strict about them. most of these are pretty boring
changes like indentation, but if possible i'd like to get an explicit
ACK from at least one or two people on the core team that these changes
are okay.

for reference, here is the zulip thread that lead to this CL:
  https://zulip.lix.systems/#narrow/channel/8-Testing-.2F-functional2/topic/.E2.9C.94.20repl-characterization.20tests.20not.20failing/near/10276

ps: i had to turn clang-format off around the macro for text node
declarations because it re-formatted the entire macro, causing a lot
of noising and producing uglier code; if this isn't okay or if there's
a better alternative, please let me know!

Change-Id: I1d6d92eb3e9cb705ecfeccd7b9294d6cfd7fe25b
2026-04-27 23:40:56 +02:00

115 lines
2.5 KiB
Plaintext

Printing a string with escapes in it will render as a string normally.
nix-repl> "meow\n\nmeowmeowmeow"
"meow\n\nmeowmeowmeow"
But with :p on the string itself it will print it literally to the output.
nix-repl> :p "meow\n\nmeowmeowmeow"
meow
meowmeowmeow
nix-repl> builtins.listToAttrs (builtins.genList (x: { name = "meow${toString x}"; value = { meow = { inherit x; s = "meowmeow\n\n${toString x}"; }; }; }) 10)
{
meow0 = { ... };
meow1 = { ... };
meow2 = { ... };
meow3 = { ... };
meow4 = { ... };
meow5 = { ... };
meow6 = { ... };
meow7 = { ... };
meow8 = { ... };
meow9 = { ... };
}
Also, :p will expand attrs, but it will leave the strings escaped as normal if
they aren't the top level item being printed.
nix-repl> :p builtins.listToAttrs (builtins.genList (x: { name = "meow${toString x}"; value = { meow = { inherit x; s = "meowmeow\n\n${toString x}"; }; }; }) 10)
{
meow0 = {
meow = {
s = "meowmeow\n\n0";
x = 0;
};
};
meow1 = {
meow = {
s = "meowmeow\n\n1";
x = 1;
};
};
meow2 = {
meow = {
s = "meowmeow\n\n2";
x = 2;
};
};
meow3 = {
meow = {
s = "meowmeow\n\n3";
x = 3;
};
};
meow4 = {
meow = {
s = "meowmeow\n\n4";
x = 4;
};
};
meow5 = {
meow = {
s = "meowmeow\n\n5";
x = 5;
};
};
meow6 = {
meow = {
s = "meowmeow\n\n6";
x = 6;
};
};
meow7 = {
meow = {
s = "meowmeow\n\n7";
x = 7;
};
};
meow8 = {
meow = {
s = "meowmeow\n\n8";
x = 8;
};
};
meow9 = {
meow = {
s = "meowmeow\n\n9";
x = 9;
};
};
}
Printing an environment with :env after adding a variable to the scope
nix-repl> foo = "bar"
nix-repl> :env
Env level 0
static: foo
Env level 1
abort baseNameOf break builtins derivation derivationStrict dirOf false fetchGit fetchMercurial fetchTarball fetchTree fromTOML import isNull map null placeholder removeAttrs scopedImport throw toString true
Printing a derivation or something
nix-repl> fakeDrv = let drvAttrs = { builder = "meow"; system = "meower"; name = "mrowmrow"; }; in { inherit (drvAttrs) builder system name; inherit drvAttrs; type = "derivation"; }
nix-repl> :p fakeDrv
{
builder = "meow";
drvAttrs = «3 attributes elided»;
name = "mrowmrow";
system = "meower";
type = "derivation";
}