From 9c7e9fed578b58fff14e7a3dd95bdad62ff6ab31 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 6 Nov 2017 18:11:38 -0200 Subject: Tests: build using INCDIR for an external dependency --- spec/build_spec.lua | 26 ++++++++++++++++++++---- test/testfiles/with_external_dep-0.1-1.rockspec | 25 +++++++++++++++++++++++ test/testfiles/with_external_dep.c | 10 +++++++++ test/testfiles/with_external_dep/foo/foo.h | 1 + test/testfiles/with_external_dep/foo/foo.h.gch | Bin 0 -> 1503664 bytes 5 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 test/testfiles/with_external_dep-0.1-1.rockspec create mode 100644 test/testfiles/with_external_dep.c create mode 100644 test/testfiles/with_external_dep/foo/foo.h create mode 100644 test/testfiles/with_external_dep/foo/foo.h.gch diff --git a/spec/build_spec.lua b/spec/build_spec.lua index ffae144d..c6d5f717 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -189,12 +189,30 @@ describe("LuaRocks build tests #blackbox #b_build", function() assert.is_true(os.remove("validate-args-1.5.4-1.rockspec")) end) - it("LuaRocks build missing external", function() - assert.is_false(run.luarocks_bool("build " .. testing_paths.testing_dir .. "/testfiles/missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\"")) - end) - it("LuaRocks build invalid patch", function() assert.is_false(run.luarocks_bool("build " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) end) end) + + describe("external dependencies", function() + setup(function() + test_env.mock_server_init() + end) + + teardown(function() + test_env.mock_server_done() + end) + + it("fails when missing external dependency", function() + assert.is_false(run.luarocks_bool("build " .. testing_paths.testing_dir .. "/testfiles/missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\"")) + end) + + it("builds with external dependency", function() + local rockspec = testing_paths.testing_dir .. "/testfiles/with_external_dep-0.1-1.rockspec" + local foo_incdir = testing_paths.testing_dir .. "/testfiles/with_external_dep" + assert.is_truthy(run.luarocks_bool("build " .. rockspec .. " FOO_INCDIR=\"" .. foo_incdir .. "\"")) + assert.is.truthy(run.luarocks("show with_external_dep")) + end) + end) + end) diff --git a/test/testfiles/with_external_dep-0.1-1.rockspec b/test/testfiles/with_external_dep-0.1-1.rockspec new file mode 100644 index 00000000..45fea4bd --- /dev/null +++ b/test/testfiles/with_external_dep-0.1-1.rockspec @@ -0,0 +1,25 @@ +package = "with_external_dep" +version = "0.1-1" +source = { + url = "http://localhost:8080/file/with_external_dep.c" +} +description = { + summary = "An example rockspec", +} +external_dependencies = { + FOO = { + header = "foo/foo.h" + } +} +dependencies = { + "lua >= 5.1" +} +build = { + type = "builtin", + modules = { + with_external_dep = { + sources = "with_external_dep.c", + incdirs = "$(FOO_INCDIR)", + } + } +} diff --git a/test/testfiles/with_external_dep.c b/test/testfiles/with_external_dep.c new file mode 100644 index 00000000..16435d8f --- /dev/null +++ b/test/testfiles/with_external_dep.c @@ -0,0 +1,10 @@ +#include +#include +#include + +int luaopen_with_external_dep(lua_State* L) { + lua_newtable(L); + lua_pushinteger(L, FOO); + lua_setfield(L, -2, "foo"); + return 1; +} diff --git a/test/testfiles/with_external_dep/foo/foo.h b/test/testfiles/with_external_dep/foo/foo.h new file mode 100644 index 00000000..eedd558f --- /dev/null +++ b/test/testfiles/with_external_dep/foo/foo.h @@ -0,0 +1 @@ +#define FOO 42 diff --git a/test/testfiles/with_external_dep/foo/foo.h.gch b/test/testfiles/with_external_dep/foo/foo.h.gch new file mode 100644 index 00000000..66165c9e Binary files /dev/null and b/test/testfiles/with_external_dep/foo/foo.h.gch differ -- cgit v1.2.3-55-g6feb