mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2025-12-11 17:50:11 +01:00
Compare commits
4 commits
c2a1208534
...
22b43c9fe8
| Author | SHA1 | Date | |
|---|---|---|---|
| 22b43c9fe8 | |||
| b2fb77ecc9 | |||
| 0272a8b0dc | |||
| d7e4902fed |
5 changed files with 37 additions and 13 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
[](https://builtwithnix.org)
|
[](https://builtwithnix.org)
|
||||||
[](https://gitlab.com/TECHNOFAB/nixtest/-/commits/main)
|
[](https://gitlab.com/TECHNOFAB/nixtest/-/commits/main)
|
||||||

|

|
||||||
[](https://gitlab.com/TECHNOFAB/nixtest/-/releases)
|
[](https://gitlab.com/TECHNOFAB/nixtest/-/releases)
|
||||||
[](https://tec.tf/#support)
|
[](https://tec.tf/#support)
|
||||||
[](https://nixtest.projects.tf)
|
[](https://nixtest.projects.tf)
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,12 @@
|
||||||
};
|
};
|
||||||
devenv.shells.default = {
|
devenv.shells.default = {
|
||||||
containers = pkgs.lib.mkForce {};
|
containers = pkgs.lib.mkForce {};
|
||||||
packages = with pkgs; [gopls gore go-junit-report];
|
packages = with pkgs; [gore go-junit-report];
|
||||||
|
|
||||||
languages.go.enable = true;
|
languages.go = {
|
||||||
|
enable = true;
|
||||||
|
enableHardeningWorkaround = true;
|
||||||
|
};
|
||||||
|
|
||||||
pre-commit.hooks = {
|
pre-commit.hooks = {
|
||||||
treefmt = {
|
treefmt = {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,11 @@ in rec {
|
||||||
}: let
|
}: let
|
||||||
files = builtins.readDir dir;
|
files = builtins.readDir dir;
|
||||||
matchingFiles = builtins.filter (name: builtins.match pattern name != null) (builtins.attrNames files);
|
matchingFiles = builtins.filter (name: builtins.match pattern name != null) (builtins.attrNames files);
|
||||||
imports = map (file: /${dir}/${file}) matchingFiles;
|
imports = map (file:
|
||||||
|
if builtins.isString dir
|
||||||
|
then (builtins.unsafeDiscardStringContext dir) + "/${file}"
|
||||||
|
else /${dir}/${file})
|
||||||
|
matchingFiles;
|
||||||
in {
|
in {
|
||||||
inherit imports;
|
inherit imports;
|
||||||
# automatically set the base so test filepaths are easier to read
|
# automatically set the base so test filepaths are easier to read
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,17 @@
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) mkOptionType mkOption types;
|
inherit
|
||||||
|
(lib)
|
||||||
|
mkOptionType
|
||||||
|
mkOption
|
||||||
|
types
|
||||||
|
filterAttrs
|
||||||
|
isType
|
||||||
|
removePrefix
|
||||||
|
assertMsg
|
||||||
|
generators
|
||||||
|
;
|
||||||
|
|
||||||
nixtest-lib = import ./default.nix {inherit pkgs lib;};
|
nixtest-lib = import ./default.nix {inherit pkgs lib;};
|
||||||
|
|
||||||
|
|
@ -16,14 +26,14 @@
|
||||||
unset = {
|
unset = {
|
||||||
_type = "unset";
|
_type = "unset";
|
||||||
};
|
};
|
||||||
isUnset = lib.isType "unset";
|
isUnset = isType "unset";
|
||||||
|
|
||||||
filterUnset = value:
|
filterUnset = value:
|
||||||
if builtins.isAttrs value && !builtins.hasAttr "_type" value
|
if builtins.isAttrs value && !builtins.hasAttr "_type" value
|
||||||
then let
|
then let
|
||||||
filteredAttrs = builtins.mapAttrs (n: v: filterUnset v) value;
|
filteredAttrs = builtins.mapAttrs (n: v: filterUnset v) value;
|
||||||
in
|
in
|
||||||
lib.filterAttrs (name: value: (!isUnset value)) filteredAttrs
|
filterAttrs (name: value: (!isUnset value)) filteredAttrs
|
||||||
else if builtins.isList value
|
else if builtins.isList value
|
||||||
then builtins.filter (elem: !isUnset elem) (map filterUnset value)
|
then builtins.filter (elem: !isUnset elem) (map filterUnset value)
|
||||||
else value;
|
else value;
|
||||||
|
|
@ -42,18 +52,18 @@
|
||||||
if isUnset val
|
if isUnset val
|
||||||
then val
|
then val
|
||||||
else let
|
else let
|
||||||
fileRelative = lib.removePrefix testsBase val.file;
|
fileRelative = removePrefix testsBase val.file;
|
||||||
in "${fileRelative}:${toString val.line}";
|
in "${fileRelative}:${toString val.line}";
|
||||||
};
|
};
|
||||||
type = mkOption {
|
type = mkOption {
|
||||||
type = types.enum ["unit" "snapshot" "script"];
|
type = types.enum ["unit" "snapshot" "script"];
|
||||||
default = "unit";
|
default = "unit";
|
||||||
apply = value:
|
apply = value:
|
||||||
assert lib.assertMsg (value != "script" || !isUnset config.script)
|
assert assertMsg (value != "script" || !isUnset config.script)
|
||||||
"test '${config.name}' as type 'script' requires 'script' to be set";
|
"test '${config.name}' as type 'script' requires 'script' to be set";
|
||||||
assert lib.assertMsg (value != "unit" || !isUnset config.expected)
|
assert assertMsg (value != "unit" || !isUnset config.expected)
|
||||||
"test '${config.name}' as type 'unit' requires 'expected' to be set";
|
"test '${config.name}' as type 'unit' requires 'expected' to be set";
|
||||||
assert lib.assertMsg (
|
assert assertMsg (
|
||||||
let
|
let
|
||||||
actualIsUnset = isUnset config.actual;
|
actualIsUnset = isUnset config.actual;
|
||||||
actualDrvIsUnset = isUnset config.actualDrv;
|
actualDrvIsUnset = isUnset config.actualDrv;
|
||||||
|
|
@ -81,7 +91,7 @@
|
||||||
apply = val:
|
apply = val:
|
||||||
if isUnset val || config.format == "json"
|
if isUnset val || config.format == "json"
|
||||||
then val
|
then val
|
||||||
else lib.generators.toPretty {} val;
|
else generators.toPretty {} val;
|
||||||
};
|
};
|
||||||
actual = mkOption {
|
actual = mkOption {
|
||||||
type = types.anything;
|
type = types.anything;
|
||||||
|
|
@ -89,7 +99,7 @@
|
||||||
apply = val:
|
apply = val:
|
||||||
if isUnset val || config.format == "json"
|
if isUnset val || config.format == "json"
|
||||||
then val
|
then val
|
||||||
else lib.generators.toPretty {} val;
|
else generators.toPretty {} val;
|
||||||
};
|
};
|
||||||
actualDrv = mkOption {
|
actualDrv = mkOption {
|
||||||
type = types.either types.package unsetType;
|
type = types.either types.package unsetType;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,10 @@
|
||||||
actual = ntlib.helpers.toPrettyFile (ntlib.autodiscover {
|
actual = ntlib.helpers.toPrettyFile (ntlib.autodiscover {
|
||||||
dir = ./fixtures;
|
dir = ./fixtures;
|
||||||
});
|
});
|
||||||
|
# tests if strings with store path context work
|
||||||
|
actualDirString = ntlib.helpers.toPrettyFile (ntlib.autodiscover {
|
||||||
|
dir = "${./fixtures}";
|
||||||
|
});
|
||||||
in
|
in
|
||||||
# sh
|
# sh
|
||||||
''
|
''
|
||||||
|
|
@ -20,6 +24,9 @@
|
||||||
${ntlib.helpers.scriptHelpers}
|
${ntlib.helpers.scriptHelpers}
|
||||||
assert_file_contains ${actual} "sample_test.nix" "should find sample_test.nix"
|
assert_file_contains ${actual} "sample_test.nix" "should find sample_test.nix"
|
||||||
assert_file_contains ${actual} "base = \"/nix/store/.*-source/tests/fixtures/\"" "should set base to fixtures dir"
|
assert_file_contains ${actual} "base = \"/nix/store/.*-source/tests/fixtures/\"" "should set base to fixtures dir"
|
||||||
|
|
||||||
|
assert_file_contains ${actualDirString} "sample_test.nix" "should find sample_test.nix"
|
||||||
|
assert_file_contains ${actualDirString} "base = \"/nix/store/.*-fixtures/\"" "should set base to fixtures dir"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue