biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / build-support / trivial-builders / test / writeCBin.nix
blob56cab45b3801601723f189f602ca0de956f61014
1 /*
2   Run with:
4       cd nixpkgs
5       nix-build -A tests.trivial-builders.writeCBin
6 */
8 { lib, writeCBin, runCommand }:
9 let
10   output = "hello";
11   pkg = writeCBin "test-script" ''
12     #include <stdio.h>
13     int main () {
14       printf("hello\n");
15       return 0;
16     }
17   '';
19   assert pkg.meta.mainProgram == "test-script";
20   runCommand "test-writeCBin" { } ''
22     echo Testing with getExe...
24     target=${lib.getExe pkg}
25     expected=${lib.escapeShellArg output}
26     got=$("$target")
27     if [[ "$got" != "$expected" ]]; then
28       echo "wrong output: expected $expected, got $got"
29       exit 1
30     fi
32     echo Testing with makeBinPath...
34     PATH="${lib.makeBinPath [ pkg ]}:$PATH"
35     got=$(test-script)
36     if [[ "$got" != "$expected" ]]; then
37       echo "wrong output: expected $expected, got $got"
38       exit 1
39     fi
41     touch $out
42   ''