aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSewbacca <sewbacca@kolabnow.com>2024-03-04 12:57:12 -0300
committerHisham Muhammad <hisham@gobolinux.org>2024-03-04 21:52:09 +0000
commit1f3e8794254d32d44c510e3868378b2f969b0ba6 (patch)
tree2e0826d5f4694223f4fe7f81e537b280749b33a0
parent531393e338746830aa6138c2f671ffc4e4db9e28 (diff)
downloadluarocks-1f3e8794254d32d44c510e3868378b2f969b0ba6.tar.gz
luarocks-1f3e8794254d32d44c510e3868378b2f969b0ba6.tar.bz2
luarocks-1f3e8794254d32d44c510e3868378b2f969b0ba6.zip
tests: add tests for fs.execute_env using variables with spaces
Co-Authored-By: Hisham Muhammad <hisham@gobolinux.org>
-rw-r--r--spec/unit/fs_spec.lua51
-rw-r--r--spec/util/test_env.lua10
2 files changed, 61 insertions, 0 deletions
diff --git a/spec/unit/fs_spec.lua b/spec/unit/fs_spec.lua
index 5718aea4..621a7727 100644
--- a/spec/unit/fs_spec.lua
+++ b/spec/unit/fs_spec.lua
@@ -1541,4 +1541,55 @@ describe("luarocks.fs #unit", function()
1541 end) 1541 end)
1542 end) 1542 end)
1543 1543
1544 describe("fs.execute_env", function()
1545 local tmpname
1546 local tmplua
1547 local LUA = "lua"
1548
1549 local function readfile(pathname)
1550 local file = assert(io.open(pathname, "rb"))
1551 local data = file:read "*a"
1552 file:close()
1553 return data
1554 end
1555
1556 lazy_setup(function()
1557 tmpname = os.tmpname()
1558
1559 tmplua = os.tmpname()
1560 local f = assert(io.open(tmplua, 'wb'))
1561 f:write [[
1562 local out = io.open((...), 'wb')
1563 out:write(os.getenv 'FOO')
1564 out:close()
1565 ]]
1566 f:close()
1567 LUA = test_env.testing_paths.lua
1568 end)
1569
1570 after_each(function()
1571 os.remove(tmpname)
1572 end)
1573
1574 lazy_teardown(function()
1575 os.remove(tmpname)
1576 end)
1577
1578 it("passes variables w/o spaces correctly", function()
1579 fs.execute_env({
1580 FOO = "BAR",
1581 }, LUA, tmplua, tmpname)
1582 local data = readfile(tmpname)
1583 assert.same("BAR", data)
1584 end)
1585
1586 it("passes variables w/ spaces correctly", function()
1587 fs.execute_env({
1588 FOO = "BAR with spaces",
1589 }, LUA, tmplua, tmpname)
1590 local data = readfile(tmpname)
1591 assert.same("BAR with spaces", data)
1592 end)
1593 end)
1594
1544end) 1595end)
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua
index be75b4ec..2255d141 100644
--- a/spec/util/test_env.lua
+++ b/spec/util/test_env.lua
@@ -118,6 +118,16 @@ os.rename = function(a, b) -- luacheck: ignore
118 return os_rename(V(a), V(b)) 118 return os_rename(V(a), V(b))
119end 119end
120 120
121-- Monkeypatch incorrect tmpname's on some Lua distributions for Windows
122local os_tmpname = os.tmpname
123os.tmpname = function() -- luacheck:ignore
124 local name = os_tmpname()
125 if name:sub(1, 1) == '\\' then
126 name = os.getenv "TEMP"..name
127 end
128 return name
129end
130
121local lfs_chdir = lfs.chdir 131local lfs_chdir = lfs.chdir
122lfs.chdir = function(d) -- luacheck: ignore 132lfs.chdir = function(d) -- luacheck: ignore
123 return lfs_chdir(V(d)) 133 return lfs_chdir(V(d))