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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
818 B
Nix
Raw Normal View History

2024-05-02 00:46:19 +00:00
/*
Run with:
cd nixpkgs
nix-build -A tests.trivial-builders.writeCBin
*/
{
lib,
writeCBin,
runCommand,
}:
let
output = "hello";
pkg = writeCBin "test-script" ''
#include <stdio.h>
int main () {
printf("hello\n");
return 0;
}
'';
in
assert pkg.meta.mainProgram == "test-script";
runCommand "test-writeCBin" { } ''
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
''