summaryrefslogtreecommitdiff
path: root/pkgs/test/haskell/env/default.nix
blob: ae337d835c004751a083433f667c140c0c13ae2f (plain)
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
45
46
47
48
49
50
51
52
53
54
55
{
  lib,
  haskellPackages,
}:

let
  withEnv =
    env:
    haskellPackages.mkDerivation {
      pname = "puppy";
      version = "1.0.0";
      src = null;
      license = null;

      inherit env;
    };

  failures = lib.runTests {
    testCanSetEnv = {
      expr =
        (withEnv {
          PUPPY = "DOGGY";
        }).drvAttrs.PUPPY;
      expected = "DOGGY";
    };

    testCanSetEnvMultiple = {
      expr =
        let
          env =
            (withEnv {
              PUPPY = "DOGGY";
              SILLY = "GOOFY";
            }).drvAttrs;
        in
        {
          inherit (env) PUPPY SILLY;
        };
      expected = {
        PUPPY = "DOGGY";
        SILLY = "GOOFY";
      };
    };

    testCanSetEnvPassthru = {
      expr =
        (withEnv {
          PUPPY = "DOGGY";
        }).passthru.env.PUPPY;
      expected = "DOGGY";
    };
  };
in
# TODO: Use `lib.debug.throwTestFailures`: https://github.com/NixOS/nixpkgs/pull/416207
lib.optional (failures != [ ]) (throw "${lib.generators.toPretty { } failures}")