Skip to content

Commit 6224ea9

Browse files
committed
fix(rocks): use forward slash in package.path and package.cpath
The enable() function used backslash separators (\?.lua, \?\init.lua, \\?.ext) which only work on Windows. On Unix systems this produces invalid paths like /usr/share/lua/5.4\?.lua. Lua's package.path uses forward slashes on all platforms. Fix all three patterns to use / instead of \.
1 parent 7ed00de commit 6224ea9

2 files changed

Lines changed: 40 additions & 5 deletions

File tree

lua/plug/rocks/init.lua

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,16 @@ function M.enable()
6161
vim.system({ 'luarocks', 'config', '--json' }):wait().stdout
6262
)
6363
package.path = string.format(
64-
'%s;%s%s;%s%s;',
64+
'%s;%s/?.lua;%s/?/init.lua;',
6565
package.path,
6666
luarocks_config.deploy_lua_dir,
67-
[[\?.lua]],
68-
luarocks_config.deploy_lua_dir,
69-
[[\?\init.lua]]
67+
luarocks_config.deploy_lua_dir
7068
)
7169
--- D:\Scoop\apps\luarocks\current\rocks\lib\lua\5.4\?.dll
7270
package.cpath = package.cpath
7371
.. ';'
7472
.. luarocks_config.deploy_lib_dir
75-
.. '\\?.'
73+
.. '/?.'
7674
.. luarocks_config.external_lib_extension
7775
vim.env.LUA_PATH = package.path
7876
vim.env.LUA_CPATH = package.cpath

test/rocks_spec.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
-- test/rocks_spec.lua
2+
-- Tests for plug.rocks module
3+
4+
local lu = require('luaunit')
5+
local rocks = require('plug.rocks')
6+
7+
local TestRocks = {}
8+
9+
function TestRocks:testUnifyPathExists()
10+
lu.assertEquals(type(rocks.unify_path), 'function')
11+
end
12+
13+
function TestRocks:testUnifyPathBasic()
14+
local result = rocks.unify_path('/tmp/test.lua')
15+
lu.assertNotNil(result)
16+
lu.assertStrContains(result, 'test.lua')
17+
end
18+
19+
function TestRocks:testGetReturnsNilForUnknownRock()
20+
-- get() should return nil for a non-existent rock name
21+
local result = rocks.get('nonexistent-rock-12345')
22+
lu.assertNil(result)
23+
end
24+
25+
function TestRocks:testEnableDoesNotError()
26+
-- enable() should not error even if luarocks is not installed
27+
rocks.enable()
28+
lu.assertTrue(true)
29+
end
30+
31+
function TestRocks:testSetRtpDoesNotErrorForUnknownSpec()
32+
rocks.set_rtp({ name = 'nonexistent-rock-12345' })
33+
lu.assertTrue(true)
34+
end
35+
36+
return TestRocks
37+

0 commit comments

Comments
 (0)