feat(tvix/eval): strengthen significantly catchable test suite

Adds a bunch (notably certain overlapping) tests for catchable situations.

This should cover many scenarios, argument is catchable, element in argument is catchable, function returns
catchable in the middle of the processing, etc.

Co-authored-by: Aspen Smith <root@gws.fyi>
Change-Id: Icd722cf8dbc91a24f45cd540a328711e5826f76c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10621
Reviewed-by: aspen <root@gws.fyi>
Tested-by: BuildkiteCI
This commit is contained in:
Ryan Lahfa 2024-01-14 04:07:33 +01:00 committed by raitobezarius
parent d10c5309bc
commit 7b1632ec71
72 changed files with 210 additions and 0 deletions

View file

@ -0,0 +1 @@
(builtins.tryEval (builtins.throw (builtins.abort "abc"))).success

View file

@ -0,0 +1 @@
(builtins.tryEval (builtins.abort (builtins.throw "abc"))).success

View file

@ -0,0 +1 @@
[ false false false ]

View file

@ -0,0 +1 @@
map (e: (builtins.tryEval e).success) [ (builtins.all (builtins.throw "a") [ "" ]) (builtins.all (x: true) (builtins.throw "b")) (builtins.all (_: builtins.throw "x") [ "" ]) ]

View file

@ -0,0 +1 @@
[ false false false ]

View file

@ -0,0 +1 @@
map (e: (builtins.tryEval e).success) [ (builtins.any (builtins.throw "a") [ "" ]) (builtins.any (x: true) (builtins.throw "b")) (builtins.any (_: builtins.throw "a") [ "" ]) ]

View file

@ -0,0 +1 @@
(builtins.tryEval (builtins.attrValues (builtins.throw "a"))).success

View file

@ -0,0 +1 @@
[ false false ]

View file

@ -0,0 +1 @@
map (e: (builtins.tryEval e).success) [ (builtins.catAttrs "a" (builtins.throw "b")) (builtins.catAttrs (builtins.throw "a") { a = 1; }) ]

View file

@ -0,0 +1 @@
[ false false true ]

View file

@ -0,0 +1 @@
map (e: (builtins.tryEval e).success) [ (builtins.concatLists (builtins.throw "a")) (builtins.concatLists [ [] (builtins.throw "a") ]) (builtins.concatLists [ [] [] [ builtins.throw "a" ] ]) ]

View file

@ -0,0 +1 @@
[ false false false ]

View file

@ -0,0 +1 @@
map (e: (builtins.tryEval e).success) [ (builtins.concatMap (builtins.throw "a") [ "" ]) (builtins.concatMap (_: builtins.throw "x") [ "" ]) (builtins.concatMap (_: []) (builtins.throw "a")) ]

View file

@ -0,0 +1 @@
[ false false false ]

View file

@ -0,0 +1 @@
map (e: (builtins.tryEval e).success) [ (builtins.concatStringsSep (builtins.throw "a") [ "" ]) (builtins.concatStringsSep "," (builtins.throw "a")) (builtins.concatStringsSep "," [ "a" (builtins.throw "a") ]) ]

View file

@ -0,0 +1 @@
[ false false false ]

View file

@ -0,0 +1 @@
map (e: (builtins.tryEval e).success) [ (builtins.filter (builtins.throw "a") [ "" ]) (builtins.filter (x: true) (builtins.throw "b")) (builtins.filter (_: builtins.throw "x") [ "" ]) ]

View file

@ -0,0 +1 @@
[ false false false false true true ]

View file

