aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2022-06-06 15:28:14 -0300
committerHisham Muhammad <hisham@gobolinux.org>2022-06-06 17:14:52 -0300
commitbec4a9cbf72c8e392163f50f7b6bbb18763d9f90 (patch)
treeec131971a48b331bdd05b074eb365f3bae1d3d36 /spec
parent292a274fd02b88a729d474b544829c53e138a57b (diff)
downloadluarocks-bec4a9cbf72c8e392163f50f7b6bbb18763d9f90.tar.gz
luarocks-bec4a9cbf72c8e392163f50f7b6bbb18763d9f90.tar.bz2
luarocks-bec4a9cbf72c8e392163f50f7b6bbb18763d9f90.zip
loader.which: new option for searching package.path and cpath
Adds a new second argument, `where`, a string which indicates places to search for the module. If `where` contains "l", it will search using the LuaRocks loader; if it contains "p", it will look in the filesystem using package.path and package.cpath. You can use both at the same time. If successful, it will return four values. * If found using the LuaRocks loader, it will return: * filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so"), * rock name * rock version * "l" to indicate the match comes from the loader. * If found scanning package.path and package.cpath, it will return: * filename of the module (eg. "/usr/local/lib/lua/5.1/socket/core.so"), * "path" or "cpath" * nil * "p" to indicate the match comes from scanning package.path and cpath. If unsuccessful, nothing is returned.
Diffstat (limited to 'spec')
-rw-r--r--spec/loader_spec.lua25
1 files changed, 18 insertions, 7 deletions
diff --git a/spec/loader_spec.lua b/spec/loader_spec.lua
index 35179080..c8526117 100644
--- a/spec/loader_spec.lua
+++ b/spec/loader_spec.lua
@@ -4,10 +4,21 @@ local testing_paths = test_env.testing_paths
4local write_file = test_env.write_file 4local write_file = test_env.write_file
5 5
6describe("luarocks.loader", function() 6describe("luarocks.loader", function()
7
8 before_each(function()
9 test_env.setup_specs()
10 end)
11
7 describe("#unit", function() 12 describe("#unit", function()
8 it("starts", function() 13 it("starts", function()
9 assert(run.lua_bool([[-e "require 'luarocks.loader'; print(package.loaded['luarocks.loaded'])"]])) 14 assert(run.lua_bool([[-e "require 'luarocks.loader'; print(package.loaded['luarocks.loaded'])"]]))
10 end) 15 end)
16
17 describe("which", function()
18 it("finds modules using package.path", function()
19 assert(run.lua_bool([[-e "loader = require 'luarocks.loader'; local x,y,z,p = loader.which('luarocks.loader', 'p'); assert(p == 'p')"]]))
20 end)
21 end)
11 end) 22 end)
12 23
13 describe("#integration", function() 24 describe("#integration", function()
@@ -21,13 +32,13 @@ describe("luarocks.loader", function()
21 url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/rock_b_01.lua" 32 url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/rock_b_01.lua"
22 } 33 }
23 build = { 34 build = {
24 type = "builtin", 35 type = "builtin",
25 modules = { 36 modules = {
26 rock_b = "rock_b_01.lua" 37 rock_b = "rock_b_01.lua"
27 } 38 }
28 } 39 }
29 ]], finally) 40 ]], finally)
30 41
31 write_file("rock_b_10.lua", "print('ROCK B 1.0'); return {}", finally) 42 write_file("rock_b_10.lua", "print('ROCK B 1.0'); return {}", finally)
32 write_file("rock_b-1.0-1.rockspec", [[ 43 write_file("rock_b-1.0-1.rockspec", [[
33 package = "rock_b" 44 package = "rock_b"
@@ -36,13 +47,13 @@ describe("luarocks.loader", function()
36 url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/rock_b_10.lua" 47 url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/rock_b_10.lua"
37 } 48 }
38 build = { 49 build = {
39 type = "builtin", 50 type = "builtin",
40 modules = { 51 modules = {
41 rock_b = "rock_b_10.lua" 52 rock_b = "rock_b_10.lua"
42 } 53 }
43 } 54 }
44 ]], finally) 55 ]], finally)
45 56
46 write_file("rock_a.lua", "require('rock_b'); return {}", finally) 57 write_file("rock_a.lua", "require('rock_b'); return {}", finally)
47 write_file("rock_a-2.0-1.rockspec", [[ 58 write_file("rock_a-2.0-1.rockspec", [[
48 package = "rock_a" 59 package = "rock_a"
@@ -54,7 +65,7 @@ describe("luarocks.loader", function()
54 "rock_b < 1.0", 65 "rock_b < 1.0",
55 } 66 }
56 build = { 67 build = {
57 type = "builtin", 68 type = "builtin",
58 modules = { 69 modules = {
59 rock_a = "rock_a.lua" 70 rock_a = "rock_a.lua"
60 } 71 }
@@ -64,9 +75,9 @@ describe("luarocks.loader", function()
64 print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=" .. testing_paths.testing_tree .. " ./rock_b-0.1-1.rockspec")) 75 print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=" .. testing_paths.testing_tree .. " ./rock_b-0.1-1.rockspec"))
65 print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=" .. testing_paths.testing_tree .. " ./rock_b-1.0-1.rockspec --keep")) 76 print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=" .. testing_paths.testing_tree .. " ./rock_b-1.0-1.rockspec --keep"))
66 print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=" .. testing_paths.testing_tree .. " ./rock_a-2.0-1.rockspec")) 77 print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=" .. testing_paths.testing_tree .. " ./rock_a-2.0-1.rockspec"))
67 78
68 local output = run.lua([[-e "require 'luarocks.loader'; require('rock_a')"]]) 79 local output = run.lua([[-e "require 'luarocks.loader'; require('rock_a')"]])
69 80
70 assert.matches("ROCK B 0.1", output, 1, true) 81 assert.matches("ROCK B 0.1", output, 1, true)
71 end) 82 end)
72 end) 83 end)