From 0a5c5eee15072b712d0cee4cce8d642d1177ff76 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 2 Sep 2019 14:10:26 -0300 Subject: fs: fix Lua wrapper for interactive mode --- spec/init_spec.lua | 39 +++++++++++++++++++++++++++++++++++++++ src/luarocks/fs/unix.lua | 2 +- 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() assert.truthy(lfs.attributes(myproject .. "/myproject-dev-1.rockspec")) end, finally) end) + + it("lua wrapper works", function() + test_env.run_in_tmp(function(tmpdir) + local myproject = tmpdir .. "/myproject" + lfs.mkdir(myproject) + lfs.chdir(myproject) + + assert(run.luarocks("init")) + if is_win then + assert.truthy(lfs.attributes(myproject .. "/lua.bat")) + assert.truthy(lfs.attributes(myproject .. "/luarocks.bat")) + local pd = assert(io.popen([[echo print(_VERSION) | lua.bat]], "r")) + local output = pd:read("*a") + pd:close() + assert.match("5", output, 1, true) + local fd = io.open("hello.lua", "w") + fd:write("print('hello' .. _VERSION)") + fd:close() + pd = assert(io.popen([[lua.bat hello.lua]], "r")) + output = pd:read("*a") + pd:close() + assert.match("hello", output, 1, true) + else + assert.truthy(lfs.attributes(myproject .. "/lua")) + assert.truthy(lfs.attributes(myproject .. "/luarocks")) + local pd = assert(io.popen([[echo "print('hello ' .. _VERSION)" | ./lua]], "r")) + local output = pd:read("*a") + pd:close() + assert.match("hello", output, 1, true) + local fd = io.open("hello.lua", "w") + fd:write("print('hello' .. _VERSION)") + fd:close() + pd = assert(io.popen([[./lua ./hello.lua]], "r")) + output = pd:read("*a") + pd:close() + assert.match("hello", output, 1, true) + end + end, finally) + end) it("LuaRocks init with given arguments", function() 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, ...) fs.Q(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)), "-e", fs.Q(table.concat(luainit, ";")), - script and fs.Q(script) or "", + script and fs.Q(script) or [[$([ "$*" ] || echo -i)]], ... } 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, ...) fs.Qb(dir.path(cfg.variables["LUA_BINDIR"], cfg.lua_interpreter)), "-e", fs.Qb(table.concat(luainit, ";")), - script and fs.Qb(script) or "", + script and fs.Qb(script) or "%I%", ... } wrapper:write("@echo off\r\n") wrapper:write("setlocal\r\n") + if not script then + wrapper:write([[IF "%*"=="" (set I=-i) ELSE (set I=)]] .. "\r\n") + end wrapper:write("set "..fs.Qb("LUAROCKS_SYSCONFDIR="..cfg.sysconfdir) .. "\r\n") wrapper:write(table.concat(argv, " ") .. " %*\r\n") wrapper:write("exit /b %ERRORLEVEL%\r\n") -- cgit v1.2.3-55-g6feb