aboutsummaryrefslogtreecommitdiff
path: root/spec/unit/deps_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/deps_spec.lua')
-rw-r--r--spec/unit/deps_spec.lua144
1 files changed, 144 insertions, 0 deletions
diff --git a/spec/unit/deps_spec.lua b/spec/unit/deps_spec.lua
new file mode 100644
index 00000000..b8c89a2d
--- /dev/null
+++ b/spec/unit/deps_spec.lua
@@ -0,0 +1,144 @@
1local test_env = require("spec.util.test_env")
2local testing_paths = test_env.testing_paths
3
4local cfg = require("luarocks.core.cfg")
5local deps = require("luarocks.deps")
6local fs = require("luarocks.fs")
7
8describe("LuaRocks deps #unit", function()
9 local runner
10
11 lazy_setup(function()
12 cfg.init()
13 fs.init()
14 deps.check_lua_incdir(cfg.variables)
15 deps.check_lua_libdir(cfg.variables)
16
17 runner = require("luacov.runner")
18 runner.init(testing_paths.testrun_dir .. "/luacov.config")
19 runner.tick = true
20 end)
21
22 lazy_teardown(function()
23 runner.shutdown()
24 end)
25
26 describe("deps", function()
27 describe("deps.autodetect_external_dependencies", function()
28 it("returns false if the given build table has no external dependencies", function()
29 local build_table = {
30 type = "builtin"
31 }
32
33 assert.falsy(deps.autodetect_external_dependencies(build_table))
34 end)
35
36 it("returns a table of the external dependencies found in the given build table", function()
37 local build_table = {
38 type = "builtin",
39 modules = {
40 module1 = {
41 libraries = { "foo1", "foo2" },
42 },
43 module2 = {
44 libraries = "foo3"
45 },
46 }
47 }
48
49 local extdeps = deps.autodetect_external_dependencies(build_table)
50 assert.same(extdeps["FOO1"], { library = "foo1" })
51 assert.same(extdeps["FOO2"], { library = "foo2" })
52 assert.same(extdeps["FOO3"], { library = "foo3" })
53 end)
54
55 it("adds proper include and library dirs to the given build table", function()
56 local build_table
57
58 build_table = {
59 type = "builtin",
60 modules = {
61 module1 = {
62 libraries = "foo"
63 }
64 }
65 }
66 deps.autodetect_external_dependencies(build_table)
67 assert.same(build_table, {
68 type = "builtin",
69 modules = {
70 module1 = {
71 libraries = "foo",
72 incdirs = { "$(FOO_INCDIR)" },
73 libdirs = { "$(FOO_LIBDIR)" }
74 }
75 }
76 })
77
78 build_table = {
79 type = "builtin",
80 modules = {
81 module1 = {
82 libraries = "foo",
83 incdirs = { "INCDIRS" }
84 }
85 }
86 }
87 deps.autodetect_external_dependencies(build_table)
88 assert.same(build_table, {
89 type = "builtin",
90 modules = {
91 module1 = {
92 libraries = "foo",
93 incdirs = { "INCDIRS" },
94 libdirs = { "$(FOO_LIBDIR)" }
95 }
96 }
97 })
98
99 build_table = {
100 type = "builtin",
101 modules = {
102 module1 = {
103 libraries = "foo",
104 libdirs = { "LIBDIRS" }
105 }
106 }
107 }
108 deps.autodetect_external_dependencies(build_table)
109 assert.same(build_table, {
110 type = "builtin",
111 modules = {
112 module1 = {
113 libraries = "foo",
114 incdirs = { "$(FOO_INCDIR)" },
115 libdirs = { "LIBDIRS" }
116 }
117 }
118 })
119
120 build_table = {
121 type = "builtin",
122 modules = {
123 module1 = {
124 libraries = "foo",
125 incdirs = { "INCDIRS" },
126 libdirs = { "LIBDIRS" }
127 }
128 }
129 }
130 deps.autodetect_external_dependencies(build_table)
131 assert.same(build_table, {
132 type = "builtin",
133 modules = {
134 module1 = {
135 libraries = "foo",
136 incdirs = { "INCDIRS" },
137 libdirs = { "LIBDIRS" }
138 }
139 }
140 })
141 end)
142 end)
143 end)
144end)