summary refs log tree commit diff
path: root/lib/strings.nix
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2018-08-06 01:36:09 +0200
committerProfpatsch <mail@profpatsch.de>2018-09-06 18:14:27 +0200
commit3e45b61a9920466a8ea06b8ad9350d56ade435bc (patch)
tree1913cb4951336a37ed9921a538db5a50c7b62008 /lib/strings.nix
parent320cdecd1697020cb367adc1f8408dbf689ca254 (diff)
downloadnixpkgs-3e45b61a9920466a8ea06b8ad9350d56ade435bc.tar
nixpkgs-3e45b61a9920466a8ea06b8ad9350d56ade435bc.tar.gz
nixpkgs-3e45b61a9920466a8ea06b8ad9350d56ade435bc.tar.bz2
nixpkgs-3e45b61a9920466a8ea06b8ad9350d56ade435bc.tar.lz
nixpkgs-3e45b61a9920466a8ea06b8ad9350d56ade435bc.tar.xz
nixpkgs-3e45b61a9920466a8ea06b8ad9350d56ade435bc.tar.zst
nixpkgs-3e45b61a9920466a8ea06b8ad9350d56ade435bc.zip
lib/trivial: add a few examples of usage of assertMsg/assertOneOf
Diffstat (limited to 'lib/strings.nix')
-rw-r--r--lib/strings.nix7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index 833f69d2fbf..0c4095bb55c 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -410,7 +410,7 @@ rec {
       components = splitString "/" url;
       filename = lib.last components;
       name = builtins.head (splitString sep filename);
-    in assert name !=  filename; name;
+    in assert name != filename; name;
 
   /* Create an --{enable,disable}-<feat> string that can be passed to
      standard GNU Autoconf scripts.
@@ -468,7 +468,10 @@ rec {
       strw = lib.stringLength str;
       reqWidth = width - (lib.stringLength filler);
     in
-      assert strw <= width;
+      assert lib.assertMsg (strw <= width)
+        "fixedWidthString: requested string length (${
+          toString width}) must not be shorter than actual length (${
+            toString strw})";
       if strw == width then str else filler + fixedWidthString reqWidth filler str;
 
   /* Format a number adding leading zeroes up to fixed width.