From 0a9e1c089b338d0ae99eb839ecd6b6f1956555ff Mon Sep 17 00:00:00 2001 From: atagen Date: Tue, 3 Dec 2024 12:25:08 +1100 Subject: [PATCH] create nix test infrastructure --- flake.nix | 40 +++++++++++++++++++++++++++++++++++++++- nix/default.nix | 35 +++++++++++++++++++++++++---------- nix/test.nix | 20 ++++++++++++++++++++ 3 files changed, 84 insertions(+), 11 deletions(-) create mode 100644 nix/test.nix diff --git a/flake.nix b/flake.nix index ad636c1..fa1fb65 100644 --- a/flake.nix +++ b/flake.nix @@ -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; + }; } ) // { diff --git a/nix/default.nix b/nix/default.nix index aa2db52..c357f1f 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -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 + ''; } diff --git a/nix/test.nix b/nix/test.nix new file mode 100644 index 0000000..9efa93a --- /dev/null +++ b/nix/test.nix @@ -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} + ''; +}