mirror of
https://github.com/numtide/flake-utils.git
synced 2024-11-26 10:34:00 +03:00
Add checks-utils (#36)
* Add checks-utils overlay Add checks-utils overlay Fix example flake inputs Fix string expected exception * Update check-utils implementation * nixpkgs-fmt
This commit is contained in:
parent
7d706970d9
commit
98c8d36b18
22
check-utils.nix
Normal file
22
check-utils.nix
Normal file
@ -0,0 +1,22 @@
|
||||
systemOrPkgs:
|
||||
let
|
||||
str = it: if it == null then "null" else (toString it);
|
||||
system = systemOrPkgs.system or systemOrPkgs;
|
||||
test = name: command: derivation {
|
||||
inherit name system;
|
||||
builder = "/bin/sh";
|
||||
args = [ "-c" command ];
|
||||
};
|
||||
in
|
||||
{
|
||||
|
||||
isEqual = a: b:
|
||||
if a == b
|
||||
then test "SUCCESS__${str a}__IS_EQUAL__${str b}" "echo success > $out"
|
||||
else test "FAILURE__${str a}__NOT_EQUAL__${str b}" "exit 1";
|
||||
|
||||
hasKey = attrset: key:
|
||||
if attrset ? ${str key}
|
||||
then test "SUCCESS__${str key}__EXISTS_IN_ATTRSET" "echo success > $out"
|
||||
else test "FAILURE__${str key}__DOES_NOT_EXISTS_IN_ATTRSET_SIZE_${str(builtins.length (builtins.attrNames attrset))}" "exit 1";
|
||||
}
|
@ -135,14 +135,18 @@ let
|
||||
# This function tries to capture a common flake pattern.
|
||||
simpleFlake = import ./simpleFlake.nix { inherit lib; };
|
||||
|
||||
# Helper functions for Nix evaluation
|
||||
check-utils = import ./check-utils.nix;
|
||||
|
||||
lib = {
|
||||
inherit
|
||||
allSystems
|
||||
check-utils
|
||||
defaultSystems
|
||||
eachDefaultSystem
|
||||
eachSystem
|
||||
flattenTree
|
||||
filterPackages
|
||||
flattenTree
|
||||
mkApp
|
||||
simpleFlake
|
||||
;
|
||||
|
29
examples/checks-utils/flake.nix
Normal file
29
examples/checks-utils/flake.nix
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
description = "Flake utils demo";
|
||||
|
||||
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
inherit (flake-utils.lib.check-utils system) isEqual hasKey;
|
||||
|
||||
testDataset = { key1 = "value1"; key2 = "value2"; key3 = "value3"; };
|
||||
in
|
||||
rec {
|
||||
checks = {
|
||||
valid_key1 = isEqual testDataset.key1 "value1";
|
||||
contains_key2 = hasKey testDataset "key2";
|
||||
|
||||
failing_valid_key1 = isEqual testDataset.key1 "failing-data";
|
||||
failing_contains_key2 = hasKey testDataset "failing-data";
|
||||
|
||||
number_formatting_isEqual = isEqual testDataset.key1 123;
|
||||
number_formatting_hasKey = hasKey testDataset 123;
|
||||
|
||||
null_formatting_key1 = isEqual testDataset.key1 null;
|
||||
null_formatting_hasKey = hasKey testDataset null;
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
@ -6,11 +6,12 @@ let
|
||||
nameValuePair = name: value: { inherit name value; };
|
||||
filterAttrs = pred: set:
|
||||
listToAttrs (
|
||||
concatMap (name:
|
||||
let v = set.${name}; in
|
||||
if pred name v then [(nameValuePair name v)] else []
|
||||
)
|
||||
(attrNames set)
|
||||
concatMap
|
||||
(name:
|
||||
let v = set.${name}; in
|
||||
if pred name v then [ (nameValuePair name v) ] else [ ]
|
||||
)
|
||||
(attrNames set)
|
||||
);
|
||||
|
||||
# Everything that nix flake check requires for the packages output
|
||||
@ -22,9 +23,9 @@ let
|
||||
isBroken = meta.broken or false;
|
||||
platforms = meta.hydraPlatforms or meta.platforms or allSystems;
|
||||
in
|
||||
# check for isDerivation, so this is independently useful of
|
||||
# check for isDerivation, so this is independently useful of
|
||||
# flattenTree, which also does filter on derviations
|
||||
isDerivation v && !isBroken && builtins.elem system platforms
|
||||
isDerivation v && !isBroken && builtins.elem system platforms
|
||||
;
|
||||
in
|
||||
filterAttrs sieve packages
|
||||
|
Loading…
Reference in New Issue
Block a user