aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--spec/build_spec.lua23
-rw-r--r--spec/fixtures/c_module-1.0-1.rockspec11
-rw-r--r--spec/fixtures/c_module.c9
-rw-r--r--spec/fixtures/git_repo/.gitignore2
-rw-r--r--spec/fixtures/git_repo/LICENSE19
-rw-r--r--spec/fixtures/git_repo/README.md3
-rw-r--r--spec/init_spec.lua83
-rw-r--r--spec/path_spec.lua15
8 files changed, 161 insertions, 4 deletions
diff --git a/spec/build_spec.lua b/spec/build_spec.lua
index 5f1eefd0..f042cbb9 100644
--- a/spec/build_spec.lua
+++ b/spec/build_spec.lua
@@ -35,13 +35,28 @@ describe("LuaRocks build tests #integration", function()
35 end) 35 end)
36 36
37 describe("LuaRocks build - basic testing set", function() 37 describe("LuaRocks build - basic testing set", function()
38 it("LuaRocks build with no flags/arguments", function()
39 assert.is_false(run.luarocks_bool("build"))
40 end)
41
42 it("LuaRocks build invalid", function() 38 it("LuaRocks build invalid", function()
43 assert.is_false(run.luarocks_bool("build invalid")) 39 assert.is_false(run.luarocks_bool("build invalid"))
44 end) 40 end)
41
42 it("LuaRocks build with no arguments behaves as luarocks make", function()
43 local tmpdir = test_env.get_tmp_path()
44 lfs.mkdir(tmpdir)
45 local olddir = lfs.currentdir()
46 lfs.chdir(tmpdir)
47 test_env.copy(testing_paths.fixtures_dir .. "/c_module-1.0-1.rockspec", tmpdir .. "/c_module-1.0-1.rockspec")
48 test_env.copy(testing_paths.fixtures_dir .. "/c_module.c", tmpdir .. "/c_module.c")
49
50 assert.is_true(run.luarocks_bool("build"))
51 if test_env.TEST_TARGET_OS == "windows" then
52 assert.truthy(lfs.attributes(tmpdir .. "/c_module.dll"))
53 else
54 assert.truthy(lfs.attributes(tmpdir .. "/c_module.so"))
55 end
56
57 lfs.chdir(olddir)
58 lfs.rmdir(tmpdir)
59 end)
45 end) 60 end)
46 61
47 describe("LuaRocks build - building lpeg with flags", function() 62 describe("LuaRocks build - building lpeg with flags", function()
diff --git a/spec/fixtures/c_module-1.0-1.rockspec b/spec/fixtures/c_module-1.0-1.rockspec
new file mode 100644
index 00000000..2913ecf6
--- /dev/null
+++ b/spec/fixtures/c_module-1.0-1.rockspec
@@ -0,0 +1,11 @@
1package = "c_module"
2version = "1.0-1"
3source = {
4 url = "http://example.com/c_module"
5}
6build = {
7 type = "builtin",
8 modules = {
9 c_module = { "c_module.c" }
10 }
11}
diff --git a/spec/fixtures/c_module.c b/spec/fixtures/c_module.c
new file mode 100644
index 00000000..4c27dda8
--- /dev/null
+++ b/spec/fixtures/c_module.c
@@ -0,0 +1,9 @@
1#include <lua.h>
2#include <lauxlib.h>
3
4int luaopen_c_module(lua_State* L) {
5 lua_newtable(L);
6 lua_pushinteger(L, 1);
7 lua_setfield(L, -2, "c_module");
8 return 1;
9}
diff --git a/spec/fixtures/git_repo/.gitignore b/spec/fixtures/git_repo/.gitignore
new file mode 100644
index 00000000..9e639210
--- /dev/null
+++ b/spec/fixtures/git_repo/.gitignore
@@ -0,0 +1,2 @@
1/.gitignore
2/foo
diff --git a/spec/fixtures/git_repo/LICENSE b/spec/fixtures/git_repo/LICENSE
new file mode 100644
index 00000000..e8c415d1
--- /dev/null
+++ b/spec/fixtures/git_repo/LICENSE
@@ -0,0 +1,19 @@
1Copyright (c) 2018 Test
2
3Permission is hereby granted, free of charge, to any person obtaining a copy
4of this software and associated documentation files (the "Software"), to deal
5in the Software without restriction, including without limitation the rights
6to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7copies of the Software, and to permit persons to whom the Software is
8furnished to do so, subject to the following conditions:
9
10The above copyright notice and this permission notice shall be included in all
11copies or substantial portions of the Software.
12
13THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19SOFTWARE.
diff --git a/spec/fixtures/git_repo/README.md b/spec/fixtures/git_repo/README.md
new file mode 100644
index 00000000..220327e5
--- /dev/null
+++ b/spec/fixtures/git_repo/README.md
@@ -0,0 +1,3 @@
1
2
3Test repo
diff --git a/spec/init_spec.lua b/spec/init_spec.lua
new file mode 100644
index 00000000..2d28bfe7
--- /dev/null
+++ b/spec/init_spec.lua
@@ -0,0 +1,83 @@
1local test_env = require("spec.util.test_env")
2local run = test_env.run
3local testing_paths = test_env.testing_paths
4local get_tmp_path = test_env.get_tmp_path
5local copy_dir = test_env.copy_dir
6local is_win = test_env.TEST_TARGET_OS == "windows"
7
8test_env.unload_luarocks()
9
10describe("Luarocks init test #integration", function()
11 local tmpdir
12
13 after_each(function()
14 if tmpdir then
15 lfs.rmdir(tmpdir)
16 tmpdir = nil
17 end
18 end)
19
20 it("LuaRocks init with no arguments", function()
21 tmpdir = get_tmp_path()
22 lfs.mkdir(tmpdir)
23 local myproject = tmpdir .. "/myproject"
24 lfs.mkdir(myproject)
25 local olddir = lfs.currentdir()
26 lfs.chdir(myproject)
27
28 assert(run.luarocks("init"))
29 if is_win then
30 assert.truthy(lfs.attributes(myproject .. "/lua.bat"))
31 assert.truthy(lfs.attributes(myproject .. "/luarocks.bat"))
32 else
33 assert.truthy(lfs.attributes(myproject .. "/lua"))
34 assert.truthy(lfs.attributes(myproject .. "/luarocks"))
35 end
36 assert.truthy(lfs.attributes(myproject .. "/lua_modules"))
37 assert.truthy(lfs.attributes(myproject .. "/.luarocks"))
38 assert.truthy(lfs.attributes(myproject .. "/.luarocks/config-" .. test_env.lua_version .. ".lua"))
39 assert.truthy(lfs.attributes(myproject .. "/.gitignore"))
40 assert.truthy(lfs.attributes(myproject .. "/myproject-dev-1.rockspec"))
41
42 lfs.chdir(olddir)
43 end)
44
45 it("LuaRocks init with given arguments", function()
46 tmpdir = get_tmp_path()
47 lfs.mkdir(tmpdir)
48 local myproject = tmpdir .. "/myproject"
49 lfs.mkdir(myproject)
50 local olddir = lfs.currentdir()
51 lfs.chdir(myproject)
52
53 assert(run.luarocks("init customname 1.0"))
54 assert.truthy(lfs.attributes(myproject .. "/customname-1.0-1.rockspec"))
55
56 lfs.chdir(olddir)
57 end)
58
59 it("LuaRocks init in a git repo", function()
60 tmpdir = get_tmp_path()
61 lfs.mkdir(tmpdir)
62 local olddir = lfs.currentdir()
63 lfs.chdir(tmpdir)
64 local myproject = tmpdir .. "/myproject"
65 copy_dir(testing_paths.fixtures_dir .. "/git_repo", myproject)
66 lfs.chdir(myproject)
67
68 assert(run.luarocks("init"))
69 local fd = assert(io.open(myproject .. "/myproject-dev-1.rockspec", "r"))
70 local content = assert(fd:read("*a"))
71 assert.truthy(content:find("summary = \"Test repo\""))
72 assert.truthy(content:find("detailed = .+Test repo.+"))
73 assert.truthy(content:find("license = \"MIT\""))
74
75 fd = assert(io.open(myproject .. "/.gitignore", "r"))
76 content = assert(fd:read("*a"))
77 assert.truthy(content:find("/foo"))
78 assert.truthy(content:find("/lua"))
79 assert.truthy(content:find("/lua_modules"))
80
81 lfs.chdir(olddir)
82 end)
83end)
diff --git a/spec/path_spec.lua b/spec/path_spec.lua
index 0b115d5c..3a7dcea2 100644
--- a/spec/path_spec.lua
+++ b/spec/path_spec.lua
@@ -57,4 +57,19 @@ describe("LuaRocks path tests #integration", function()
57 it("LuaRocks path with tree", function() 57 it("LuaRocks path with tree", function()
58 assert.is_true(run.luarocks_bool("path --tree=lua_modules")) 58 assert.is_true(run.luarocks_bool("path --tree=lua_modules"))
59 end) 59 end)
60
61 it("LuaRocks path with project-tree", function()
62 local path1 = "/share/lua/5%." .. test_env.lua_version:sub(3, 3) .. "/%?%.lua"
63 local path2 = "/share/lua/5%." .. test_env.lua_version:sub(3, 3) .. "/%?/init%.lua"
64
65 local path = run.luarocks("path --project-tree=foo")
66 assert.truthy(path:find("foo" .. path1))
67 assert.truthy(path:find("foo" .. path2))
68
69 path = run.luarocks("path --project-tree=foo --tree=bar")
70 assert.falsy(path:find("foo" .. path1))
71 assert.falsy(path:find("foo" .. path2))
72 assert.truthy(path:find("bar" .. path1))
73 assert.truthy(path:find("bar" .. path2))
74 end)
60end) 75end)