diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-09-21 01:24:27 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-10-04 16:29:03 +0200 |
commit | ac2c8d321c879aa36046d404661e8a3e9c7a93fe (patch) | |
tree | ca9971347ef2e2ddf76d240aca703bb8e7628c3e /lib | |
parent | efbcf5938fca42f004e34c3f56f9ab1a12a95559 (diff) |
lib.fileset: Make expectEqual check more
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/fileset/tests.sh | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/fileset/tests.sh b/lib/fileset/tests.sh index 1b53e33073ef..13e984806c7d 100755 --- a/lib/fileset/tests.sh +++ b/lib/fileset/tests.sh @@ -57,18 +57,35 @@ with lib.fileset;' expectEqual() { local actualExpr=$1 local expectedExpr=$2 - if ! actualResult=$(nix-instantiate --eval --strict --show-trace \ + if actualResult=$(nix-instantiate --eval --strict --show-trace 2>"$tmp"/actualStderr \ --expr "$prefixExpression ($actualExpr)"); then - die "$actualExpr failed to evaluate, but it was expected to succeed" + actualExitCode=$? + else + actualExitCode=$? fi - if ! expectedResult=$(nix-instantiate --eval --strict --show-trace \ + actualStderr=$(< "$tmp"/actualStderr) + + if expectedResult=$(nix-instantiate --eval --strict --show-trace 2>"$tmp"/expectedStderr \ --expr "$prefixExpression ($expectedExpr)"); then - die "$expectedExpr failed to evaluate, but it was expected to succeed" + expectedExitCode=$? + else + expectedExitCode=$? + fi + expectedStderr=$(< "$tmp"/expectedStderr) + + if [[ "$actualExitCode" != "$expectedExitCode" ]]; then + echo "$actualStderr" >&2 + echo "$actualResult" >&2 + die "$actualExpr should have exited with $expectedExitCode, but it exited with $actualExitCode" fi if [[ "$actualResult" != "$expectedResult" ]]; then die "$actualExpr should have evaluated to $expectedExpr:\n$expectedResult\n\nbut it evaluated to\n$actualResult" fi + + if [[ "$actualStderr" != "$expectedStderr" ]]; then + die "$actualExpr should have had this on stderr:\n$expectedStderr\n\nbut it was\n$actualStderr" + fi } # Check that a nix expression evaluates successfully to a store path and returns it (without quotes). |