nix: Add checks

This commit is contained in:
Akshay Mankar 2023-12-01 14:34:41 +01:00
parent 264846a521
commit e7206e5aa2
Signed by: axeman
GPG key ID: CA08F3AB62369B89
2 changed files with 41 additions and 2 deletions

6
answers.nix Normal file
View file

@ -0,0 +1,6 @@
{
day1 = {
part1 = "53194";
part2 = "54249";
};
}

View file

@ -34,6 +34,7 @@
ghc94Pkgs = pkgs.haskell.packages.ghc94.override { ghc94Pkgs = pkgs.haskell.packages.ghc94.override {
overrides = ghcOverrides; overrides = ghcOverrides;
}; };
answers = import ./answers.nix;
in rec { in rec {
packages = rec { packages = rec {
dev-env = ghc94Pkgs.shellFor { dev-env = ghc94Pkgs.shellFor {
@ -43,10 +44,42 @@
(pkgs.haskell-language-server.override {supportedGhcVersions = ["948"];}) (pkgs.haskell-language-server.override {supportedGhcVersions = ["948"];})
pkgs.cabal2nix pkgs.cabal2nix
pkgs.ormolu pkgs.ormolu
pkgs.shellcheck
]; ];
}; };
aoc2023 = ghc94Pkgs.aoc2023; aoc2023-haskell = ghc94Pkgs.aoc2023;
aoc2023-bash =
let bashDir = pkgs.runCommand "aoc2023-bash" {} ''
mkdir $out
cp -r ${./bash} $out/bin
chmod -R +w $out
patchShebangs $out
'';
in pkgs.writeShellApplication {
name = "aoc2023";
runtimeInputs = [ pkgs.util-linux ];
text = ''
${bashDir}/bin/main.sh "''${@}"
'';
}; };
};
checks =
let mkCheck = (prefix: exec: day: parts: {
name = "${prefix}-${day}";
value = pkgs.testers.testEqualContents {
assertion = day;
expected = pkgs.writeText "expected" ''
Part 1 Answer: ${parts.part1}
Part 2 Answer: ${parts.part2}
'';
actual = pkgs.runCommand "actual" {} ''
"${exec}" "${day}" < "${./input}/${day}" >$out
'';
};
});
in pkgs.lib.attrsets.mapAttrs' (mkCheck "haskell" "${packages.aoc2023-haskell}/bin/aoc2023") answers
// pkgs.lib.attrsets.mapAttrs' (mkCheck "bash" "${packages.aoc2023-bash}/bin/aoc2023") answers;
defaultPackage = packages.dev-env; defaultPackage = packages.dev-env;
}); });
} }