[nix] Allow skipping checks

main
Akshay Mankar 2023-12-03 21:36:27 +01:00
parent b58db2d3c0
commit cbf8bfce32
Signed by: axeman
GPG Key ID: CA08F3AB62369B89
2 changed files with 35 additions and 19 deletions

View File

@ -2,13 +2,22 @@
day1 = {
part1 = "53194";
part2 = "54249";
checkHaskell = true;
checkBash = true;
checkRust = true;
};
day2 = {
part1 = "2406";
part2 = "78375";
checkHaskell = true;
checkBash = true;
checkRust = true;
};
day3 = {
part1 = "531932";
part2 = "73646890";
checkHaskell = true;
checkBash = false;
checkRust = false;
};
}

View File

@ -56,31 +56,38 @@
filter = path: type:
let baseName = baseNameOf (toString path);
in pkgs.lib.cleanSourceFilter path type &&
(pkgs.lib.strings.hasInfix "rust" path ||
baseName == "Cargo.toml" ||
baseName == "Cargo.lock");
(pkgs.lib.strings.hasInfix "rust" path ||
baseName == "Cargo.toml" ||
baseName == "Cargo.lock");
};
cargoSha256 = "sha256-e27WE9K2yby+6vzu0cDojtG0+aTdED7vt7wFgEd2dAw=";
};
};
checks =
let mkCheck = (lang: exec: day: parts: {
name = "${lang}-${day}";
value = pkgs.testers.testEqualContents {
assertion = "${lang}: ${day}";
expected = pkgs.writeText "expected" ''
Part 1 Answer: ${parts.part1}
Part 2 Answer: ${parts.part2}
'';
actual = pkgs.runCommandLocal "actual" {} ''
"${exec}" "${day}" < "${./input}/${day}" >$out
'';
};
});
let mkCheck = (lang: exec: day: assertions:
if assertions."check${lang}" then {
name = "${lang}-${day}";
value = pkgs.testers.testEqualContents {
assertion = "${lang}: ${day}";
expected = pkgs.writeText "expected" ''
Part 1 Answer: ${assertions.part1}
Part 2 Answer: ${assertions.part2}
'';
actual = pkgs.runCommandLocal "actual" {} ''
"${exec}" "${day}" < "${./input}/${day}" >$out
'';
};
}
else {
name = "${lang}-${day}-skipped";
value = pkgs.hello;
}
);
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
// pkgs.lib.attrsets.mapAttrs' (mkCheck "rust" "${packages.aoc2023-rust}/bin/aoc2023") answers;
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
// pkgs.lib.attrsets.mapAttrs' (mkCheck "Rust" "${packages.aoc2023-rust}/bin/aoc2023") answers;
defaultPackage = packages.dev-env;
});
}