mirror of
https://github.com/NixOS/nix
synced 2025-07-07 14:21:48 +02:00
Merge pull request #11043 from hercules-ci/assert-eq
`assert`: Report why values aren't equal
This commit is contained in:
commit
d08bb025e1
31 changed files with 547 additions and 7 deletions
|
@ -0,0 +1,8 @@
|
|||
error:
|
||||
… while evaluating the condition of the assertion '({ a = true; } == { a = true; b = true; })'
|
||||
at /pwd/lang/eval-fail-assert-equal-attrs-names-2.nix:1:1:
|
||||
1| assert { a = true; } == { a = true; b = true; };
|
||||
| ^
|
||||
2| throw "unreachable"
|
||||
|
||||
error: attribute names of attribute set '{ a = true; }' differs from attribute set '{ a = true; b = true; }'
|
|
@ -0,0 +1,2 @@
|
|||
assert { a = true; } == { a = true; b = true; };
|
||||
throw "unreachable"
|
|
@ -0,0 +1,8 @@
|
|||
error:
|
||||
… while evaluating the condition of the assertion '({ a = true; b = true; } == { a = true; })'
|
||||
at /pwd/lang/eval-fail-assert-equal-attrs-names.nix:1:1:
|
||||
1| assert { a = true; b = true; } == { a = true; };
|
||||
| ^
|
||||
2| throw "unreachable"
|
||||
|
||||
error: attribute names of attribute set '{ a = true; b = true; }' differs from attribute set '{ a = true; }'
|
|
@ -0,0 +1,2 @@
|
|||
assert { a = true; b = true; } == { a = true; };
|
||||
throw "unreachable"
|
|
@ -0,0 +1,26 @@
|
|||
error:
|
||||
… while evaluating the condition of the assertion '({ foo = { outPath = "/nix/store/0"; type = "derivation"; }; } == { foo = { devious = true; outPath = "/nix/store/1"; type = "derivation"; }; })'
|
||||
at /pwd/lang/eval-fail-assert-equal-derivations-extra.nix:1:1:
|
||||
1| assert
|
||||
| ^
|
||||
2| { foo = { type = "derivation"; outPath = "/nix/store/0"; }; }
|
||||
|
||||
… while comparing attribute 'foo'
|
||||
|
||||
… where left hand side is
|
||||
at /pwd/lang/eval-fail-assert-equal-derivations-extra.nix:2:5:
|
||||
1| assert
|
||||
2| { foo = { type = "derivation"; outPath = "/nix/store/0"; }; }
|
||||
| ^
|
||||
3| ==
|
||||
|
||||
… where right hand side is
|
||||
at /pwd/lang/eval-fail-assert-equal-derivations-extra.nix:4:5:
|
||||
3| ==
|
||||
4| { foo = { type = "derivation"; outPath = "/nix/store/1"; devious = true; }; };
|
||||
| ^
|
||||
5| throw "unreachable"
|
||||
|
||||
… while comparing a derivation by its 'outPath' attribute
|
||||
|
||||
error: string '"/nix/store/0"' is not equal to string '"/nix/store/1"'
|
|
@ -0,0 +1,5 @@
|
|||
assert
|
||||
{ foo = { type = "derivation"; outPath = "/nix/store/0"; }; }
|
||||
==
|
||||
{ foo = { type = "derivation"; outPath = "/nix/store/1"; devious = true; }; };
|
||||
throw "unreachable"
|
|
@ -0,0 +1,26 @@
|
|||
error:
|
||||
… while evaluating the condition of the assertion '({ foo = { ignored = (abort "not ignored"); outPath = "/nix/store/0"; type = "derivation"; }; } == { foo = { ignored = (abort "not ignored"); outPath = "/nix/store/1"; type = "derivation"; }; })'
|
||||
at /pwd/lang/eval-fail-assert-equal-derivations.nix:1:1:
|
||||
1| assert
|
||||
| ^
|
||||
2| { foo = { type = "derivation"; outPath = "/nix/store/0"; ignored = abort "not ignored"; }; }
|
||||
|
||||
… while comparing attribute 'foo'
|
||||
|
||||
… where left hand side is
|
||||
at /pwd/lang/eval-fail-assert-equal-derivations.nix:2:5:
|
||||
1| assert
|
||||
2| { foo = { type = "derivation"; outPath = "/nix/store/0"; ignored = abort "not ignored"; }; }
|
||||
| ^
|
||||
3| ==
|
||||
|
||||
… where right hand side is
|
||||
at /pwd/lang/eval-fail-assert-equal-derivations.nix:4:5:
|
||||
3| ==
|
||||
4| { foo = { type = "derivation"; outPath = "/nix/store/1"; ignored = abort "not ignored"; }; };
|
||||
| ^
|
||||
5| throw "unreachable"
|
||||
|
||||
… while comparing a derivation by its 'outPath' attribute
|
||||
|
||||
error: string '"/nix/store/0"' is not equal to string '"/nix/store/1"'
|
|
@ -0,0 +1,5 @@
|
|||
assert
|
||||
{ foo = { type = "derivation"; outPath = "/nix/store/0"; ignored = abort "not ignored"; }; }
|
||||
==
|
||||
{ foo = { type = "derivation"; outPath = "/nix/store/1"; ignored = abort "not ignored"; }; };
|
||||
throw "unreachable"
|
22
tests/functional/lang/eval-fail-assert-equal-floats.err.exp
Normal file
22
tests/functional/lang/eval-fail-assert-equal-floats.err.exp
Normal file
|
@ -0,0 +1,22 @@
|
|||
error:
|
||||
… while evaluating the condition of the assertion '({ b = 1; } == { b = 1.01; })'
|
||||
at /pwd/lang/eval-fail-assert-equal-floats.nix:1:1:
|
||||
1| assert { b = 1.0; } == { b = 1.01; };
|
||||
| ^
|
||||
2| abort "unreachable"
|
||||
|
||||
… while comparing attribute 'b'
|
||||
|
||||
… where left hand side is
|
||||
at /pwd/lang/eval-fail-assert-equal-floats.nix:1:10:
|
||||
1| assert { b = 1.0; } == { b = 1.01; };
|
||||
| ^
|
||||
2| abort "unreachable"
|
||||
|
||||
… where right hand side is
|
||||
at /pwd/lang/eval-fail-assert-equal-floats.nix:1:26:
|
||||
1| assert { b = 1.0; } == { b = 1.01; };
|
||||
| ^
|
||||
2| abort "unreachable"
|
||||
|
||||
error: a float with value '1' is not equal to a float with value '1.01'
|
2
tests/functional/lang/eval-fail-assert-equal-floats.nix
Normal file
2
tests/functional/lang/eval-fail-assert-equal-floats.nix
Normal file
|
@ -0,0 +1,2 @@
|
|||
assert { b = 1.0; } == { b = 1.01; };
|
||||
abort "unreachable"
|
|
@ -0,0 +1,9 @@
|
|||
error:
|
||||
… while evaluating the condition of the assertion '((x: x) == (x: x))'
|
||||
at /pwd/lang/eval-fail-assert-equal-function-direct.nix:3:1:
|
||||
2| # This only compares a direct comparison and makes no claims about functions in nested structures.
|
||||
3| assert
|
||||
| ^
|
||||
4| (x: x)
|
||||
|
||||
error: distinct functions and immediate comparisons of identical functions compare as unequal
|
|
@ -0,0 +1,7 @@
|
|||
# Note: functions in nested structures, e.g. attributes, may be optimized away by pointer identity optimization.
|
||||
# This only compares a direct comparison and makes no claims about functions in nested structures.
|
||||
assert
|
||||
(x: x)
|
||||
==
|
||||
(x: x);
|
||||
abort "unreachable"
|
|
@ -0,0 +1,8 @@
|
|||
error:
|
||||
… while evaluating the condition of the assertion '(1 == 1.1)'
|
||||
at /pwd/lang/eval-fail-assert-equal-int-float.nix:1:1:
|
||||
1| assert 1 == 1.1;
|
||||
| ^
|
||||
2| throw "unreachable"
|
||||
|
||||
error: an integer with value '1' is not equal to a float with value '1.1'
|
|
@ -0,0 +1,2 @@
|
|||
assert 1 == 1.1;
|
||||
throw "unreachable"
|
22
tests/functional/lang/eval-fail-assert-equal-ints.err.exp
Normal file
22
tests/functional/lang/eval-fail-assert-equal-ints.err.exp
Normal file
|
@ -0,0 +1,22 @@
|
|||
error:
|
||||
… while evaluating the condition of the assertion '({ b = 1; } == { b = 2; })'
|
||||
at /pwd/lang/eval-fail-assert-equal-ints.nix:1:1:
|
||||
1| assert { b = 1; } == { b = 2; };
|
||||
| ^
|
||||
2| abort "unreachable"
|
||||
|
||||
… while comparing attribute 'b'
|
||||
|
||||
… where left hand side is
|
||||
at /pwd/lang/eval-fail-assert-equal-ints.nix:1:10:
|
||||
1| assert { b = 1; } == { b = 2; };
|
||||
| ^
|
||||
2| abort "unreachable"
|
||||
|
||||
… where right hand side is
|
||||
at /pwd/lang/eval-fail-assert-equal-ints.nix:1:24:
|
||||
1| assert { b = 1; } == { b = 2; };
|
||||
| ^
|
||||
2| abort "unreachable"
|
||||
|
||||
error: an integer with value '1' is not equal to an integer with value '2'
|
2
tests/functional/lang/eval-fail-assert-equal-ints.nix
Normal file
2
tests/functional/lang/eval-fail-assert-equal-ints.nix
Normal file
|
@ -0,0 +1,2 @@
|
|||
assert { b = 1; } == { b = 2; };
|
||||
abort "unreachable"
|
|
@ -0,0 +1,8 @@
|
|||
error:
|
||||
… while evaluating the condition of the assertion '([ (1) (0) ] == [ (10) ])'
|
||||
at /pwd/lang/eval-fail-assert-equal-list-length.nix:1:1:
|
||||
1| assert [ 1 0 ] == [ 10 ];
|
||||
| ^
|
||||
2| throw "unreachable"
|
||||
|
||||
error: list of size '2' is not equal to list of size '1', left hand side is '[ 1 0 ]', right hand side is '[ 10 ]'
|
|
@ -0,0 +1,2 @@
|
|||
assert [ 1 0 ] == [ 10 ];
|
||||
throw "unreachable"
|
|
@ -0,0 +1,8 @@
|
|||
error:
|
||||
… while evaluating the condition of the assertion '(/pwd/lang/foo == /pwd/lang/bar)'
|
||||
at /pwd/lang/eval-fail-assert-equal-paths.nix:1:1:
|
||||
1| assert ./foo == ./bar;
|
||||
| ^
|
||||
2| throw "unreachable"
|
||||
|
||||
error: path '/pwd/lang/foo' is not equal to path '/pwd/lang/bar'
|
2
tests/functional/lang/eval-fail-assert-equal-paths.nix
Normal file
2
tests/functional/lang/eval-fail-assert-equal-paths.nix
Normal file
|
@ -0,0 +1,2 @@
|
|||
assert ./foo == ./bar;
|
||||
throw "unreachable"
|
|
@ -0,0 +1,22 @@
|
|||
error:
|
||||
… while evaluating the condition of the assertion '({ ding = false; } == { ding = null; })'
|
||||
at /pwd/lang/eval-fail-assert-equal-type-nested.nix:1:1:
|
||||
1| assert { ding = false; } == { ding = null; };
|
||||
| ^
|
||||
2| abort "unreachable"
|
||||
|
||||
… while comparing attribute 'ding'
|
||||
|
||||
… where left hand side is
|
||||
at /pwd/lang/eval-fail-assert-equal-type-nested.nix:1:10:
|
||||
1| assert { ding = false; } == { ding = null; };
|
||||
| ^
|
||||
2| abort "unreachable"
|
||||
|
||||
… where right hand side is
|
||||
at /pwd/lang/eval-fail-assert-equal-type-nested.nix:1:31:
|
||||
1| assert { ding = false; } == { ding = null; };
|
||||
| ^
|
||||
2| abort "unreachable"
|
||||
|
||||
error: a Boolean of value 'false' is not equal to null of value 'null'
|
|
@ -0,0 +1,2 @@
|
|||
assert { ding = false; } == { ding = null; };
|
||||
abort "unreachable"
|
|
@ -0,0 +1,8 @@
|
|||
error:
|
||||
… while evaluating the condition of the assertion '(false == null)'
|
||||
at /pwd/lang/eval-fail-assert-equal-type.nix:1:1:
|
||||
1| assert false == null;
|
||||
| ^
|
||||
2| abort "unreachable"
|
||||
|
||||
error: a Boolean of value 'false' is not equal to null of value 'null'
|
2
tests/functional/lang/eval-fail-assert-equal-type.nix
Normal file
2
tests/functional/lang/eval-fail-assert-equal-type.nix
Normal file
|
@ -0,0 +1,2 @@
|
|||
assert false == null;
|
||||
abort "unreachable"
|
74
tests/functional/lang/eval-fail-assert-nested-bool.err.exp
Normal file
74
tests/functional/lang/eval-fail-assert-nested-bool.err.exp
Normal file
|
@ -0,0 +1,74 @@
|
|||
error:
|
||||
… while evaluating the condition of the assertion '({ a = { b = [ ({ c = { d = true; }; }) ]; }; } == { a = { b = [ ({ c = { d = false; }; }) ]; }; })'
|
||||
at /pwd/lang/eval-fail-assert-nested-bool.nix:1:1:
|
||||
1| assert
|
||||
| ^
|
||||
2| { a.b = [ { c.d = true; } ]; }
|
||||
|
||||
… while comparing attribute 'a'
|
||||
|
||||
… where left hand side is
|
||||
at /pwd/lang/eval-fail-assert-nested-bool.nix:2:5:
|
||||
1| assert
|
||||
2| { a.b = [ { c.d = true; } ]; }
|
||||
| ^
|
||||
3| ==
|
||||
|
||||
… where right hand side is
|
||||
at /pwd/lang/eval-fail-assert-nested-bool.nix:4:5:
|
||||
3| ==
|
||||
4| { a.b = [ { c.d = false; } ]; };
|
||||
| ^
|
||||
5|
|
||||
|
||||
… while comparing attribute 'b'
|
||||
|
||||
… where left hand side is
|
||||
at /pwd/lang/eval-fail-assert-nested-bool.nix:2:5:
|
||||
1| assert
|
||||
2| { a.b = [ { c.d = true; } ]; }
|
||||
| ^
|
||||
3| ==
|
||||
|
||||
… where right hand side is
|
||||
at /pwd/lang/eval-fail-assert-nested-bool.nix:4:5:
|
||||
3| ==
|
||||
4| { a.b = [ { c.d = false; } ]; };
|
||||
| ^
|
||||
5|
|
||||
|
||||
… while comparing list element 0
|
||||
|
||||
… while comparing attribute 'c'
|
||||
|
||||
… where left hand side is
|
||||
at /pwd/lang/eval-fail-assert-nested-bool.nix:2:15:
|
||||
1| assert
|
||||
2| { a.b = [ { c.d = true; } ]; }
|
||||
| ^
|
||||
3| ==
|
||||
|
||||
… where right hand side is
|
||||
at /pwd/lang/eval-fail-assert-nested-bool.nix:4:15:
|
||||
3| ==
|
||||
4| { a.b = [ { c.d = false; } ]; };
|
||||
| ^
|
||||
5|
|
||||
|
||||
… while comparing attribute 'd'
|
||||
|
||||
… where left hand side is
|
||||
at /pwd/lang/eval-fail-assert-nested-bool.nix:2:15:
|
||||
1| assert
|
||||
2| { a.b = [ { c.d = true; } ]; }
|
||||
| ^
|
||||
3| ==
|
||||
|
||||
… where right hand side is
|
||||
at /pwd/lang/eval-fail-assert-nested-bool.nix:4:15:
|
||||
3| ==
|
||||
4| { a.b = [ { c.d = false; } ]; };
|
||||
| ^
|
||||
5|
|
||||
|
||||
error: boolean 'true' is not equal to boolean 'false'
|
6
tests/functional/lang/eval-fail-assert-nested-bool.nix
Normal file
6
tests/functional/lang/eval-fail-assert-nested-bool.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
assert
|
||||
{ a.b = [ { c.d = true; } ]; }
|
||||
==
|
||||
{ a.b = [ { c.d = false; } ]; };
|
||||
|
||||
abort "unreachable"
|
|
@ -20,9 +20,11 @@ error:
|
|||
| ^
|
||||
3|
|
||||
|
||||
error: assertion '(arg == "y")' failed
|
||||
at /pwd/lang/eval-fail-assert.nix:2:12:
|
||||
… while evaluating the condition of the assertion '(arg == "y")'
|
||||
at /pwd/lang/eval-fail-assert.nix:2:12:
|
||||
1| let {
|
||||
2| x = arg: assert arg == "y"; 123;
|
||||
| ^
|
||||
3|
|
||||
|
||||
error: string '"x"' is not equal to string '"y"'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue