From d0be9e98109428e67e4b7fab3e49728cc6633073 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Thu, 17 Sep 2020 18:08:44 +0200 Subject: [PATCH] =?UTF-8?q?lib/generators.toPretty:=20Switch=20away=20from?= =?UTF-8?q?=20=CE=B4=20and=20=CE=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - These symbols can be confusing for those not familiar with them - There's no harm in making these more obvious - Terminals may not print them correctly either Also changes the function argument printing slightly to be more obvious --- lib/generators.nix | 12 +++++------- lib/tests/misc.nix | 13 ++++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/generators.nix b/lib/generators.nix index 81bedd13d80a..205092a2681b 100644 --- a/lib/generators.nix +++ b/lib/generators.nix @@ -237,10 +237,8 @@ rec { # apply pretty values if allowed if attrNames v == [ "__pretty" "val" ] && allowPrettyValues then v.__pretty v.val - # TODO: there is probably a better representation? else if v ? type && v.type == "derivation" then - "<δ:${v.name}>" - # "<δ:${concatStringsSep "," (builtins.attrNames v)}>" + "" else "{" + introSpace + libStr.concatStringsSep introSpace (libAttr.mapAttrsToList (name: value: @@ -248,11 +246,11 @@ rec { + outroSpace + "}" else if isFunction v then let fna = lib.functionArgs v; - showFnas = concatStringsSep "," (libAttr.mapAttrsToList - (name: hasDefVal: if hasDefVal then "(${name})" else name) + showFnas = concatStringsSep ", " (libAttr.mapAttrsToList + (name: hasDefVal: if hasDefVal then name + "?" else name) fna); - in if fna == {} then "<λ>" - else "<λ:{${showFnas}}>" + in if fna == {} then "" + else "" else abort "generators.toPretty: should never happen (v = ${v})"; in go ""; diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 813a8e7f815f..2456b52c099c 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -445,7 +445,10 @@ runTests { expected = builtins.toJSON val; }; - testToPretty = { + testToPretty = + let + deriv = derivation { name = "test"; builder = "/bin/sh"; system = builtins.currentSystem; }; + in { expr = mapAttrs (const (generators.toPretty { multiline = false; })) rec { int = 42; float = 0.1337; @@ -459,7 +462,7 @@ runTests { functionArgs = { arg ? 4, foo }: arg; list = [ 3 4 function [ false ] ]; attrs = { foo = null; "foo bar" = "baz"; }; - drv = derivation { name = "test"; system = builtins.currentSystem; }; + drv = deriv; }; expected = rec { int = "42"; @@ -470,11 +473,11 @@ runTests { newlinestring = "\"\\n\""; path = "/foo"; null_ = "null"; - function = "<λ>"; - functionArgs = "<λ:{(arg),foo}>"; + function = ""; + functionArgs = ""; list = "[ 3 4 ${function} [ false ] ]"; attrs = "{ foo = null; \"foo bar\" = \"baz\"; }"; - drv = "<δ:test>"; + drv = ""; }; };