lol
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 243 lines 7.4 kB view raw
1{ 2 lib, 3 buildPackages, 4 callPackage, 5 pkgs, 6 pkgsLinux, 7 8 diffoscopeMinimal, 9 runCommand, 10 runCommandWith, 11 stdenv, 12 stdenvNoCC, 13 replaceVars, 14 testers, 15}: 16# Documentation is in doc/build-helpers/testers.chapter.md 17{ 18 # See https://nixos.org/manual/nixpkgs/unstable/#tester-lycheeLinkCheck 19 # or doc/build-helpers/testers.chapter.md 20 inherit (callPackage ./lychee.nix { }) lycheeLinkCheck; 21 22 # See https://nixos.org/manual/nixpkgs/unstable/#tester-testBuildFailure 23 # or doc/build-helpers/testers.chapter.md 24 testBuildFailure = 25 drv: 26 drv.overrideAttrs (orig: { 27 builder = buildPackages.bash; 28 args = [ 29 (replaceVars ./expect-failure.sh { 30 coreutils = buildPackages.coreutils; 31 vars = lib.toShellVars { 32 outputNames = (orig.outputs or [ "out" ]); 33 }; 34 }) 35 orig.realBuilder or stdenv.shell 36 ] 37 ++ orig.args or [ 38 "-e" 39 ../../stdenv/generic/source-stdenv.sh 40 (orig.builder or ../../stdenv/generic/default-builder.sh) 41 ]; 42 }); 43 44 # See https://nixos.org/manual/nixpkgs/unstable/#tester-testBuildFailurePrime 45 # or doc/build-helpers/testers.chapter.md 46 testBuildFailure' = callPackage ./testBuildFailurePrime { }; 47 48 # See https://nixos.org/manual/nixpkgs/unstable/#tester-testEqualDerivation 49 # or doc/build-helpers/testers.chapter.md 50 testEqualDerivation = callPackage ./test-equal-derivation.nix { }; 51 52 # See https://nixos.org/manual/nixpkgs/unstable/#tester-testEqualContents 53 # or doc/build-helpers/testers.chapter.md 54 testEqualContents = 55 { 56 assertion, 57 actual, 58 expected, 59 postFailureMessage ? null, 60 }: 61 runCommand "equal-contents-${lib.strings.toLower assertion}" 62 { 63 inherit 64 assertion 65 actual 66 expected 67 postFailureMessage 68 ; 69 nativeBuildInputs = [ diffoscopeMinimal ]; 70 } 71 '' 72 echo "Checking:" 73 printf '%s\n' "$assertion" 74 if ! diffoscope --no-progress --text-color=always --exclude-directory-metadata=no -- "$actual" "$expected" 75 then 76 echo 77 echo 'Contents must be equal, but were not!' 78 if [[ -n "''${postFailureMessage:-}" ]]; then 79 echo 80 echo "$postFailureMessage" 81 fi 82 echo 83 echo "+: expected, at $expected" 84 echo "-: unexpected, at $actual" 85 false 86 else 87 echo "expected $expected and actual $actual match." 88 echo OK 89 touch -- "$out" 90 fi 91 ''; 92 93 # See https://nixos.org/manual/nixpkgs/unstable/#tester-testEqualArrayOrMap 94 # or doc/build-helpers/testers.chapter.md 95 testEqualArrayOrMap = callPackage ./testEqualArrayOrMap { }; 96 97 # See https://nixos.org/manual/nixpkgs/unstable/#tester-testVersion 98 # or doc/build-helpers/testers.chapter.md 99 testVersion = 100 { 101 package, 102 command ? "${package.meta.mainProgram or package.pname or package.name} --version", 103 version ? package.version, 104 }: 105 runCommand "${package.name}-test-version" 106 { 107 nativeBuildInputs = [ package ]; 108 meta.timeout = 60; 109 } 110 '' 111 if output=$(${command} 2>&1 | sed -e 's|${builtins.storeDir}/[^/ ]*/|{{storeDir}}/|g'); then 112 if grep -Fw -- "${version}" - <<< "$output"; then 113 touch $out 114 else 115 echo "Version string '${version}' not found!" >&2 116 echo "The output was:" >&2 117 echo "$output" >&2 118 exit 1 119 fi 120 else 121 echo -n ${lib.escapeShellArg command} >&2 122 echo " returned a non-zero exit code." >&2 123 echo "$output" >&2 124 exit 1 125 fi 126 ''; 127 128 # See https://nixos.org/manual/nixpkgs/unstable/#tester-invalidateFetcherByDrvHash 129 # or doc/build-helpers/testers.chapter.md 130 invalidateFetcherByDrvHash = 131 f: args: 132 let 133 drvPath = (f args).drvPath; 134 # It's safe to discard the context, because we don't access the path. 135 salt = builtins.unsafeDiscardStringContext (lib.substring 0 12 (baseNameOf drvPath)); 136 # New derivation incorporating the original drv hash in the name 137 salted = f (args // { name = "${args.name or "source"}-salted-${salt}"; }); 138 # Make sure we did change the derivation. If the fetcher ignores `name`, 139 # `invalidateFetcherByDrvHash` doesn't work. 140 checked = 141 if salted.drvPath == drvPath then 142 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." 143 else 144 salted; 145 in 146 checked; 147 148 # See https://nixos.org/manual/nixpkgs/unstable/#tester-runCommand 149 runCommand = testers.invalidateFetcherByDrvHash ( 150 { 151 hash ? pkgs.emptyFile.outputHash, 152 name, 153 script, 154 stdenv ? stdenvNoCC, 155 ... 156 }@args: 157 158 runCommandWith { 159 inherit name stdenv; 160 161 derivationArgs = { 162 outputHash = hash; 163 outputHashMode = "recursive"; 164 } 165 // lib.removeAttrs args [ 166 "hash" 167 "name" 168 "script" 169 "stdenv" 170 ]; 171 } script 172 ); 173 174 # See https://nixos.org/manual/nixpkgs/unstable/#tester-runNixOSTest 175 # or doc/build-helpers/testers.chapter.md 176 runNixOSTest = 177 let 178 nixos = import ../../../nixos/lib { 179 inherit lib; 180 }; 181 in 182 testModule: 183 nixos.runTest { 184 _file = "pkgs.runNixOSTest implementation"; 185 imports = [ 186 (lib.setDefaultModuleLocation "the argument that was passed to pkgs.runNixOSTest" testModule) 187 ]; 188 hostPkgs = pkgs; 189 node.pkgs = pkgsLinux; 190 }; 191 192 # See https://nixos.org/manual/nixpkgs/unstable/#tester-invalidateFetcherByDrvHash 193 # or doc/build-helpers/testers.chapter.md 194 nixosTest = 195 let 196 /* 197 The nixos/lib/testing-python.nix module, preapplied with arguments that 198 make sense for this evaluation of Nixpkgs. 199 */ 200 nixosTesting = ( 201 import ../../../nixos/lib/testing-python.nix { 202 inherit (stdenv.hostPlatform) system; 203 inherit pkgs; 204 extraConfigurations = [ 205 ( 206 { lib, ... }: 207 { 208 config.nixpkgs.pkgs = lib.mkDefault pkgsLinux; 209 } 210 ) 211 ]; 212 } 213 ); 214 in 215 test: 216 let 217 loadedTest = if builtins.typeOf test == "path" then import test else test; 218 calledTest = lib.toFunction loadedTest pkgs; 219 in 220 nixosTesting.simpleTest calledTest; 221 222 hasPkgConfigModule = 223 { moduleName, ... }@args: 224 lib.warn 225 "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." 226 ( 227 testers.hasPkgConfigModules ( 228 builtins.removeAttrs args [ "moduleName" ] 229 // { 230 moduleNames = [ moduleName ]; 231 } 232 ) 233 ); 234 hasPkgConfigModules = callPackage ./hasPkgConfigModules/tester.nix { }; 235 236 hasCmakeConfigModules = callPackage ./hasCmakeConfigModules/tester.nix { }; 237 238 testMetaPkgConfig = callPackage ./testMetaPkgConfig/tester.nix { }; 239 240 shellcheck = callPackage ./shellcheck/tester.nix { }; 241 242 shfmt = callPackage ./shfmt { }; 243}