2024-05-02 00:46:19 +00:00
|
|
|
/*
|
|
|
|
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" { } ''
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
echo Testing with getExe...
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
target=${lib.getExe pkg}
|
|
|
|
expected=${lib.escapeShellArg output}
|
|
|
|
got=$("$target")
|
|
|
|
if [[ "$got" != "$expected" ]]; then
|
|
|
|
echo "wrong output: expected $expected, got $got"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
echo Testing with makeBinPath...
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
PATH="${lib.makeBinPath [ pkg ]}:$PATH"
|
|
|
|
got=$(test-script)
|
|
|
|
if [[ "$got" != "$expected" ]]; then
|
|
|
|
echo "wrong output: expected $expected, got $got"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-06-30 08:16:52 +00:00
|
|
|
|
2024-05-02 00:46:19 +00:00
|
|
|
touch $out
|
|
|
|
''
|