2022-04-20 14:31:36 +01:00
|
|
|
{ pkgs, lib, callPackage, runCommand }:
|
2022-04-20 03:50:27 +01:00
|
|
|
{
|
2022-04-20 16:43:21 +01:00
|
|
|
|
|
|
|
/* 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; }))
|
|
|
|
*/
|
2022-04-20 03:50:27 +01:00
|
|
|
testEqualDerivation = callPackage ./test-equal-derivation.nix { };
|
2022-04-20 14:31:36 +01:00
|
|
|
|
|
|
|
/* Checks the command output contains the specified version
|
2022-04-20 16:43:21 +01:00
|
|
|
|
|
|
|
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";
|
|
|
|
};
|
|
|
|
*/
|
2022-04-20 14:31:36 +01:00
|
|
|
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
|
|
|
|
'';
|
2022-04-20 03:50:27 +01:00
|
|
|
}
|