@ -0,0 +1,8 @@
map (e: (builtins.tryEval e).success) [
(builtins.foldl' (builtins.throw "a") {} [ {} {} {} ])
(builtins.foldl' (x: y: x // y) {} (builtins.throw "b"))
(builtins.foldl' (_: _: builtins.throw "x") {} [ {} ])
(builtins.foldl' (x: y: x // y) (builtins.throw "x") [ {} ])
(builtins.foldl' (x: y: x // y) {} [ {} { a = builtins.throw "z"; } {} ])
(builtins.foldl' (x: y: x // y) {} [ {} { b = 3; a = builtins.throw "u"; } {} ])
]

View file

@ -0,0 +1 @@
(builtins.tryEval (builtins.fromJSON (builtins.throw "a"))).success

View file

@ -0,0 +1,4 @@
map (e: (builtins.tryEval e).success) [
(builtins.functionArgs (_: builtins.throw "a"))
(builtins.functionArgs (builtins.throw "b"))
]

View file

@ -0,0 +1 @@
[ true false true ]

View file

@ -0,0 +1,5 @@
map (e: (builtins.tryEval e).success) [
(builtins.genList (builtins.throw "a") 10)
(builtins.genList (i: "") (builtins.throw "b"))
(builtins.genList (i: builtins.throw "x") 5)
]

View file

@ -0,0 +1 @@
(builtins.tryEval (builtins.getContext (builtins.throw "a"))).success

View file

@ -0,0 +1 @@
(builtins.tryEval (builtins.hasContext (builtins.throw "a"))).success

View file

@ -0,0 +1 @@
[ false false ]

View file

@ -0,0 +1,4 @@
map (e: (builtins.tryEval e).success) [
(builtins.head (builtins.throw "a"))
(builtins.head [ (builtins.throw "a") ])
]

View file

@ -0,0 +1 @@
[ false false false false false false false false false ]

View file

@ -0,0 +1,14 @@
let
isTypeFns = [
builtins.isAttrs
builtins.isBool
builtins.isFloat
builtins.isFunction
builtins.isInt
builtins.isList
builtins.isNull
builtins.isPath
builtins.isString
];
in
map (fn: (builtins.tryEval (fn (builtins.throw "is type"))).success) isTypeFns

View file

@ -0,0 +1 @@
[ false true true false false ]

View file

@ -0,0 +1,7 @@
map (e: (builtins.tryEval e).success) [
(builtins.listToAttrs [ { name = builtins.throw "a"; value = "b"; } ])
(builtins.listToAttrs [ { name = "a"; value = builtins.throw "b"; } ])
(builtins.listToAttrs [ { name = "a"; value = "b"; } { name = "c"; value = builtins.throw "d"; } ])
(builtins.listToAttrs [ { name = "a"; value = "b"; } (builtins.throw "e") ])
(builtins.listToAttrs (builtins.throw "f"))
]

View file

@ -0,0 +1 @@
[ true false true ]

View file

@ -0,0 +1,5 @@
map (e: (builtins.tryEval e).success) [
(builtins.map (builtins.throw "a") [ "" ])
(builtins.map (x: true) (builtins.throw "b"))
(builtins.map (_: builtins.throw "x") [ "" ])
]

View file

@ -0,0 +1 @@
(builtins.tryEval (builtins.parseDrvName (builtins.throw "a"))).success

View file

@ -0,0 +1 @@
[ false false false ]

View file

@ -0,0 +1,5 @@
map (e: (builtins.tryEval e).success) [
(builtins.partition (builtins.throw "a") [ "" ])
(builtins.partition (x: true) (builtins.throw "b"))
(builtins.partition (_: builtins.throw "x") [ "" ])
]

View file

@ -0,0 +1 @@
[ false false true false ]

View file

@ -0,0 +1,6 @@
map (e: (builtins.tryEval e).success) [
(builtins.removeAttrs (builtins.throw "a") [ "a" ])
(builtins.removeAttrs { a = {}; } (builtins.throw "b"))
(builtins.removeAttrs { a = builtins.throw "b"; } [ "a" ])
(builtins.removeAttrs { "${builtins.throw "c"}" = "b"; } [ "c" ])
]

View file

@ -0,0 +1 @@
[ false false false false false false false false false ]

View file

@ -0,0 +1,16 @@
map (e: (builtins.tryEval e).success) [
# This one may be hard to read for non-experts.
# Replace strings is a special built-in compared to others in the sense
# it might attempt to lazily evaluate things upon successful replacements,
# so it would not be surprising that some of the non-replacements which could throw
# could be ignored by laziness. It is not the case though.
(builtins.replaceStrings [ "a" (builtins.throw "b") ] [ "c" "d" ] "ab")
(builtins.replaceStrings [ "a" (builtins.throw "b") ] [ "c" "d" ] "a")
(builtins.replaceStrings [ "a" "b" ] [ "c" (builtins.throw "d") ] "a")
(builtins.replaceStrings [ "a" "b" ] [ "c" (builtins.throw "d") ] "ab")
(builtins.replaceStrings [ "" ] [ (builtins.throw "d") ] "ab")
(builtins.replaceStrings [ "a" "" ] [ "b" (builtins.throw "d") ] "ab")
(builtins.replaceStrings (builtins.throw "z") [ ] "ab")
(builtins.replaceStrings [ ] (builtins.throw "z") "ab")
(builtins.replaceStrings [ ] [ ] (builtins.throw "z"))
]

View file

@ -0,0 +1 @@
[ false false true false ]

View file

@ -0,0 +1,6 @@
map (e: (builtins.tryEval e).success) [
(builtins.sort (builtins.throw "a") [ "" ])
(builtins.sort (x: y: true) (builtins.throw "b"))
(builtins.sort (_: _: builtins.throw "x") [ "" ])
(builtins.sort (_: _: builtins.throw "x") [ "" "" ])
]

View file

@ -0,0 +1 @@
[ false false ]

View file

@ -0,0 +1,4 @@
map (e: (builtins.tryEval e).success) [
(builtins.split (builtins.throw "regex") "abc")
(builtins.split "[^/]" (builtins.throw "string"))
]

View file

@ -0,0 +1,4 @@
map (e: (builtins.tryEval e).success) [
(builtins.stringLength (builtins.throw "a"))
# FIXME(raitobezarius): test coercions too.
]

View file

@ -0,0 +1 @@
[ false true true true ]

View file

@ -0,0 +1,6 @@
map (e: (builtins.tryEval e).success) [
(builtins.tail (builtins.throw "a"))
(builtins.tail [ (builtins.throw "a") ])
(builtins.tail [ (builtins.throw "a") "a" ])
(builtins.tail [ (builtins.throw "a") (builtins.throw "a") ])
]

View file

@ -0,0 +1 @@
[ false false false false ]

View file

@ -0,0 +1,14 @@
map (e: (builtins.tryEval (builtins.toJSON e)).success) [
(builtins.throw "a")
{
a = builtins.throw "attribute a";
}
{
a.b.c.d.e.f.g.h.i = builtins.throw "deep i";
}
{
x = 32;
y = builtins.throw "second argument";
}
# FIXME(raitobezarius): we would like to test coercions, i.e. `toFile` and `derivation` containing throwables.
]

View file

@ -0,0 +1 @@
[ false false ]

View file

@ -0,0 +1,5 @@
map (e: (builtins.tryEval (builtins.toPath e)).success) [
(builtins.throw "a")
(./xyz + (builtins.throw "p"))
# FIXME: test derivations and files.
]

View file

@ -0,0 +1 @@
[ false false false false ]

View file

@ -0,0 +1,7 @@
map (e: (builtins.tryEval (builtins.toString e)).success) [
(builtins.throw "a")
[ (builtins.throw "a") ]
[ "abc" (builtins.throw "a") ]
"abc${builtins.throw "c"}"
# FIXME: test derivations and files.
]

View file

@ -0,0 +1 @@
[ false false false false true false false ]

View file

@ -0,0 +1,15 @@
map (e: (builtins.tryEval (builtins.toXML e)).success) [
(builtins.throw "a")
[ (builtins.throw "a") ]
[ "abc" (builtins.throw "a") ]
"abc${builtins.throw "c"}"
(_: builtins.throw "d")
{
u = builtins.throw "x";
v = "a";
}
{
u.i.w.x.z = builtins.throw "n";
}
# FIXME: test derivations and files.
]

View file

@ -0,0 +1 @@
[ false true true false ]

View file

@ -0,0 +1,9 @@
map (e: (builtins.tryEval (builtins.typeOf e)).success) [
(builtins.throw "a")
{
a = builtins.throw "b";
}
[ (builtins.throw "c") ]
(./xyz + (builtins.throw "p"))
# FIXME: test derivations and files.
]

View file

@ -0,0 +1,4 @@
map (e: (builtins.tryEval (builtins.unsafeDiscardStringContext e)).success) [
(builtins.throw "a")
# FIXME: test derivations with throwables.
]

View file

@ -0,0 +1 @@
false

View file

@ -0,0 +1 @@
(builtins.tryEval (builtins.throw (builtins.throw "a"))).success

View file

@ -0,0 +1,5 @@
map (e: (builtins.tryEval e).success) [
(builtins.groupBy (builtins.throw "a") [ "" ])
(builtins.groupBy (x: true) (builtins.throw "b"))
(builtins.groupBy (_: builtins.throw "x") [ "" ])
]

View file

@ -51,6 +51,7 @@ let
"eval-okay-floor.nix" = [ nix ];
"eval-okay-groupBy.nix" = [ nix ];
"eval-okay-zipAttrsWith.nix" = [ nix ];
"eval-okay-builtins-group-by-propagate-catchable.nix" = [ nix ];
# Comparable lists are not in Nix 2.3
"eval-okay-sort.nix" = [ nix ];
"eval-okay-compare-lists.nix" = [ nix ];
@ -75,6 +76,12 @@ let
# b72bc4a972fe568744d98b89d63adcd504cb586c
"eval-okay-identifier-formatting.nix" = [ nix ];
# Different catchable behavior between nix 2.3 and 2.18
"eval-okay-builtins-map-propagate-catchable.nix" = [ nix_latest ];
"eval-okay-builtins-gen-list-propagate-catchable.nix" = [ nix_latest ];
"eval-okay-builtins-replace-strings-propagate-catchable.nix" =
[ nix_latest ];
# TODO(sterni): support diffing working directory and home relative paths
# like C++ Nix test suite (using string replacement).
"eval-okay-path-antiquotation.nix" = true;