nixpkgs/pkgs/build-support/trivial-builders/test/write-shell-script.nix
Naïm Favier e6f19ea429
writeTextFile: chmod before checkPhase
Set the executable bit before running the check phase, so that the check
phase can run the script to test its behaviour.

This aligns with what `concatTextFile` is doing.

Also use explicit `if` statements so that we don't silently ignore
`chmod` failures.
2023-03-29 14:06:45 +02:00

14 lines
381 B
Nix

{ lib, writeShellScript }: let
output = "hello";
in (writeShellScript "test-script" ''
echo ${lib.escapeShellArg output}
'').overrideAttrs (old: {
checkPhase = old.checkPhase or "" + ''
expected=${lib.escapeShellArg output}
got=$("$target")
if [[ "$got" != "$expected" ]]; then
echo "wrong output: expected $expected, got $got"
exit 1
fi
'';
})