16 # Documentation is in doc/build-helpers/testers.chapter.md
18 # See https://nixos.org/manual/nixpkgs/unstable/#tester-lycheeLinkCheck
19 # or doc/build-helpers/testers.chapter.md
20 inherit (callPackage ./lychee.nix {}) lycheeLinkCheck;
22 # See https://nixos.org/manual/nixpkgs/unstable/#tester-testBuildFailure
23 # or doc/build-helpers/testers.chapter.md
24 testBuildFailure = drv: drv.overrideAttrs (orig: {
25 builder = buildPackages.bash;
27 (substituteAll { coreutils = buildPackages.coreutils; src = ./expect-failure.sh; })
28 orig.realBuilder or stdenv.shell
29 ] ++ orig.args or ["-e" (orig.builder or ../../stdenv/generic/default-builder.sh)];
32 # See https://nixos.org/manual/nixpkgs/unstable/#tester-testEqualDerivation
33 # or doc/build-helpers/testers.chapter.md
34 testEqualDerivation = callPackage ./test-equal-derivation.nix { };
36 # See https://nixos.org/manual/nixpkgs/unstable/#tester-testEqualContents
37 # or doc/build-helpers/testers.chapter.md
42 }: runCommand "equal-contents-${lib.strings.toLower assertion}" {
43 inherit assertion actual expected;
44 nativeBuildInputs = [ diffoscopeMinimal ];
47 printf '%s\n' "$assertion"
48 if ! diffoscope --no-progress --text-color=always --exclude-directory-metadata=no -- "$actual" "$expected"
51 echo 'Contents must be equal, but were not!'
53 echo "+: expected, at $expected"
54 echo "-: unexpected, at $actual"
57 echo "expected $expected and actual $actual match."
63 # See https://nixos.org/manual/nixpkgs/unstable/#tester-testVersion
64 # or doc/build-helpers/testers.chapter.md
67 command ? "${package.meta.mainProgram or package.pname or package.name} --version",
68 version ? package.version,
69 }: runCommand "${package.name}-test-version" { nativeBuildInputs = [ package ]; meta.timeout = 60; } ''
70 if output=$(${command} 2>&1 | sed -e 's|${builtins.storeDir}/[^/ ]*/|{{storeDir}}/|g'); then
71 if grep -Fw -- "${version}" - <<< "$output"; then
74 echo "Version string '${version}' not found!" >&2
75 echo "The output was:" >&2
80 echo -n ${lib.escapeShellArg command} >&2
81 echo " returned a non-zero exit code." >&2
87 # See https://nixos.org/manual/nixpkgs/unstable/#tester-invalidateFetcherByDrvHash
88 # or doc/build-helpers/testers.chapter.md
89 invalidateFetcherByDrvHash = f: args:
91 drvPath = (f args).drvPath;
92 # It's safe to discard the context, because we don't access the path.
93 salt = builtins.unsafeDiscardStringContext (lib.substring 0 12 (baseNameOf drvPath));
94 # New derivation incorporating the original drv hash in the name
95 salted = f (args // { name = "${args.name or "source"}-salted-${salt}"; });
96 # Make sure we did change the derivation. If the fetcher ignores `name`,
97 # `invalidateFetcherByDrvHash` doesn't work.
99 if salted.drvPath == drvPath
100 then throw "invalidateFetcherByDrvHash: Adding the derivation hash to the fixed-output derivation name had no effect. Make sure the fetcher's name argument ends up in the derivation name. Otherwise, the fetcher will not be re-run when its implementation changes. This is important for testing."
104 # See https://nixos.org/manual/nixpkgs/unstable/#tester-runCommand
105 runCommand = testers.invalidateFetcherByDrvHash (
107 hash ? pkgs.emptyFile.outputHash,
119 outputHashMode = "recursive";
120 } // lib.removeAttrs args [
129 # See https://nixos.org/manual/nixpkgs/unstable/#tester-runNixOSTest
130 # or doc/build-helpers/testers.chapter.md
132 let nixos = import ../../../nixos/lib {
137 _file = "pkgs.runNixOSTest implementation";
139 (lib.setDefaultModuleLocation "the argument that was passed to pkgs.runNixOSTest" testModule)
142 node.pkgs = pkgsLinux;
145 # See https://nixos.org/manual/nixpkgs/unstable/#tester-invalidateFetcherByDrvHash
146 # or doc/build-helpers/testers.chapter.md
149 /* The nixos/lib/testing-python.nix module, preapplied with arguments that
150 * make sense for this evaluation of Nixpkgs.
153 (import ../../../nixos/lib/testing-python.nix {
154 inherit (stdenv.hostPlatform) system;
156 extraConfigurations = [(
158 config.nixpkgs.pkgs = lib.mkDefault pkgsLinux;
165 loadedTest = if builtins.typeOf test == "path"
168 calledTest = lib.toFunction loadedTest pkgs;
170 nixosTesting.simpleTest calledTest;
173 { moduleName, ... }@args:
174 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." (
175 testers.hasPkgConfigModules (builtins.removeAttrs args [ "moduleName" ] // {
176 moduleNames = [ moduleName ];
179 hasPkgConfigModules = callPackage ./hasPkgConfigModules/tester.nix { };
181 testMetaPkgConfig = callPackage ./testMetaPkgConfig/tester.nix { };
183 shellcheck = callPackage ./shellcheck/tester.nix { };