tests: Improve handling of spaces in $PATH
(cherry picked from commit b2590f2e47fe8ab7352a9e3769b195ff9f398dd7)