mirror of
https://github.com/NixOS/nix.git
synced 2025-11-28 05:00:58 +01:00
tests: add tests for dynamic attribute in let and inherit
Regression tests for the previous commit. Co-authored-by: Sergei Zimmerman <sergei@zimmerman.foo> Co-authored-by: piegames <git@piegames.de>
This commit is contained in:
parent
97abcda9cc
commit
0c0a41a81a
13 changed files with 68 additions and 0 deletions
|
|
@ -79,6 +79,8 @@
|
|||
# Not supported by nixfmt
|
||||
''^tests/functional/lang/eval-okay-deprecate-cursed-or\.nix$''
|
||||
''^tests/functional/lang/eval-okay-attrs5\.nix$''
|
||||
''^tests/functional/lang/eval-fail-dynamic-attrs-inherit\.nix$''
|
||||
''^tests/functional/lang/eval-fail-dynamic-attrs-inherit-2\.nix$''
|
||||
|
||||
# More syntax tests
|
||||
# These tests, or parts of them, should have been parse-* test cases.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
error: dynamic attributes not allowed in inherit
|
||||
at /pwd/lang/eval-fail-dynamic-attrs-inherit-2.nix:5:15:
|
||||
4| {
|
||||
5| inherit (a) ${"b" + ""};
|
||||
| ^
|
||||
6| }
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
let
|
||||
a.b = 1;
|
||||
in
|
||||
{
|
||||
inherit (a) ${"b" + ""};
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
error: dynamic attributes not allowed in inherit
|
||||
at /pwd/lang/eval-fail-dynamic-attrs-inherit.nix:5:11:
|
||||
4| {
|
||||
5| inherit ${"a" + ""};
|
||||
| ^
|
||||
6| }
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
let
|
||||
a = 1;
|
||||
in
|
||||
{
|
||||
inherit ${"a" + ""};
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: dynamic attributes not allowed in let
|
||||
at /pwd/lang/eval-fail-dynamic-attrs-let-2.nix:1:1:
|
||||
1| let
|
||||
| ^
|
||||
2| ${"${"a"}"} = 1;
|
||||
4
tests/functional/lang/eval-fail-dynamic-attrs-let-2.nix
Normal file
4
tests/functional/lang/eval-fail-dynamic-attrs-let-2.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
let
|
||||
${"${"a"}"} = 1;
|
||||
in
|
||||
a
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: dynamic attributes not allowed in let
|
||||
at /pwd/lang/eval-fail-dynamic-attrs-let-3.nix:1:1:
|
||||
1| let
|
||||
| ^
|
||||
2| "${"a"}" = 1;
|
||||
4
tests/functional/lang/eval-fail-dynamic-attrs-let-3.nix
Normal file
4
tests/functional/lang/eval-fail-dynamic-attrs-let-3.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
let
|
||||
"${"a"}" = 1;
|
||||
in
|
||||
a
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
error: dynamic attributes not allowed in let
|
||||
at /pwd/lang/eval-fail-dynamic-attrs-let.nix:1:1:
|
||||
1| let
|
||||
| ^
|
||||
2| ${"a" + ""} = 1;
|
||||
4
tests/functional/lang/eval-fail-dynamic-attrs-let.nix
Normal file
4
tests/functional/lang/eval-fail-dynamic-attrs-let.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
let
|
||||
${"a" + ""} = 1;
|
||||
in
|
||||
a
|
||||
1
tests/functional/lang/eval-okay-dynamic-attrs-3.exp
Normal file
1
tests/functional/lang/eval-okay-dynamic-attrs-3.exp
Normal file
|
|
@ -0,0 +1 @@
|
|||
{ a = 1; attrs = { b = 1; c = 1; d = 1; }; b = 1; c = 1; d = 1; }
|
||||
14
tests/functional/lang/eval-okay-dynamic-attrs-3.nix
Normal file
14
tests/functional/lang/eval-okay-dynamic-attrs-3.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# dynamic attrs are not generally allowed in `let`, and inherit, but they are if they only contain a string
|
||||
let
|
||||
${"a"} = 1;
|
||||
attrs = rec {
|
||||
b = c;
|
||||
${"c"} = d;
|
||||
d = a;
|
||||
};
|
||||
in
|
||||
{
|
||||
inherit ${"a"};
|
||||
inherit attrs;
|
||||
inherit (attrs) ${"b"} ${"c"} d;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue