Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test-utilities: version test #121896

Merged
merged 1 commit into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkgs/applications/graphics/ImageMagick/7.0.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
, bzip2, zlib, libX11, libXext, libXt, fontconfig, freetype, ghostscript, libjpeg, djvulibre
, lcms2, openexr, libpng, librsvg, libtiff, libxml2, openjpeg, libwebp, libheif
, ApplicationServices
, testVersion, imagemagick
}:

let
Expand Down Expand Up @@ -72,6 +73,9 @@ stdenv.mkDerivation rec {
done
'';

passthru.tests.version =
testVersion { package = imagemagick; };

meta = with lib; {
homepage = "http://www.imagemagick.org/";
description = "A software suite to create, edit, compose, or convert bitmap images";
Expand Down
10 changes: 9 additions & 1 deletion pkgs/applications/misc/hello/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{ lib, stdenv, fetchurl }:
{ lib
, stdenv
, fetchurl
, testVersion
, hello
}:

stdenv.mkDerivation rec {
pname = "hello";
Expand All @@ -11,6 +16,9 @@ stdenv.mkDerivation rec {

doCheck = true;

passthru.tests.version =
testVersion { package = hello; };

meta = with lib; {
description = "A program that produces a familiar, friendly greeting";
longDescription = ''
Expand Down
8 changes: 3 additions & 5 deletions pkgs/applications/networking/seaweedfs/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ lib
, fetchFromGitHub
, buildGoModule
, runCommand
, testVersion
, seaweedfs
}:

Expand All @@ -20,10 +20,8 @@ buildGoModule rec {

subPackages = [ "weed" ];

passthru.tests.check-version = runCommand "weed-version" { meta.timeout = 3; } ''
${seaweedfs}/bin/weed version | grep -Fw ${version}
touch $out
'';
passthru.tests.version =
testVersion { package = seaweedfs; command = "weed version"; };

meta = with lib; {
description = "Simple and highly scalable distributed file system";
Expand Down
13 changes: 8 additions & 5 deletions pkgs/applications/science/logic/key/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
, ant
, jre
, makeWrapper
, runCommand
, testVersion
, key
}:

Expand Down Expand Up @@ -51,10 +51,13 @@ in stdenv.mkDerivation rec {
--add-flags "-cp $out/share/java/KeY.jar de.uka.ilkd.key.core.Main"
'';

passthru.tests.check-version = runCommand "key-help" {} ''
${key}/bin/KeY --help | grep 2.5 # Wrong version in the code. On next version change to ${version}
touch $out
'';
passthru.tests.version =
testVersion {
package = key;
command = "KeY --help";
# Wrong '2.5' version in the code. On next version change to ${version}
version = "2.5";
};

meta = with lib; {
description = "Java formal verification tool";
Expand Down
33 changes: 33 additions & 0 deletions pkgs/build-support/trivial-builders.nix
Original file line number Diff line number Diff line change
Expand Up @@ -541,4 +541,37 @@ rec {
phases = "unpackPhase patchPhase installPhase";
installPhase = "cp -R ./ $out";
};

/* Checks the command output contains the specified version
*
raboof marked this conversation as resolved.
Show resolved Hide resolved
* Although simplistic, this test assures that the main program
* can run. While there's no substitute for a real test case,
* it does catch dynamic linking errors and such. It also provides
* some protection against accidentally building the wrong version,
* for example when using an 'old' hash in a fixed-output derivation.
*
* Examples:
*
* passthru.tests.version = testVersion { package = hello; };
*
* passthru.tests.version = testVersion {
* package = seaweedfs;
* command = "weed version";
* };
*
* passthru.tests.version = testVersion {
* package = key;
* command = "KeY --help";
* # Wrong '2.5' version in the code. Drop on next version.
* version = "2.5";
* };
*/
testVersion =
{ package,
command ? "${package.meta.mainProgram or package.pname or package.name} --version",
version ? package.version,
}: runCommand "test-version" { nativeBuildInputs = [ package ]; meta.timeout = 60; } ''
0x4A6F marked this conversation as resolved.
Show resolved Hide resolved
${command} | grep -Fw ${version}
touch $out
'';
}