Skip to content

Commit

Permalink
WIP problems testing
Browse files Browse the repository at this point in the history
Run with `nix-build -A tests.problems`
  • Loading branch information
infinisil committed Jul 21, 2024
1 parent 08d0536 commit 9b55daf
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkgs/test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ with pkgs;

overriding = callPackage ./overriding.nix { };

problems = recurseIntoAttrs (callPackage ./problems { });

texlive = callPackage ./texlive {};

cuda = callPackage ./cuda { };
Expand Down
15 changes: 15 additions & 0 deletions pkgs/test/problems/cases/removed-error/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ nixpkgs }:
let
pkgs = import nixpkgs {
system = "x86_64-linux";
overlays = [ ];
config = { };
};
in
pkgs.stdenvNoCC.mkDerivation {
pname = "a";
version = "0";
meta.problems = {
removal.message = "This package has been abandoned upstream and will be removed";
};
}
32 changes: 32 additions & 0 deletions pkgs/test/problems/cases/removed-error/expected-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error: Package ‘a-0’ in /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-default.nix:11 has some problem that must be acknowledged, refusing to evaluate.



Package problems:

- removal: This package has been abandoned upstream and will be removed

You can use it anyway by ignoring its problems, using one of the
following methods:

a) For `nixos-rebuild` you can add "warn" or "ignore" entries to
`nixpkgs.config.problems.handlers` inside configuration.nix,
like this:

{
nixpkgs.config.problems.handlers = {
"a"."removal" = "warn";
};
}

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
"warn" or "ignore" to `problems.handlers` in
~/.config/nixpkgs/config.nix, like this:

{
problems.handlers = {
"a"."removal" = "warn";
};
}

(use '--show-trace' to show detailed location information)
53 changes: 53 additions & 0 deletions pkgs/test/problems/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
lib,
nixVersions,
runCommandNoCC,
removeReferencesTo,
path,
}:
let
nixpkgs = lib.cleanSource path;
in
lib.mapAttrs (
name: _:
let
nixFile = "${./cases + "/${name}/default.nix"}";
result = runCommandNoCC "test-problems-${name}" {
nativeBuildInputs = [
removeReferencesTo
];
} ''
export NIX_STATE_DIR=$(mktemp -d)
mkdir $out
command=(
# FIXME: Using this version because it doesn't print a trace by default
# Probably should have some regex-style error matching instead
"${lib.getBin nixVersions.minimum}/bin/nix-instantiate"
${nixFile}
# Readonly mode because we don't need to write anything to the store
"--readonly-mode"
"--arg"
"nixpkgs"
"${nixpkgs}"
)
echo "''${command[*]@Q}" > $out/command
echo "Running ''${command[*]@Q}"
set +e
"''${command[@]}" > >(tee $out/stdout) 2> >(tee $out/stderr)
set +e
echo "$?" > $out/code
echo "Command exited with code $(<$out/code)"
remove-references-to -t ${nixFile} $out/*
'';
checker = runCommandNoCC "test-problems-check-${name}" { } ''
if ! diff ${result}/stderr ${./cases + "/${name}/expected-stderr"}; then
echo "Output of $(< ${result}/command) does not match what was expected (${result}/stderr)"
exit 1
fi
touch $out
'';
in
lib.nameValuePair name checker
) (builtins.readDir ./cases)

0 comments on commit 9b55daf

Please sign in to comment.