git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #121896 from raboof/extract-version-test-to-utility

test-utilities: version test

commitaaec26af39dbfb597c3c56889f72fc676d7116cc authorRobert Hensing <roberth@users.noreply.github.com> dateFri 7 May 2021, 11:56 (6 years ago) parent26cb44fb68130f
5 files changed+57−11
pkgs/applications/graphics/ImageMagick/7.0.nix+4 pkgs/applications/misc/hello/default.nix+9−1 pkgs/applications/networking/seaweedfs/default.nix+3−5 pkgs/applications/science/logic/key/default.nix+8−5 pkgs/build-support/trivial-builders.nix+33
pkgs/applications/graphics/ImageMagick/7.0.nix+4
@@ -2,6 +2,7 @@
22, bzip2, zlib, libX11, libXext, libXt, fontconfig, freetype, ghostscript, libjpeg, djvulibre
33, lcms2, openexr, libpng, librsvg, libtiff, libxml2, openjpeg, libwebp, libheif
44, ApplicationServices
5+, testVersion, imagemagick
56}:
67
78let
@@ -72,6 +73,9 @@ stdenv.mkDerivation rec {
7273 done
7374 '';
7475
76+ passthru.tests.version =
77+ testVersion { package = imagemagick; };
78+
7579 meta = with lib; {
7680 homepage = "http://www.imagemagick.org/";
7781 description = "A software suite to create, edit, compose, or convert bitmap images";
pkgs/applications/misc/hello/default.nix+9−1
@@ -1,4 +1,9 @@
1−{ lib, stdenv, fetchurl }:
1+{ lib
2+, stdenv
3+, fetchurl
4+, testVersion
5+, hello
6+}:
27
38stdenv.mkDerivation rec {
49 pname = "hello";
@@ -11,6 +16,9 @@ stdenv.mkDerivation rec {
1116
1217 doCheck = true;
1318
19+ passthru.tests.version =
20+ testVersion { package = hello; };
21+
1422 meta = with lib; {
1523 description = "A program that produces a familiar, friendly greeting";
1624 longDescription = ''
pkgs/applications/networking/seaweedfs/default.nix+3−5
@@ -1,7 +1,7 @@
11{ lib
22, fetchFromGitHub
33, buildGoModule
4−, runCommand
4+, testVersion
55, seaweedfs
66}:
77
@@ -20,10 +20,8 @@ buildGoModule rec {
2020
2121 subPackages = [ "weed" ];
2222
23− passthru.tests.check-version = runCommand "weed-version" { meta.timeout = 3; } ''
24− ${seaweedfs}/bin/weed version | grep -Fw ${version}
25− touch $out
26− '';
23+ passthru.tests.version =
24+ testVersion { package = seaweedfs; command = "weed version"; };
2725
2826 meta = with lib; {
2927 description = "Simple and highly scalable distributed file system";
pkgs/applications/science/logic/key/default.nix+8−5
@@ -5,7 +5,7 @@
55, ant
66, jre
77, makeWrapper
8−, runCommand
8+, testVersion
99, key
1010}:
1111
@@ -51,10 +51,13 @@ in stdenv.mkDerivation rec {
5151 --add-flags "-cp $out/share/java/KeY.jar de.uka.ilkd.key.core.Main"
5252 '';
5353
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− '';
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+ };
5861
5962 meta = with lib; {
6063 description = "Java formal verification tool";
pkgs/build-support/trivial-builders.nix+33
@@ -541,4 +541,37 @@ rec {
541541 phases = "unpackPhase patchPhase installPhase";
542542 installPhase = "cp -R ./ $out";
543543 };
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+ '';
544577}