tests/functional2/lang: Some refactorings

I did a pass through all files, fixing bits that have annoyed me here
and there based on vibes. Roughly:

- Replaced some out values like bools or strings with lists where
appropriate. Those tests were likely older than the value printer
- Added some parser tests where it makes sense
- Gently touched some formatting woes, while trying to not cause too
much diff noise
- Removed some dead `with (import ./lib.nix);` code

Change-Id: I8c40b2110f0b7799f68ae38ba61f049c5f1f6ee8
This commit is contained in:
piegames
2026-04-19 16:07:54 +02:00
parent ae4b3d585d
commit 5afda956a7
37 changed files with 330 additions and 135 deletions
+7 -1
View File
@@ -1 +1,7 @@
({ __functor = self: x: self.foo && x; foo = false; } // { foo = true; }) true
(
{
__functor = self: x: self.foo && x;
foo = false;
}
// { foo = true; }
) true
@@ -1 +1 @@
"foo 22 80 itchyxac"
[ 22 80 "itchy" "x" "a" "c" ]
@@ -1,12 +1,12 @@
warning: using or as an identifier is deprecated because it cannot be used in most places (try let or = 1; in or). Use --extra-deprecated-features or-as-identifier to disable this warning.
at /pwd/in.nix:9:3:
8|
9| or = x: y: x || y;
at /pwd/in.nix:6:3:
5| bs = { f-o-o.bar = "foo"; };
6| or = x: y: x || y;
| ^
10|
7| in
warning: using or as an argument is deprecated because it is parsed with the wrong precedence which may cause unexpected behavior. Use --extra-deprecated-features or-as-identifier to disable this warning.
at /pwd/in.nix:23:11:
22| # it short-circuits and never runs into the type error
23| (fold or [] [true false false])
| ^
24| ]
at /pwd/in.nix:20:9:
19| # it short-circuits and never runs into the type error
20| (fold or [] [true false false])
| ^
21| ]
@@ -1 +1 @@
true
[ "test" "caseok" true [ "key 1" ] ]
+3 -4
View File
@@ -5,7 +5,6 @@ let
Z = "z";
in
if builtins.hasAttr A as then
builtins.getAttr A as
else
assert builtins.hasAttr Z as; builtins.getAttr Z as
assert !(builtins.hasAttr A as);
assert builtins.hasAttr Z as;
builtins.getAttr Z as
+9 -6
View File
@@ -14,9 +14,12 @@ let
};
in
if config.services.sshd.enable
then "foo ${toString config.services.sshd.port} ${toString config.services.httpd.port} ${config.hostName}"
+ "${config.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z}"
+ "${config.foo.a}"
+ "${config.foo.b.c}"
else "bar"
assert config.services.sshd.enable;
[
config.services.sshd.port
config.services.httpd.port
config.hostName
config.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z
config.foo.a
config.foo.b.c
]
+11 -4
View File
@@ -1,7 +1,14 @@
let
as = { x.y.z = 123; a.b.c = 456; };
bs = null;
in [ (as ? x) (as ? y) (as ? x.y.z) (as ? x.y.z.a) (as ? x.y.a) (as ? a.b.c) (bs ? x) (bs ? x.y.z) ]
in
[
(as ? x)
(as ? y)
(as ? x.y.z)
(as ? x.y.z.a)
(as ? x.y.a)
(as ? a.b.c)
(bs ? x)
(bs ? x.y.z)
]
+14 -17
View File
@@ -1,24 +1,21 @@
with import ./lib.nix;
let
as = { x.y.z = 123; a.b.c = 456; };
bs = { f-o-o.bar = "foo"; };
or = x: y: x || y;
in
[ as.x.y.z
as.foo or "foo"
as.x.y.bla or as.a.b.c
as.a.b.c or as.x.y.z
as.x.y.bla or bs.f-o-o.bar or "xyzzy"
as.x.y.bla or bs.bar.foo or "xyzzy"
(123).bla or null.foo or "xyzzy"
# Backwards compatibility test for `fun or` being handled as intended.
# n.b. this code contains a type error, because the nul value should be false instead of [].
# but the code expands to `true || (false || (false || [])))`, so as long as at least one value in the list is true
# it short-circuits and never runs into the type error
(fold or [] [true false false])
]
[
as.x.y.z
as.foo or "foo"
as.x.y.bla or as.a.b.c
as.a.b.c or as.x.y.z
as.x.y.bla or bs.f-o-o.bar or "xyzzy"
as.x.y.bla or bs.bar.foo or "xyzzy"
(123).bla or null.foo or "xyzzy"
# Backwards compatibility test for `fun or` being handled as intended.
# n.b. this code contains a type error, because the nul value should be false instead of [].
# but the code expands to `true || (false || (false || [])))`, so as long as at least one value in the list is true
# it short-circuits and never runs into the type error
(fold or [] [true false false])
]
@@ -1,4 +1,5 @@
{ x = 123;
{
x = 123;
y = 456;
x = 789;
}
@@ -1,13 +1,10 @@
rec {
as = {
x = 123;
y = 456;
};
bs = {
x = 789;
inherit (as) x;
};
}
@@ -1,13 +1,10 @@
rec {
as = {
x = 123;
y = 456;
};
bs = rec {
x = 789;
inherit (as) x;
};
}
@@ -1,7 +1,5 @@
rec {
x = 1;
as = {
inherit x;
inherit x;
@@ -14,7 +14,5 @@ let
# variable.
"foo bar" = 1;
in t1 == "test"
&& t2 == "caseok"
&& t3 == true
&& t4 == ["key 1"]
in
[ t1 t2 t3 t4 ]
@@ -1,6 +1,6 @@
error: attribute 'x' already defined at /pwd/in.nix:1:3
at /pwd/in.nix:3:3:
2| y = 456;
3| x = 789;
error: attribute 'x' already defined at /pwd/in.nix:2:3
at /pwd/in.nix:4:3:
3| y = 456;
4| x = 789;
| ^
4| }
5| }
@@ -1,6 +1,6 @@
error: attribute 'x' already defined at /pwd/in.nix:9:5
at /pwd/in.nix:10:18:
9| x = 789;
10| inherit (as) x;
error: attribute 'x' already defined at /pwd/in.nix:7:5
at /pwd/in.nix:8:18:
7| x = 789;
8| inherit (as) x;
| ^
11| };
9| };
@@ -1,6 +1,6 @@
error: attribute 'x' already defined at /pwd/in.nix:9:5
at /pwd/in.nix:10:18:
9| x = 789;
10| inherit (as) x;
error: attribute 'x' already defined at /pwd/in.nix:7:5
at /pwd/in.nix:8:18:
7| x = 789;
8| inherit (as) x;
| ^
11| };
9| };
@@ -1,6 +1,6 @@
error: attribute 'x' already defined at /pwd/in.nix:6:13
at /pwd/in.nix:7:13:
6| inherit x;
7| inherit x;
error: attribute 'x' already defined at /pwd/in.nix:4:13
at /pwd/in.nix:5:13:
4| inherit x;
5| inherit x;
| ^
8| };
6| };
+7 -6
View File
@@ -1,8 +1,9 @@
# See also the "arithmetic" tests
[
(builtins.add 2 3)
(builtins.add 2 2)
(builtins.typeOf (builtins.add 2 2))
("t" + "t")
(builtins.typeOf (builtins.add 2.0 2))
(builtins.add 2.0 2)
(builtins.add 2 3)
(builtins.add 2 2)
(builtins.typeOf (builtins.add 2 2))
("t" + "t")
(builtins.typeOf (builtins.add 2.0 2))
(builtins.add 2.0 2)
]
@@ -1,6 +1,7 @@
with builtins;
[ (any (x: x == 1) [])
[
(any (x: x == 1) [])
(any (x: x == 1) [2 3 4])
(any (x: x == 1) [1 2 3 4])
(any (x: x == 1) [4 3 2 1])
@@ -1,5 +1,6 @@
with import ./lib.nix;
[ (builtins.concatMap (x: if x / 2 * 2 == x then [] else [ x ]) (range 0 10))
[
(builtins.concatMap (x: if x / 2 * 2 == x then [] else [ x ]) (range 0 10))
(builtins.concatMap (x: [x] ++ ["z"]) ["a" "b"])
]
@@ -1,6 +1,7 @@
with builtins;
[ (concatStringsSep "" [])
[
(concatStringsSep "" [])
(concatStringsSep "" ["foo" "bar" "xyzzy"])
(concatStringsSep ", " ["foo" "bar" "xyzzy"])
(concatStringsSep ", " ["foo"])
@@ -1 +1 @@
[ "23" "24" "23" "23" ]
[ 23 24 23 23 ]
@@ -1,9 +1,7 @@
with import ./lib.nix;
let
n1 = builtins.floor 23.5;
n2 = builtins.ceil 23.5;
n3 = builtins.floor 23;
n4 = builtins.ceil 23;
in
map toString [ n1 n2 n3 n4 ]
[ n1 n2 n3 n4 ]
@@ -1,6 +1,6 @@
let
alphabet =
{ a = "a";
alphabet = {
a = "a";
b = "b";
c = "c";
d = "d";
@@ -33,7 +33,8 @@ let
};
alphabetFail = builtins.mapAttrs throw alphabet;
in
[ (builtins.intersectAttrs { a = abort "l1"; } { b = abort "r1"; })
[
(builtins.intersectAttrs { a = abort "l1"; } { b = abort "r1"; })
(builtins.intersectAttrs { a = abort "l2"; } { a = 1; })
(builtins.intersectAttrs alphabetFail { a = 1; })
(builtins.intersectAttrs { a = abort "laa"; } alphabet)
@@ -1,3 +1 @@
with import ./lib.nix;
builtins.mapAttrs (name: value: name + "-" + value) { x = "foo"; y = "bar"; }
@@ -1 +1 @@
builtins.parseFlakeRef "github:NixOS/nixpkgs/23.05?dir=lib"
builtins.parseFlakeRef "github:NixOS/nixpkgs/23.05?dir=lib"
+7 -7
View File
@@ -1,7 +1,7 @@
builtins.path
{ path = ./.;
filter = path: _: baseNameOf path == "data";
recursive = true;
sha256 = "1yhm3gwvg5a41yylymgblsclk95fs6jy72w0wv925mmidlhcq4sw";
name = "output";
}
builtins.path {
path = ./.;
filter = path: _: baseNameOf path == "data";
recursive = true;
sha256 = "1yhm3gwvg5a41yylymgblsclk95fs6jy72w0wv925mmidlhcq4sw";
name = "output";
}
@@ -1,7 +1,7 @@
error: attribute 'x' missing
at /pwd/in.nix:4:29:
at /pwd/in.nix:4:27:
3| in
4| (removeAttrs attrs ["x"]).x
| ^
4| (removeAttrs attrs ["x"]).x
| ^
5|
Did you mean y?
@@ -1,4 +1,4 @@
let
attrs = {x = 123; y = 456;};
in
(removeAttrs attrs ["x"]).x
(removeAttrs attrs ["x"]).x
@@ -1,6 +1,7 @@
with builtins;
[ (replaceStrings ["o"] ["a"] "foobar")
[
(replaceStrings ["o"] ["a"] "foobar")
(replaceStrings ["o"] [""] "foobar")
(replaceStrings ["oo"] ["u"] "foobar")
(replaceStrings ["oo" "a"] ["a" "oo"] "foobar")
+2 -1
View File
@@ -1,6 +1,7 @@
with builtins;
[ (sort lessThan [ 483 249 526 147 42 77 ])
[
(sort lessThan [ 483 249 526 147 42 77 ])
(sort (x: y: y < x) [ 483 249 526 147 42 77 ])
(sort lessThan [ "foo" "bar" "xyzzy" "fnord" ])
(sort (x: y: x.key < y.key)
+13 -13
View File
@@ -1,13 +1,13 @@
builtins.toJSON
{ a = 123;
b = -456;
c = "foo";
d = "foo\n\"bar\"";
e = true;
f = false;
g = [ 1 2 3 ];
h = [ "a" [ "b" { "foo\nbar" = {}; } ] ];
i = 1 + 2;
j = 1.44;
k = { __toString = self: self.a; a = "foo"; };
}
builtins.toJSON {
a = 123;
b = -456;
c = "foo";
d = "foo\n\"bar\"";
e = true;
f = false;
g = [ 1 2 3 ];
h = [ "a" [ "b" { "foo\nbar" = {}; } ] ];
i = 1 + 2;
j = 1.44;
k = { __toString = self: self.a; a = "foo"; };
}
@@ -0,0 +1,153 @@
_type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprConcatStrings
es:
- _type: ExprLiteral
value: a
valueType: String
- _type: ExprLiteral
value: b
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: c
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: d
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: e
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: f
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: g
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: h
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: i
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: j
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: k
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: l
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: m
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: n
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: o
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: p
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: q
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: r
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: s
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: t
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: u
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: v
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: w
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: x
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: y
valueType: String
isInterpolation: false
- _type: ExprLiteral
value: z
valueType: String
isInterpolation: false
+12 -12
View File
@@ -66,15 +66,15 @@ let
};
in
[ pkgs.stdenv.name
pkgs.fetchurl.name
pkgs.aterm.name
pkgs2.aterm.name
pkgs.xorg.libX11.name
pkgs.xorg.libXv.name
pkgs.mplayer.name
pkgs2.mplayer.name
pkgs.nix.name
pkgs2.nix.name
]
[
pkgs.stdenv.name
pkgs.fetchurl.name
pkgs.aterm.name
pkgs2.aterm.name
pkgs.xorg.libX11.name
pkgs.xorg.libXv.name
pkgs.mplayer.name
pkgs2.mplayer.name
pkgs.nix.name
pkgs2.nix.name
]
@@ -0,0 +1,34 @@
_type: ExprIf
cond:
_type: ExprOpNEq
e1:
_type: ExprLiteral
value: foo
valueType: String
e2:
_type: ExprConcatStrings
es:
- _type: ExprLiteral
value: f
valueType: String
- _type: ExprLiteral
value: oo
valueType: String
isInterpolation: false
else:
_type: ExprIf
cond:
_type: ExprVar
value: 'false'
else:
_type: ExprLiteral
value: 3
valueType: Int
then:
_type: ExprLiteral
value: 2
valueType: Int
then:
_type: ExprLiteral
value: 1
valueType: Int
+2 -1
View File
@@ -1,6 +1,7 @@
with builtins;
[ (isNull null)
[
(isNull null)
(isNull (x: x))
(isFunction (x: x))
(isFunction "fnord")
+2 -1
View File
@@ -1,5 +1,6 @@
# This test needs to be run with --extra-deprecated-features url-literals
[ x:x
[
x:x
https://svn.cs.uu.nl:12443/repos/trace/trunk
http://www2.mplayerhq.hu/MPlayer/releases/fonts/font-arial-iso-8859-1.tar.bz2
http://losser.st-lab.cs.uu.nl/~armijn/.nix/gcc-3.3.4-static-nix.tar.gz