Add `isStorePath` tests (#26223)

authored by

Profpatsch and committed by zimbatm.tngl.sh 3fa1be6f c6ea7d3a

+34 -4
+34 -4
lib/tests/misc.nix
··· 1 1 # to run these tests: 2 2 # nix-instantiate --eval --strict nixpkgs/lib/tests/misc.nix 3 3 # if the resulting list is empty, all tests passed 4 - let inherit (builtins) add; in 5 4 with import ../default.nix; 6 5 7 6 runTests { ··· 86 85 testSplitStringsLastEmpty = { 87 86 expr = strings.splitString ":" "2001:db8:0:0042::8a2e:370:"; 88 87 expected = [ "2001" "db8" "0" "0042" "" "8a2e" "370" "" ]; 88 + }; 89 + 90 + testIsStorePath = { 91 + expr = 92 + let goodPath = 93 + "/nix/store/d945ibfx9x185xf04b890y4f9g3cbb63-python-2.7.11"; 94 + in { 95 + storePath = isStorePath goodPath; 96 + storePathAppendix = isStorePath 97 + "${goodPath}/bin/python"; 98 + nonAbsolute = isStorePath (concatStrings (tail (stringToCharacters goodPath))); 99 + asPath = isStorePath (builtins.toPath goodPath); 100 + otherPath = isStorePath "/something/else"; 101 + otherVals = { 102 + attrset = isStorePath {}; 103 + list = isStorePath []; 104 + int = isStorePath 42; 105 + }; 106 + }; 107 + expected = { 108 + storePath = true; 109 + storePathAppendix = false; 110 + nonAbsolute = false; 111 + asPath = true; 112 + otherPath = false; 113 + otherVals = { 114 + attrset = false; 115 + list = false; 116 + int = false; 117 + }; 118 + }; 89 119 }; 90 120 91 121 # LISTS ··· 266 296 res4 = let x = defaultOverridableDelayableArgs id { a = 7; }; 267 297 in (x.merge) ( x: { b = 10; }); 268 298 res5 = let x = defaultOverridableDelayableArgs id { a = 7; }; 269 - in (x.merge) ( x: { a = add x.a 3; }); 270 - res6 = let x = defaultOverridableDelayableArgs id { a = 7; mergeAttrBy = { a = add; }; }; 299 + in (x.merge) ( x: { a = builtins.add x.a 3; }); 300 + res6 = let x = defaultOverridableDelayableArgs id { a = 7; mergeAttrBy = { a = builtins.add; }; }; 271 301 y = x.merge {}; 272 302 in (y.merge) { a = 10; }; 273 303 274 304 resRem7 = res6.replace (a: removeAttrs a ["a"]); 275 305 276 - resReplace6 = let x = defaultOverridableDelayableArgs id { a = 7; mergeAttrBy = { a = add; }; }; 306 + resReplace6 = let x = defaultOverridableDelayableArgs id { a = 7; mergeAttrBy = { a = builtins.add; }; }; 277 307 x2 = x.merge { a = 20; }; # now we have 27 278 308 in (x2.replace) { a = 10; }; # and override the value by 10 279 309