nixpkgs/pkgs/build-support/trivial-builders/test/writeScriptBin.nix
Robert Hensing d1dc8384ca writeCBin: Add meta.mainProgram
... and add tests.
2023-07-26 18:22:26 +02:00

39 lines
825 B
Nix

/*
Run with:
cd nixpkgs
nix-build -A tests.trivial-builders.writeShellScriptBin
*/
{ lib, writeScriptBin, runCommand }:
let
output = "hello";
pkg = writeScriptBin "test-script" ''
echo ${lib.escapeShellArg output}
'';
in
assert pkg.meta.mainProgram == "test-script";
runCommand "test-writeScriptBin" { } ''
echo Testing with getExe...
target=${lib.getExe pkg}
expected=${lib.escapeShellArg output}
got=$("$target")
if [[ "$got" != "$expected" ]]; then
echo "wrong output: expected $expected, got $got"
exit 1
fi
echo Testing with makeBinPath...
PATH="${lib.makeBinPath [ pkg ]}:$PATH"
got=$(test-script)
if [[ "$got" != "$expected" ]]; then
echo "wrong output: expected $expected, got $got"
exit 1
fi
touch $out
''