From d7c49ca7152768114a9359b729557f77b8343545 Mon Sep 17 00:00:00 2001 From: Gerg-L Date: Fri, 13 Oct 2023 20:45:19 -0400 Subject: [PATCH 1/2] lib.getExe': check arguments --- lib/meta.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/meta.nix b/lib/meta.nix index 44730a71551e..2e817c42327d 100644 --- a/lib/meta.nix +++ b/lib/meta.nix @@ -162,5 +162,12 @@ rec { getExe' pkgs.imagemagick "convert" => "/nix/store/5rs48jamq7k6sal98ymj9l4k2bnwq515-imagemagick-7.1.1-15/bin/convert" */ - getExe' = x: y: "${lib.getBin x}/bin/${y}"; + getExe' = x: y: + assert lib.assertMsg (lib.isDerivation x) + "lib.meta.getExe': The first argument is of type ${builtins.typeOf x}, but it should be a derivation instead."; + assert lib.assertMsg (lib.isString y) + "lib.meta.getExe': The second argument is of type ${builtins.typeOf y}, but it should be a string instead."; + assert lib.assertMsg (builtins.length (lib.splitString "/" y) == 1) + "lib.meta.getExe': The second argument \"${y}\" is a nested path with a \"/\" character, but it should just be the name of the executable instead."; + "${lib.getBin x}/bin/${y}"; } From d2161d06321770f37fd86bfa15296dd8de0196a0 Mon Sep 17 00:00:00 2001 From: Gerg-L Date: Mon, 16 Oct 2023 18:55:38 -0400 Subject: [PATCH 2/2] lib/tests: add tests for getExe' and getExe --- lib/tests/misc.nix | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 2e7fda2b1f8b..47853f47278a 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -1906,4 +1906,32 @@ runTests { expr = (with types; either int (listOf (either bool str))).description; expected = "signed integer or list of (boolean or string)"; }; + +# Meta + testGetExe'Output = { + expr = getExe' { + type = "derivation"; + out = "somelonghash"; + bin = "somelonghash"; + } "executable"; + expected = "somelonghash/bin/executable"; + }; + + testGetExeOutput = { + expr = getExe { + type = "derivation"; + out = "somelonghash"; + bin = "somelonghash"; + meta.mainProgram = "mainProgram"; + }; + expected = "somelonghash/bin/mainProgram"; + }; + + testGetExe'FailureFirstArg = testingThrow ( + getExe' "not a derivation" "executable" + ); + + testGetExe'FailureSecondArg = testingThrow ( + getExe' { type = "derivation"; } "dir/executable" + ); }