mirror of
https://github.com/SebastianWendel/nixpkgs.git
synced 2024-09-20 12:29:02 +02:00
testers.hasPkgConfigModule: Extract and add tests, docs
This commit is contained in:
parent
f192e96d07
commit
b6bec17eb9
|
@ -1,6 +1,19 @@
|
||||||
# Testers {#chap-testers}
|
# Testers {#chap-testers}
|
||||||
This chapter describes several testing builders which are available in the <literal>testers</literal> namespace.
|
This chapter describes several testing builders which are available in the <literal>testers</literal> namespace.
|
||||||
|
|
||||||
|
## `hasPkgConfigModule` {#tester-hasPkgConfigModule}
|
||||||
|
|
||||||
|
Checks whether a package exposes a certain `pkg-config` module.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
passthru.tests.pkg-config = testers.hasPkgConfigModule {
|
||||||
|
package = finalAttrs.finalPackage;
|
||||||
|
moduleName = "libfoo";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## `testVersion` {#tester-testVersion}
|
## `testVersion` {#tester-testVersion}
|
||||||
|
|
||||||
Checks the command output contains the specified version
|
Checks the command output contains the specified version
|
||||||
|
|
|
@ -121,4 +121,6 @@
|
||||||
in
|
in
|
||||||
nixosTesting.simpleTest calledTest;
|
nixosTesting.simpleTest calledTest;
|
||||||
|
|
||||||
|
hasPkgConfigModule = callPackage ./hasPkgConfigModule/tester.nix { };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
47
pkgs/build-support/testers/hasPkgConfigModule/tester.nix
Normal file
47
pkgs/build-support/testers/hasPkgConfigModule/tester.nix
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
# Static arguments
|
||||||
|
{ runCommand, pkg-config }:
|
||||||
|
|
||||||
|
# Tester arguments
|
||||||
|
{ package,
|
||||||
|
moduleName,
|
||||||
|
testName ? "check-pkg-config-${moduleName}",
|
||||||
|
}:
|
||||||
|
|
||||||
|
runCommand testName {
|
||||||
|
nativeBuildInputs = [ pkg-config ];
|
||||||
|
buildInputs = [ package ];
|
||||||
|
inherit moduleName;
|
||||||
|
meta = {
|
||||||
|
description = "Test whether ${package.name} exposes pkg-config module ${moduleName}";
|
||||||
|
}
|
||||||
|
# Make sure licensing info etc is preserved, as this is a concern for e.g. cache.nixos.org,
|
||||||
|
# as hydra can't check this meta info in dependencies.
|
||||||
|
# The test itself is just Nixpkgs, with MIT license.
|
||||||
|
// builtins.intersectAttrs
|
||||||
|
{
|
||||||
|
available = throw "unused";
|
||||||
|
broken = throw "unused";
|
||||||
|
insecure = throw "unused";
|
||||||
|
license = throw "unused";
|
||||||
|
maintainers = throw "unused";
|
||||||
|
platforms = throw "unused";
|
||||||
|
unfree = throw "unused";
|
||||||
|
unsupported = throw "unused";
|
||||||
|
}
|
||||||
|
package.meta;
|
||||||
|
} ''
|
||||||
|
echo "checking pkg-config module $moduleName in $buildInputs"
|
||||||
|
set +e
|
||||||
|
version="$(pkg-config --modversion $moduleName)"
|
||||||
|
r=$?
|
||||||
|
set -e
|
||||||
|
if [[ $r = 0 ]]; then
|
||||||
|
echo "✅ pkg-config module $moduleName exists and has version $version"
|
||||||
|
echo "$version" > $out
|
||||||
|
else
|
||||||
|
echo "These modules were available in the input propagation closure:"
|
||||||
|
pkg-config --list-all
|
||||||
|
echo "❌ pkg-config module $moduleName was not found"
|
||||||
|
false
|
||||||
|
fi
|
||||||
|
''
|
36
pkgs/build-support/testers/hasPkgConfigModule/tests.nix
Normal file
36
pkgs/build-support/testers/hasPkgConfigModule/tests.nix
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
# cd nixpkgs
|
||||||
|
# nix-build -A tests.testers.hasPkgConfigModule
|
||||||
|
{ lib, testers, zlib, runCommand }:
|
||||||
|
|
||||||
|
lib.recurseIntoAttrs {
|
||||||
|
|
||||||
|
zlib-has-zlib = testers.hasPkgConfigModule {
|
||||||
|
package = zlib;
|
||||||
|
moduleName = "zlib";
|
||||||
|
};
|
||||||
|
|
||||||
|
zlib-does-not-have-ylib = runCommand "zlib-does-not-have-ylib" {
|
||||||
|
failed = testers.testBuildFailure (
|
||||||
|
testers.hasPkgConfigModule {
|
||||||
|
package = zlib;
|
||||||
|
moduleName = "ylib";
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} ''
|
||||||
|
echo 'it logs a relevant error message'
|
||||||
|
{
|
||||||
|
grep -F "pkg-config module ylib was not found" $failed/testBuildFailure.log
|
||||||
|
}
|
||||||
|
|
||||||
|
echo 'it logs which pkg-config modules are available, to be helpful'
|
||||||
|
{
|
||||||
|
# grep -v: the string zlib does also occur in a store path in an earlier message, which isn't particularly helpful
|
||||||
|
grep -v "checking pkg-config module" < $failed/testBuildFailure.log \
|
||||||
|
| grep -F "zlib"
|
||||||
|
}
|
||||||
|
|
||||||
|
# done
|
||||||
|
touch $out
|
||||||
|
'';
|
||||||
|
|
||||||
|
}
|
|
@ -12,6 +12,8 @@ let
|
||||||
|
|
||||||
in
|
in
|
||||||
lib.recurseIntoAttrs {
|
lib.recurseIntoAttrs {
|
||||||
|
hasPkgConfigModule = pkgs.callPackage ../hasPkgConfigModule/tests.nix { };
|
||||||
|
|
||||||
# Check that the wiring of nixosTest is correct.
|
# Check that the wiring of nixosTest is correct.
|
||||||
# Correct operation of the NixOS test driver should be asserted elsewhere.
|
# Correct operation of the NixOS test driver should be asserted elsewhere.
|
||||||
nixosTest-example = pkgs-with-overlay.testers.nixosTest ({ lib, pkgs, figlet, ... }: {
|
nixosTest-example = pkgs-with-overlay.testers.nixosTest ({ lib, pkgs, figlet, ... }: {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# cd nixpkgs
|
# cd nixpkgs
|
||||||
# nix-build -A tests.pkg-config.defaultPkgConfigPackages
|
# nix-build -A tests.pkg-config.defaultPkgConfigPackages
|
||||||
{ lib, pkg-config, defaultPkgConfigPackages, runCommand }:
|
{ lib, pkg-config, defaultPkgConfigPackages, runCommand, testers }:
|
||||||
let
|
let
|
||||||
inherit (lib.strings) escapeNixIdentifier;
|
inherit (lib.strings) escapeNixIdentifier;
|
||||||
|
|
||||||
|
@ -39,45 +39,7 @@ let
|
||||||
else if pkg.meta.broken
|
else if pkg.meta.broken
|
||||||
then null
|
then null
|
||||||
|
|
||||||
else makePkgConfigTest moduleName pkg;
|
else testers.hasPkgConfigModule { inherit moduleName; package = pkg; };
|
||||||
|
|
||||||
makePkgConfigTest = moduleName: pkg: runCommand "check-pkg-config-${moduleName}" {
|
|
||||||
nativeBuildInputs = [ pkg-config ];
|
|
||||||
buildInputs = [ pkg ];
|
|
||||||
inherit moduleName;
|
|
||||||
meta = {
|
|
||||||
description = "Test whether ${pkg.name} exposes pkg-config module ${moduleName}";
|
|
||||||
}
|
|
||||||
# Make sure licensing info etc is preserved, as this is a concern for e.g. cache.nixos.org,
|
|
||||||
# as hydra can't check this meta info in dependencies.
|
|
||||||
# The test itself is just Nixpkgs, with MIT license.
|
|
||||||
// builtins.intersectAttrs
|
|
||||||
{
|
|
||||||
available = throw "unused";
|
|
||||||
broken = throw "unused";
|
|
||||||
insecure = throw "unused";
|
|
||||||
license = throw "unused";
|
|
||||||
maintainers = throw "unused";
|
|
||||||
platforms = throw "unused";
|
|
||||||
unfree = throw "unused";
|
|
||||||
unsupported = throw "unused";
|
|
||||||
}
|
|
||||||
pkg.meta;
|
|
||||||
} ''
|
|
||||||
echo "checking pkg-config module $moduleName in $buildInputs"
|
|
||||||
set +e
|
|
||||||
version="$(pkg-config --modversion $moduleName)"
|
|
||||||
r=$?
|
|
||||||
set -e
|
|
||||||
if [[ $r = 0 ]]; then
|
|
||||||
echo "✅ pkg-config module $moduleName exists and has version $version"
|
|
||||||
echo "$version" > $out
|
|
||||||
else
|
|
||||||
echo "These modules were available in the input propagation closure:"
|
|
||||||
pkg-config --list-all
|
|
||||||
echo "❌ pkg-config module $moduleName was not found"
|
|
||||||
false
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
in
|
in
|
||||||
lib.recurseIntoAttrs allTests // { inherit tests-combined; }
|
lib.recurseIntoAttrs allTests // { inherit tests-combined; }
|
||||||
|
|
Loading…
Reference in a new issue