diff options
-rw-r--r-- | spec/unit/fs_spec.lua | 51 | ||||
-rw-r--r-- | spec/util/test_env.lua | 10 |
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 | |||
1544 | end) | 1595 | end) |
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)) |
119 | end | 119 | end |
120 | 120 | ||
121 | -- Monkeypatch incorrect tmpname's on some Lua distributions for Windows | ||
122 | local os_tmpname = os.tmpname | ||
123 | os.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 | ||
129 | end | ||
130 | |||
121 | local lfs_chdir = lfs.chdir | 131 | local lfs_chdir = lfs.chdir |
122 | lfs.chdir = function(d) -- luacheck: ignore | 132 | lfs.chdir = function(d) -- luacheck: ignore |
123 | return lfs_chdir(V(d)) | 133 | return lfs_chdir(V(d)) |