test-utilities: version test

Extract 'version test' to a reusable test utility as discussed in
https://github.com/NixOS/nixpkgs/pull/119636#issuecomment-826137021 and

+57 -11
+4
pkgs/applications/graphics/ImageMagick/7.0.nix
··· 2 , bzip2, zlib, libX11, libXext, libXt, fontconfig, freetype, ghostscript, libjpeg, djvulibre 3 , lcms2, openexr, libpng, librsvg, libtiff, libxml2, openjpeg, libwebp, libheif 4 , ApplicationServices 5 }: 6 7 let ··· 71 sed 's|-lgs|-L${lib.getLib ghostscript}/lib -lgs|' -i $la 72 done 73 ''; 74 75 meta = with lib; { 76 homepage = "http://www.imagemagick.org/";
··· 2 , bzip2, zlib, libX11, libXext, libXt, fontconfig, freetype, ghostscript, libjpeg, djvulibre 3 , lcms2, openexr, libpng, librsvg, libtiff, libxml2, openjpeg, libwebp, libheif 4 , ApplicationServices 5 + , testVersion, imagemagick 6 }: 7 8 let ··· 72 sed 's|-lgs|-L${lib.getLib ghostscript}/lib -lgs|' -i $la 73 done 74 ''; 75 + 76 + passthru.tests.version = 77 + testVersion { package = imagemagick; }; 78 79 meta = with lib; { 80 homepage = "http://www.imagemagick.org/";
+9 -1
pkgs/applications/misc/hello/default.nix
··· 1 - { lib, stdenv, fetchurl }: 2 3 stdenv.mkDerivation rec { 4 pname = "hello"; ··· 10 }; 11 12 doCheck = true; 13 14 meta = with lib; { 15 description = "A program that produces a familiar, friendly greeting";
··· 1 + { lib 2 + , stdenv 3 + , fetchurl 4 + , testVersion 5 + , hello 6 + }: 7 8 stdenv.mkDerivation rec { 9 pname = "hello"; ··· 15 }; 16 17 doCheck = true; 18 + 19 + passthru.tests.version = 20 + testVersion { package = hello; }; 21 22 meta = with lib; { 23 description = "A program that produces a familiar, friendly greeting";
+3 -5
pkgs/applications/networking/seaweedfs/default.nix
··· 1 { lib 2 , fetchFromGitHub 3 , buildGoModule 4 - , runCommand 5 , seaweedfs 6 }: 7 ··· 20 21 subPackages = [ "weed" ]; 22 23 - passthru.tests.check-version = runCommand "weed-version" { meta.timeout = 3; } '' 24 - ${seaweedfs}/bin/weed version | grep -Fw ${version} 25 - touch $out 26 - ''; 27 28 meta = with lib; { 29 description = "Simple and highly scalable distributed file system";
··· 1 { lib 2 , fetchFromGitHub 3 , buildGoModule 4 + , testVersion 5 , seaweedfs 6 }: 7 ··· 20 21 subPackages = [ "weed" ]; 22 23 + passthru.tests.version = 24 + testVersion { package = seaweedfs; command = "weed version"; }; 25 26 meta = with lib; { 27 description = "Simple and highly scalable distributed file system";
+8 -5
pkgs/applications/science/logic/key/default.nix
··· 5 , ant 6 , jre 7 , makeWrapper 8 - , runCommand 9 , key 10 }: 11 ··· 51 --add-flags "-cp $out/share/java/KeY.jar de.uka.ilkd.key.core.Main" 52 ''; 53 54 - passthru.tests.check-version = runCommand "key-help" {} '' 55 - ${key}/bin/KeY --help | grep 2.5 # Wrong version in the code. On next version change to ${version} 56 - touch $out 57 - ''; 58 59 meta = with lib; { 60 description = "Java formal verification tool";
··· 5 , ant 6 , jre 7 , makeWrapper 8 + , testVersion 9 , key 10 }: 11 ··· 51 --add-flags "-cp $out/share/java/KeY.jar de.uka.ilkd.key.core.Main" 52 ''; 53 54 + passthru.tests.version = 55 + testVersion { 56 + package = key; 57 + command = "KeY --help"; 58 + # Wrong '2.5' version in the code. On next version change to ${version} 59 + version = "2.5"; 60 + }; 61 62 meta = with lib; { 63 description = "Java formal verification tool";
+33
pkgs/build-support/trivial-builders.nix
··· 541 phases = "unpackPhase patchPhase installPhase"; 542 installPhase = "cp -R ./ $out"; 543 }; 544 }
··· 541 phases = "unpackPhase patchPhase installPhase"; 542 installPhase = "cp -R ./ $out"; 543 }; 544 + 545 + /* Checks the command output contains the specified version 546 + * 547 + * Although simplistic, this test assures that the main program 548 + * can run. While there's no substitute for a real test case, 549 + * it does catch dynamic linking errors and such. It also provides 550 + * some protection against accidentally building the wrong version, 551 + * for example when using an 'old' hash in a fixed-output derivation. 552 + * 553 + * Examples: 554 + * 555 + * passthru.tests.version = testVersion { package = hello; }; 556 + * 557 + * passthru.tests.version = testVersion { 558 + * package = seaweedfs; 559 + * command = "weed version"; 560 + * }; 561 + * 562 + * passthru.tests.version = testVersion { 563 + * package = key; 564 + * command = "KeY --help"; 565 + * # Wrong '2.5' version in the code. Drop on next version. 566 + * version = "2.5"; 567 + * }; 568 + */ 569 + testVersion = 570 + { package, 571 + command ? "${package.meta.mainProgram or package.pname or package.name} --version", 572 + version ? package.version, 573 + }: runCommand "test-version" { nativeBuildInputs = [ package ]; meta.timeout = 60; } '' 574 + ${command} | grep -Fw ${version} 575 + touch $out 576 + ''; 577 }