nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 nix,
4 runCommand,
5 removeReferencesTo,
6 path,
7 gitMinimal,
8}:
9let
10 nixpkgs = lib.cleanSource path;
11 unitResult = import ./unit.nix { inherit lib; };
12in
13assert lib.assertMsg (unitResult == [ ])
14 "problems/unit.nix failing: ${lib.generators.toPretty { } unitResult}";
15lib.mapAttrs (
16 name: _:
17 let
18 nixFile = "${./cases + "/${name}/default.nix"}";
19 result = runCommand "test-problems-${name}" { nativeBuildInputs = [ removeReferencesTo ]; } ''
20 export NIX_STATE_DIR=$(mktemp -d)
21 mkdir $out
22
23 command=(
24 # FIXME: Using this version because it doesn't print a trace by default
25 # Probably should have some regex-style error matching instead
26 "${lib.getBin nix}/bin/nix-instantiate"
27 ${nixFile}
28 # Readonly mode because we don't need to write anything to the store
29 "--readonly-mode"
30 "--arg"
31 "nixpkgs"
32 "${nixpkgs}"
33 )
34
35 echo "''${command[*]@Q}" > $out/command
36 echo "Running ''${command[*]@Q}"
37 set +e
38 "''${command[@]}" >$out/stdout 2>$out/stderr
39 set +e
40 echo "$?" > $out/code
41 echo "Command exited with code $(<$out/code)"
42 remove-references-to -t ${nixFile} $out/stderr
43 if grep '(stack trace truncated.*)' $out/stderr; then
44 sed -i -n '/(stack trace truncated.*)/,$ p' $out/stderr
45 fi
46 sed -i 's/^ //' $out/stderr
47 '';
48 checker = runCommand "test-problems-check-${name}" { } ''
49 if ! PAGER=cat ${lib.getExe gitMinimal} diff --no-index ${
50 ./cases + "/${name}/expected-stderr"
51 } ${result}/stderr ; then
52 echo "Output of $(< ${result}/command) does not match what was expected. To adapt:"
53 echo "cp ${result}/stderr ${lib.path.removePrefix path ./cases + "/${name}/expected-stderr"}"
54 exit 1
55 fi
56 touch $out
57 '';
58 in
59 checker
60) (builtins.readDir ./cases)