core/pkgs/build-support/trivial-builders/test/writeScriptBin.nix

43 lines
793 B
Nix
Raw Normal View History

2024-05-02 00:46:19 +00:00
/*
Run with:
cd nixpkgs
nix-build -A tests.trivial-builders.writeShellScriptBin
*/
2024-06-30 08:12:46 +00:00
{
lib,
writeScriptBin,
runCommand,
}:
2024-05-02 00:46:19 +00:00
let
output = "hello";
pkg = writeScriptBin "test-script" ''
echo ${lib.escapeShellArg output}
'';
in
2024-06-30 08:12:46 +00:00
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
''