Merge pull request #239132 from amjoseph-nixpkgs/pr/toLosslessStringMaybe/unexpose
lib/system: move toLosslessStringMaybe into lib/tests
This commit is contained in:
commit
35480b65f4
@ -27,21 +27,6 @@ rec {
|
||||
let removeFunctions = a: lib.filterAttrs (_: v: !builtins.isFunction v) a;
|
||||
in a: b: removeFunctions a == removeFunctions b;
|
||||
|
||||
/*
|
||||
Try to convert an elaborated system back to a simple string. If not possible,
|
||||
return null. So we have the property:
|
||||
|
||||
sys: _valid_ sys ->
|
||||
sys == elaborate (toLosslessStringMaybe sys)
|
||||
|
||||
NOTE: This property is not guaranteed when `sys` was elaborated by a different
|
||||
version of Nixpkgs.
|
||||
*/
|
||||
toLosslessStringMaybe = sys:
|
||||
if lib.isString sys then sys
|
||||
else if equals sys (elaborate sys.system) then sys.system
|
||||
else null;
|
||||
|
||||
/* List of all Nix system doubles the nixpkgs flake will expose the package set
|
||||
for. All systems listed here must be supported by nixpkgs as `localSystem`.
|
||||
|
||||
|
@ -9,6 +9,22 @@ let
|
||||
expr = lib.sort lib.lessThan x;
|
||||
expected = lib.sort lib.lessThan y;
|
||||
};
|
||||
|
||||
/*
|
||||
Try to convert an elaborated system back to a simple string. If not possible,
|
||||
return null. So we have the property:
|
||||
|
||||
sys: _valid_ sys ->
|
||||
sys == elaborate (toLosslessStringMaybe sys)
|
||||
|
||||
NOTE: This property is not guaranteed when `sys` was elaborated by a different
|
||||
version of Nixpkgs.
|
||||
*/
|
||||
toLosslessStringMaybe = sys:
|
||||
if lib.isString sys then sys
|
||||
else if lib.systems.equals sys (lib.systems.elaborate sys.system) then sys.system
|
||||
else null;
|
||||
|
||||
in
|
||||
lib.runTests (
|
||||
# We assert that the new algorithmic way of generating these lists matches the
|
||||
@ -55,11 +71,11 @@ lib.runTests (
|
||||
};
|
||||
|
||||
test_toLosslessStringMaybe_example_x86_64-linux = {
|
||||
expr = lib.systems.toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux");
|
||||
expr = toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux");
|
||||
expected = "x86_64-linux";
|
||||
};
|
||||
test_toLosslessStringMaybe_fail = {
|
||||
expr = lib.systems.toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux" // { something = "extra"; });
|
||||
expr = toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux" // { something = "extra"; });
|
||||
expected = null;
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user