Skip to content

Commit

Permalink
check-meta: type check for tests failing WIP
Browse files Browse the repository at this point in the history
nix-build -A hello
  • Loading branch information
Profpatsch committed Apr 1, 2018
1 parent 589d1c5 commit d74203a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
12 changes: 11 additions & 1 deletion pkgs/applications/misc/hello/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, fetchurl }:
{ stdenv, fetchurl, pkgs }:

stdenv.mkDerivation rec {
name = "hello-2.10";
Expand All @@ -20,5 +20,15 @@ stdenv.mkDerivation rec {
license = stdenv.lib.licenses.gpl3Plus;
maintainers = [ stdenv.lib.maintainers.eelco ];
platforms = stdenv.lib.platforms.all;

tests = {
"onetestyboi" = pkgs.runCommand "hi" {
# meta.description = "hi";
passthru = {
isVmTest = "string";
foo = { a = [ [] ]; b = [ "foo" 42 ]; };
};
} ''touch $out'';
};
};
}
28 changes: 27 additions & 1 deletion pkgs/stdenv/generic/check-meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let
# See discussion at https://github.com/NixOS/nixpkgs/pull/25304#issuecomment-298385426
# for why this defaults to false, but I (@copumpkin) want to default it to true soon.
shouldCheckMeta = config.checkMeta or false;
shouldCheckMeta = config.checkMeta or true; #or false;

allowUnfree = config.allowUnfree or false || builtins.getEnv "NIXPKGS_ALLOW_UNFREE" == "1";

Expand Down Expand Up @@ -176,6 +176,32 @@ let
platforms = list platform;
hydraPlatforms = list platform;
broken = bool;
tests =
let
derivationPredicate = t: restrict {
description = "<δ>: ${t.description}";
type = t;
check = lib.isDerivation;
};
testT = derivationPredicate (productOpt {
open = true;
opt = {};
req = {
name = string;
passthru = product {
isVmTest = bool;
foo = attrs (list string);
};
# TODO: meta should reuse metaType and add some
# fields to the req attribute
meta = productOpt {
open = true;
req.description = string;
opt.platforms = list platform;
};
};
});
in attrs testT;

# Weirder stuff that doesn't appear in the documentation?
knownVulnerabilities = list string;
Expand Down

1 comment on commit d74203a

@Profpatsch
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error: Package ‘hello-2.10’ in /home/philip/nixpkgs/pkgs/applications/misc/hello/default.nix:14 has an invalid meta attrset:
tests.onetestyboi.meta should be: { description: string, [platforms: list of one of [ string, any type ]], … }
but is: { "available" = true; "name" = "hi"; "outputsToInstall" = [ "out" ]; "position" = "/home/philip/nixpkgs/pkgs/build-support/trivial-builders.nix:7"; }
tests.onetestyboi.passthru.foo.a.0 should be: string
but is: [  ]
tests.onetestyboi.passthru.foo.b.1 should be: string
but is: 42
tests.onetestyboi.passthru.isVmTest should be: boolean
but is: "string"
, refusing to evaluate.


(use '--show-trace' to show detailed location information)

Please sign in to comment.