jaq: init passthru.tests

Signed-off-by: Ethan Carter Edwards <ethan@ethancedwards.com>
This commit is contained in:
Ethan Carter Edwards
2025-08-27 15:17:50 -04:00
parent 1e8218a50c
commit 5051bfc798
+39 -1
View File
@@ -4,6 +4,7 @@
fetchFromGitHub,
versionCheckHook,
nix-update-script,
runCommand,
}:
rustPlatform.buildRustPackage (finalAttrs: {
@@ -25,7 +26,44 @@ rustPlatform.buildRustPackage (finalAttrs: {
versionCheckProgramArg = "--version";
doInstallCheck = true;
passthru.updateScript = nix-update-script { };
passthru = {
updateScript = nix-update-script { };
tests.simple =
runCommand "jaq-test"
{
nativeBuildInputs = [ finalAttrs.finalPackage ];
}
''
set -o pipefail
# checking if 1 + 2 == 3.
if [[ "$(echo '{"a": 1, "b": 2}' | jaq 'add')" -eq 3 ]]; then
echo "test 1 passed"
else
echo "test 1 failed"
exit 1
fi
# echo out 0-3, map over them multiplying by 2, keep all elements under 5, add the results up together. Should be 6
if [[ "$(echo '[0, 1, 2, 3]' | jaq 'map(.*2) | [.[] | select(. < 5)] | add')" -eq 6 ]]; then
echo "test 2 passed"
else
echo "test 2 failed"
exit 1
fi
# fail on malformed input
if ! echo "0, 1, 4, " | jaq &>/dev/null; then
echo "test 3 passed"
else
echo "test 3 failed"
exit 1
fi
echo "All tests passed!"
touch $out
'';
};
meta = {
description = "Jq clone focused on correctness, speed and simplicity";