about summary refs log tree commit diff
path: root/nixpkgs/pkgs/build-support/trivial-builders/test/writeScriptBin.nix
blob: 1487443130dab9a821caddae806f0f44b9b85e12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
  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
  ''