diff options
author | George Roman <george.roman.99@gmail.com> | 2018-07-24 11:09:42 +0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-24 15:41:22 -0300 |
commit | 8e6a83911027de167d689d060ce581f653d73213 (patch) | |
tree | 622218f964f10a27b7922bcfcd3bf14fd6c1735b /spec/build_spec.lua | |
parent | 961670659be3e986bc74b9b8c2a296f4640302e5 (diff) | |
download | luarocks-8e6a83911027de167d689d060ce581f653d73213.tar.gz luarocks-8e6a83911027de167d689d060ce581f653d73213.tar.bz2 luarocks-8e6a83911027de167d689d060ce581f653d73213.zip |
Tests: add test_env.run_in_tmp utility function
Diffstat (limited to 'spec/build_spec.lua')
-rw-r--r-- | spec/build_spec.lua | 336 |
1 files changed, 147 insertions, 189 deletions
diff --git a/spec/build_spec.lua b/spec/build_spec.lua index 62fbb353..4bf0d96c 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua | |||
@@ -54,31 +54,25 @@ describe("LuaRocks build tests #integration", function() | |||
54 | end) | 54 | end) |
55 | 55 | ||
56 | it("LuaRocks build with no arguments behaves as luarocks make", function() | 56 | it("LuaRocks build with no arguments behaves as luarocks make", function() |
57 | local olddir = lfs.currentdir() | 57 | test_env.run_in_tmp(function(tmpdir) |
58 | local tmpdir = get_tmp_path() | 58 | write_file("c_module-1.0-1.rockspec", [[ |
59 | lfs.mkdir(tmpdir) | 59 | package = "c_module" |
60 | lfs.chdir(tmpdir) | 60 | version = "1.0-1" |
61 | 61 | source = { | |
62 | write_file("c_module-1.0-1.rockspec", [[ | 62 | url = "http://example.com/c_module" |
63 | package = "c_module" | ||
64 | version = "1.0-1" | ||
65 | source = { | ||
66 | url = "http://example.com/c_module" | ||
67 | } | ||
68 | build = { | ||
69 | type = "builtin", | ||
70 | modules = { | ||
71 | c_module = { "c_module.c" } | ||
72 | } | 63 | } |
73 | } | 64 | build = { |
74 | ]], finally) | 65 | type = "builtin", |
75 | write_file("c_module.c", c_module_source, finally) | 66 | modules = { |
76 | 67 | c_module = { "c_module.c" } | |
77 | assert.is_true(run.luarocks_bool("build")) | 68 | } |
78 | assert.truthy(lfs.attributes(tmpdir .. "/c_module." .. test_env.lib_extension)) | 69 | } |
79 | 70 | ]], finally) | |
80 | lfs.chdir(olddir) | 71 | write_file("c_module.c", c_module_source, finally) |
81 | lfs.rmdir(tmpdir) | 72 | |
73 | assert.is_true(run.luarocks_bool("build")) | ||
74 | assert.truthy(lfs.attributes(tmpdir .. "/c_module." .. test_env.lib_extension)) | ||
75 | end, finally) | ||
82 | end) | 76 | end) |
83 | end) | 77 | end) |
84 | 78 | ||
@@ -94,31 +88,25 @@ describe("LuaRocks build tests #integration", function() | |||
94 | end) | 88 | end) |
95 | 89 | ||
96 | it("LuaRocks build verbose", function() | 90 | it("LuaRocks build verbose", function() |
97 | local olddir = lfs.currentdir() | 91 | test_env.run_in_tmp(function(tmpdir) |
98 | local tmpdir = get_tmp_path() | 92 | write_file("test-1.0-1.rockspec", [[ |
99 | lfs.mkdir(tmpdir) | 93 | package = "test" |
100 | lfs.chdir(tmpdir) | 94 | version = "1.0-1" |
101 | 95 | source = { | |
102 | write_file("test-1.0-1.rockspec", [[ | 96 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" |
103 | package = "test" | ||
104 | version = "1.0-1" | ||
105 | source = { | ||
106 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
107 | } | ||
108 | build = { | ||
109 | type = "builtin", | ||
110 | modules = { | ||
111 | test = "test.lua" | ||
112 | } | 97 | } |
113 | } | 98 | build = { |
114 | ]], finally) | 99 | type = "builtin", |
115 | write_file("test.lua", "return {}", finally) | 100 | modules = { |
116 | 101 | test = "test.lua" | |
117 | assert.is_true(run.luarocks_bool("build --verbose test-1.0-1.rockspec")) | 102 | } |
118 | assert.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) | 103 | } |
104 | ]], finally) | ||
105 | write_file("test.lua", "return {}", finally) | ||
119 | 106 | ||
120 | lfs.chdir(olddir) | 107 | assert.is_true(run.luarocks_bool("build --verbose test-1.0-1.rockspec")) |
121 | lfs.rmdir(tmpdir) | 108 | assert.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) |
109 | end, finally) | ||
122 | end) | 110 | end) |
123 | 111 | ||
124 | it("LuaRocks build lpeg branch=master", function() | 112 | it("LuaRocks build lpeg branch=master", function() |
@@ -163,70 +151,58 @@ describe("LuaRocks build tests #integration", function() | |||
163 | end) | 151 | end) |
164 | 152 | ||
165 | it("LuaRocks build fails if the current platform is not supported", function() | 153 | it("LuaRocks build fails if the current platform is not supported", function() |
166 | local olddir = lfs.currentdir() | 154 | test_env.run_in_tmp(function(tmpdir) |
167 | local tmpdir = get_tmp_path() | 155 | write_file("test-1.0-1.rockspec", [[ |
168 | lfs.mkdir(tmpdir) | 156 | package = "test" |
169 | lfs.chdir(tmpdir) | 157 | version = "1.0-1" |
170 | 158 | source = { | |
171 | write_file("test-1.0-1.rockspec", [[ | 159 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" |
172 | package = "test" | ||
173 | version = "1.0-1" | ||
174 | source = { | ||
175 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
176 | } | ||
177 | supported_platforms = { | ||
178 | "unix", "macosx" | ||
179 | } | ||
180 | build = { | ||
181 | type = "builtin", | ||
182 | modules = { | ||
183 | test = "test.lua" | ||
184 | } | 160 | } |
185 | } | 161 | supported_platforms = { |
186 | ]], finally) | 162 | "unix", "macosx" |
187 | write_file("test.lua", "return {}", finally) | 163 | } |
188 | 164 | build = { | |
189 | if test_env.TEST_TARGET_OS == "windows" then | 165 | type = "builtin", |
190 | assert.is_false(run.luarocks_bool("build test-1.0-1.rockspec")) -- Error: This rockspec does not support windows platforms | 166 | modules = { |
191 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) | 167 | test = "test.lua" |
192 | else | 168 | } |
193 | assert.is_true(run.luarocks_bool("build test-1.0-1.rockspec")) | 169 | } |
194 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) | 170 | ]], finally) |
195 | end | 171 | write_file("test.lua", "return {}", finally) |
196 | 172 | ||
197 | lfs.chdir(olddir) | 173 | if test_env.TEST_TARGET_OS == "windows" then |
198 | lfs.rmdir(tmpdir) | 174 | assert.is_false(run.luarocks_bool("build test-1.0-1.rockspec")) -- Error: This rockspec does not support windows platforms |
175 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) | ||
176 | else | ||
177 | assert.is_true(run.luarocks_bool("build test-1.0-1.rockspec")) | ||
178 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) | ||
179 | end | ||
180 | end, finally) | ||
199 | end) | 181 | end) |
200 | 182 | ||
201 | it("LuaRocks build with skipping dependency checks", function() | 183 | it("LuaRocks build with skipping dependency checks", function() |
202 | local olddir = lfs.currentdir() | 184 | test_env.run_in_tmp(function(tmpdir) |
203 | local tmpdir = get_tmp_path() | 185 | write_file("test-1.0-1.rockspec", [[ |
204 | lfs.mkdir(tmpdir) | 186 | package = "test" |
205 | lfs.chdir(tmpdir) | 187 | version = "1.0-1" |
206 | 188 | source = { | |
207 | write_file("test-1.0-1.rockspec", [[ | 189 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" |
208 | package = "test" | ||
209 | version = "1.0-1" | ||
210 | source = { | ||
211 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
212 | } | ||
213 | dependencies = { | ||
214 | "a_rock 1.0" | ||
215 | } | ||
216 | build = { | ||
217 | type = "builtin", | ||
218 | modules = { | ||
219 | test = "test.lua" | ||
220 | } | 190 | } |
221 | } | 191 | dependencies = { |
222 | ]], finally) | 192 | "a_rock 1.0" |
223 | write_file("test.lua", "return {}", finally) | 193 | } |
224 | 194 | build = { | |
225 | assert.is_true(run.luarocks_bool("build test-1.0-1.rockspec --deps-mode=none")) | 195 | type = "builtin", |
226 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) | 196 | modules = { |
197 | test = "test.lua" | ||
198 | } | ||
199 | } | ||
200 | ]], finally) | ||
201 | write_file("test.lua", "return {}", finally) | ||
227 | 202 | ||
228 | lfs.chdir(olddir) | 203 | assert.is_true(run.luarocks_bool("build test-1.0-1.rockspec --deps-mode=none")) |
229 | lfs.rmdir(tmpdir) | 204 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) |
205 | end) | ||
230 | end) | 206 | end) |
231 | 207 | ||
232 | it("LuaRocks build lmathx deps partial match", function() | 208 | it("LuaRocks build lmathx deps partial match", function() |
@@ -291,70 +267,58 @@ describe("LuaRocks build tests #integration", function() | |||
291 | end) | 267 | end) |
292 | 268 | ||
293 | it("LuaRocks build only deps of a given rockspec", function() | 269 | it("LuaRocks build only deps of a given rockspec", function() |
294 | local olddir = lfs.currentdir() | 270 | test_env.run_in_tmp(function(tmpdir) |
295 | local tmpdir = get_tmp_path() | 271 | write_file("test-1.0-1.rockspec", [[ |
296 | lfs.mkdir(tmpdir) | 272 | package = "test" |
297 | lfs.chdir(tmpdir) | 273 | version = "1.0-1" |
298 | 274 | source = { | |
299 | write_file("test-1.0-1.rockspec", [[ | 275 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" |
300 | package = "test" | ||
301 | version = "1.0-1" | ||
302 | source = { | ||
303 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
304 | } | ||
305 | dependencies = { | ||
306 | "a_rock 1.0" | ||
307 | } | ||
308 | build = { | ||
309 | type = "builtin", | ||
310 | modules = { | ||
311 | test = "test.lua" | ||
312 | } | 276 | } |
313 | } | 277 | dependencies = { |
314 | ]], finally) | 278 | "a_rock 1.0" |
315 | write_file("test.lua", "return {}", finally) | 279 | } |
316 | 280 | build = { | |
317 | assert.is.truthy(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --only-deps")) | 281 | type = "builtin", |
318 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) | 282 | modules = { |
319 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) | 283 | test = "test.lua" |
284 | } | ||
285 | } | ||
286 | ]], finally) | ||
287 | write_file("test.lua", "return {}", finally) | ||
320 | 288 | ||
321 | lfs.chdir(olddir) | 289 | assert.is.truthy(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --only-deps")) |
322 | lfs.rmdir(tmpdir) | 290 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) |
291 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) | ||
292 | end, finally) | ||
323 | end) | 293 | end) |
324 | 294 | ||
325 | it("LuaRocks build only deps of a given rock", function() | 295 | it("LuaRocks build only deps of a given rock", function() |
326 | local olddir = lfs.currentdir() | 296 | test_env.run_in_tmp(function(tmpdir) |
327 | local tmpdir = get_tmp_path() | 297 | write_file("test-1.0-1.rockspec", [[ |
328 | lfs.mkdir(tmpdir) | 298 | package = "test" |
329 | lfs.chdir(tmpdir) | 299 | version = "1.0-1" |
330 | 300 | source = { | |
331 | write_file("test-1.0-1.rockspec", [[ | 301 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" |
332 | package = "test" | ||
333 | version = "1.0-1" | ||
334 | source = { | ||
335 | url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" | ||
336 | } | ||
337 | dependencies = { | ||
338 | "a_rock 1.0" | ||
339 | } | ||
340 | build = { | ||
341 | type = "builtin", | ||
342 | modules = { | ||
343 | test = "test.lua" | ||
344 | } | 302 | } |
345 | } | 303 | dependencies = { |
346 | ]], finally) | 304 | "a_rock 1.0" |
347 | write_file("test.lua", "return {}", finally) | 305 | } |
348 | 306 | build = { | |
349 | assert.is.truthy(run.luarocks_bool("pack test-1.0-1.rockspec")) | 307 | type = "builtin", |
350 | assert.is.truthy(lfs.attributes("test-1.0-1.src.rock")) | 308 | modules = { |
309 | test = "test.lua" | ||
310 | } | ||
311 | } | ||
312 | ]], finally) | ||
313 | write_file("test.lua", "return {}", finally) | ||
351 | 314 | ||
352 | assert.is.truthy(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.src.rock --only-deps")) | 315 | assert.is.truthy(run.luarocks_bool("pack test-1.0-1.rockspec")) |
353 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) | 316 | assert.is.truthy(lfs.attributes("test-1.0-1.src.rock")) |
354 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) | ||
355 | 317 | ||
356 | lfs.chdir(olddir) | 318 | assert.is.truthy(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.src.rock --only-deps")) |
357 | lfs.rmdir(tmpdir) | 319 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) |
320 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) | ||
321 | end, finally) | ||
358 | end) | 322 | end) |
359 | 323 | ||
360 | it("LuaRocks build with https", function() | 324 | it("LuaRocks build with https", function() |
@@ -480,37 +444,31 @@ describe("LuaRocks build tests #integration", function() | |||
480 | end) | 444 | end) |
481 | 445 | ||
482 | it("fails when missing external dependency", function() | 446 | it("fails when missing external dependency", function() |
483 | local tmpdir = get_tmp_path() | 447 | test_env.run_in_tmp(function(tmpdir) |
484 | local olddir = lfs.currentdir() | 448 | write_file("missing_external-0.1-1.rockspec", [[ |
485 | lfs.mkdir(tmpdir) | 449 | package = "missing_external" |
486 | lfs.chdir(tmpdir) | 450 | version = "0.1-1" |
487 | 451 | source = { | |
488 | write_file("missing_external-0.1-1.rockspec", [[ | 452 | url = "https://example.com/build.lua" |
489 | package = "missing_external" | ||
490 | version = "0.1-1" | ||
491 | source = { | ||
492 | url = "https://example.com/build.lua" | ||
493 | } | ||
494 | external_dependencies = { | ||
495 | INEXISTENT = { | ||
496 | library = "inexistentlib*", | ||
497 | header = "inexistentheader*.h", | ||
498 | } | 453 | } |
499 | } | 454 | external_dependencies = { |
500 | dependencies = { | 455 | INEXISTENT = { |
501 | "lua >= 5.1" | 456 | library = "inexistentlib*", |
502 | } | 457 | header = "inexistentheader*.h", |
503 | build = { | 458 | } |
504 | type = "builtin", | ||
505 | modules = { | ||
506 | build = "build.lua" | ||
507 | } | 459 | } |
508 | } | 460 | dependencies = { |
509 | ]], finally) | 461 | "lua >= 5.1" |
510 | assert.is_false(run.luarocks_bool("build missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\"")) | 462 | } |
511 | 463 | build = { | |
512 | lfs.chdir(olddir) | 464 | type = "builtin", |
513 | lfs.rmdir(tmpdir) | 465 | modules = { |
466 | build = "build.lua" | ||
467 | } | ||
468 | } | ||
469 | ]], finally) | ||
470 | assert.is_false(run.luarocks_bool("build missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\"")) | ||
471 | end, finally) | ||
514 | end) | 472 | end) |
515 | 473 | ||
516 | it("builds with external dependency", function() | 474 | it("builds with external dependency", function() |