nix-super/tests/unit/libexpr
Rebecca Turner 0fa08b4516
Unify and refactor value printing
Previously, there were two mostly-identical value printers -- one in
`libexpr/eval.cc` (which didn't force values) and one in
`libcmd/repl.cc` (which did force values and also printed ANSI color
codes).

This PR unifies both of these printers into `print.cc` and provides a
`PrintOptions` struct for controlling the output, which allows for
toggling whether values are forced, whether repeated values are tracked,
and whether ANSI color codes are displayed.

Additionally, `PrintOptions` allows tuning the maximum number of
attributes, list items, and bytes in a string that will be displayed;
this makes it ideal for contexts where printing too much output (e.g.
all of Nixpkgs) is distracting. (As requested by @roberth in
https://github.com/NixOS/nix/pull/9554#issuecomment-1845095735)

Please read the tests for example output.

Future work:
- It would be nice to provide this function as a builtin, perhaps
  `builtins.toStringDebug` -- a printing function that never fails would
  be useful when debugging Nix code.
- It would be nice to support customizing `PrintOptions` members on the
  command line, e.g. `--option to-string-max-attrs 1000`.
2024-01-11 16:34:36 -08:00
..
flake getNameFromURL(): Support uppercase characters in attribute names 2023-12-22 16:35:58 +01:00
value Unify and refactor value printing 2024-01-11 16:34:36 -08:00
derived-path.cc Move tests to separate directories, and document 2023-12-01 10:48:58 -05:00
error_traces.cc Revert "Print the value in error: cannot coerce messages (#9553)" 2023-12-09 02:13:32 +01:00
eval.cc allowed-uris: Match whole schemes also when scheme is not followed by slashes 2023-12-11 12:18:04 +01:00
json.cc Move tests to separate directories, and document 2023-12-01 10:48:58 -05:00
local.mk Move url-name utility to libexpr/flake 2023-12-22 09:33:02 +01:00
primops.cc Organize content addressing, use SourceAccessor with Store::addToStore 2023-12-18 10:41:54 -05:00
search-path.cc Move tests to separate directories, and document 2023-12-01 10:48:58 -05:00
trivial.cc Move tests to separate directories, and document 2023-12-01 10:48:58 -05:00