summary refs log tree commit diff
path: root/pkgs/development/tools/build-managers/bazel/bash-tools-test.nix
blob: 898640a84fe6f7efb083286c4cb98f5b89ad6b01 (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
40
41
42
43
44
{ writeText, bazel, runLocal, bazelTest }:

# Tests that certain executables are available in bazel-executed bash shells.

let
  WORKSPACE = writeText "WORKSPACE" ''
    workspace(name = "our_workspace")
  '';

  fileIn = writeText "input.txt" ''
  one
  two
  three
  '';

  fileBUILD = writeText "BUILD" ''
    genrule(
      name = "tool_usage",
      srcs = [ ":input.txt" ],
      outs = [ "output.txt" ],
      cmd = "cat $(location :input.txt) | gzip - | gunzip - | awk '/t/' > $@",
    )
  '';

  workspaceDir = runLocal "our_workspace" {} ''
    mkdir $out
    cp ${WORKSPACE} $out/WORKSPACE
    cp ${fileIn} $out/input.txt
    cp ${fileBUILD} $out/BUILD
  '';

  testBazel = bazelTest {
    name = "bazel-test-bash-tools";
    bazelPkg = bazel;
    inherit workspaceDir;

    bazelScript = ''
      ${bazel}/bin/bazel build :tool_usage
      cp bazel-genfiles/output.txt $out
      echo "Testing content" && [ "$(cat $out | wc -l)" == "2" ] && echo "OK"
    '';
  };

in testBazel