diff options
author | Artturi <Artturin@artturin.com> | 2022-04-23 06:06:16 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-23 06:06:16 +0300 |
commit | 62866bc35264510ec4a9cc67b84759db64417ac9 (patch) | |
tree | 8c629c1a488308274d07732cfc98c61abf3a16b3 /pkgs/build-support | |
parent | 747594d85322e7395839d58c7aae3c8c90bfa817 (diff) | |
parent | 41808d42d21f685e3fd3cdb2c9f04082f0818e30 (diff) | |
download | nixpkgs-62866bc35264510ec4a9cc67b84759db64417ac9.tar nixpkgs-62866bc35264510ec4a9cc67b84759db64417ac9.tar.gz nixpkgs-62866bc35264510ec4a9cc67b84759db64417ac9.tar.bz2 nixpkgs-62866bc35264510ec4a9cc67b84759db64417ac9.tar.lz nixpkgs-62866bc35264510ec4a9cc67b84759db64417ac9.tar.xz nixpkgs-62866bc35264510ec4a9cc67b84759db64417ac9.tar.zst nixpkgs-62866bc35264510ec4a9cc67b84759db64417ac9.zip |
Merge pull request #169449 from Artturin/movetesting1
testers.testVersion: move from trivial-builders.nix
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/testers/default.nix | 16 | ||||
-rw-r--r-- | pkgs/build-support/testers/test-equal-derivation.nix | 17 | ||||
-rw-r--r-- | pkgs/build-support/trivial-builders.nix | 37 |
3 files changed, 15 insertions, 55 deletions
diff --git a/pkgs/build-support/testers/default.nix b/pkgs/build-support/testers/default.nix index 1d1effa3730..8b79843b833 100644 --- a/pkgs/build-support/testers/default.nix +++ b/pkgs/build-support/testers/default.nix @@ -1,4 +1,18 @@ -{ pkgs, lib, callPackage }: +{ pkgs, lib, callPackage, runCommand }: +# Documentation is in doc/builders/testers.chapter.md { testEqualDerivation = callPackage ./test-equal-derivation.nix { }; + + testVersion = + { package, + command ? "${package.meta.mainProgram or package.pname or package.name} --version", + version ? package.version, + }: runCommand "${package.name}-test-version" { nativeBuildInputs = [ package ]; meta.timeout = 60; } '' + if output=$(${command} 2>&1); then + grep -Fw "${version}" - <<< "$output" + touch $out + else + echo "$output" >&2 && exit 1 + fi + ''; } diff --git a/pkgs/build-support/testers/test-equal-derivation.nix b/pkgs/build-support/testers/test-equal-derivation.nix index 652f3716b2a..610d5f58557 100644 --- a/pkgs/build-support/testers/test-equal-derivation.nix +++ b/pkgs/build-support/testers/test-equal-derivation.nix @@ -1,22 +1,5 @@ { lib, runCommand, emptyFile, nix-diff }: -/* - Checks that two packages produce the exact same build instructions. - - This can be used to make sure that a certain difference of configuration, - such as the presence of an overlay does not cause a cache miss. - - When the derivations are equal, the return value is an empty file. - Otherwise, the build log explains the difference via `nix-diff`. - - Example: - - testEqualDerivation - "The hello package must stay the same when enabling checks." - hello - (hello.overrideAttrs(o: { doCheck = true; })) - -*/ assertion: a: b: let drvA = builtins.unsafeDiscardOutputDependency a.drvPath or (throw "testEqualDerivation second argument must be a package"); diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix index 1f9543f808e..bd14971fe78 100644 --- a/pkgs/build-support/trivial-builders.nix +++ b/pkgs/build-support/trivial-builders.nix @@ -784,41 +784,4 @@ rec { outputHash = "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5"; preferLocalBuild = true; } "mkdir $out"; - - /* Checks the command output contains the specified version - * - * Although simplistic, this test assures that the main program - * can run. While there's no substitute for a real test case, - * it does catch dynamic linking errors and such. It also provides - * some protection against accidentally building the wrong version, - * for example when using an 'old' hash in a fixed-output derivation. - * - * Examples: - * - * passthru.tests.version = testVersion { package = hello; }; - * - * passthru.tests.version = testVersion { - * package = seaweedfs; - * command = "weed version"; - * }; - * - * passthru.tests.version = testVersion { - * package = key; - * command = "KeY --help"; - * # Wrong '2.5' version in the code. Drop on next version. - * version = "2.5"; - * }; - */ - testVersion = - { package, - command ? "${package.meta.mainProgram or package.pname or package.name} --version", - version ? package.version, - }: runCommand "${package.name}-test-version" { nativeBuildInputs = [ package ]; meta.timeout = 60; } '' - if output=$(${command} 2>&1); then - grep -Fw "${version}" - <<< "$output" - touch $out - else - echo "$output" >&2 && exit 1 - fi - ''; } |