···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}