aboutsummaryrefslogtreecommitdiff
path: root/spec/build_spec.lua
diff options
context:
space:
mode:
authorGeorge Roman <george.roman.99@gmail.com>2018-06-18 18:57:47 +0300
committerHisham Muhammad <hisham@gobolinux.org>2018-06-21 23:33:00 -0300
commitbdfe731a601f3d12ffafbf504c9b06d70d5aa819 (patch)
treeb6b94d398ba01fb9345d05b55c0bf2a93801cb2a /spec/build_spec.lua
parent48ae1d2e7705af6a7527ca61710fe18ccdb7d0b9 (diff)
downloadluarocks-bdfe731a601f3d12ffafbf504c9b06d70d5aa819.tar.gz
luarocks-bdfe731a601f3d12ffafbf504c9b06d70d5aa819.tar.bz2
luarocks-bdfe731a601f3d12ffafbf504c9b06d70d5aa819.zip
Tests: replace small fixture files with inline content
Diffstat (limited to 'spec/build_spec.lua')
-rw-r--r--spec/build_spec.lua99
1 files changed, 90 insertions, 9 deletions
diff --git a/spec/build_spec.lua b/spec/build_spec.lua
index ae559654..74efccd5 100644
--- a/spec/build_spec.lua
+++ b/spec/build_spec.lua
@@ -1,7 +1,9 @@
1local test_env = require("spec.util.test_env") 1local test_env = require("spec.util.test_env")
2local lfs = require("lfs") 2local lfs = require("lfs")
3local get_tmp_path = test_env.get_tmp_path
3local run = test_env.run 4local run = test_env.run
4local testing_paths = test_env.testing_paths 5local testing_paths = test_env.testing_paths
6local write_file = test_env.write_file
5 7
6test_env.unload_luarocks() 8test_env.unload_luarocks()
7 9
@@ -40,12 +42,35 @@ describe("LuaRocks build tests #integration", function()
40 end) 42 end)
41 43
42 it("LuaRocks build with no arguments behaves as luarocks make", function() 44 it("LuaRocks build with no arguments behaves as luarocks make", function()
43 local tmpdir = test_env.get_tmp_path()
44 lfs.mkdir(tmpdir)
45 local olddir = lfs.currentdir() 45 local olddir = lfs.currentdir()
46 local tmpdir = get_tmp_path()
47 lfs.mkdir(tmpdir)
46 lfs.chdir(tmpdir) 48 lfs.chdir(tmpdir)
47 test_env.copy(testing_paths.fixtures_dir .. "/c_module-1.0-1.rockspec", tmpdir .. "/c_module-1.0-1.rockspec") 49
48 test_env.copy(testing_paths.fixtures_dir .. "/c_module.c", tmpdir .. "/c_module.c") 50 write_file("c_module-1.0-1.rockspec", [[
51 package = "c_module"
52 version = "1.0-1"
53 source = {
54 url = "http://example.com/c_module"
55 }
56 build = {
57 type = "builtin",
58 modules = {
59 c_module = { "c_module.c" }
60 }
61 }
62 ]], finally)
63 write_file("c_module.c", [[
64 #include <lua.h>
65 #include <lauxlib.h>
66
67 int luaopen_c_module(lua_State* L) {
68 lua_newtable(L);
69 lua_pushinteger(L, 1);
70 lua_setfield(L, -2, "c_module");
71 return 1;
72 }
73 ]], finally)
49 74
50 assert.is_true(run.luarocks_bool("build")) 75 assert.is_true(run.luarocks_bool("build"))
51 if test_env.TEST_TARGET_OS == "windows" then 76 if test_env.TEST_TARGET_OS == "windows" then
@@ -245,6 +270,32 @@ describe("LuaRocks build tests #integration", function()
245 end) 270 end)
246 271
247 describe("rockspec format 3.0 #rs3", function() 272 describe("rockspec format 3.0 #rs3", function()
273 local tmpdir
274 local olddir
275
276 before_each(function()
277 tmpdir = get_tmp_path()
278 olddir = lfs.currentdir()
279 lfs.mkdir(tmpdir)
280 lfs.chdir(tmpdir)
281
282 lfs.mkdir("autodetect")
283 write_file("autodetect/bla.lua", "return {}", finally)
284 write_file("c_module.c", [[
285
286 ]], finally)
287 end)
288
289 after_each(function()
290 if olddir then
291 lfs.chdir(olddir)
292 if tmpdir then
293 lfs.rmdir("autodetect")
294 lfs.rmdir(tmpdir)
295 end
296 end
297 end)
298
248 it("defaults to build.type == 'builtin'", function() 299 it("defaults to build.type == 'builtin'", function()
249 local rockspec = "a_rock-1.0-1.rockspec" 300 local rockspec = "a_rock-1.0-1.rockspec"
250 test_env.write_file(rockspec, [[ 301 test_env.write_file(rockspec, [[
@@ -277,7 +328,7 @@ describe("LuaRocks build tests #integration", function()
277 package = "autodetect" 328 package = "autodetect"
278 version = "1.0-1" 329 version = "1.0-1"
279 source = { 330 source = {
280 url = "file://]] .. testing_paths.fixtures_dir .. [[/autodetect/bla.lua" 331 url = "file://autodetect/bla.lua"
281 } 332 }
282 description = { 333 description = {
283 summary = "An example rockspec", 334 summary = "An example rockspec",
@@ -299,7 +350,7 @@ describe("LuaRocks build tests #integration", function()
299 package = "autodetect" 350 package = "autodetect"
300 version = "1.0-1" 351 version = "1.0-1"
301 source = { 352 source = {
302 url = "file://]] .. testing_paths.fixtures_dir .. [[/autodetect/bla.lua" 353 url = "file://autodetect/bla.lua"
303 } 354 }
304 description = { 355 description = {
305 summary = "An example rockspec", 356 summary = "An example rockspec",
@@ -319,7 +370,7 @@ describe("LuaRocks build tests #integration", function()
319 package = "autodetect" 370 package = "autodetect"
320 version = "1.0-1" 371 version = "1.0-1"
321 source = { 372 source = {
322 url = "file://]] .. testing_paths.fixtures_dir .. [[/c_module.c" 373 url = "file://c_module.c"
323 } 374 }
324 description = { 375 description = {
325 summary = "An example rockspec", 376 summary = "An example rockspec",
@@ -348,9 +399,39 @@ describe("LuaRocks build tests #integration", function()
348 teardown(function() 399 teardown(function()
349 test_env.mock_server_done() 400 test_env.mock_server_done()
350 end) 401 end)
351 402
352 it("fails when missing external dependency", function() 403 it("fails when missing external dependency", function()
353 assert.is_false(run.luarocks_bool("build " .. testing_paths.fixtures_dir .. "/missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\"")) 404 local tmpdir = get_tmp_path()
405 local olddir = lfs.currentdir()
406 lfs.mkdir(tmpdir)
407 lfs.chdir(tmpdir)
408
409 write_file("missing_external-0.1-1.rockspec", [[
410 package = "missing_external"
411 version = "0.1-1"
412 source = {
413 url = "https://example.com/build.lua"
414 }
415 external_dependencies = {
416 INEXISTENT = {
417 library = "inexistentlib*",
418 header = "inexistentheader*.h",
419 }
420 }
421 dependencies = {
422 "lua >= 5.1"
423 }
424 build = {
425 type = "builtin",
426 modules = {
427 build = "build.lua"
428 }
429 }
430 ]], finally)
431 assert.is_false(run.luarocks_bool("build missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\""))
432
433 lfs.chdir(olddir)
434 lfs.rmdir(tmpdir)
354 end) 435 end)
355 436
356 it("builds with external dependency", function() 437 it("builds with external dependency", function()