Skip to content

Commit

Permalink
fixup: use do...end block to only shell out once
Browse files Browse the repository at this point in the history
  • Loading branch information
dundargoc committed Nov 19, 2022
1 parent 52c0ef3 commit ba3a754
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions test/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,23 +270,29 @@ function module.check_logs()
end

-- Gets (lowercase) OS name from CMake, uname, or manually check if on Windows
local function uname()
local platform
if os.getenv("SYSTEM_NAME") then -- From CMAKE_HOST_SYSTEM_NAME.
platform = string.lower(os.getenv("SYSTEM_NAME"))
return platform
end
do
local platform = nil
function module.uname()
if platform then
return platform
end

local status, f = pcall(module.popen_r, 'uname', '-s')
if status then
platform = string.lower(f:read("*l"))
f:close()
elseif package.config:sub(1,1) == '\\' then
platform = 'windows'
else
error('unknown platform')
if os.getenv("SYSTEM_NAME") then -- From CMAKE_HOST_SYSTEM_NAME.
platform = string.lower(os.getenv("SYSTEM_NAME"))
return platform
end

local status, f = pcall(module.popen_r, 'uname', '-s')
if status then
platform = string.lower(f:read("*l"))
f:close()
elseif package.config:sub(1,1) == '\\' then
platform = 'windows'
else
error('unknown platform')
end
return platform
end
return platform
end

function module.is_os(s)
Expand All @@ -297,11 +303,11 @@ function module.is_os(s)
or s == 'bsd') then
error('unknown platform: '..tostring(s))
end
return ((s == 'win' and uname() == 'windows')
or (s == 'mac' and uname() == 'darwin')
or (s == 'freebsd' and uname() == 'freebsd')
or (s == 'openbsd' and uname() == 'openbsd')
or (s == 'bsd' and string.find(uname(), 'bsd')))
return ((s == 'win' and module.uname() == 'windows')
or (s == 'mac' and module.uname() == 'darwin')
or (s == 'freebsd' and module.uname() == 'freebsd')
or (s == 'openbsd' and module.uname() == 'openbsd')
or (s == 'bsd' and string.find(module.uname(), 'bsd')))
end

local function tmpdir_get()
Expand Down

0 comments on commit ba3a754

Please sign in to comment.