nixpkgs/pkgs/build-support/testers/default.nix
Artturin 250ef1ff39 testers.testVersion: move from trivial-builders.nix
we will have more testers in the future so they should have their own
location

putting 'testers' in args will also make it simpler to use multiple testers
2022-04-22 16:22:40 +03:00

42 lines
1.3 KiB
Nix

{ pkgs, lib, callPackage, runCommand }:
{
testEqualDerivation = callPackage ./test-equal-derivation.nix { };
/* 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
'';
}