summaryrefslogtreecommitdiffstats
path: root/lib/path/tests/default.nix
blob: 1d6a55181f9f2429ca7780ea29d2d79e5892620e (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
{
  nixpkgs ? ../../..,
  system ? builtins.currentSystem,
  pkgs ? import nixpkgs {
    config = { };
    overlays = [ ];
    inherit system;
  },
  nixVersions ? import ../../tests/nix-for-tests.nix { inherit pkgs; },
  libpath ? ../..,
  # Random seed
  seed ? null,
}:

pkgs.runCommand "lib-path-tests"
  {
    nativeBuildInputs = [
      nixVersions.stable
    ]
    ++ (with pkgs; [
      jq
      bc
    ]);
  }
  ''
    # Needed to make Nix evaluation work
    export TEST_ROOT=$(pwd)/test-tmp
    export NIX_BUILD_HOOK=
    export NIX_CONF_DIR=$TEST_ROOT/etc
    export NIX_LOCALSTATE_DIR=$TEST_ROOT/var
    export NIX_LOG_DIR=$TEST_ROOT/var/log/nix
    export NIX_STATE_DIR=$TEST_ROOT/var/nix
    export NIX_STORE_DIR=$TEST_ROOT/store
    export PAGER=cat

    cp -r ${libpath} lib
    export TEST_LIB=$PWD/lib

    echo "Running unit tests lib/path/tests/unit.nix"
    nix-instantiate --eval --show-trace \
      --argstr libpath "$TEST_LIB" \
      lib/path/tests/unit.nix

    echo "Running property tests lib/path/tests/prop.sh"
    bash lib/path/tests/prop.sh ${toString seed}

    touch $out
  ''