about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorArnout Engelen <arnout@bzzt.net>2021-05-06 10:08:08 +0200
committerArnout Engelen <arnout@bzzt.net>2021-05-07 09:53:35 +0200
commitb68130fd2cb836f80ee6c8eb8840c39a12c50bef (patch)
treeb600e65b2bc257a42dd5935f21c935e1a11feed3 /pkgs/build-support
parent39e6bf76474ce742eb027a88c4da6331f0a1526f (diff)
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
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/trivial-builders.nix33
1 files changed, 33 insertions, 0 deletions
diff --git a/pkgs/build-support/trivial-builders.nix b/pkgs/build-support/trivial-builders.nix
index 4995efd9a4bfc..142a04f9a10c4 100644
--- a/pkgs/build-support/trivial-builders.nix
+++ b/pkgs/build-support/trivial-builders.nix
@@ -541,4 +541,37 @@ rec {
       phases = "unpackPhase patchPhase installPhase";
       installPhase = "cp -R ./ $out";
     };
+
+  /* Checks the command output contains the specified version
+   *
+   * 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; } ''
+      ${command} | grep -Fw ${version}
+      touch $out
+    '';
 }