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
|
@ -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.
|
# This function tries to capture a common flake pattern.
|
||||||
simpleFlake = import ./simpleFlake.nix { inherit lib; };
|
simpleFlake = import ./simpleFlake.nix { inherit lib; };
|
||||||
|
|
||||||
|
# Helper functions for Nix evaluation
|
||||||
|
check-utils = import ./check-utils.nix;
|
||||||
|
|
||||||
lib = {
|
lib = {
|
||||||
inherit
|
inherit
|
||||||
allSystems
|
allSystems
|
||||||
|
check-utils
|
||||||
defaultSystems
|
defaultSystems
|
||||||
eachDefaultSystem
|
eachDefaultSystem
|
||||||
eachSystem
|
eachSystem
|
||||||
flattenTree
|
|
||||||
filterPackages
|
filterPackages
|
||||||
|
flattenTree
|
||||||
mkApp
|
mkApp
|
||||||
simpleFlake
|
simpleFlake
|
||||||
;
|
;
|
||||||
|
|
|
@ -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,7 +6,8 @@ let
|
||||||
nameValuePair = name: value: { inherit name value; };
|
nameValuePair = name: value: { inherit name value; };
|
||||||
filterAttrs = pred: set:
|
filterAttrs = pred: set:
|
||||||
listToAttrs (
|
listToAttrs (
|
||||||
concatMap (name:
|
concatMap
|
||||||
|
(name:
|
||||||
let v = set.${name}; in
|
let v = set.${name}; in
|
||||||
if pred name v then [ (nameValuePair name v) ] else [ ]
|
if pred name v then [ (nameValuePair name v) ] else [ ]
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue