test-utilities: version test

Extract 'version test' to a reusable test utility as discussed in
https://github.com/NixOS/nixpkgs/pull/119636#issuecomment-826137021 and
This commit is contained in:
Arnout Engelen
2021-05-07 09:53:35 +02:00
parent 39e6bf7647
commit b68130fd2c
5 changed files with 57 additions and 11 deletions
+33
View File
@@ -541,4 +541,37 @@ rec {
phases = "unpackPhase patchPhase installPhase";
installPhase = "cp -R ./ $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 "test-version" { nativeBuildInputs = [ package ]; meta.timeout = 60; } ''
${command} | grep -Fw ${version}
touch $out
'';
}