diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-29 00:46:06 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-29 15:46:16 +0000 |
commit | f76b7a2b13e411df2e696146bb0a6396781acd92 (patch) | |
tree | 38ed32f81f05f6eacd03f36eacd5341e7b1d17dd | |
parent | 0ca8c460e867356342180bb625760ed9201a5503 (diff) | |
download | luarocks-f76b7a2b13e411df2e696146bb0a6396781acd92.tar.gz luarocks-f76b7a2b13e411df2e696146bb0a6396781acd92.tar.bz2 luarocks-f76b7a2b13e411df2e696146bb0a6396781acd92.zip |
tests: speed up and simplify
-rw-r--r-- | spec/build_spec.lua | 71 | ||||
-rw-r--r-- | spec/config_spec.lua | 2 | ||||
-rw-r--r-- | spec/doc_spec.lua | 5 | ||||
-rw-r--r-- | spec/install_spec.lua | 35 | ||||
-rw-r--r-- | spec/list_spec.lua | 5 | ||||
-rw-r--r-- | spec/make_manifest_spec.lua | 13 | ||||
-rw-r--r-- | spec/make_spec.lua | 42 | ||||
-rw-r--r-- | spec/purge_spec.lua | 32 | ||||
-rw-r--r-- | spec/quick/admin_make_manifest.q | 46 | ||||
-rw-r--r-- | spec/quick/build.q | 103 | ||||
-rw-r--r-- | spec/quick/doc.q | 13 | ||||
-rw-r--r-- | spec/quick/install.q | 60 | ||||
-rw-r--r-- | spec/quick/list.q | 37 | ||||
-rw-r--r-- | spec/quick/make.q | 51 | ||||
-rw-r--r-- | spec/quick/purge.q | 103 | ||||
-rw-r--r-- | spec/unit/dir_spec.lua | 2 | ||||
-rw-r--r-- | spec/unit/fetch_spec.lua | 2 | ||||
-rw-r--r-- | spec/unit/fun_spec.lua | 2 | ||||
-rw-r--r-- | spec/unit/rockspecs_spec.lua | 2 | ||||
-rw-r--r-- | spec/unit/sysdetect_spec.lua | 10 | ||||
-rw-r--r-- | spec/unit/util_spec.lua | 2 | ||||
-rw-r--r-- | spec/util/quick.lua | 46 | ||||
-rw-r--r-- | spec/util/test_env.lua | 87 | ||||
-rw-r--r-- | src/luarocks/cmd.lua | 31 |
24 files changed, 507 insertions, 295 deletions
diff --git a/spec/build_spec.lua b/spec/build_spec.lua index d07447c1..00eac2e1 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua | |||
@@ -154,77 +154,6 @@ describe("LuaRocks build #integration", function() | |||
154 | end, finally) | 154 | end, finally) |
155 | end) | 155 | end) |
156 | 156 | ||
157 | it("supports --pin #pinning", function() | ||
158 | test_env.run_in_tmp(function(tmpdir) | ||
159 | write_file("test-1.0-1.rockspec", [[ | ||
160 | package = "test" | ||
161 | version = "1.0-1" | ||
162 | source = { | ||
163 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
164 | } | ||
165 | dependencies = { | ||
166 | "a_rock >= 0.8" | ||
167 | } | ||
168 | build = { | ||
169 | type = "builtin", | ||
170 | modules = { | ||
171 | test = "test.lua" | ||
172 | } | ||
173 | } | ||
174 | ]]) | ||
175 | write_file("test.lua", "return {}") | ||
176 | |||
177 | assert.is_true(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --pin --tree=lua_modules")) | ||
178 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) | ||
179 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/2.0-1/a_rock-2.0-1.rockspec")) | ||
180 | local lockfilename = "./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/luarocks.lock" | ||
181 | assert.is.truthy(lfs.attributes(lockfilename)) | ||
182 | local lockdata = loadfile(lockfilename)() | ||
183 | assert.same({ | ||
184 | dependencies = { | ||
185 | ["a_rock"] = "2.0-1", | ||
186 | ["lua"] = test_env.lua_version .. "-1", | ||
187 | } | ||
188 | }, lockdata) | ||
189 | end, finally) | ||
190 | end) | ||
191 | |||
192 | it("supports --pin --only-deps #pinning", function() | ||
193 | test_env.run_in_tmp(function(tmpdir) | ||
194 | write_file("test-1.0-1.rockspec", [[ | ||
195 | package = "test" | ||
196 | version = "1.0-1" | ||
197 | source = { | ||
198 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
199 | } | ||
200 | dependencies = { | ||
201 | "a_rock >= 0.8" | ||
202 | } | ||
203 | build = { | ||
204 | type = "builtin", | ||
205 | modules = { | ||
206 | test = "test.lua" | ||
207 | } | ||
208 | } | ||
209 | ]]) | ||
210 | write_file("test.lua", "return {}") | ||
211 | |||
212 | assert.is_true(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --pin --only-deps --tree=lua_modules")) | ||
213 | assert.is.falsy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) | ||
214 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/2.0-1/a_rock-2.0-1.rockspec")) | ||
215 | assert.is.truthy(lfs.attributes("./luarocks.lock")) | ||
216 | local lockfilename = "./luarocks.lock" | ||
217 | assert.is.truthy(lfs.attributes(lockfilename)) | ||
218 | local lockdata = loadfile(lockfilename)() | ||
219 | assert.same({ | ||
220 | dependencies = { | ||
221 | ["a_rock"] = "2.0-1", | ||
222 | ["lua"] = test_env.lua_version .. "-1", | ||
223 | } | ||
224 | }, lockdata) | ||
225 | end, finally) | ||
226 | end) | ||
227 | |||
228 | it("lmathx deps partial match", function() | 157 | it("lmathx deps partial match", function() |
229 | if test_env.LUA_V == "5.1" or test_env.LUAJIT_V then | 158 | if test_env.LUA_V == "5.1" or test_env.LUAJIT_V then |
230 | assert.is_true(run.luarocks_bool("build lmathx")) | 159 | assert.is_true(run.luarocks_bool("build lmathx")) |
diff --git a/spec/config_spec.lua b/spec/config_spec.lua index 6bfac433..9dd8fbcb 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua | |||
@@ -142,7 +142,7 @@ describe("LuaRocks config tests #integration", function() | |||
142 | 142 | ||
143 | it("can read as JSON", function() | 143 | it("can read as JSON", function() |
144 | local output = run.luarocks("config rocks_trees --json") | 144 | local output = run.luarocks("config rocks_trees --json") |
145 | assert.match('^%["', output) | 145 | assert.match('^%[{', output) |
146 | end) | 146 | end) |
147 | 147 | ||
148 | it("reads an array -> hash config key", function() | 148 | it("reads an array -> hash config key", function() |
diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua index 062b36e7..f48f951a 100644 --- a/spec/doc_spec.lua +++ b/spec/doc_spec.lua | |||
@@ -126,11 +126,6 @@ describe("luarocks doc #integration", function() | |||
126 | end, finally) | 126 | end, finally) |
127 | end) | 127 | end) |
128 | 128 | ||
129 | it("with --local", function() | ||
130 | assert.is_true(run.luarocks_bool("install --local --server=" .. testing_paths.fixtures_dir .. "/a_repo a_rock")) | ||
131 | assert.is_true(run.luarocks_bool("doc --server=" .. testing_paths.fixtures_dir .. "/a_repo a_rock --local")) | ||
132 | end) | ||
133 | |||
134 | it("with --porcelain", function() | 129 | it("with --porcelain", function() |
135 | test_env.run_in_tmp(function(tmpdir) | 130 | test_env.run_in_tmp(function(tmpdir) |
136 | test_env.write_file("test-1.0-1.rockspec", [[ | 131 | test_env.write_file("test-1.0-1.rockspec", [[ |
diff --git a/spec/install_spec.lua b/spec/install_spec.lua index b4b064f0..66000c36 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua | |||
@@ -142,41 +142,6 @@ describe("luarocks install #integration", function() | |||
142 | assert.is_true(os.remove("luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) | 142 | assert.is_true(os.remove("luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) |
143 | end) | 143 | end) |
144 | 144 | ||
145 | it("installation rolls back on failure", function() | ||
146 | if test_env.TYPE_TEST_ENV ~= "full" then | ||
147 | assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket ${LUASOCKET}")) | ||
148 | local luadir = testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION | ||
149 | lfs.mkdir(luadir) | ||
150 | |||
151 | run.luarocks_bool("remove " .. "luasocket") | ||
152 | |||
153 | -- create a file where a folder should be | ||
154 | local fd = io.open(luadir .. "/socket", "w") | ||
155 | fd:write("\n") | ||
156 | fd:close() | ||
157 | |||
158 | -- try to install and fail | ||
159 | assert.is_false(run.luarocks_bool("install " .. "luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) | ||
160 | |||
161 | -- file is still there | ||
162 | assert.is.truthy(lfs.attributes(luadir .. "/socket")) | ||
163 | -- no left overs from failed installation | ||
164 | assert.is.falsy(lfs.attributes(luadir .. "/mime.lua")) | ||
165 | |||
166 | -- remove file | ||
167 | assert.is_true(os.remove(luadir .. "/socket")) | ||
168 | |||
169 | -- try again and succeed | ||
170 | assert.is_true(run.luarocks_bool("install " .. "luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) | ||
171 | |||
172 | -- files installed successfully | ||
173 | assert.is.truthy(lfs.attributes(luadir .. "/socket/ftp.lua")) | ||
174 | assert.is.truthy(lfs.attributes(luadir .. "/mime.lua")) | ||
175 | |||
176 | assert.is_true(os.remove("luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) | ||
177 | end | ||
178 | end) | ||
179 | |||
180 | it("binary rock of cprint", function() | 145 | it("binary rock of cprint", function() |
181 | assert.is_true(run.luarocks_bool("build --pack-binary-rock cprint")) | 146 | assert.is_true(run.luarocks_bool("build --pack-binary-rock cprint")) |
182 | assert.is_true(run.luarocks_bool("install cprint-${CPRINT}." .. test_env.platform .. ".rock")) | 147 | assert.is_true(run.luarocks_bool("install cprint-${CPRINT}." .. test_env.platform .. ".rock")) |
diff --git a/spec/list_spec.lua b/spec/list_spec.lua index eeeb79d2..08d85879 100644 --- a/spec/list_spec.lua +++ b/spec/list_spec.lua | |||
@@ -19,11 +19,6 @@ describe("luarocks list #integration", function() | |||
19 | assert.match("luacov", output) | 19 | assert.match("luacov", output) |
20 | end) | 20 | end) |
21 | 21 | ||
22 | it("--porcelain", function() | ||
23 | local output = run.luarocks("list --porcelain") | ||
24 | assert.is.truthy(output:find(V"luacov\t${LUACOV}\tinstalled\t" .. testing_paths.testing_sys_rocks, 1, true)) | ||
25 | end) | ||
26 | |||
27 | it("shows version number", function() | 22 | it("shows version number", function() |
28 | local output = run.luarocks("list") | 23 | local output = run.luarocks("list") |
29 | assert.is.truthy(output:find("luacov")) | 24 | assert.is.truthy(output:find("luacov")) |
diff --git a/spec/make_manifest_spec.lua b/spec/make_manifest_spec.lua deleted file mode 100644 index 146b6178..00000000 --- a/spec/make_manifest_spec.lua +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | local test_env = require("spec.util.test_env") | ||
2 | local run = test_env.run | ||
3 | |||
4 | describe("luarocks make_manifest #integration", function() | ||
5 | |||
6 | before_each(function() | ||
7 | test_env.setup_specs() | ||
8 | end) | ||
9 | |||
10 | it("runs", function() | ||
11 | assert.is_true(run.luarocks_admin_bool("make_manifest")) | ||
12 | end) | ||
13 | end) | ||
diff --git a/spec/make_spec.lua b/spec/make_spec.lua index 6cce0543..b0572630 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua | |||
@@ -213,48 +213,6 @@ describe("luarocks make #integration", function() | |||
213 | end, finally) | 213 | end, finally) |
214 | end) | 214 | end) |
215 | 215 | ||
216 | it("overrides luarocks.lock with --pin #pinning", function() | ||
217 | test_env.run_in_tmp(function(tmpdir) | ||
218 | write_file("test-2.0-1.rockspec", [[ | ||
219 | package = "test" | ||
220 | version = "2.0-1" | ||
221 | source = { | ||
222 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
223 | } | ||
224 | dependencies = { | ||
225 | "a_rock >= 0.8" | ||
226 | } | ||
227 | build = { | ||
228 | type = "builtin", | ||
229 | modules = { | ||
230 | test = "test.lua" | ||
231 | } | ||
232 | } | ||
233 | ]]) | ||
234 | write_file("test.lua", "return {}") | ||
235 | write_file("luarocks.lock", [[ | ||
236 | return { | ||
237 | dependencies = { | ||
238 | ["a_rock"] = "1.0-1", | ||
239 | } | ||
240 | } | ||
241 | ]]) | ||
242 | |||
243 | print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=lua_modules --pin")) | ||
244 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/2.0-1/test-2.0-1.rockspec")) | ||
245 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/2.0-1/a_rock-2.0-1.rockspec")) | ||
246 | local lockfilename = "./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/2.0-1/luarocks.lock" | ||
247 | assert.is.truthy(lfs.attributes(lockfilename)) | ||
248 | local lockdata = loadfile(lockfilename)() | ||
249 | assert.same({ | ||
250 | dependencies = { | ||
251 | ["a_rock"] = "2.0-1", | ||
252 | ["lua"] = test_env.lua_version .. "-1", | ||
253 | } | ||
254 | }, lockdata) | ||
255 | end, finally) | ||
256 | end) | ||
257 | |||
258 | describe("#ddt upgrading rockspecs with double deploy types", function() | 216 | describe("#ddt upgrading rockspecs with double deploy types", function() |
259 | local deploy_lib_dir = testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION | 217 | local deploy_lib_dir = testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION |
260 | local deploy_lua_dir = testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION | 218 | local deploy_lua_dir = testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION |
diff --git a/spec/purge_spec.lua b/spec/purge_spec.lua deleted file mode 100644 index 7fdb74f4..00000000 --- a/spec/purge_spec.lua +++ /dev/null | |||
@@ -1,32 +0,0 @@ | |||
1 | local test_env = require("spec.util.test_env") | ||
2 | local run = test_env.run | ||
3 | local testing_paths = test_env.testing_paths | ||
4 | |||
5 | local extra_rocks = { | ||
6 | "/say-1.0-1.src.rock", | ||
7 | } | ||
8 | |||
9 | describe("luarocks purge #integration", function() | ||
10 | before_each(function() | ||
11 | test_env.setup_specs(extra_rocks) | ||
12 | end) | ||
13 | |||
14 | it("missing tree", function() | ||
15 | assert.is_false(run.luarocks_bool("purge --tree=" .. testing_paths.testing_tree)) | ||
16 | end) | ||
17 | it("tree with no string", function() | ||
18 | assert.is_false(run.luarocks_bool("purge --tree=")) | ||
19 | end) | ||
20 | it("tree with no string", function() | ||
21 | assert.is_true(run.luarocks_bool("purge --tree=" .. testing_paths.testing_sys_tree)) | ||
22 | end) | ||
23 | it("tree missing files", function() | ||
24 | assert.is_true(run.luarocks_bool("install say 1.0")) | ||
25 | test_env.remove_dir(testing_paths.testing_sys_tree .. "/share/lua/"..test_env.lua_version.."/say") | ||
26 | assert.is_true(run.luarocks_bool("purge --tree=" .. testing_paths.testing_sys_tree)) | ||
27 | assert.is_false(test_env.exists(testing_paths.testing_sys_rocks .. "/say")) | ||
28 | end) | ||
29 | it("old versions tree", function() | ||
30 | assert.is_true(run.luarocks_bool("purge --old-versions --tree=" .. testing_paths.testing_sys_tree)) | ||
31 | end) | ||
32 | end) | ||
diff --git a/spec/quick/admin_make_manifest.q b/spec/quick/admin_make_manifest.q new file mode 100644 index 00000000..da203a05 --- /dev/null +++ b/spec/quick/admin_make_manifest.q | |||
@@ -0,0 +1,46 @@ | |||
1 | SUITE: luarocks-admin make_manifest | ||
2 | |||
3 | ================================================================================ | ||
4 | TEST: runs | ||
5 | |||
6 | FILE: test-1.0-1.rockspec | ||
7 | -------------------------------------------------------------------------------- | ||
8 | package = "test" | ||
9 | version = "1.0-1" | ||
10 | source = { | ||
11 | url = "file://%{url(tmpdir)}/test.lua" | ||
12 | } | ||
13 | build = { | ||
14 | type = "builtin", | ||
15 | modules = { | ||
16 | test = "test.lua" | ||
17 | } | ||
18 | } | ||
19 | -------------------------------------------------------------------------------- | ||
20 | |||
21 | FILE: test.lua | ||
22 | -------------------------------------------------------------------------------- | ||
23 | return {} | ||
24 | -------------------------------------------------------------------------------- | ||
25 | |||
26 | RUN: luarocks make --pack-binary-rock ./test-1.0-1.rockspec | ||
27 | |||
28 | RUN: luarocks-admin make_manifest . | ||
29 | |||
30 | FILE_CONTENTS: ./manifest-%{lua_version} | ||
31 | -------------------------------------------------------------------------------- | ||
32 | commands = {} | ||
33 | modules = {} | ||
34 | repository = { | ||
35 | test = { | ||
36 | ["1.0-1"] = { | ||
37 | { | ||
38 | arch = "all" | ||
39 | }, | ||
40 | { | ||
41 | arch = "rockspec" | ||
42 | } | ||
43 | } | ||
44 | } | ||
45 | } | ||
46 | -------------------------------------------------------------------------------- | ||
diff --git a/spec/quick/build.q b/spec/quick/build.q index a1731da2..ee519adf 100644 --- a/spec/quick/build.q +++ b/spec/quick/build.q | |||
@@ -1,4 +1,7 @@ | |||
1 | TEST: luarocks build: fails when given invalid argument | 1 | SUITE: luarocks build |
2 | |||
3 | ================================================================================ | ||
4 | TEST: fails when given invalid argument | ||
2 | RUN: luarocks build aoesuthaoeusahtoeustnaou --only-server=localhost | 5 | RUN: luarocks build aoesuthaoeusahtoeustnaou --only-server=localhost |
3 | EXIT: 1 | 6 | EXIT: 1 |
4 | STDERR: | 7 | STDERR: |
@@ -9,7 +12,7 @@ Could not find a result named aoesuthaoeusahtoeustnaou | |||
9 | 12 | ||
10 | 13 | ||
11 | ================================================================================ | 14 | ================================================================================ |
12 | TEST: luarocks build: with no arguments behaves as luarocks make | 15 | TEST: with no arguments behaves as luarocks make |
13 | 16 | ||
14 | FILE: c_module-1.0-1.rockspec | 17 | FILE: c_module-1.0-1.rockspec |
15 | -------------------------------------------------------------------------------- | 18 | -------------------------------------------------------------------------------- |
@@ -43,7 +46,7 @@ EXISTS: c_module.%{lib_extension} | |||
43 | 46 | ||
44 | 47 | ||
45 | ================================================================================ | 48 | ================================================================================ |
46 | TEST: luarocks build: defaults to builtin type | 49 | TEST: defaults to builtin type |
47 | 50 | ||
48 | FILE: a_rock-1.0-1.rockspec | 51 | FILE: a_rock-1.0-1.rockspec |
49 | -------------------------------------------------------------------------------- | 52 | -------------------------------------------------------------------------------- |
@@ -74,7 +77,7 @@ a_rock 1.0 | |||
74 | 77 | ||
75 | 78 | ||
76 | ================================================================================ | 79 | ================================================================================ |
77 | TEST: luarocks build: fails if no permissions to access the specified tree #unix | 80 | TEST: fails if no permissions to access the specified tree #unix |
78 | 81 | ||
79 | RUN: luarocks build --tree=/usr ./a_rock-1.0.1-rockspec | 82 | RUN: luarocks build --tree=/usr ./a_rock-1.0.1-rockspec |
80 | EXIT: 4 | 83 | EXIT: 4 |
@@ -99,7 +102,7 @@ NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec | |||
99 | 102 | ||
100 | 103 | ||
101 | ================================================================================ | 104 | ================================================================================ |
102 | TEST: luarocks build: fails if no permissions to access the parent #unix | 105 | TEST: fails if no permissions to access the parent #unix |
103 | 106 | ||
104 | RUN: luarocks build --tree=/usr/invalid ./a_rock-1.0.1-rockspec | 107 | RUN: luarocks build --tree=/usr/invalid ./a_rock-1.0.1-rockspec |
105 | EXIT: 4 | 108 | EXIT: 4 |
@@ -160,3 +163,93 @@ STDOUT: | |||
160 | a_rock 1.0-1 is already installed | 163 | a_rock 1.0-1 is already installed |
161 | Use --force to reinstall | 164 | Use --force to reinstall |
162 | -------------------------------------------------------------------------------- | 165 | -------------------------------------------------------------------------------- |
166 | |||
167 | |||
168 | |||
169 | ================================================================================ | ||
170 | TEST: supports --pin #pinning | ||
171 | |||
172 | FILE: test-1.0-1.rockspec | ||
173 | -------------------------------------------------------------------------------- | ||
174 | package = "test" | ||
175 | version = "1.0-1" | ||
176 | source = { | ||
177 | url = "file://%{url(tmpdir)}/test.lua" | ||
178 | } | ||
179 | dependencies = { | ||
180 | "a_rock >= 0.8" | ||
181 | } | ||
182 | build = { | ||
183 | type = "builtin", | ||
184 | modules = { | ||
185 | test = "test.lua" | ||
186 | } | ||
187 | } | ||
188 | -------------------------------------------------------------------------------- | ||
189 | |||
190 | FILE: test.lua | ||
191 | -------------------------------------------------------------------------------- | ||
192 | return {} | ||
193 | -------------------------------------------------------------------------------- | ||
194 | |||
195 | RUN: luarocks build --only-server=%{fixtures_dir}/a_repo test-1.0-1.rockspec --pin --tree=lua_modules | ||
196 | |||
197 | EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/test/1.0-1/test-1.0-1.rockspec | ||
198 | EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/a_rock/2.0-1/a_rock-2.0-1.rockspec | ||
199 | |||
200 | EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/test/1.0-1/luarocks.lock | ||
201 | |||
202 | FILE_CONTENTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/test/1.0-1/luarocks.lock | ||
203 | -------------------------------------------------------------------------------- | ||
204 | return { | ||
205 | dependencies = { | ||
206 | a_rock = "2.0-1", | ||
207 | lua = "%{lua_version}-1" | ||
208 | } | ||
209 | } | ||
210 | -------------------------------------------------------------------------------- | ||
211 | |||
212 | |||
213 | |||
214 | ================================================================================ | ||
215 | TEST: supports --pin --only-deps #pinning | ||
216 | |||
217 | FILE: test-1.0-1.rockspec | ||
218 | -------------------------------------------------------------------------------- | ||
219 | package = "test" | ||
220 | version = "1.0-1" | ||
221 | source = { | ||
222 | url = "file://%{url(tmpdir)}/test.lua" | ||
223 | } | ||
224 | dependencies = { | ||
225 | "a_rock >= 0.8" | ||
226 | } | ||
227 | build = { | ||
228 | type = "builtin", | ||
229 | modules = { | ||
230 | test = "test.lua" | ||
231 | } | ||
232 | } | ||
233 | -------------------------------------------------------------------------------- | ||
234 | |||
235 | FILE: test.lua | ||
236 | -------------------------------------------------------------------------------- | ||
237 | return {} | ||
238 | -------------------------------------------------------------------------------- | ||
239 | |||
240 | RUN: luarocks build --only-server=%{fixtures_dir}/a_repo test-1.0-1.rockspec --pin --only-deps --tree=lua_modules | ||
241 | |||
242 | NOT_EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/test/1.0-1/test-1.0-1.rockspec | ||
243 | EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/a_rock/2.0-1/a_rock-2.0-1.rockspec | ||
244 | |||
245 | EXISTS: ./luarocks.lock | ||
246 | |||
247 | FILE_CONTENTS: ./luarocks.lock | ||
248 | -------------------------------------------------------------------------------- | ||
249 | return { | ||
250 | dependencies = { | ||
251 | a_rock = "2.0-1", | ||
252 | lua = "%{lua_version}-1" | ||
253 | } | ||
254 | } | ||
255 | -------------------------------------------------------------------------------- | ||
diff --git a/spec/quick/doc.q b/spec/quick/doc.q new file mode 100644 index 00000000..4c71f838 --- /dev/null +++ b/spec/quick/doc.q | |||
@@ -0,0 +1,13 @@ | |||
1 | SUITE: luarocks doc | ||
2 | |||
3 | ================================================================================ | ||
4 | TEST: --local | ||
5 | |||
6 | RUN: luarocks install --local --only-server=%{fixtures_dir}/a_repo a_rock | ||
7 | |||
8 | RUN: luarocks doc a_rock --local | ||
9 | |||
10 | STDOUT: | ||
11 | -------------------------------------------------------------------------------- | ||
12 | opening http://www.example.com | ||
13 | -------------------------------------------------------------------------------- | ||
diff --git a/spec/quick/install.q b/spec/quick/install.q index 503aaacc..72795504 100644 --- a/spec/quick/install.q +++ b/spec/quick/install.q | |||
@@ -415,3 +415,63 @@ STDOUT: | |||
415 | myrock 1.0-1 is already installed | 415 | myrock 1.0-1 is already installed |
416 | Use --force to reinstall | 416 | Use --force to reinstall |
417 | -------------------------------------------------------------------------------- | 417 | -------------------------------------------------------------------------------- |
418 | |||
419 | |||
420 | |||
421 | ================================================================================ | ||
422 | TEST: installation rolls back on failure | ||
423 | |||
424 | FILE: myrock-1.0-1.rockspec | ||
425 | -------------------------------------------------------------------------------- | ||
426 | rockspec_format = "3.0" | ||
427 | package = "myrock" | ||
428 | version = "1.0-1" | ||
429 | source = { | ||
430 | url = "file://%{url(tmpdir)}/rock.lua" | ||
431 | } | ||
432 | build = { | ||
433 | modules = { | ||
434 | ["folder.rock"] = "rock.lua", | ||
435 | ["xyz"] = "xyz.lua", | ||
436 | }, | ||
437 | } | ||
438 | -------------------------------------------------------------------------------- | ||
439 | |||
440 | FILE: rock.lua | ||
441 | -------------------------------------------------------------------------------- | ||
442 | return {} | ||
443 | -------------------------------------------------------------------------------- | ||
444 | |||
445 | FILE: xyz.lua | ||
446 | -------------------------------------------------------------------------------- | ||
447 | return {} | ||
448 | -------------------------------------------------------------------------------- | ||
449 | |||
450 | RUN: luarocks make --pack-binary-rock ./myrock-1.0-1.rockspec | ||
451 | |||
452 | FILE: %{testing_sys_tree}/share/lua/%{lua_version}/folder | ||
453 | -------------------------------------------------------------------------------- | ||
454 | a file where a folder should be | ||
455 | -------------------------------------------------------------------------------- | ||
456 | |||
457 | Try to install and fail because the file is in the folder's spot: | ||
458 | |||
459 | RUN: luarocks install ./myrock-1.0-1.all.rock | ||
460 | EXIT: 1 | ||
461 | |||
462 | EXISTS: %{testing_sys_tree}/share/lua/%{lua_version}/folder | ||
463 | |||
464 | No leftovers from the failed installation: | ||
465 | |||
466 | NOT_EXISTS: %{testing_sys_tree}/share/lua/%{lua_version}/xyz.lua | ||
467 | |||
468 | Now we remove the file... | ||
469 | |||
470 | RM: %{testing_sys_tree}/share/lua/%{lua_version}/folder | ||
471 | |||
472 | Try again and succeed: | ||
473 | |||
474 | RUN: luarocks install ./myrock-1.0-1.all.rock | ||
475 | |||
476 | EXISTS: %{testing_sys_tree}/share/lua/%{lua_version}/folder/rock.lua | ||
477 | EXISTS: %{testing_sys_tree}/share/lua/%{lua_version}/xyz.lua | ||
diff --git a/spec/quick/list.q b/spec/quick/list.q index fbb3f557..a40f37ef 100644 --- a/spec/quick/list.q +++ b/spec/quick/list.q | |||
@@ -1,5 +1,7 @@ | |||
1 | SUITE: luarocks list | ||
2 | |||
1 | ================================================================================ | 3 | ================================================================================ |
2 | TEST: luarocks list: invalid tree | 4 | TEST: invalid tree |
3 | 5 | ||
4 | RUN: luarocks --tree=%{path(/some/invalid/tree)} list | 6 | RUN: luarocks --tree=%{path(/some/invalid/tree)} list |
5 | 7 | ||
@@ -8,3 +10,36 @@ STDOUT: | |||
8 | Rocks installed for Lua %{lua_version} in %{path(/some/invalid/tree)} | 10 | Rocks installed for Lua %{lua_version} in %{path(/some/invalid/tree)} |
9 | -------------------------------------------------------------------------------- | 11 | -------------------------------------------------------------------------------- |
10 | 12 | ||
13 | |||
14 | |||
15 | ================================================================================ | ||
16 | TEST: --porcelain | ||
17 | |||
18 | FILE: a_rock-1.0-1.rockspec | ||
19 | -------------------------------------------------------------------------------- | ||
20 | rockspec_format = "3.0" | ||
21 | package = "a_rock" | ||
22 | version = "1.0-1" | ||
23 | source = { | ||
24 | url = "file://%{url(%{fixtures_dir})}/a_rock.lua" | ||
25 | } | ||
26 | description = { | ||
27 | summary = "An example rockspec", | ||
28 | } | ||
29 | dependencies = { | ||
30 | "lua >= 5.1" | ||
31 | } | ||
32 | build = { | ||
33 | modules = { | ||
34 | build = "a_rock.lua" | ||
35 | }, | ||
36 | } | ||
37 | -------------------------------------------------------------------------------- | ||
38 | RUN: luarocks build a_rock-1.0-1.rockspec | ||
39 | |||
40 | RUN: luarocks list --porcelain | ||
41 | |||
42 | STDOUT: | ||
43 | -------------------------------------------------------------------------------- | ||
44 | a_rock 1.0-1 installed %{testing_sys_rocks} | ||
45 | -------------------------------------------------------------------------------- | ||
diff --git a/spec/quick/make.q b/spec/quick/make.q new file mode 100644 index 00000000..c77bb499 --- /dev/null +++ b/spec/quick/make.q | |||
@@ -0,0 +1,51 @@ | |||
1 | SUITE: luarocks make | ||
2 | |||
3 | ================================================================================ | ||
4 | TEST: overrides luarocks.lock with --pin #pinning | ||
5 | |||
6 | FILE: test-2.0-1.rockspec | ||
7 | -------------------------------------------------------------------------------- | ||
8 | package = "test" | ||
9 | version = "2.0-1" | ||
10 | source = { | ||
11 | url = "file://%{path(tmpdir)}/test.lua" | ||
12 | } | ||
13 | dependencies = { | ||
14 | "a_rock >= 0.8" | ||
15 | } | ||
16 | build = { | ||
17 | type = "builtin", | ||
18 | modules = { | ||
19 | test = "test.lua" | ||
20 | } | ||
21 | } | ||
22 | -------------------------------------------------------------------------------- | ||
23 | |||
24 | FILE: test.lua | ||
25 | -------------------------------------------------------------------------------- | ||
26 | return {} | ||
27 | -------------------------------------------------------------------------------- | ||
28 | |||
29 | FILE: luarocks.lock | ||
30 | -------------------------------------------------------------------------------- | ||
31 | return { | ||
32 | dependencies = { | ||
33 | ["a_rock"] = "1.0-1", | ||
34 | } | ||
35 | } | ||
36 | -------------------------------------------------------------------------------- | ||
37 | |||
38 | RUN: luarocks make --only-server=%{fixtures_dir}/a_repo --pin --tree=lua_modules | ||
39 | |||
40 | EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/test/2.0-1/test-2.0-1.rockspec | ||
41 | EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/a_rock/2.0-1/a_rock-2.0-1.rockspec | ||
42 | |||
43 | FILE_CONTENTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/test/2.0-1/luarocks.lock | ||
44 | -------------------------------------------------------------------------------- | ||
45 | return { | ||
46 | dependencies = { | ||
47 | a_rock = "2.0-1", | ||
48 | lua = "%{lua_version}-1" | ||
49 | } | ||
50 | } | ||
51 | -------------------------------------------------------------------------------- | ||
diff --git a/spec/quick/purge.q b/spec/quick/purge.q new file mode 100644 index 00000000..a3f24b99 --- /dev/null +++ b/spec/quick/purge.q | |||
@@ -0,0 +1,103 @@ | |||
1 | SUITE: luarocks purge | ||
2 | |||
3 | ================================================================================ | ||
4 | TEST: needs a --tree argument | ||
5 | RUN: luarocks purge | ||
6 | EXIT: 1 | ||
7 | |||
8 | ================================================================================ | ||
9 | TEST: missing tree | ||
10 | RUN: luarocks purge --tree=missing-tree | ||
11 | EXIT: 1 | ||
12 | |||
13 | ================================================================================ | ||
14 | TEST: missing --tree argument | ||
15 | RUN: luarocks purge --tree= | ||
16 | EXIT: 1 | ||
17 | |||
18 | |||
19 | ================================================================================ | ||
20 | TEST: runs | ||
21 | |||
22 | FILE: testrock-1.0-1.rockspec | ||
23 | -------------------------------------------------------------------------------- | ||
24 | package = "testrock" | ||
25 | version = "1.0-1" | ||
26 | source = { | ||
27 | url = "file://%{url(tmpdir)}/testrock.lua" | ||
28 | } | ||
29 | dependencies = { | ||
30 | "a_rock >= 0.8" | ||
31 | } | ||
32 | build = { | ||
33 | type = "builtin", | ||
34 | modules = { | ||
35 | testrock = "testrock.lua" | ||
36 | } | ||
37 | } | ||
38 | -------------------------------------------------------------------------------- | ||
39 | |||
40 | FILE: testrock.lua | ||
41 | -------------------------------------------------------------------------------- | ||
42 | return {} | ||
43 | -------------------------------------------------------------------------------- | ||
44 | |||
45 | RUN: luarocks build --only-server=%{fixtures_dir}/a_repo testrock-1.0-1.rockspec | ||
46 | |||
47 | EXISTS: %{testing_sys_rocks}/testrock | ||
48 | EXISTS: %{testing_sys_rocks}/a_rock | ||
49 | |||
50 | RUN: luarocks purge --tree=%{testing_sys_tree} | ||
51 | |||
52 | NOT_EXISTS: %{testing_sys_rocks}/testrock | ||
53 | NOT_EXISTS: %{testing_sys_rocks}/a_rock | ||
54 | |||
55 | |||
56 | |||
57 | ================================================================================ | ||
58 | TEST: works with missing files | ||
59 | |||
60 | FILE: testrock-1.0-1.rockspec | ||
61 | -------------------------------------------------------------------------------- | ||
62 | package = "testrock" | ||
63 | version = "1.0-1" | ||
64 | source = { | ||
65 | url = "file://%{url(tmpdir)}/testrock.lua" | ||
66 | } | ||
67 | dependencies = { | ||
68 | "a_rock >= 0.8" | ||
69 | } | ||
70 | build = { | ||
71 | type = "builtin", | ||
72 | modules = { | ||
73 | testrock = "testrock.lua" | ||
74 | } | ||
75 | } | ||
76 | -------------------------------------------------------------------------------- | ||
77 | |||
78 | FILE: testrock.lua | ||
79 | -------------------------------------------------------------------------------- | ||
80 | return {} | ||
81 | -------------------------------------------------------------------------------- | ||
82 | |||
83 | RUN: luarocks build --only-server=%{fixtures_dir}/a_repo testrock-1.0-1.rockspec | ||
84 | |||
85 | RMDIR: %{testing_sys_tree}/share/lua/%{lua_version}/testrock | ||
86 | |||
87 | RUN: luarocks purge --tree=%{testing_sys_tree} | ||
88 | |||
89 | NOT_EXISTS: %{testing_sys_rocks}/testrock | ||
90 | NOT_EXISTS: %{testing_sys_rocks}/a_rock | ||
91 | |||
92 | |||
93 | |||
94 | ================================================================================ | ||
95 | TEST: --old-versions | ||
96 | |||
97 | RUN: luarocks install --only-server=%{fixtures_dir}/a_repo a_rock 2.0 | ||
98 | RUN: luarocks install --only-server=%{fixtures_dir}/a_repo a_rock 1.0 --keep | ||
99 | |||
100 | RUN: luarocks purge --old-versions --tree=%{testing_sys_tree} | ||
101 | |||
102 | EXISTS: %{testing_sys_rocks}/a_rock/2.0-1 | ||
103 | NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1 | ||
diff --git a/spec/unit/dir_spec.lua b/spec/unit/dir_spec.lua index da5d6389..55dd6e0e 100644 --- a/spec/unit/dir_spec.lua +++ b/spec/unit/dir_spec.lua | |||
@@ -8,7 +8,7 @@ local dir = require("luarocks.dir") | |||
8 | describe("luarocks.dir #unit", function() | 8 | describe("luarocks.dir #unit", function() |
9 | local runner | 9 | local runner |
10 | 10 | ||
11 | setup(function() | 11 | lazy_setup(function() |
12 | runner = require("luacov.runner") | 12 | runner = require("luacov.runner") |
13 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | 13 | runner.init(testing_paths.testrun_dir .. "/luacov.config") |
14 | end) | 14 | end) |
diff --git a/spec/unit/fetch_spec.lua b/spec/unit/fetch_spec.lua index 4fc01d80..bea50d78 100644 --- a/spec/unit/fetch_spec.lua +++ b/spec/unit/fetch_spec.lua | |||
@@ -20,7 +20,7 @@ describe("luarocks fetch #unit", function() | |||
20 | 20 | ||
21 | local runner | 21 | local runner |
22 | 22 | ||
23 | setup(function() | 23 | lazy_setup(function() |
24 | cfg.init() | 24 | cfg.init() |
25 | fs.init() | 25 | fs.init() |
26 | 26 | ||
diff --git a/spec/unit/fun_spec.lua b/spec/unit/fun_spec.lua index d7db1362..bffb60d7 100644 --- a/spec/unit/fun_spec.lua +++ b/spec/unit/fun_spec.lua | |||
@@ -6,7 +6,7 @@ local fun = require("luarocks.fun") | |||
6 | describe("luarocks.fun #unit", function() | 6 | describe("luarocks.fun #unit", function() |
7 | local runner | 7 | local runner |
8 | 8 | ||
9 | setup(function() | 9 | lazy_setup(function() |
10 | runner = require("luacov.runner") | 10 | runner = require("luacov.runner") |
11 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | 11 | runner.init(testing_paths.testrun_dir .. "/luacov.config") |
12 | end) | 12 | end) |
diff --git a/spec/unit/rockspecs_spec.lua b/spec/unit/rockspecs_spec.lua index 5b0573fe..7eb033c8 100644 --- a/spec/unit/rockspecs_spec.lua +++ b/spec/unit/rockspecs_spec.lua | |||
@@ -6,7 +6,7 @@ local lfs = require("lfs") | |||
6 | 6 | ||
7 | describe("luarocks.rockspecs #unit", function() | 7 | describe("luarocks.rockspecs #unit", function() |
8 | 8 | ||
9 | setup(function() | 9 | lazy_setup(function() |
10 | cfg.init() | 10 | cfg.init() |
11 | end) | 11 | end) |
12 | 12 | ||
diff --git a/spec/unit/sysdetect_spec.lua b/spec/unit/sysdetect_spec.lua index 6ec6f6b6..d3b16955 100644 --- a/spec/unit/sysdetect_spec.lua +++ b/spec/unit/sysdetect_spec.lua | |||
@@ -4,9 +4,13 @@ local lfs = require("lfs") | |||
4 | 4 | ||
5 | describe("luarocks.core.sysdetect #unix #unit", function() | 5 | describe("luarocks.core.sysdetect #unix #unit", function() |
6 | 6 | ||
7 | setup(function() | 7 | lazy_setup(function() |
8 | os.execute("[ -e binary-samples ] || git clone --depth=1 https://github.com/hishamhm/binary-samples") | 8 | os.execute([=[ |
9 | os.execute("cd binary-samples && git pull") | 9 | [ -e binary-samples ] || { |
10 | git clone --depth=1 https://github.com/hishamhm/binary-samples | ||
11 | ( cd binary-samples && git pull ) | ||
12 | } | ||
13 | ]=]) | ||
10 | end) | 14 | end) |
11 | 15 | ||
12 | local files = { | 16 | local files = { |
diff --git a/spec/unit/util_spec.lua b/spec/unit/util_spec.lua index bb427b3e..8b234b2e 100644 --- a/spec/unit/util_spec.lua +++ b/spec/unit/util_spec.lua | |||
@@ -8,7 +8,7 @@ local core_util = require("luarocks.core.util") | |||
8 | describe("luarocks.util #unit", function() | 8 | describe("luarocks.util #unit", function() |
9 | local runner | 9 | local runner |
10 | 10 | ||
11 | setup(function() | 11 | lazy_setup(function() |
12 | runner = require("luacov.runner") | 12 | runner = require("luacov.runner") |
13 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | 13 | runner.init(testing_paths.testrun_dir .. "/luacov.config") |
14 | end) | 14 | end) |
diff --git a/spec/util/quick.lua b/spec/util/quick.lua index c313f575..5c49fff9 100644 --- a/spec/util/quick.lua +++ b/spec/util/quick.lua | |||
@@ -159,6 +159,16 @@ local function parse(filename) | |||
159 | cur_block = cur_op | 159 | cur_block = cur_op |
160 | cur_block_name = "FILE" | 160 | cur_block_name = "FILE" |
161 | table.insert(stack, "block start") | 161 | table.insert(stack, "block start") |
162 | elseif cmd == "FILE_CONTENTS" then | ||
163 | cur_op = { | ||
164 | op = "FILE_CONTENTS", | ||
165 | name = arg, | ||
166 | data = {}, | ||
167 | } | ||
168 | table.insert(cur_test.ops, cur_op) | ||
169 | cur_block = cur_op | ||
170 | cur_block_name = "FILE_CONTENTS" | ||
171 | table.insert(stack, "block start") | ||
162 | elseif cmd == "RUN" then | 172 | elseif cmd == "RUN" then |
163 | local program, args = arg:match("([^ ]+)%s*(.*)$") | 173 | local program, args = arg:match("([^ ]+)%s*(.*)$") |
164 | if not program then | 174 | if not program then |
@@ -195,6 +205,20 @@ local function parse(filename) | |||
195 | line = cur_line, | 205 | line = cur_line, |
196 | } | 206 | } |
197 | table.insert(cur_test.ops, cur_op) | 207 | table.insert(cur_test.ops, cur_op) |
208 | elseif cmd == "RMDIR" then | ||
209 | cur_op = { | ||
210 | op = "RMDIR", | ||
211 | file = dir.normalize(arg), | ||
212 | line = cur_line, | ||
213 | } | ||
214 | table.insert(cur_test.ops, cur_op) | ||
215 | elseif cmd == "RM" then | ||
216 | cur_op = { | ||
217 | op = "RM", | ||
218 | file = dir.normalize(arg), | ||
219 | line = cur_line, | ||
220 | } | ||
221 | table.insert(cur_test.ops, cur_op) | ||
198 | elseif cmd == "EXIT" then | 222 | elseif cmd == "EXIT" then |
199 | if not cur_op or cur_op.op ~= "RUN" then | 223 | if not cur_op or cur_op.op ~= "RUN" then |
200 | fail("EXIT must be given in the context of a RUN") | 224 | fail("EXIT must be given in the context of a RUN") |
@@ -346,6 +370,28 @@ function quick.compile(filename, env) | |||
346 | op.file = native_slash(op.file) | 370 | op.file = native_slash(op.file) |
347 | write(([=[ ok, err = make_dir(%q) ]=]):format(op.file)) | 371 | write(([=[ ok, err = make_dir(%q) ]=]):format(op.file)) |
348 | write(([=[ assert.truthy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) | 372 | write(([=[ assert.truthy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) |
373 | elseif op.op == "RMDIR" then | ||
374 | op.file = native_slash(op.file) | ||
375 | write(([=[ ok, err = test_env.remove_dir(%q) ]=]):format(op.file)) | ||
376 | write(([=[ assert.falsy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) | ||
377 | elseif op.op == "RM" then | ||
378 | op.file = native_slash(op.file) | ||
379 | write(([=[ ok, err = os.remove(%q) ]=]):format(op.file)) | ||
380 | write(([=[ assert.falsy((lfs.attributes(%q) or {}).mode == "file", error_message(%d, "RM failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) | ||
381 | elseif op.op == "FILE_CONTENTS" then | ||
382 | write(([=[ do ]=])) | ||
383 | write(([=[ local fd_file = assert(io.open(%q, "rb")) ]=]):format(op.name)) | ||
384 | write(([=[ local file_data = fd_file:read("*a") ]=])) | ||
385 | write(([=[ fd_file:close() ]=])) | ||
386 | write([=[ local block_at = 1 ]=]) | ||
387 | write([=[ local s, e, line ]=]) | ||
388 | for i, line in ipairs(op.data) do | ||
389 | write(([=[ line = %q ]=]):format(line)) | ||
390 | write(([=[ s, e = string.find(file_data, line, 1, true) ]=])) | ||
391 | write(([=[ assert(s, error_message(%d, "FILE_CONTENTS %s did not match: " .. line, file_data)) ]=]):format(op.start + i, op.name)) | ||
392 | write(([=[ block_at = e + 1 ]=]):format(i)) | ||
393 | end | ||
394 | write([=[ end ]=]) | ||
349 | elseif op.op == "RUN" then | 395 | elseif op.op == "RUN" then |
350 | local cmd_helper = cmd_helpers[op.program] or ("%q"):format(op.program) | 396 | local cmd_helper = cmd_helpers[op.program] or ("%q"):format(op.program) |
351 | local redirs = " 1>stdout.txt 2>stderr.txt " | 397 | local redirs = " 1>stdout.txt 2>stderr.txt " |
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index 8ccb494b..be75b4ec 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua | |||
@@ -527,21 +527,6 @@ function test_env.write_file(pathname, str, finally) | |||
527 | end | 527 | end |
528 | end | 528 | end |
529 | 529 | ||
530 | --- Create md5sum of directory structure recursively, based on filename and size | ||
531 | -- @param path string: path to directory for generate md5sum | ||
532 | -- @return md5sum string: md5sum of directory | ||
533 | local function hash_environment(path) | ||
534 | if test_env.TEST_TARGET_OS == "linux" then | ||
535 | return execute_output(C("cd", path, "&& find . -printf \"%s %p\n\" | md5sum")) | ||
536 | elseif test_env.TEST_TARGET_OS == "osx" then | ||
537 | return execute_output(C("find", path, "-type f -exec stat -f \"%z %N\" {} \\; | md5")) | ||
538 | elseif test_env.TEST_TARGET_OS == "windows" then | ||
539 | return execute_output( | ||
540 | "\"" .. C(tool("find"), Q(path), "-printf", "\"%s %p\"") .. "\"" .. | ||
541 | " > temp_sum.txt && certUtil -hashfile temp_sum.txt && del temp_sum.txt") | ||
542 | end | ||
543 | end | ||
544 | |||
545 | --- Create environment variables needed for tests | 530 | --- Create environment variables needed for tests |
546 | -- @param testing_paths table: table with paths to testing directory | 531 | -- @param testing_paths table: table with paths to testing directory |
547 | -- @return env_variables table: table with created environment variables | 532 | -- @return env_variables table: table with created environment variables |
@@ -551,6 +536,7 @@ local function create_env(testing_paths) | |||
551 | local lrprefix = testing_paths.testing_lrprefix | 536 | local lrprefix = testing_paths.testing_lrprefix |
552 | local tree = testing_paths.testing_tree | 537 | local tree = testing_paths.testing_tree |
553 | local sys_tree = testing_paths.testing_sys_tree | 538 | local sys_tree = testing_paths.testing_sys_tree |
539 | local deps_tree = testing_paths.testing_deps_tree | ||
554 | 540 | ||
555 | if test_env.LUAJIT_V then | 541 | if test_env.LUAJIT_V then |
556 | lua_v="5.1" | 542 | lua_v="5.1" |
@@ -567,38 +553,31 @@ local function create_env(testing_paths) | |||
567 | else | 553 | else |
568 | table.insert(lua_path, dir_path(lrprefix, "share", "lua", lua_v, "?.lua")) | 554 | table.insert(lua_path, dir_path(lrprefix, "share", "lua", lua_v, "?.lua")) |
569 | end | 555 | end |
570 | table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?.lua")) | 556 | table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?.lua")) |
571 | table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?", "init.lua")) | 557 | table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?", "init.lua")) |
572 | table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?.lua")) | 558 | table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?.lua")) |
573 | table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?", "init.lua")) | 559 | table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?", "init.lua")) |
560 | table.insert(lua_path, dir_path(deps_tree, "share", "lua", lua_v, "?.lua")) | ||
561 | table.insert(lua_path, dir_path(deps_tree, "share", "lua", lua_v, "?", "init.lua")) | ||
574 | table.insert(lua_path, dir_path(testing_paths.src_dir, "?.lua")) | 562 | table.insert(lua_path, dir_path(testing_paths.src_dir, "?.lua")) |
575 | env_variables.LUA_PATH = table.concat(lua_path, ";") .. ";" | 563 | env_variables.LUA_PATH = table.concat(lua_path, ";") .. ";" |
576 | 564 | ||
577 | local lua_cpath = {} | 565 | local lua_cpath = {} |
578 | local lib_pattern = "?." .. test_env.lib_extension | 566 | local lib_pattern = "?." .. test_env.lib_extension |
579 | table.insert(lua_cpath, dir_path(tree, "lib", "lua", lua_v, lib_pattern)) | 567 | table.insert(lua_cpath, dir_path(tree, "lib", "lua", lua_v, lib_pattern)) |
580 | table.insert(lua_cpath, dir_path(sys_tree, "lib", "lua", lua_v, lib_pattern)) | 568 | table.insert(lua_cpath, dir_path(sys_tree, "lib", "lua", lua_v, lib_pattern)) |
569 | table.insert(lua_cpath, dir_path(deps_tree, "lib", "lua", lua_v, lib_pattern)) | ||
581 | env_variables.LUA_CPATH = table.concat(lua_cpath, ";") .. ";" | 570 | env_variables.LUA_CPATH = table.concat(lua_cpath, ";") .. ";" |
582 | 571 | ||
583 | local path = { os.getenv("PATH") } | 572 | local path = { os.getenv("PATH") } |
584 | table.insert(path, dir_path(tree, "bin")) | 573 | table.insert(path, dir_path(tree, "bin")) |
585 | table.insert(path, dir_path(sys_tree, "bin")) | 574 | table.insert(path, dir_path(sys_tree, "bin")) |
575 | table.insert(path, dir_path(deps_tree, "bin")) | ||
586 | env_variables.PATH = table.concat(path, test_env.TARGET_OS == "windows" and ";" or ":") | 576 | env_variables.PATH = table.concat(path, test_env.TARGET_OS == "windows" and ";" or ":") |
587 | 577 | ||
588 | return env_variables | 578 | return env_variables |
589 | end | 579 | end |
590 | 580 | ||
591 | --- Create md5sums of origin system and system-copy testing directory | ||
592 | -- @param testing_paths table: table with paths to testing directory | ||
593 | -- @return md5sums table: table of md5sums of system and system-copy testing directory | ||
594 | local function create_md5sums(testing_paths) | ||
595 | local md5sums = {} | ||
596 | md5sums.testing_tree_copy_md5 = hash_environment(testing_paths.testing_tree_copy) | ||
597 | md5sums.testing_sys_tree_copy_md5 = hash_environment(testing_paths.testing_sys_tree_copy) | ||
598 | |||
599 | return md5sums | ||
600 | end | ||
601 | |||
602 | local function make_run_function(cmd_name, exec_function, with_coverage, do_print) | 581 | local function make_run_function(cmd_name, exec_function, with_coverage, do_print) |
603 | local cmd_prefix = Q(test_env.testing_paths.lua) | 582 | local cmd_prefix = Q(test_env.testing_paths.lua) |
604 | local testrun_dir = test_env.testing_paths.testrun_dir | 583 | local testrun_dir = test_env.testing_paths.testrun_dir |
@@ -663,43 +642,23 @@ local function build_environment(rocks, env_variables) | |||
663 | local testing_paths = test_env.testing_paths | 642 | local testing_paths = test_env.testing_paths |
664 | test_env.remove_dir(testing_paths.testing_tree) | 643 | test_env.remove_dir(testing_paths.testing_tree) |
665 | test_env.remove_dir(testing_paths.testing_sys_tree) | 644 | test_env.remove_dir(testing_paths.testing_sys_tree) |
666 | test_env.remove_dir(testing_paths.testing_tree_copy) | ||
667 | test_env.remove_dir(testing_paths.testing_sys_tree_copy) | ||
668 | 645 | ||
669 | lfs.mkdir(testing_paths.testing_tree) | 646 | lfs.mkdir(testing_paths.testing_tree) |
670 | lfs.mkdir(testing_paths.testing_sys_tree) | 647 | lfs.mkdir(testing_paths.testing_sys_tree) |
648 | lfs.mkdir(testing_paths.testing_deps_tree) | ||
671 | 649 | ||
672 | test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_server))) | 650 | test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_server))) |
673 | test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_cache))) | 651 | test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_cache))) |
674 | 652 | ||
675 | for _, rock in ipairs(rocks) do | 653 | for _, rock in ipairs(rocks) do |
676 | local only_server = "--only-server=" .. testing_paths.testing_cache | 654 | local only_server = "--only-server=" .. testing_paths.testing_cache |
677 | local tree = "--tree=" .. testing_paths.testing_sys_tree | 655 | local tree = "--tree=" .. testing_paths.testing_deps_tree |
678 | if not test_env.run.luarocks_nocov(test_env.quiet(C("install", only_server, tree, Q(rock)), env_variables)) then | 656 | if not test_env.run.luarocks_nocov(test_env.quiet(C("install", only_server, tree, Q(rock)), env_variables)) then |
679 | assert(test_env.run.luarocks_nocov(C("build", tree, Q(rock)), env_variables)) | 657 | assert(test_env.run.luarocks_nocov(C("build", tree, Q(rock)), env_variables)) |
680 | assert(test_env.run.luarocks_nocov(C("pack", tree, Q(rock)), env_variables)) | 658 | assert(test_env.run.luarocks_nocov(C("pack", tree, Q(rock)), env_variables)) |
681 | move_file(rock .. "-*.rock", testing_paths.testing_cache) | 659 | move_file(rock .. "-*.rock", testing_paths.testing_cache) |
682 | end | 660 | end |
683 | end | 661 | end |
684 | |||
685 | test_env.copy_dir(testing_paths.testing_tree, testing_paths.testing_tree_copy) | ||
686 | test_env.copy_dir(testing_paths.testing_sys_tree, testing_paths.testing_sys_tree_copy) | ||
687 | end | ||
688 | |||
689 | --- Reset testing environment | ||
690 | local function reset_environment(testing_paths, md5sums) | ||
691 | local testing_tree_md5 = hash_environment(testing_paths.testing_tree) | ||
692 | local testing_sys_tree_md5 = hash_environment(testing_paths.testing_sys_tree) | ||
693 | |||
694 | if testing_tree_md5 ~= md5sums.testing_tree_copy_md5 then | ||
695 | test_env.remove_dir(testing_paths.testing_tree) | ||
696 | test_env.copy_dir(testing_paths.testing_tree_copy, testing_paths.testing_tree) | ||
697 | end | ||
698 | |||
699 | if testing_sys_tree_md5 ~= md5sums.testing_sys_tree_copy_md5 then | ||
700 | test_env.remove_dir(testing_paths.testing_sys_tree) | ||
701 | test_env.copy_dir(testing_paths.testing_sys_tree_copy, testing_paths.testing_sys_tree) | ||
702 | end | ||
703 | end | 662 | end |
704 | 663 | ||
705 | local function find_lua() | 664 | local function find_lua() |
@@ -765,15 +724,15 @@ local function create_testing_paths(suffix) | |||
765 | paths.testrun_dir = testrun_dir | 724 | paths.testrun_dir = testrun_dir |
766 | paths.testing_lrprefix = dir_path(testrun_dir, "testing_lrprefix-" .. suffix) | 725 | paths.testing_lrprefix = dir_path(testrun_dir, "testing_lrprefix-" .. suffix) |
767 | paths.testing_tree = dir_path(testrun_dir, "testing-" .. suffix) | 726 | paths.testing_tree = dir_path(testrun_dir, "testing-" .. suffix) |
768 | paths.testing_tree_copy = dir_path(testrun_dir, "testing_copy-" .. suffix) | ||
769 | paths.testing_sys_tree = dir_path(testrun_dir, "testing_sys-" .. suffix) | 727 | paths.testing_sys_tree = dir_path(testrun_dir, "testing_sys-" .. suffix) |
770 | paths.testing_sys_tree_copy = dir_path(testrun_dir, "testing_sys_copy-" .. suffix) | 728 | paths.testing_deps_tree = dir_path(testrun_dir, "testing_deps-" .. suffix) |
771 | paths.testing_cache = dir_path(testrun_dir, "testing_cache-" .. suffix) | 729 | paths.testing_cache = dir_path(testrun_dir, "testing_cache-" .. suffix) |
772 | paths.testing_server = dir_path(testrun_dir, "testing_server-" .. suffix) | 730 | paths.testing_server = dir_path(testrun_dir, "testing_server-" .. suffix) |
773 | 731 | ||
774 | local rocks_v = "rocks-" .. test_env.lua_version | 732 | local rocks_v = "rocks-" .. test_env.lua_version |
775 | paths.testing_rocks = dir_path(paths.testing_tree, "lib", "luarocks", rocks_v) | 733 | paths.testing_rocks = dir_path(paths.testing_tree, "lib", "luarocks", rocks_v) |
776 | paths.testing_sys_rocks = dir_path(paths.testing_sys_tree, "lib", "luarocks", rocks_v) | 734 | paths.testing_sys_rocks = dir_path(paths.testing_sys_tree, "lib", "luarocks", rocks_v) |
735 | paths.testing_deps_rocks = dir_path(paths.testing_deps_tree, "lib", "luarocks", rocks_v) | ||
777 | 736 | ||
778 | if test_env.TEST_TARGET_OS == "windows" then | 737 | if test_env.TEST_TARGET_OS == "windows" then |
779 | paths.luarocks_tmp = os.getenv("TEMP") | 738 | paths.luarocks_tmp = os.getenv("TEMP") |
@@ -853,7 +812,8 @@ local function create_configs() | |||
853 | -- testing_config_no_downloader.lua | 812 | -- testing_config_no_downloader.lua |
854 | local config_content = substitute([[ | 813 | local config_content = substitute([[ |
855 | rocks_trees = { | 814 | rocks_trees = { |
856 | "%{testing_tree}", | 815 | { name = "user", root = "%{testing_tree}" }, |
816 | { name = "deps", root = "%{testing_deps_tree}" }, | ||
857 | { name = "system", root = "%{testing_sys_tree}" }, | 817 | { name = "system", root = "%{testing_sys_tree}" }, |
858 | } | 818 | } |
859 | rocks_servers = { | 819 | rocks_servers = { |
@@ -870,6 +830,7 @@ local function create_configs() | |||
870 | ]], { | 830 | ]], { |
871 | user = "testuser", | 831 | user = "testuser", |
872 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, | 832 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, |
833 | testing_deps_tree = test_env.testing_paths.testing_deps_tree, | ||
873 | testing_tree = test_env.testing_paths.testing_tree, | 834 | testing_tree = test_env.testing_paths.testing_tree, |
874 | testing_server = test_env.testing_paths.testing_server, | 835 | testing_server = test_env.testing_paths.testing_server, |
875 | testing_cache = test_env.testing_paths.testing_cache | 836 | testing_cache = test_env.testing_paths.testing_cache |
@@ -885,6 +846,7 @@ local function create_configs() | |||
885 | config_content = substitute([[ | 846 | config_content = substitute([[ |
886 | rocks_trees = { | 847 | rocks_trees = { |
887 | "%{testing_tree}", | 848 | "%{testing_tree}", |
849 | "%{testing_deps_tree}", | ||
888 | "%{testing_sys_tree}", | 850 | "%{testing_sys_tree}", |
889 | } | 851 | } |
890 | local_cache = "%{testing_cache}" | 852 | local_cache = "%{testing_cache}" |
@@ -898,6 +860,7 @@ local function create_configs() | |||
898 | ]], { | 860 | ]], { |
899 | user = "testuser", | 861 | user = "testuser", |
900 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, | 862 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, |
863 | testing_deps_tree = test_env.testing_paths.testing_deps_tree, | ||
901 | testing_tree = test_env.testing_paths.testing_tree, | 864 | testing_tree = test_env.testing_paths.testing_tree, |
902 | testing_cache = test_env.testing_paths.testing_cache | 865 | testing_cache = test_env.testing_paths.testing_cache |
903 | }) | 866 | }) |
@@ -1140,7 +1103,7 @@ function test_env.main() | |||
1140 | build_environment(rocks, env_vars) | 1103 | build_environment(rocks, env_vars) |
1141 | end | 1104 | end |
1142 | 1105 | ||
1143 | --- Function for initial setup of environment, variables, md5sums for spec files | 1106 | --- Function for initial setup of environment and variables |
1144 | function test_env.setup_specs(extra_rocks, use_mock) | 1107 | function test_env.setup_specs(extra_rocks, use_mock) |
1145 | test_env.unload_luarocks() | 1108 | test_env.unload_luarocks() |
1146 | 1109 | ||
@@ -1169,7 +1132,6 @@ function test_env.setup_specs(extra_rocks, use_mock) | |||
1169 | 1132 | ||
1170 | test_env.platform = get_luarocks_platform(test_env.env_variables) | 1133 | test_env.platform = get_luarocks_platform(test_env.env_variables) |
1171 | test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" | 1134 | test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" |
1172 | test_env.md5sums = create_md5sums(test_env.testing_paths) | ||
1173 | test_env.setup_done = true | 1135 | test_env.setup_done = true |
1174 | title("RUNNING TESTS") | 1136 | title("RUNNING TESTS") |
1175 | end | 1137 | end |
@@ -1186,7 +1148,8 @@ function test_env.setup_specs(extra_rocks, use_mock) | |||
1186 | end | 1148 | end |
1187 | 1149 | ||
1188 | if test_env.RESET_ENV then | 1150 | if test_env.RESET_ENV then |
1189 | reset_environment(test_env.testing_paths, test_env.md5sums, variables) | 1151 | test_env.remove_dir(test_env.testing_paths.testing_tree) |
1152 | test_env.remove_dir(test_env.testing_paths.testing_sys_tree) | ||
1190 | end | 1153 | end |
1191 | 1154 | ||
1192 | lfs.chdir(testrun_dir) | 1155 | lfs.chdir(testrun_dir) |
diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 452237d2..200ec13b 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua | |||
@@ -63,6 +63,19 @@ do | |||
63 | cfg.deploy_lib_dir = cfg.deploy_lib_dir:gsub("/+$", "") | 63 | cfg.deploy_lib_dir = cfg.deploy_lib_dir:gsub("/+$", "") |
64 | end | 64 | end |
65 | 65 | ||
66 | local function set_named_tree(args, name) | ||
67 | for _, tree in ipairs(cfg.rocks_trees) do | ||
68 | if type(tree) == "table" and name == tree.name then | ||
69 | if not tree.root then | ||
70 | return nil, "Configuration error: tree '"..tree.name.."' has no 'root' field." | ||
71 | end | ||
72 | replace_tree(args, tree.root, tree) | ||
73 | return true | ||
74 | end | ||
75 | end | ||
76 | return false | ||
77 | end | ||
78 | |||
66 | process_tree_args = function(args, project_dir) | 79 | process_tree_args = function(args, project_dir) |
67 | 80 | ||
68 | if args.global then | 81 | if args.global then |
@@ -70,17 +83,7 @@ do | |||
70 | end | 83 | end |
71 | 84 | ||
72 | if args.tree then | 85 | if args.tree then |
73 | local named = false | 86 | local named = set_named_tree(args, args.tree) |
74 | for _, tree in ipairs(cfg.rocks_trees) do | ||
75 | if type(tree) == "table" and args.tree == tree.name then | ||
76 | if not tree.root then | ||
77 | return nil, "Configuration error: tree '"..tree.name.."' has no 'root' field." | ||
78 | end | ||
79 | replace_tree(args, tree.root, tree) | ||
80 | named = true | ||
81 | break | ||
82 | end | ||
83 | end | ||
84 | if not named then | 87 | if not named then |
85 | local root_dir = fs.absolute_name(args.tree) | 88 | local root_dir = fs.absolute_name(args.tree) |
86 | replace_tree(args, root_dir) | 89 | replace_tree(args, root_dir) |
@@ -94,7 +97,7 @@ do | |||
94 | "You are running as a superuser, which is intended for system-wide operation.\n".. | 97 | "You are running as a superuser, which is intended for system-wide operation.\n".. |
95 | "To force using the superuser's home, use --tree explicitly." | 98 | "To force using the superuser's home, use --tree explicitly." |
96 | else | 99 | else |
97 | replace_tree(args, cfg.home_tree) | 100 | set_named_tree(args, "user") |
98 | end | 101 | end |
99 | elseif args.project_tree then | 102 | elseif args.project_tree then |
100 | local tree = args.project_tree | 103 | local tree = args.project_tree |
@@ -102,9 +105,7 @@ do | |||
102 | manif.load_rocks_tree_manifests() | 105 | manif.load_rocks_tree_manifests() |
103 | path.use_tree(tree) | 106 | path.use_tree(tree) |
104 | elseif cfg.local_by_default then | 107 | elseif cfg.local_by_default then |
105 | if cfg.home_tree then | 108 | set_named_tree(args, "user") |
106 | replace_tree(args, cfg.home_tree) | ||
107 | end | ||
108 | elseif project_dir then | 109 | elseif project_dir then |
109 | local project_tree = project_dir .. "/lua_modules" | 110 | local project_tree = project_dir .. "/lua_modules" |
110 | table.insert(cfg.rocks_trees, 1, { name = "project", root = project_tree } ) | 111 | table.insert(cfg.rocks_trees, 1, { name = "project", root = project_tree } ) |