create nix test infrastructure

This commit is contained in:
atagen 2024-12-03 12:25:08 +11:00
parent 192561577e
commit 0a9e1c089b
3 changed files with 84 additions and 11 deletions

View File

@ -51,10 +51,37 @@
ocaml-lsp
ocamlformat
ocamlformat-rpc-lib
pkgs.just
];
in {
devShells.default = mkShell {
buildInputs = minimal ++ dev;
shellHook = let
justFile = ''
default:
@just --list
@build:
nix build .#debug --offline
@release:
nix build --offline
@test:
printf "\\n\\n\\t************ running nix+dune tests ************\\n\\n\\n"
nix flake check --offline
nix build .#tests --offline
printf "\\n\\n\\t************ running visual test ************\\n\\n\\n"
echo one two three four | CULRS="(255,0,0);(0,0,255);#00FF00" CULR_ORDER="1;0;2" result/bin/culr
'';
in ''
printf '${justFile}' > justfile
'';
};
checks.default = pkgs.callPackage ./nix/test.nix {
culr = self.packages.${system}.tests;
inherit version;
};
packages.default = pkgs.callPackage ./nix/default.nix {
@ -62,7 +89,18 @@
inherit version;
};
defaultPackage = self.packages.${system}.default;
packages.debug = pkgs.callPackage ./nix/default.nix {
debug = true;
ocaml-deps = minimal;
inherit version;
};
packages.tests = pkgs.callPackage ./nix/default.nix {
debug = true;
ocaml-deps = minimal;
doCheck = true;
inherit version;
};
}
)
// {

View File

@ -1,15 +1,30 @@
{
ocaml-deps,
ocamlPackages,
version,
...
}:
lib,
ocaml-deps,
ocamlPackages,
version,
debug ? false,
...
}:
ocamlPackages.buildDunePackage {
pname = "culr";
version = "0.1-${version}";
pname = "culr";
version = "0.1-${version}";
minimalOCamlVersion = "5.2";
minimalOCamlVersion = "5.2";
src = ./..;
buildInputs = ocaml-deps;
src = ./..;
buildInputs = ocaml-deps;
buildPhase =
if debug
then ''
runHook preBuild
dune build --profile debug -p culr ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
runHook postBuild
''
else ''
runHook preBuild
dune build --profile release -p culr ''${enableParallelBuilding:+-j $NIX_BUILD_CORES}
runHook postBuild
'';
}

20
nix/test.nix Normal file
View File

@ -0,0 +1,20 @@
{
pkgs,
lib,
culr,
version,
...
}:
pkgs.stdenvNoCC.mkDerivation {
pname = "culr-tests";
version = "${version}";
nativebuildInputs = [culr];
doCheck = true;
checkPhase = ''
CULRS="(255,0,0);(0,0,255)"
CULR_ORDER=1,0
echo "one two three four" | ${lib.getExe culr}
'';
}