diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-26 12:31:19 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-26 12:31:19 -0300 |
commit | cda1078b7cfa7d9bc822074a54aa4f54e7a3eb27 (patch) | |
tree | e97eb413edd92df4825b7b778813909da4c1c66f | |
parent | b65f5304f224ce7f9edd0faa2bbd152dc8f8ddf2 (diff) | |
download | luarocks-tests-more-quick.tar.gz luarocks-tests-more-quick.tar.bz2 luarocks-tests-more-quick.zip |
tests: replace some more tests with quick teststests-more-quick
-rw-r--r-- | spec/install_spec.lua | 69 | ||||
-rw-r--r-- | spec/quick/install.q | 257 | ||||
-rw-r--r-- | spec/util/quick.lua | 45 |
3 files changed, 287 insertions, 84 deletions
diff --git a/spec/install_spec.lua b/spec/install_spec.lua index d410ca97..45979b9c 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua | |||
@@ -20,14 +20,11 @@ local extra_rocks = { | |||
20 | "/lxsh-${LXSH}.rockspec", | 20 | "/lxsh-${LXSH}.rockspec", |
21 | "/say-1.2-1.src.rock", | 21 | "/say-1.2-1.src.rock", |
22 | "/say-1.0-1.src.rock", | 22 | "/say-1.0-1.src.rock", |
23 | "/wsapi-1.6-1.src.rock", | ||
24 | "/luafilesystem-${LUAFILESYSTEM}.src.rock", | 23 | "/luafilesystem-${LUAFILESYSTEM}.src.rock", |
25 | "/luafilesystem-${LUAFILESYSTEM_OLD}.src.rock", | 24 | "/luafilesystem-${LUAFILESYSTEM_OLD}.src.rock", |
26 | "spec/fixtures/a_repo/has_build_dep-1.0-1.all.rock", | 25 | "spec/fixtures/a_repo/has_build_dep-1.0-1.all.rock", |
27 | "spec/fixtures/a_repo/a_build_dep-1.0-1.all.rock", | 26 | "spec/fixtures/a_repo/a_build_dep-1.0-1.all.rock", |
28 | "spec/fixtures/a_repo/a_rock-1.0-1.src.rock", | 27 | "spec/fixtures/a_repo/a_rock-1.0-1.src.rock", |
29 | "spec/fixtures/a_repo/non_lua_file-1.0-1.src.rock", | ||
30 | "spec/fixtures/a_repo/non_lua_file-1.0-2.src.rock", | ||
31 | } | 28 | } |
32 | 29 | ||
33 | describe("luarocks install #integration", function() | 30 | describe("luarocks install #integration", function() |
@@ -37,22 +34,6 @@ describe("luarocks install #integration", function() | |||
37 | end) | 34 | end) |
38 | 35 | ||
39 | describe("basic tests", function() | 36 | describe("basic tests", function() |
40 | it("fails with no flags/arguments", function() | ||
41 | assert.is_false(run.luarocks_bool("install")) | ||
42 | end) | ||
43 | |||
44 | it("fails with invalid argument", function() | ||
45 | assert.is_false(run.luarocks_bool("install invalid")) | ||
46 | end) | ||
47 | |||
48 | it("fails invalid patch", function() | ||
49 | assert.is_false(run.luarocks_bool("install " .. testing_paths.fixtures_dir .. "/invalid_patch-0.1-1.rockspec")) | ||
50 | end) | ||
51 | |||
52 | it("fails invalid rock", function() | ||
53 | assert.is_false(run.luarocks_bool("install \"invalid.rock\" ")) | ||
54 | end) | ||
55 | |||
56 | it("fails with local flag as root #unix", function() | 37 | it("fails with local flag as root #unix", function() |
57 | if test_env.TYPE_TEST_ENV ~= "full" then | 38 | if test_env.TYPE_TEST_ENV ~= "full" then |
58 | assert.is_false(run.luarocks_bool("install --local luasocket ", { USER = "root" } )) | 39 | assert.is_false(run.luarocks_bool("install --local luasocket ", { USER = "root" } )) |
@@ -71,38 +52,15 @@ describe("luarocks install #integration", function() | |||
71 | end | 52 | end |
72 | end) | 53 | end) |
73 | 54 | ||
74 | it("fails not a zip file", function() | ||
75 | test_env.run_in_tmp(function(tmpdir) | ||
76 | write_file("not_a_zipfile-1.0-1.src.rock", [[ | ||
77 | I am not a .zip file! | ||
78 | ]], finally) | ||
79 | assert.is_false(run.luarocks_bool("install not_a_zipfile-1.0-1.src.rock")) | ||
80 | end, finally) | ||
81 | end) | ||
82 | |||
83 | it("only-deps of lxsh show there is no lxsh", function() | 55 | it("only-deps of lxsh show there is no lxsh", function() |
84 | assert.is_true(run.luarocks_bool("install lxsh ${LXSH} --only-deps")) | 56 | assert.is_true(run.luarocks_bool("install lxsh ${LXSH} --only-deps")) |
85 | assert.is_false(run.luarocks_bool("show lxsh")) | 57 | assert.is_false(run.luarocks_bool("show lxsh")) |
86 | end) | 58 | end) |
87 | 59 | ||
88 | it("fails with incompatible architecture", function() | ||
89 | assert.is_false(run.luarocks_bool("install \"foo-1.0-1.impossible-x86.rock\" ")) | ||
90 | end) | ||
91 | |||
92 | it("installs a package with an executable", function() | ||
93 | assert(run.luarocks_bool("install wsapi")) | ||
94 | end) | ||
95 | |||
96 | it("installs a package with a dependency", function() | 60 | it("installs a package with a dependency", function() |
97 | assert.is_true(run.luarocks_bool("install has_build_dep")) | 61 | assert.is_true(run.luarocks_bool("install has_build_dep")) |
98 | assert.is_true(run.luarocks_bool("show a_rock")) | 62 | assert.is_true(run.luarocks_bool("show a_rock")) |
99 | end) | 63 | end) |
100 | |||
101 | it("installs a package without its documentation", function() | ||
102 | assert.is_true(run.luarocks_bool("install wsapi 1.6 --no-doc")) | ||
103 | assert.is_true(run.luarocks_bool("show wsapi 1.6")) | ||
104 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/wsapi/1.6-1/doc")) | ||
105 | end) | ||
106 | end) | 64 | end) |
107 | 65 | ||
108 | describe("#namespaces", function() | 66 | describe("#namespaces", function() |
@@ -172,33 +130,6 @@ describe("luarocks install #integration", function() | |||
172 | assert.is.falsy(lfs.attributes(relative_path)) | 130 | assert.is.falsy(lfs.attributes(relative_path)) |
173 | end) | 131 | end) |
174 | 132 | ||
175 | it('handle versioned modules when installing another version with --keep #268', function() | ||
176 | local libdir = testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION | ||
177 | |||
178 | assert.is_true(run.luarocks_bool("install luafilesystem")) | ||
179 | assert.is.truthy(lfs.attributes(libdir .."/lfs."..test_env.lib_extension)) | ||
180 | |||
181 | local suffix = (V"${LUAFILESYSTEM_OLD}"):gsub("[%.%-]", "_") | ||
182 | |||
183 | assert.is_true(run.luarocks_bool("install luafilesystem ${LUAFILESYSTEM_OLD} --keep")) | ||
184 | assert.is.truthy(lfs.attributes(libdir .. "/lfs."..test_env.lib_extension)) | ||
185 | assert.is.truthy(lfs.attributes(libdir .. "/luafilesystem_"..suffix.."-lfs."..test_env.lib_extension)) | ||
186 | |||
187 | assert.is_true(run.luarocks_bool("install luafilesystem")) | ||
188 | assert.is.truthy(lfs.attributes(libdir .. "/lfs."..test_env.lib_extension)) | ||
189 | assert.is.falsy(lfs.attributes(libdir .. "/luafilesystem_"..suffix.."-lfs."..test_env.lib_extension)) | ||
190 | end) | ||
191 | |||
192 | it('handle non-Lua files in build.install.lua when upgrading sailorproject/sailor#138', function() | ||
193 | assert.is_true(run.luarocks_bool("install non_lua_file 1.0-1 --deps-mode=none")) | ||
194 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION.."/sailor/blank-app/.htaccess")) | ||
195 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION.."/sailor/blank-app/.htaccess~")) | ||
196 | |||
197 | assert.is_true(run.luarocks_bool("install non_lua_file 1.0-2 --deps-mode=none")) | ||
198 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION.."/sailor/blank-app/.htaccess")) | ||
199 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION.."/sailor/blank-app/.htaccess~")) | ||
200 | end) | ||
201 | |||
202 | it("only-deps of luasocket packed rock", function() | 133 | it("only-deps of luasocket packed rock", function() |
203 | assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket ${LUASOCKET}")) | 134 | assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket ${LUASOCKET}")) |
204 | local output = run.luarocks("install --only-deps " .. "luasocket-${LUASOCKET}." .. test_env.platform .. ".rock") | 135 | local output = run.luarocks("install --only-deps " .. "luasocket-${LUASOCKET}." .. test_env.platform .. ".rock") |
diff --git a/spec/quick/install.q b/spec/quick/install.q index 2bccf2f1..ab576605 100644 --- a/spec/quick/install.q +++ b/spec/quick/install.q | |||
@@ -1,5 +1,91 @@ | |||
1 | SUITE: luarocks install | ||
2 | |||
3 | =============================================================================== | ||
4 | TEST: fails with no flags or arguments | ||
5 | RUN: luarocks install | ||
6 | EXIT: 1 | ||
7 | |||
8 | |||
9 | |||
10 | =============================================================================== | ||
11 | TEST: fails with an unknown rock | ||
12 | RUN: luarocks install aoeuaoeuaoeiaoeuaoeua | ||
13 | EXIT: 1 | ||
14 | |||
15 | |||
16 | |||
17 | =============================================================================== | ||
18 | TEST: fails with an invalid .rock argument | ||
19 | RUN: luarocks install "invalid.rock" | ||
20 | EXIT: 1 | ||
21 | |||
22 | |||
23 | |||
24 | =============================================================================== | ||
25 | TEST: fails with incompatible architecture | ||
26 | RUN: luarocks install foo-1.0-1.impossible-x86.rock | ||
27 | EXIT: 1 | ||
28 | STDERR: | ||
29 | -------------------------------------------------------------------------------- | ||
30 | Incompatible architecture | ||
31 | -------------------------------------------------------------------------------- | ||
32 | |||
33 | |||
34 | |||
1 | =============================================================================== | 35 | =============================================================================== |
2 | TEST: luarocks install: handle versioned modules when installing another version with --keep #268 | 36 | TEST: fails if not a zip file |
37 | |||
38 | FILE: not_a_zipfile-1.0-1.src.rock | ||
39 | -------------------------------------------------------------------------------- | ||
40 | I am not a zip file! | ||
41 | -------------------------------------------------------------------------------- | ||
42 | RUN: luarocks install not_a_zipfile-1.0-1.src.rock | ||
43 | EXIT: 1 | ||
44 | |||
45 | |||
46 | |||
47 | =============================================================================== | ||
48 | TEST: fails with an invalid patch | ||
49 | |||
50 | FILE: invalid_patch-0.1-1.rockspec | ||
51 | -------------------------------------------------------------------------------- | ||
52 | package = "invalid_patch" | ||
53 | version = "0.1-1" | ||
54 | source = { | ||
55 | -- any valid URL | ||
56 | url = "https://raw.github.com/keplerproject/luarocks/master/src/luarocks/build.lua" | ||
57 | } | ||
58 | description = { | ||
59 | summary = "A rockspec with an invalid patch", | ||
60 | } | ||
61 | dependencies = { | ||
62 | "lua >= 5.1" | ||
63 | } | ||
64 | build = { | ||
65 | type = "builtin", | ||
66 | modules = { | ||
67 | build = "build.lua" | ||
68 | }, | ||
69 | patches = { | ||
70 | ["I_am_an_invalid_patch.patch"] = | ||
71 | [[ | ||
72 | diff -Naur luadoc-3.0.1/src/luadoc/doclet/html.lua luadoc-3.0.1-new/src/luadoc/doclet/html.lua | ||
73 | --- luadoc-3.0.1/src/luadoc/doclet/html.lua2007-12-21 15:50:48.000000000 -0200 | ||
74 | +++ luadoc-3.0.1-new/src/luadoc/doclet/html.lua2008-02-28 01:59:53.000000000 -0300 | ||
75 | @@ -18,6 +18,7 @@ | ||
76 | - gabba gabba gabba | ||
77 | + gobo gobo gobo | ||
78 | ]] | ||
79 | } | ||
80 | } | ||
81 | -------------------------------------------------------------------------------- | ||
82 | RUN: luarocks invalid_patch-0.1-1.rockspec | ||
83 | EXIT: 1 | ||
84 | |||
85 | |||
86 | |||
87 | ================================================================================ | ||
88 | TEST: handle versioned modules when installing another version with --keep #268 | ||
3 | 89 | ||
4 | FILE: myrock-1.0-1.rockspec | 90 | FILE: myrock-1.0-1.rockspec |
5 | -------------------------------------------------------------------------------- | 91 | -------------------------------------------------------------------------------- |
@@ -56,8 +142,8 @@ NOT_EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/myrock_1_0_1-rock.lua | |||
56 | 142 | ||
57 | 143 | ||
58 | 144 | ||
59 | =============================================================================== | 145 | ================================================================================ |
60 | TEST: luarocks install: handle versioned libraries when installing another version with --keep #268 | 146 | TEST: handle versioned libraries when installing another version with --keep #268 |
61 | 147 | ||
62 | FILE: myrock-1.0-1.rockspec | 148 | FILE: myrock-1.0-1.rockspec |
63 | -------------------------------------------------------------------------------- | 149 | -------------------------------------------------------------------------------- |
@@ -122,3 +208,168 @@ RUN: luarocks install ./myrock-2.0-1.%{platform}.rock | |||
122 | 208 | ||
123 | EXISTS: %{testing_sys_tree}/lib/lua/%{LUA_VERSION}/c_module.%{lib_extension} | 209 | EXISTS: %{testing_sys_tree}/lib/lua/%{LUA_VERSION}/c_module.%{lib_extension} |
124 | NOT_EXISTS: %{testing_sys_tree}/lib/lua/%{LUA_VERSION}/myrock_1_0_1-c_module.%{lib_extension} | 210 | NOT_EXISTS: %{testing_sys_tree}/lib/lua/%{LUA_VERSION}/myrock_1_0_1-c_module.%{lib_extension} |
211 | |||
212 | |||
213 | |||
214 | ================================================================================ | ||
215 | TEST: installs a package with a bin entry | ||
216 | |||
217 | FILE: myrock-1.0-1.rockspec | ||
218 | -------------------------------------------------------------------------------- | ||
219 | rockspec_format = "3.0" | ||
220 | package = "myrock" | ||
221 | version = "1.0-1" | ||
222 | source = { | ||
223 | url = "file://%{url(tmpdir)}/rock.lua" | ||
224 | } | ||
225 | build = { | ||
226 | modules = { rock = "rock.lua" }, | ||
227 | install = { | ||
228 | bin = { | ||
229 | ["scripty"] = "rock.lua", | ||
230 | } | ||
231 | } | ||
232 | } | ||
233 | -------------------------------------------------------------------------------- | ||
234 | |||
235 | FILE: rock.lua | ||
236 | -------------------------------------------------------------------------------- | ||
237 | return "hello" | ||
238 | -------------------------------------------------------------------------------- | ||
239 | |||
240 | RUN: luarocks build myrock-1.0-1.rockspec | ||
241 | EXISTS: %{testing_sys_tree}/bin/scripty%{wrapper_extension} | ||
242 | RUN: luarocks pack myrock | ||
243 | RUN: luarocks remove myrock | ||
244 | NOT_EXISTS: %{testing_sys_tree}/bin/scripty%{wrapper_extension} | ||
245 | |||
246 | RUN: luarocks install myrock-1.0-1.all.rock | ||
247 | EXISTS: %{testing_sys_tree}/bin/scripty%{wrapper_extension} | ||
248 | |||
249 | |||
250 | |||
251 | ================================================================================ | ||
252 | TEST: installs a package without its documentation using --no-doc | ||
253 | |||
254 | FILE: myrock-1.0-1.rockspec | ||
255 | -------------------------------------------------------------------------------- | ||
256 | rockspec_format = "3.0" | ||
257 | package = "myrock" | ||
258 | version = "1.0-1" | ||
259 | source = { | ||
260 | url = "." | ||
261 | } | ||
262 | build = { | ||
263 | modules = { rock = "rock.lua" }, | ||
264 | install = { | ||
265 | bin = { | ||
266 | ["scripty"] = "rock.lua", | ||
267 | } | ||
268 | } | ||
269 | } | ||
270 | -------------------------------------------------------------------------------- | ||
271 | |||
272 | FILE: rock.lua | ||
273 | -------------------------------------------------------------------------------- | ||
274 | return "hello" | ||
275 | -------------------------------------------------------------------------------- | ||
276 | |||
277 | FILE: doc/something | ||
278 | -------------------------------------------------------------------------------- | ||
279 | a doc | ||
280 | -------------------------------------------------------------------------------- | ||
281 | |||
282 | RUN: luarocks make | ||
283 | EXISTS: %{testing_sys_rocks}/myrock/1.0-1/doc/something | ||
284 | RUN: luarocks pack myrock | ||
285 | RUN: luarocks remove myrock | ||
286 | NOT_EXISTS: %{testing_sys_rocks}/myrock/1.0-1/doc/something | ||
287 | |||
288 | RUN: luarocks install myrock-1.0-1.all.rock | ||
289 | EXISTS: %{testing_sys_rocks}/myrock/1.0-1/doc/something | ||
290 | RUN: luarocks remove myrock | ||
291 | NOT_EXISTS: %{testing_sys_rocks}/myrock/1.0-1/doc/something | ||
292 | |||
293 | RUN: luarocks install myrock-1.0-1.all.rock --no-doc | ||
294 | NOT_EXISTS: %{testing_sys_rocks}/myrock/1.0-1/doc/something | ||
295 | |||
296 | |||
297 | |||
298 | ================================================================================ | ||
299 | TEST: handle non-Lua files in build.install.lua when upgrading sailorproject/sailor#138 | ||
300 | |||
301 | FILE: myrock-1.0-1.rockspec | ||
302 | -------------------------------------------------------------------------------- | ||
303 | rockspec_format = "3.0" | ||
304 | package = "myrock" | ||
305 | version = "1.0-1" | ||
306 | source = { | ||
307 | url = "." | ||
308 | } | ||
309 | build = { | ||
310 | modules = { | ||
311 | rock = "rock.lua", | ||
312 | }, | ||
313 | install = { | ||
314 | lua = { | ||
315 | ["sailor.blank-app.htaccess"] = "src/sailor/blank-app/.htaccess", | ||
316 | } | ||
317 | } | ||
318 | } | ||
319 | -------------------------------------------------------------------------------- | ||
320 | |||
321 | FILE: myrock-1.0-2.rockspec | ||
322 | -------------------------------------------------------------------------------- | ||
323 | rockspec_format = "3.0" | ||
324 | package = "myrock" | ||
325 | version = "1.0-2" | ||
326 | source = { | ||
327 | url = "." | ||
328 | } | ||
329 | build = { | ||
330 | modules = { | ||
331 | rock = "rock.lua", | ||
332 | }, | ||
333 | install = { | ||
334 | lua = { | ||
335 | ["sailor.blank-app.htaccess"] = "src/sailor/blank-app/.htaccess", | ||
336 | } | ||
337 | } | ||
338 | } | ||
339 | -------------------------------------------------------------------------------- | ||
340 | |||
341 | FILE: rock.lua | ||
342 | -------------------------------------------------------------------------------- | ||
343 | return "hello" | ||
344 | -------------------------------------------------------------------------------- | ||
345 | |||
346 | FILE: src/sailor/blank-app/.htaccess | ||
347 | -------------------------------------------------------------------------------- | ||
348 | # I am just a file | ||
349 | -------------------------------------------------------------------------------- | ||
350 | |||
351 | Prepare two versions as .rock packages with the same non-Lua asset: | ||
352 | |||
353 | RUN: luarocks make ./myrock-1.0-1.rockspec | ||
354 | RUN: luarocks pack myrock | ||
355 | RUN: luarocks remove myrock | ||
356 | |||
357 | RUN: luarocks make ./myrock-1.0-2.rockspec | ||
358 | RUN: luarocks pack myrock | ||
359 | RUN: luarocks remove myrock | ||
360 | |||
361 | Now install the first one, and check that the asset was installed, with no "~" | ||
362 | backup leftover: | ||
363 | |||
364 | RUN: luarocks install myrock-1.0-1.all.rock --no-doc | ||
365 | |||
366 | EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess | ||
367 | NOT_EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess~ | ||
368 | |||
369 | Then install the second one, and the asset should be replaced, again with no | ||
370 | "~" backup leftover: | ||
371 | |||
372 | RUN: luarocks install myrock-1.0-2.all.rock --no-doc | ||
373 | |||
374 | EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess | ||
375 | NOT_EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess~ | ||
diff --git a/spec/util/quick.lua b/spec/util/quick.lua index 1fcf2b36..d7df7bb1 100644 --- a/spec/util/quick.lua +++ b/spec/util/quick.lua | |||
@@ -46,6 +46,7 @@ local function parse(filename) | |||
46 | local tests = {} | 46 | local tests = {} |
47 | 47 | ||
48 | local cur_line = 0 | 48 | local cur_line = 0 |
49 | local cur_suite = "" | ||
49 | local cur_test | 50 | local cur_test |
50 | local cur_op | 51 | local cur_op |
51 | local cur_block | 52 | local cur_block |
@@ -54,7 +55,7 @@ local function parse(filename) | |||
54 | 55 | ||
55 | local function start_test(arg) | 56 | local function start_test(arg) |
56 | cur_test = { | 57 | cur_test = { |
57 | name = arg, | 58 | name = cur_suite .. arg, |
58 | ops = {}, | 59 | ops = {}, |
59 | } | 60 | } |
60 | cur_op = nil | 61 | cur_op = nil |
@@ -137,6 +138,8 @@ local function parse(filename) | |||
137 | local cmd, arg = parse_cmd(line) | 138 | local cmd, arg = parse_cmd(line) |
138 | if cmd == "TEST" then | 139 | if cmd == "TEST" then |
139 | start_test(arg) | 140 | start_test(arg) |
141 | elseif cmd == "SUITE" then | ||
142 | cur_suite = arg .. ": " | ||
140 | elseif cmd then | 143 | elseif cmd then |
141 | fail("expected TEST, got " .. cmd) | 144 | fail("expected TEST, got " .. cmd) |
142 | elseif is_blank(line) then | 145 | elseif is_blank(line) then |
@@ -175,12 +178,14 @@ local function parse(filename) | |||
175 | cur_op = { | 178 | cur_op = { |
176 | op = "EXISTS", | 179 | op = "EXISTS", |
177 | file = dir.normalize(arg), | 180 | file = dir.normalize(arg), |
181 | line = cur_line, | ||
178 | } | 182 | } |
179 | table.insert(cur_test.ops, cur_op) | 183 | table.insert(cur_test.ops, cur_op) |
180 | elseif cmd == "NOT_EXISTS" then | 184 | elseif cmd == "NOT_EXISTS" then |
181 | cur_op = { | 185 | cur_op = { |
182 | op = "NOT_EXISTS", | 186 | op = "NOT_EXISTS", |
183 | file = dir.normalize(arg), | 187 | file = dir.normalize(arg), |
188 | line = cur_line, | ||
184 | } | 189 | } |
185 | table.insert(cur_test.ops, cur_op) | 190 | table.insert(cur_test.ops, cur_op) |
186 | elseif cmd == "MKDIR" then | 191 | elseif cmd == "MKDIR" then |
@@ -271,6 +276,12 @@ function quick.compile(filename, env) | |||
271 | table.insert(code, table.concat({...})) | 276 | table.insert(code, table.concat({...})) |
272 | end | 277 | end |
273 | 278 | ||
279 | write(([=[ ]=])) | ||
280 | write(([=[ -- **************************************** ]=])) | ||
281 | write(([=[ -- %s ]=]):format(t.name)) | ||
282 | write(([=[ -- **************************************** ]=])) | ||
283 | write(([=[ ]=])) | ||
284 | |||
274 | write([=[ local test_env = require("spec.util.test_env") ]=]) | 285 | write([=[ local test_env = require("spec.util.test_env") ]=]) |
275 | write([=[ local lfs = require("lfs") ]=]) | 286 | write([=[ local lfs = require("lfs") ]=]) |
276 | write([=[ local fs = require("lfs") ]=]) | 287 | write([=[ local fs = require("lfs") ]=]) |
@@ -278,6 +289,18 @@ function quick.compile(filename, env) | |||
278 | write([=[ local luarocks_cmd = test_env.execute_helper(test_env.Q(test_env.testing_paths.lua) .. " " .. test_env.testing_paths.src_dir .. "/bin/luarocks", false, test_env.env_variables):sub(1, -5) ]=]) | 289 | write([=[ local luarocks_cmd = test_env.execute_helper(test_env.Q(test_env.testing_paths.lua) .. " " .. test_env.testing_paths.src_dir .. "/bin/luarocks", false, test_env.env_variables):sub(1, -5) ]=]) |
279 | write([=[ local luarocks_admin_cmd = test_env.execute_helper(test_env.Q(test_env.testing_paths.lua) .. " " .. test_env.testing_paths.src_dir .. "/bin/luarocks-admin", false, test_env.env_variables):sub(1, -5) ]=]) | 290 | write([=[ local luarocks_admin_cmd = test_env.execute_helper(test_env.Q(test_env.testing_paths.lua) .. " " .. test_env.testing_paths.src_dir .. "/bin/luarocks-admin", false, test_env.env_variables):sub(1, -5) ]=]) |
280 | 291 | ||
292 | write([=[ local function make_dir(dirname) ]=]) | ||
293 | write([=[ local bits = {} ]=]) | ||
294 | write([=[ if dirname:sub(1, 1) == dir_sep then bits[1] = "" end ]=]) | ||
295 | write([=[ local ok, err ]=]) | ||
296 | write([=[ for p in dirname:gmatch("[^" .. dir_sep .. "]+") do ]=]) | ||
297 | write([=[ table.insert(bits, p) ]=]) | ||
298 | write([=[ ok, err = lfs.mkdir(table.concat(bits, dir_sep)) ]=]) | ||
299 | write([=[ end ]=]) | ||
300 | write([=[ local exists = (lfs.attributes(dirname) or {}).mode == "directory" ]=]) | ||
301 | write([=[ return exists, (not exists) and err ]=]) | ||
302 | write([=[ end ]=]) | ||
303 | |||
281 | write(([=[ local function error_message(line, msg, input) ]=])) | 304 | write(([=[ local function error_message(line, msg, input) ]=])) |
282 | write(([=[ local out = {"\n\n", %q, ":", line, ": ", msg} ]=]):format(filename)) | 305 | write(([=[ local out = {"\n\n", %q, ":", line, ": ", msg} ]=]):format(filename)) |
283 | write(([=[ if input then ]=])) | 306 | write(([=[ if input then ]=])) |
@@ -302,27 +325,25 @@ function quick.compile(filename, env) | |||
302 | write([=[ return (s:gsub("%%{url%(tmpdir%)}", (tmpdir:gsub("\\", "/"))) ]=]) | 325 | write([=[ return (s:gsub("%%{url%(tmpdir%)}", (tmpdir:gsub("\\", "/"))) ]=]) |
303 | write([=[ :gsub("%%{tmpdir}", (tmpdir:gsub("[\\/]", dir_sep)))) ]=]) | 326 | write([=[ :gsub("%%{tmpdir}", (tmpdir:gsub("[\\/]", dir_sep)))) ]=]) |
304 | write([=[ end ]=]) | 327 | write([=[ end ]=]) |
328 | write([=[ local ok, err ]=]) | ||
305 | for _, op in ipairs(t.ops) do | 329 | for _, op in ipairs(t.ops) do |
306 | if op.op == "FILE" then | 330 | if op.op == "FILE" then |
331 | if op.name:match("[\\/]") then | ||
332 | write(([=[ make_dir(%q) ]=]):format(dir.dir_name(op.name))) | ||
333 | end | ||
307 | write(([=[ test_env.write_file(handle_tmpdir(%q), handle_tmpdir([=====[ ]=]):format(op.name)) | 334 | write(([=[ test_env.write_file(handle_tmpdir(%q), handle_tmpdir([=====[ ]=]):format(op.name)) |
308 | for _, line in ipairs(op.data) do | 335 | for _, line in ipairs(op.data) do |
309 | write(line) | 336 | write(line) |
310 | end | 337 | end |
311 | write([=[ ]=====]), finally) ]=]) | 338 | write([=[ ]=====]), finally) ]=]) |
312 | elseif op.op == "EXISTS" then | 339 | elseif op.op == "EXISTS" then |
313 | write(([=[ assert.truthy(lfs.attributes(%q)) ]=]):format(op.file)) | 340 | write(([=[ ok, err = lfs.attributes(%q) ]=]):format(op.file)) |
341 | write(([=[ assert.truthy(ok, error_message(%d, "EXISTS failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.line, op.file)) | ||
314 | elseif op.op == "NOT_EXISTS" then | 342 | elseif op.op == "NOT_EXISTS" then |
315 | write(([=[ assert.falsy(lfs.attributes(%q)) ]=]):format(op.file)) | 343 | write(([=[ assert.falsy(lfs.attributes(%q), error_message(%d, "NOT_EXISTS failed: " .. %q .. " exists" )) ]=]):format(op.file, op.line, op.file)) |
316 | elseif op.op == "MKDIR" then | 344 | elseif op.op == "MKDIR" then |
317 | local bits = {} | ||
318 | op.file = native_slash(op.file) | 345 | op.file = native_slash(op.file) |
319 | if op.file:sub(1, 1) == dir_sep then bits[1] = "" end | 346 | write(([=[ ok, err = make_dir(%q) ]=]):format(op.file)) |
320 | write([=[ local ok, err ]=]) | ||
321 | for p in op.file:gmatch("[^" .. dir_sep .. "]+") do | ||
322 | table.insert(bits, p) | ||
323 | local d = table.concat(bits, dir_sep) | ||
324 | write(([=[ ok, err = lfs.mkdir(%q) ]=]):format(d, d)) | ||
325 | end | ||
326 | write(([=[ assert.truthy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) | 347 | write(([=[ assert.truthy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) |
327 | elseif op.op == "RUN" then | 348 | elseif op.op == "RUN" then |
328 | local cmd_helper = cmd_helpers[op.program] or op.program | 349 | local cmd_helper = cmd_helpers[op.program] or op.program |
@@ -411,7 +432,7 @@ function quick.compile(filename, env) | |||
411 | write([=[ end ]=]) | 432 | write([=[ end ]=]) |
412 | 433 | ||
413 | local program = table.concat(code, "\n") | 434 | local program = table.concat(code, "\n") |
414 | local chunk = assert(load(program, "@" .. filename .. ": test " .. tn, "t", env or _ENV)) | 435 | local chunk = assert(load(program, "@" .. filename .. ":[TEST " .. tn .. "]", "t", env or _ENV)) |
415 | if env and setfenv then | 436 | if env and setfenv then |
416 | setfenv(chunk, env) | 437 | setfenv(chunk, env) |
417 | end | 438 | end |