chore: initial prototype

This commit is contained in:
technofab 2025-05-03 22:05:29 +02:00
commit c1c19c324d
16 changed files with 1099 additions and 0 deletions

31
lib/default.nix Normal file
View file

@ -0,0 +1,31 @@
{pkgs, ...}: {
mkTest = {
type ? "unit",
name,
description ? "",
expected ? null,
actual ? null,
actualDrv ? null,
pos ? null,
}: {
inherit type name description expected actual;
actualDrv = actualDrv.drvPath or "";
pos =
if pos == null
then ""
else "${pos.file}:${toString pos.line}:${toString pos.column}";
};
mkSuite = name: tests: {
inherit name tests;
};
exportSuites = suites: let
suitesList =
if builtins.isList suites
then suites
else [suites];
testsMapped = builtins.toJSON suitesList;
in
pkgs.runCommand "tests.json" {} ''
echo '${testsMapped}' > $out
'';
}

6
lib/flake.nix Normal file
View file

@ -0,0 +1,6 @@
{
outputs = inputs: {
lib = import ./.;
flakeModule = import ./flakeModule.nix;
};
}

41
lib/flakeModule.nix Normal file
View file

@ -0,0 +1,41 @@
{
flake-parts-lib,
lib,
...
}: let
inherit (lib) mkOption types;
in {
options.perSystem = flake-parts-lib.mkPerSystemOption (
{
config,
pkgs,
...
}: let
nixtests-lib = import ./. {inherit pkgs;};
in {
options.testSuites = mkOption {
type = types.attrsOf (types.listOf types.attrs);
default = {};
};
config.legacyPackages = rec {
"nixtests" = let
suites = map (suiteName: let
tests = builtins.getAttr suiteName config.testSuites;
in
nixtests-lib.mkSuite
suiteName
(map (test: nixtests-lib.mkTest test) tests))
(builtins.attrNames config.testSuites);
in
nixtests-lib.exportSuites suites;
"nixtests:run" = let
program = pkgs.callPackage ./../package.nix {};
in
pkgs.writeShellScriptBin "nixtests:run" ''
${program}/bin/nixtest --tests=${nixtests} "$@"
'';
};
}
);
}