diff options
author | Robert Hensing <robert@roberthensing.nl> | 2023-01-29 09:27:29 +0100 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2023-01-30 00:35:34 +0100 |
commit | b6bec17eb9b8f256151c396282ad76db255fff91 (patch) | |
tree | 0094313f2c03a372defbaaebc0a4acf02933a462 /pkgs/build-support/testers | |
parent | f192e96d0771a9c8fa8e8c73e6ef66af56a548f8 (diff) |
testers.hasPkgConfigModule: Extract and add tests, docs
Diffstat (limited to 'pkgs/build-support/testers')
-rw-r--r-- | pkgs/build-support/testers/default.nix | 2 | ||||
-rw-r--r-- | pkgs/build-support/testers/hasPkgConfigModule/tester.nix | 47 | ||||
-rw-r--r-- | pkgs/build-support/testers/hasPkgConfigModule/tests.nix | 36 | ||||
-rw-r--r-- | pkgs/build-support/testers/test/default.nix | 2 |
4 files changed, 87 insertions, 0 deletions
diff --git a/pkgs/build-support/testers/default.nix b/pkgs/build-support/testers/default.nix index 6ab0ee843cb08..15694162edde3 100644 --- a/pkgs/build-support/testers/default.nix +++ b/pkgs/build-support/testers/default.nix @@ -121,4 +121,6 @@ in nixosTesting.simpleTest calledTest; + hasPkgConfigModule = callPackage ./hasPkgConfigModule/tester.nix { }; + } diff --git a/pkgs/build-support/testers/hasPkgConfigModule/tester.nix b/pkgs/build-support/testers/hasPkgConfigModule/tester.nix new file mode 100644 index 0000000000000..c8342cdd5c3bf --- /dev/null +++ b/pkgs/build-support/testers/hasPkgConfigModule/tester.nix @@ -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 + '' diff --git a/pkgs/build-support/testers/hasPkgConfigModule/tests.nix b/pkgs/build-support/testers/hasPkgConfigModule/tests.nix new file mode 100644 index 0000000000000..8005c3f937095 --- /dev/null +++ b/pkgs/build-support/testers/hasPkgConfigModule/tests.nix @@ -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 + ''; + +} diff --git a/pkgs/build-support/testers/test/default.nix b/pkgs/build-support/testers/test/default.nix index 0a5381b2b738d..313c556737fb3 100644 --- a/pkgs/build-support/testers/test/default.nix +++ b/pkgs/build-support/testers/test/default.nix @@ -12,6 +12,8 @@ let in lib.recurseIntoAttrs { + hasPkgConfigModule = pkgs.callPackage ../hasPkgConfigModule/tests.nix { }; + # Check that the wiring of nixosTest is correct. # Correct operation of the NixOS test driver should be asserted elsewhere. nixosTest-example = pkgs-with-overlay.testers.nixosTest ({ lib, pkgs, figlet, ... }: { |