tests: verify that NIX_DAEMON_PACKAGE's version looks like a version

Followup to https://gerrit.lix.systems/c/lix/+/1417 to ensure that this
parser will never take something that doesn't look like a version.

It turns out this problem is less alarming than initially thought
because it only applies to the testsuite in a non-default mode.

Change-Id: I26aba24aaf0215f2b782966314b94784db766266
This commit is contained in:
jade 2024-06-10 17:04:54 -07:00
parent 6939ffc9f9
commit d9345d8836

View file

@ -146,8 +146,12 @@ fi
isDaemonNewer () { isDaemonNewer () {
[[ -n "${NIX_DAEMON_PACKAGE:-}" ]] || return 0 [[ -n "${NIX_DAEMON_PACKAGE:-}" ]] || return 0
local requiredVersion="$1" local requiredVersion="$1"
local versionOutput=$($NIX_DAEMON_PACKAGE/bin/nix daemon --version) local versionOutput
versionOutput=$("$NIX_DAEMON_PACKAGE/bin/nix" daemon --version)
local daemonVersion=${versionOutput##* } local daemonVersion=${versionOutput##* }
if [[ ! $daemonVersion =~ [[:digit:]]+\.[[:digit:]]+\..* ]]; then
fail "Daemon version '$daemonVersion' does not look plausible, this is a testsuite bug!"
fi
[[ $(nix eval --expr "builtins.compareVersions ''$daemonVersion'' ''$requiredVersion''") -ge 0 ]] [[ $(nix eval --expr "builtins.compareVersions ''$daemonVersion'' ''$requiredVersion''") -ge 0 ]]
} }