testers.hasPkgConfigModules: allow checking multiple pkg-config mods
This is very useful in conjunction with meta.pkgConfigModules, as the new tester can use the list provided by this meta attribute as a default value for moduleNames, making its usage in passthru.tests very convenient. For backwards compatibility, a shim under the old name is maintained with a warning.
This commit is contained in:
parent
f1dc41a5cd
commit
af60e68744
7 changed files with 73 additions and 35 deletions
|
@ -1,17 +1,31 @@
|
|||
# Testers {#chap-testers}
|
||||
This chapter describes several testing builders which are available in the `testers` namespace.
|
||||
|
||||
## `hasPkgConfigModule` {#tester-hasPkgConfigModule}
|
||||
## `hasPkgConfigModules` {#tester-hasPkgConfigModules}
|
||||
|
||||
Checks whether a package exposes a certain `pkg-config` module.
|
||||
<!-- Old anchor name so links still work -->
|
||||
[]{#tester-hasPkgConfigModule}
|
||||
Checks whether a package exposes a given list of `pkg-config` modules.
|
||||
If the `moduleNames` argument is omitted, `hasPkgConfigModules` will
|
||||
use `meta.pkgConfigModules`.
|
||||
|
||||
Example:
|
||||
|
||||
```nix
|
||||
passthru.tests.pkg-config = testers.hasPkgConfigModule {
|
||||
passthru.tests.pkg-config = testers.hasPkgConfigModules {
|
||||
package = finalAttrs.finalPackage;
|
||||
moduleName = "libfoo";
|
||||
}
|
||||
moduleNames = [ "libfoo" ];
|
||||
};
|
||||
```
|
||||
|
||||
If the package in question has `meta.pkgConfigModules` set, it is even simpler:
|
||||
|
||||
```nix
|
||||
passthru.tests.pkg-config = testers.hasPkgConfigModules {
|
||||
package = finalAttrs.finalPackage;
|
||||
};
|
||||
|
||||
meta.pkgConfigModules = [ "libfoo" ];
|
||||
```
|
||||
|
||||
## `testVersion` {#tester-testVersion}
|
||||
|
|
|
@ -102,9 +102,8 @@ stdenv.mkDerivation (finalAttrs: {
|
|||
command = "pjsua --version";
|
||||
};
|
||||
|
||||
passthru.tests.pkg-config = testers.hasPkgConfigModule {
|
||||
passthru.tests.pkg-config = testers.hasPkgConfigModules {
|
||||
package = finalAttrs.finalPackage;
|
||||
moduleName = "libpjproject";
|
||||
};
|
||||
|
||||
passthru.tests.python-pjsua2 = runCommand "python-pjsua2" { } ''
|
||||
|
@ -118,5 +117,8 @@ stdenv.mkDerivation (finalAttrs: {
|
|||
maintainers = with maintainers; [ olynch ];
|
||||
mainProgram = "pjsua";
|
||||
platforms = platforms.linux ++ platforms.darwin;
|
||||
pkgConfigModules = [
|
||||
"libpjproject"
|
||||
];
|
||||
};
|
||||
})
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{ pkgs, buildPackages, lib, callPackage, runCommand, stdenv, substituteAll, }:
|
||||
{ pkgs, buildPackages, lib, callPackage, runCommand, stdenv, substituteAll, testers }:
|
||||
# Documentation is in doc/builders/testers.chapter.md
|
||||
{
|
||||
# See https://nixos.org/manual/nixpkgs/unstable/#tester-testBuildFailure
|
||||
|
@ -137,7 +137,14 @@
|
|||
in
|
||||
nixosTesting.simpleTest calledTest;
|
||||
|
||||
hasPkgConfigModule = callPackage ./hasPkgConfigModule/tester.nix { };
|
||||
hasPkgConfigModule =
|
||||
{ moduleName, ... }@args:
|
||||
lib.warn "testers.hasPkgConfigModule has been deprecated in favor of testers.hasPkgConfigModules. It accepts a list of strings via the moduleNames argument instead of a single moduleName." (
|
||||
testers.hasPkgConfigModules (builtins.removeAttrs args [ "moduleName" ] // {
|
||||
moduleNames = [ moduleName ];
|
||||
})
|
||||
);
|
||||
hasPkgConfigModules = callPackage ./hasPkgConfigModules/tester.nix { };
|
||||
|
||||
testMetaPkgConfig = callPackage ./testMetaPkgConfig/tester.nix { };
|
||||
}
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
# Static arguments
|
||||
{ runCommand, pkg-config }:
|
||||
{ lib, runCommand, pkg-config }:
|
||||
|
||||
# Tester arguments
|
||||
{ package,
|
||||
moduleName,
|
||||
testName ? "check-pkg-config-${moduleName}",
|
||||
moduleNames ? package.meta.pkgConfigModules,
|
||||
testName ? "check-pkg-config-${lib.concatStringsSep "-" moduleNames}",
|
||||
}:
|
||||
|
||||
runCommand testName {
|
||||
nativeBuildInputs = [ pkg-config ];
|
||||
buildInputs = [ package ];
|
||||
inherit moduleName;
|
||||
inherit moduleNames;
|
||||
meta = {
|
||||
description = "Test whether ${package.name} exposes pkg-config module ${moduleName}";
|
||||
description = "Test whether ${package.name} exposes pkg-config modules ${lib.concatStringsSep ", " moduleNames}.";
|
||||
}
|
||||
# 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.
|
||||
|
@ -30,6 +30,7 @@ runCommand testName {
|
|||
}
|
||||
package.meta;
|
||||
} ''
|
||||
for moduleName in $moduleNames; do
|
||||
echo "checking pkg-config module $moduleName in $buildInputs"
|
||||
set +e
|
||||
version="$(pkg-config --modversion $moduleName)"
|
||||
|
@ -37,11 +38,12 @@ runCommand testName {
|
|||
set -e
|
||||
if [[ $r = 0 ]]; then
|
||||
echo "✅ pkg-config module $moduleName exists and has version $version"
|
||||
echo "$version" > $out
|
||||
printf '%s\t%s\n' "$moduleName" "$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
|
||||
done
|
||||
''
|
|
@ -1,19 +1,32 @@
|
|||
# cd nixpkgs
|
||||
# nix-build -A tests.testers.hasPkgConfigModule
|
||||
{ lib, testers, zlib, runCommand }:
|
||||
{ lib, testers, zlib, openssl, runCommand }:
|
||||
|
||||
lib.recurseIntoAttrs {
|
||||
|
||||
zlib-has-zlib = testers.hasPkgConfigModule {
|
||||
zlib-has-zlib = testers.hasPkgConfigModules {
|
||||
package = zlib;
|
||||
moduleName = "zlib";
|
||||
moduleNames = [ "zlib" ];
|
||||
};
|
||||
|
||||
zlib-has-meta-pkgConfigModules = testers.hasPkgConfigModules {
|
||||
package = zlib;
|
||||
};
|
||||
|
||||
openssl-has-openssl = testers.hasPkgConfigModules {
|
||||
package = openssl;
|
||||
moduleNames = [ "openssl" ];
|
||||
};
|
||||
|
||||
openssl-has-all-meta-pkgConfigModules = testers.hasPkgConfigModules {
|
||||
package = openssl;
|
||||
};
|
||||
|
||||
zlib-does-not-have-ylib = runCommand "zlib-does-not-have-ylib" {
|
||||
failed = testers.testBuildFailure (
|
||||
testers.hasPkgConfigModule {
|
||||
testers.hasPkgConfigModules {
|
||||
package = zlib;
|
||||
moduleName = "ylib";
|
||||
moduleNames = [ "ylib" ];
|
||||
}
|
||||
);
|
||||
} ''
|
|
@ -12,7 +12,7 @@ let
|
|||
|
||||
in
|
||||
lib.recurseIntoAttrs {
|
||||
hasPkgConfigModule = pkgs.callPackage ../hasPkgConfigModule/tests.nix { };
|
||||
hasPkgConfigModules = pkgs.callPackage ../hasPkgConfigModules/tests.nix { };
|
||||
|
||||
runNixOSTest-example = pkgs-with-overlay.testers.runNixOSTest ({ lib, ... }: {
|
||||
name = "runNixOSTest-test";
|
||||
|
|
|
@ -40,7 +40,7 @@ let
|
|||
else if pkg.meta.broken
|
||||
then null
|
||||
|
||||
else testers.hasPkgConfigModule { inherit moduleName; package = pkg; };
|
||||
else testers.hasPkgConfigModules { moduleNames = [ moduleName ]; package = pkg; };
|
||||
|
||||
in
|
||||
lib.recurseIntoAttrs allTests // { inherit tests-combined; }
|
||||
|
|
Loading…
Reference in a new issue