about summary refs log tree commit diff
path: root/nix
diff options
context:
space:
mode:
authorsterni <sternenseemann@systemli.org>2022-10-09T09·22+0200
committerclbot <clbot@tvl.fyi>2022-10-09T13·25+0000
commit5174c2163730c683ca5c2a01be537c38173bab33 (patch)
treefc68079e00b37d69f917b6073651159459ef97ba /nix
parent1e852098091dcaaaf3b9750c6dff5e465403f8c3 (diff)
fix(nix/tag): correct no match check in discr r/5071
It uses discrDef internally, but passes `null` as the default tag name,
causing Nix to drop the attribute and return an empty attribute set if
the default case is hit. Consequently we need to check for the empty
attribute set, not `null` to figure out if there was no match found.

We can also test this behavior using `assertThrows` which was introduced
after the tag library was originally written.

Change-Id: I45adb2f9602762dfc867956323fb3f5ae4c8bd1d
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6904
Autosubmit: sterni <sternenseemann@systemli.org>
Reviewed-by: Profpatsch <mail@profpatsch.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'nix')
-rw-r--r--nix/tag/default.nix2
-rw-r--r--nix/tag/tests.nix5
2 files changed, 6 insertions, 1 deletions
diff --git a/nix/tag/default.nix b/nix/tag/default.nix
index 0038404460..2955656323 100644
--- a/nix/tag/default.nix
+++ b/nix/tag/default.nix
@@ -78,7 +78,7 @@ let
   # Like `discrDef`, but fail if there is no match.
   discr = fs: v:
     let res = discrDef null fs v; in
-    assert lib.assertMsg (res != null)
+    assert lib.assertMsg (res != { })
       "tag.discr: No predicate found that matches ${lib.generators.toPretty {} v}";
     res;
 
diff --git a/nix/tag/tests.nix b/nix/tag/tests.nix
index bcc42c758a..e0085b4837 100644
--- a/nix/tag/tests.nix
+++ b/nix/tag/tests.nix
@@ -4,6 +4,7 @@ let
   inherit (depot.nix.runTestsuite)
     runTestsuite
     assertEq
+    assertThrows
     it
     ;
 
@@ -50,6 +51,10 @@ let
         { int = lib.isInt; }
       ] "foo")
       { def = "foo"; })
+    (assertThrows "throws failing to match"
+      (discr [
+        { fish = x: x == 42; }
+      ] 21))
   ];
 
   match-test = it "can match things" [