fix(nix/tag): correct no match check in discr
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
This commit is contained in:
parent
1e85209809
commit
5174c21637
2 changed files with 6 additions and 1 deletions
|
@ -78,7 +78,7 @@ let
|
||||||
# Like `discrDef`, but fail if there is no match.
|
# Like `discrDef`, but fail if there is no match.
|
||||||
discr = fs: v:
|
discr = fs: v:
|
||||||
let res = discrDef null fs v; in
|
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}";
|
"tag.discr: No predicate found that matches ${lib.generators.toPretty {} v}";
|
||||||
res;
|
res;
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ let
|
||||||
inherit (depot.nix.runTestsuite)
|
inherit (depot.nix.runTestsuite)
|
||||||
runTestsuite
|
runTestsuite
|
||||||
assertEq
|
assertEq
|
||||||
|
assertThrows
|
||||||
it
|
it
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -50,6 +51,10 @@ let
|
||||||
{ int = lib.isInt; }
|
{ int = lib.isInt; }
|
||||||
] "foo")
|
] "foo")
|
||||||
{ def = "foo"; })
|
{ def = "foo"; })
|
||||||
|
(assertThrows "throws failing to match"
|
||||||
|
(discr [
|
||||||
|
{ fish = x: x == 42; }
|
||||||
|
] 21))
|
||||||
];
|
];
|
||||||
|
|
||||||
match-test = it "can match things" [
|
match-test = it "can match things" [
|
||||||
|
|
Loading…
Reference in a new issue