diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2019-09-02 14:10:26 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-09-03 14:59:43 -0300 |
commit | 0a5c5eee15072b712d0cee4cce8d642d1177ff76 (patch) | |
tree | d5af50a42837542a9a53314944b8f920be99f995 | |
parent | 62a7c4f5fbb727b2509fc6d91fb6943111d30cbd (diff) | |
download | luarocks-0a5c5eee15072b712d0cee4cce8d642d1177ff76.tar.gz luarocks-0a5c5eee15072b712d0cee4cce8d642d1177ff76.tar.bz2 luarocks-0a5c5eee15072b712d0cee4cce8d642d1177ff76.zip |
fs: fix Lua wrapper for interactive mode
-rw-r--r-- | spec/init_spec.lua | 39 | ||||
-rw-r--r-- | src/luarocks/fs/unix.lua | 2 | ||||
-rw-r--r-- | src/luarocks/fs/win32.lua | 5 |
3 files changed, 44 insertions, 2 deletions
diff --git a/spec/init_spec.lua b/spec/init_spec.lua index 9d68187c..d8a8e899 100644 --- a/spec/init_spec.lua +++ b/spec/init_spec.lua | |||
@@ -35,6 +35,45 @@ describe("Luarocks init test #integration", function() | |||
35 | assert.truthy(lfs.attributes(myproject .. "/myproject-dev-1.rockspec")) | 35 | assert.truthy(lfs.attributes(myproject .. "/myproject-dev-1.rockspec")) |
36 | end, finally) | 36 | end, finally) |
37 | end) | 37 | end) |
38 | |||
39 | it("lua wrapper works", function() | ||
40 | test_env.run_in_tmp(function(tmpdir) | ||
41 | local myproject = tmpdir .. "/myproject" | ||
42 | lfs.mkdir(myproject) | ||
43 | lfs.chdir(myproject) | ||
44 | |||
45 | assert(run.luarocks("init")) | ||
46 | if is_win then | ||
47 | assert.truthy(lfs.attributes(myproject .. "/lua.bat")) | ||
48 | assert.truthy(lfs.attributes(myproject .. "/luarocks.bat")) | ||
49 | local pd = assert(io.popen([[echo print(_VERSION) | lua.bat]], "r")) | ||
50 | local output = pd:read("*a") | ||
51 | pd:close() | ||
52 | assert.match("5", output, 1, true) | ||
53 | local fd = io.open("hello.lua", "w") | ||
54 | fd:write("print('hello' .. _VERSION)") | ||
55 | fd:close() | ||
56 | pd = assert(io.popen([[lua.bat hello.lua]], "r")) | ||
57 | output = pd:read("*a") | ||
58 | pd:close() | ||
59 | assert.match("hello", output, 1, true) | ||
60 | else | ||
61 | assert.truthy(lfs.attributes(myproject .. "/lua")) | ||
62 | assert.truthy(lfs.attributes(myproject .. "/luarocks")) | ||
63 | local pd = assert(io.popen([[echo "print('hello ' .. _VERSION)" | ./lua]], "r")) | ||
64 | local output = pd:read("*a") | ||
65 | pd:close() | ||
66 | assert.match("hello", output, 1, true) | ||
67 | local fd = io.open("hello.lua", "w") | ||
68 | fd:write("print('hello' .. _VERSION)") | ||
69 | fd:close() | ||
70 | pd = assert(io.popen([[./lua ./hello.lua]], "r")) | ||
71 | output = pd:read("*a") | ||
72 | pd:close() | ||
73 | assert.match("hello", output, 1, true) | ||
74 | end | ||
75 | end, finally) | ||
76 | end) | ||
38 | 77 | ||
39 | it("LuaRocks init with given arguments", function() | 78 | it("LuaRocks init with given arguments", function() |
40 | test_env.run_in_tmp(function(tmpdir) | 79 | test_env.run_in_tmp(function(tmpdir) |
diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index 92a2dd91..164ec75d 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua | |||
@@ -99,7 +99,7 @@ function unix.wrap_script(script, target, deps_mode, name, version, ...) | |||
99 | fs.Q(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)), | 99 | fs.Q(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)), |
100 | "-e", | 100 | "-e", |
101 | fs.Q(table.concat(luainit, ";")), | 101 | fs.Q(table.concat(luainit, ";")), |
102 | script and fs.Q(script) or "", | 102 | script and fs.Q(script) or [[$([ "$*" ] || echo -i)]], |
103 | ... | 103 | ... |
104 | } | 104 | } |
105 | 105 | ||
diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index 71b22e35..b9404a73 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua | |||
@@ -167,12 +167,15 @@ function win32.wrap_script(script, target, deps_mode, name, version, ...) | |||
167 | fs.Qb(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)), | 167 | fs.Qb(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)), |
168 | "-e", | 168 | "-e", |
169 | fs.Qb(table.concat(luainit, ";")), | 169 | fs.Qb(table.concat(luainit, ";")), |
170 | script and fs.Qb(script) or "", | 170 | script and fs.Qb(script) or "%I%", |
171 | ... | 171 | ... |
172 | } | 172 | } |
173 | 173 | ||
174 | wrapper:write("@echo off\r\n") | 174 | wrapper:write("@echo off\r\n") |
175 | wrapper:write("setlocal\r\n") | 175 | wrapper:write("setlocal\r\n") |
176 | if not script then | ||
177 | wrapper:write([[IF "%*"=="" (set I=-i) ELSE (set I=)]] .. "\r\n") | ||
178 | end | ||
176 | wrapper:write("set "..fs.Qb("LUAROCKS_SYSCONFDIR="..cfg.sysconfdir) .. "\r\n") | 179 | wrapper:write("set "..fs.Qb("LUAROCKS_SYSCONFDIR="..cfg.sysconfdir) .. "\r\n") |
177 | wrapper:write(table.concat(argv, " ") .. " %*\r\n") | 180 | wrapper:write(table.concat(argv, " ") .. " %*\r\n") |
178 | wrapper:write("exit /b %ERRORLEVEL%\r\n") | 181 | wrapper:write("exit /b %ERRORLEVEL%\r\n") |