diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-26 18:30:31 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-27 13:28:33 -0300 |
commit | 03e401231972d7b4db0145a71ce74d5d18d1a901 (patch) | |
tree | 10e59cd4fe0065ec87db0699965bb5e2f0436d74 /spec | |
parent | 5b2e63e6b087bdf626dd7cef319d6ba29f5e197c (diff) | |
download | luarocks-03e401231972d7b4db0145a71ce74d5d18d1a901.tar.gz luarocks-03e401231972d7b4db0145a71ce74d5d18d1a901.tar.bz2 luarocks-03e401231972d7b4db0145a71ce74d5d18d1a901.zip |
tests: reorganize and speed up unit tests
Diffstat (limited to 'spec')
46 files changed, 743 insertions, 736 deletions
diff --git a/spec/README.md b/spec/README.md index b55550e6..89e13ea1 100644 --- a/spec/README.md +++ b/spec/README.md | |||
@@ -5,7 +5,7 @@ | |||
5 | 5 | ||
6 | Test suite for LuaRocks project with Busted unit testing framework(http://olivinelabs.com/busted/). | 6 | Test suite for LuaRocks project with Busted unit testing framework(http://olivinelabs.com/busted/). |
7 | 7 | ||
8 | * Contains unit & integration tests | 8 | * Contains unit and integration tests |
9 | * Easy setup for your purpose on command line or from configuration file | 9 | * Easy setup for your purpose on command line or from configuration file |
10 | 10 | ||
11 | ## Dependencies | 11 | ## Dependencies |
diff --git a/spec/add_spec.lua b/spec/add_spec.lua index b17cadac..0a345753 100644 --- a/spec/add_spec.lua +++ b/spec/add_spec.lua | |||
@@ -2,8 +2,6 @@ local test_env = require("spec.util.test_env") | |||
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | local testing_paths = test_env.testing_paths | 3 | local testing_paths = test_env.testing_paths |
4 | 4 | ||
5 | test_env.unload_luarocks() | ||
6 | |||
7 | local extra_rocks = { | 5 | local extra_rocks = { |
8 | "/luasocket-${LUASOCKET}.src.rock", | 6 | "/luasocket-${LUASOCKET}.src.rock", |
9 | "/luasocket-${LUASOCKET}.rockspec" | 7 | "/luasocket-${LUASOCKET}.rockspec" |
diff --git a/spec/build_spec.lua b/spec/build_spec.lua index a2c09119..d07447c1 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua | |||
@@ -6,9 +6,7 @@ local testing_paths = test_env.testing_paths | |||
6 | local write_file = test_env.write_file | 6 | local write_file = test_env.write_file |
7 | local git_repo = require("spec.util.git_repo") | 7 | local git_repo = require("spec.util.git_repo") |
8 | 8 | ||
9 | test_env.unload_luarocks() | 9 | local cfg, fs |
10 | local cfg = require("luarocks.core.cfg") | ||
11 | local fs = require("luarocks.fs") | ||
12 | 10 | ||
13 | local extra_rocks = { | 11 | local extra_rocks = { |
14 | "/lmathx-20120430.51-1.src.rock", | 12 | "/lmathx-20120430.51-1.src.rock", |
@@ -40,13 +38,12 @@ local c_module_source = [[ | |||
40 | ]] | 38 | ]] |
41 | 39 | ||
42 | describe("LuaRocks build #integration", function() | 40 | describe("LuaRocks build #integration", function() |
43 | lazy_setup(function() | ||
44 | cfg.init() | ||
45 | fs.init() | ||
46 | end) | ||
47 | |||
48 | before_each(function() | 41 | before_each(function() |
49 | test_env.setup_specs(extra_rocks) | 42 | test_env.setup_specs(extra_rocks) |
43 | cfg = require("luarocks.core.cfg") | ||
44 | fs = require("luarocks.fs") | ||
45 | cfg.init() | ||
46 | fs.init() | ||
50 | end) | 47 | end) |
51 | 48 | ||
52 | describe("building with flags", function() | 49 | describe("building with flags", function() |
@@ -154,7 +151,7 @@ describe("LuaRocks build #integration", function() | |||
154 | 151 | ||
155 | assert.is_true(run.luarocks_bool("build test-1.0-1.rockspec --deps-mode=none")) | 152 | assert.is_true(run.luarocks_bool("build test-1.0-1.rockspec --deps-mode=none")) |
156 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) | 153 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) |
157 | end) | 154 | end, finally) |
158 | end) | 155 | end) |
159 | 156 | ||
160 | it("supports --pin #pinning", function() | 157 | it("supports --pin #pinning", function() |
@@ -459,6 +456,7 @@ describe("LuaRocks build #integration", function() | |||
459 | 456 | ||
460 | describe("#mock external dependencies", function() | 457 | describe("#mock external dependencies", function() |
461 | lazy_setup(function() | 458 | lazy_setup(function() |
459 | test_env.setup_specs(nil, "mock") | ||
462 | test_env.mock_server_init() | 460 | test_env.mock_server_init() |
463 | end) | 461 | end) |
464 | 462 | ||
diff --git a/spec/cmd_spec.lua b/spec/cmd_spec.lua index 5d6e729b..9067a160 100644 --- a/spec/cmd_spec.lua +++ b/spec/cmd_spec.lua | |||
@@ -2,11 +2,9 @@ local test_env = require("spec.util.test_env") | |||
2 | local lfs = require("lfs") | 2 | local lfs = require("lfs") |
3 | local run = test_env.run | 3 | local run = test_env.run |
4 | 4 | ||
5 | test_env.unload_luarocks() | ||
6 | |||
7 | describe("LuaRocks command line #integration", function() | 5 | describe("LuaRocks command line #integration", function() |
8 | 6 | ||
9 | setup(function() | 7 | lazy_setup(function() |
10 | test_env.setup_specs() | 8 | test_env.setup_specs() |
11 | end) | 9 | end) |
12 | 10 | ||
diff --git a/spec/config_spec.lua b/spec/config_spec.lua index 9615f050..6bfac433 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua | |||
@@ -7,13 +7,11 @@ local write_file = test_env.write_file | |||
7 | local get_tmp_path = test_env.get_tmp_path | 7 | local get_tmp_path = test_env.get_tmp_path |
8 | local hardcoded | 8 | local hardcoded |
9 | 9 | ||
10 | test_env.unload_luarocks() | ||
11 | |||
12 | describe("LuaRocks config tests #integration", function() | 10 | describe("LuaRocks config tests #integration", function() |
13 | 11 | ||
14 | setup(function() | 12 | lazy_setup(function() |
15 | test_env.setup_specs() | 13 | test_env.setup_specs() |
16 | test_env.unload_luarocks() -- need to be required here, because hardcoded is created after first loading of specs | 14 | -- needs to be required here, because hardcoded is created after first loading of specs |
17 | hardcoded = require("luarocks.core.hardcoded") | 15 | hardcoded = require("luarocks.core.hardcoded") |
18 | end) | 16 | end) |
19 | 17 | ||
diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua index 32f68f51..dd8fea64 100644 --- a/spec/deps_spec.lua +++ b/spec/deps_spec.lua | |||
@@ -3,8 +3,6 @@ local lfs = require("lfs") | |||
3 | local run = test_env.run | 3 | local run = test_env.run |
4 | local testing_paths = test_env.testing_paths | 4 | local testing_paths = test_env.testing_paths |
5 | 5 | ||
6 | test_env.unload_luarocks() | ||
7 | |||
8 | local extra_rocks = { | 6 | local extra_rocks = { |
9 | "/lxsh-${LXSH}.src.rock", | 7 | "/lxsh-${LXSH}.src.rock", |
10 | "/lxsh-${LXSH}.rockspec", | 8 | "/lxsh-${LXSH}.rockspec", |
@@ -116,146 +114,3 @@ describe("LuaRocks deps-mode #integration", function() | |||
116 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) | 114 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) |
117 | end) | 115 | end) |
118 | end) | 116 | end) |
119 | |||
120 | test_env.unload_luarocks() | ||
121 | test_env.setup_specs() | ||
122 | local cfg = require("luarocks.core.cfg") | ||
123 | local deps = require("luarocks.deps") | ||
124 | local fs = require("luarocks.fs") | ||
125 | |||
126 | describe("LuaRocks deps #unit", function() | ||
127 | local runner | ||
128 | |||
129 | lazy_setup(function() | ||
130 | runner = require("luacov.runner") | ||
131 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | ||
132 | runner.tick = true | ||
133 | cfg.init() | ||
134 | fs.init() | ||
135 | deps.check_lua_incdir(cfg.variables) | ||
136 | deps.check_lua_libdir(cfg.variables) | ||
137 | end) | ||
138 | |||
139 | lazy_teardown(function() | ||
140 | runner.shutdown() | ||
141 | end) | ||
142 | |||
143 | describe("deps", function() | ||
144 | describe("deps.autodetect_external_dependencies", function() | ||
145 | it("returns false if the given build table has no external dependencies", function() | ||
146 | local build_table = { | ||
147 | type = "builtin" | ||
148 | } | ||
149 | |||
150 | assert.falsy(deps.autodetect_external_dependencies(build_table)) | ||
151 | end) | ||
152 | |||
153 | it("returns a table of the external dependencies found in the given build table", function() | ||
154 | local build_table = { | ||
155 | type = "builtin", | ||
156 | modules = { | ||
157 | module1 = { | ||
158 | libraries = { "foo1", "foo2" }, | ||
159 | }, | ||
160 | module2 = { | ||
161 | libraries = "foo3" | ||
162 | }, | ||
163 | } | ||
164 | } | ||
165 | |||
166 | local extdeps = deps.autodetect_external_dependencies(build_table) | ||
167 | assert.same(extdeps["FOO1"], { library = "foo1" }) | ||
168 | assert.same(extdeps["FOO2"], { library = "foo2" }) | ||
169 | assert.same(extdeps["FOO3"], { library = "foo3" }) | ||
170 | end) | ||
171 | |||
172 | it("adds proper include and library dirs to the given build table", function() | ||
173 | local build_table | ||
174 | |||
175 | build_table = { | ||
176 | type = "builtin", | ||
177 | modules = { | ||
178 | module1 = { | ||
179 | libraries = "foo" | ||
180 | } | ||
181 | } | ||
182 | } | ||
183 | deps.autodetect_external_dependencies(build_table) | ||
184 | assert.same(build_table, { | ||
185 | type = "builtin", | ||
186 | modules = { | ||
187 | module1 = { | ||
188 | libraries = "foo", | ||
189 | incdirs = { "$(FOO_INCDIR)" }, | ||
190 | libdirs = { "$(FOO_LIBDIR)" } | ||
191 | } | ||
192 | } | ||
193 | }) | ||
194 | |||
195 | build_table = { | ||
196 | type = "builtin", | ||
197 | modules = { | ||
198 | module1 = { | ||
199 | libraries = "foo", | ||
200 | incdirs = { "INCDIRS" } | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | deps.autodetect_external_dependencies(build_table) | ||
205 | assert.same(build_table, { | ||
206 | type = "builtin", | ||
207 | modules = { | ||
208 | module1 = { | ||
209 | libraries = "foo", | ||
210 | incdirs = { "INCDIRS" }, | ||
211 | libdirs = { "$(FOO_LIBDIR)" } | ||
212 | } | ||
213 | } | ||
214 | }) | ||
215 | |||
216 | build_table = { | ||
217 | type = "builtin", | ||
218 | modules = { | ||
219 | module1 = { | ||
220 | libraries = "foo", | ||
221 | libdirs = { "LIBDIRS" } | ||
222 | } | ||
223 | } | ||
224 | } | ||
225 | deps.autodetect_external_dependencies(build_table) | ||
226 | assert.same(build_table, { | ||
227 | type = "builtin", | ||
228 | modules = { | ||
229 | module1 = { | ||
230 | libraries = "foo", | ||
231 | incdirs = { "$(FOO_INCDIR)" }, | ||
232 | libdirs = { "LIBDIRS" } | ||
233 | } | ||
234 | } | ||
235 | }) | ||
236 | |||
237 | build_table = { | ||
238 | type = "builtin", | ||
239 | modules = { | ||
240 | module1 = { | ||
241 | libraries = "foo", | ||
242 | incdirs = { "INCDIRS" }, | ||
243 | libdirs = { "LIBDIRS" } | ||
244 | } | ||
245 | } | ||
246 | } | ||
247 | deps.autodetect_external_dependencies(build_table) | ||
248 | assert.same(build_table, { | ||
249 | type = "builtin", | ||
250 | modules = { | ||
251 | module1 = { | ||
252 | libraries = "foo", | ||
253 | incdirs = { "INCDIRS" }, | ||
254 | libdirs = { "LIBDIRS" } | ||
255 | } | ||
256 | } | ||
257 | }) | ||
258 | end) | ||
259 | end) | ||
260 | end) | ||
261 | end) | ||
diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua index a10bb501..062b36e7 100644 --- a/spec/doc_spec.lua +++ b/spec/doc_spec.lua | |||
@@ -2,8 +2,6 @@ local test_env = require("spec.util.test_env") | |||
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | local testing_paths = test_env.testing_paths | 3 | local testing_paths = test_env.testing_paths |
4 | 4 | ||
5 | test_env.unload_luarocks() | ||
6 | |||
7 | describe("luarocks doc #integration", function() | 5 | describe("luarocks doc #integration", function() |
8 | before_each(function() | 6 | before_each(function() |
9 | test_env.setup_specs() | 7 | test_env.setup_specs() |
@@ -129,7 +127,7 @@ describe("luarocks doc #integration", function() | |||
129 | end) | 127 | end) |
130 | 128 | ||
131 | it("with --local", function() | 129 | it("with --local", function() |
132 | assert.is_true(run.luarocks_bool("install --server=" .. testing_paths.fixtures_dir .. "/a_repo a_rock")) | 130 | assert.is_true(run.luarocks_bool("install --local --server=" .. testing_paths.fixtures_dir .. "/a_repo a_rock")) |
133 | assert.is_true(run.luarocks_bool("doc --server=" .. testing_paths.fixtures_dir .. "/a_repo a_rock --local")) | 131 | assert.is_true(run.luarocks_bool("doc --server=" .. testing_paths.fixtures_dir .. "/a_repo a_rock --local")) |
134 | end) | 132 | end) |
135 | 133 | ||
diff --git a/spec/download_spec.lua b/spec/download_spec.lua index 66b12d6f..f7c10e85 100644 --- a/spec/download_spec.lua +++ b/spec/download_spec.lua | |||
@@ -3,8 +3,6 @@ local lfs = require("lfs") | |||
3 | local run = test_env.run | 3 | local run = test_env.run |
4 | local testing_paths = test_env.testing_paths | 4 | local testing_paths = test_env.testing_paths |
5 | 5 | ||
6 | test_env.unload_luarocks() | ||
7 | |||
8 | local extra_rocks = { | 6 | local extra_rocks = { |
9 | "/say-1.3-1.rockspec", | 7 | "/say-1.3-1.rockspec", |
10 | } | 8 | } |
diff --git a/spec/dummy_spec.lua b/spec/dummy_spec.lua index 80f04ffb..85fc8932 100644 --- a/spec/dummy_spec.lua +++ b/spec/dummy_spec.lua | |||
@@ -3,8 +3,7 @@ | |||
3 | local test_env = require("spec.util.test_env") | 3 | local test_env = require("spec.util.test_env") |
4 | local testing_paths = test_env.testing_paths | 4 | local testing_paths = test_env.testing_paths |
5 | 5 | ||
6 | test_env.unload_luarocks() | 6 | test_env.setup_specs() |
7 | |||
8 | local runner = require("luacov.runner") | 7 | local runner = require("luacov.runner") |
9 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | 8 | runner.init(testing_paths.testrun_dir .. "/luacov.config") |
10 | 9 | ||
diff --git a/spec/external_spec.lua b/spec/external_spec.lua index 63363b76..5a69a678 100644 --- a/spec/external_spec.lua +++ b/spec/external_spec.lua | |||
@@ -2,14 +2,13 @@ local test_env = require("spec.util.test_env") | |||
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | local testing_paths = test_env.testing_paths | 3 | local testing_paths = test_env.testing_paths |
4 | 4 | ||
5 | test_env.setup_specs() | ||
6 | |||
7 | describe("luarocks external commands #integration", function() | 5 | describe("luarocks external commands #integration", function() |
8 | setup(function() | 6 | lazy_setup(function() |
7 | test_env.setup_specs() | ||
9 | test_env.mock_server_init() | 8 | test_env.mock_server_init() |
10 | end) | 9 | end) |
11 | 10 | ||
12 | teardown(function() | 11 | lazy_teardown(function() |
13 | test_env.mock_server_done() | 12 | test_env.mock_server_done() |
14 | end) | 13 | end) |
15 | 14 | ||
diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua new file mode 100644 index 00000000..d5e93c4b --- /dev/null +++ b/spec/fs_spec.lua | |||
@@ -0,0 +1,76 @@ | |||
1 | local test_env = require("spec.util.test_env") | ||
2 | |||
3 | local lfs = require("lfs") | ||
4 | local testing_paths = test_env.testing_paths | ||
5 | local get_tmp_path = test_env.get_tmp_path | ||
6 | |||
7 | describe("luarocks.fs #integration", function() | ||
8 | |||
9 | local fs | ||
10 | |||
11 | describe("fs.download #mock", function() | ||
12 | local tmpfile | ||
13 | local tmpdir | ||
14 | |||
15 | lazy_setup(function() | ||
16 | test_env.setup_specs(nil, "mock") | ||
17 | local cfg = require("luarocks.core.cfg") | ||
18 | fs = require("luarocks.fs") | ||
19 | cfg.init() | ||
20 | fs.init() | ||
21 | test_env.mock_server_init() | ||
22 | end) | ||
23 | |||
24 | lazy_teardown(function() | ||
25 | test_env.mock_server_done() | ||
26 | end) | ||
27 | |||
28 | after_each(function() | ||
29 | if tmpfile then | ||
30 | os.remove(tmpfile) | ||
31 | tmpfile = nil | ||
32 | end | ||
33 | if tmpdir then | ||
34 | lfs.rmdir(tmpdir) | ||
35 | tmpdir = nil | ||
36 | end | ||
37 | end) | ||
38 | |||
39 | it("returns true and fetches the url argument into the specified filename", function() | ||
40 | tmpfile = get_tmp_path() | ||
41 | assert.truthy(fs.download("http://localhost:8080/file/a_rock.lua", tmpfile)) | ||
42 | local fd = assert(io.open(tmpfile, "r")) | ||
43 | local downloadcontent = assert(fd:read("*a")) | ||
44 | fd:close() | ||
45 | fd = assert(io.open(testing_paths.fixtures_dir .. "/a_rock.lua", "r")) | ||
46 | local originalcontent = assert(fd:read("*a")) | ||
47 | fd:close() | ||
48 | assert.same(downloadcontent, originalcontent) | ||
49 | end) | ||
50 | |||
51 | it("returns true and fetches the url argument into a file whose name matches the basename of the url if the filename argument is not given", function() | ||
52 | tmpdir = get_tmp_path() | ||
53 | lfs.mkdir(tmpdir) | ||
54 | fs.change_dir(tmpdir) | ||
55 | assert.truthy(fs.download("http://localhost:8080/file/a_rock.lua")) | ||
56 | tmpfile = tmpdir .. "/a_rock.lua" | ||
57 | local fd = assert(io.open(tmpfile, "r")) | ||
58 | local downloadcontent = assert(fd:read("*a")) | ||
59 | fd:close() | ||
60 | fd = assert(io.open(testing_paths.fixtures_dir .. "/a_rock.lua", "r")) | ||
61 | local originalcontent = assert(fd:read("*a")) | ||
62 | fd:close() | ||
63 | assert.same(downloadcontent, originalcontent) | ||
64 | fs.pop_dir() | ||
65 | end) | ||
66 | |||
67 | it("returns false and does nothing if the url argument contains a nonexistent file", function() | ||
68 | tmpfile = get_tmp_path() | ||
69 | assert.falsy(fs.download("http://localhost:8080/file/nonexistent", tmpfile)) | ||
70 | end) | ||
71 | |||
72 | it("returns false and does nothing if the url argument is invalid", function() | ||
73 | assert.falsy(fs.download("invalidurl")) | ||
74 | end) | ||
75 | end) | ||
76 | end) | ||
diff --git a/spec/help_spec.lua b/spec/help_spec.lua index 08ce87a9..e13f1c30 100644 --- a/spec/help_spec.lua +++ b/spec/help_spec.lua | |||
@@ -1,8 +1,6 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | 3 | ||
4 | test_env.unload_luarocks() | ||
5 | |||
6 | describe("luarocks help #integration", function() | 4 | describe("luarocks help #integration", function() |
7 | 5 | ||
8 | before_each(function() | 6 | before_each(function() |
diff --git a/spec/init_spec.lua b/spec/init_spec.lua index be10b5b1..88bd23a5 100644 --- a/spec/init_spec.lua +++ b/spec/init_spec.lua | |||
@@ -6,11 +6,9 @@ local is_win = test_env.TEST_TARGET_OS == "windows" | |||
6 | local write_file = test_env.write_file | 6 | local write_file = test_env.write_file |
7 | local lfs = require("lfs") | 7 | local lfs = require("lfs") |
8 | 8 | ||
9 | test_env.unload_luarocks() | ||
10 | |||
11 | describe("luarocks init #integration", function() | 9 | describe("luarocks init #integration", function() |
12 | 10 | ||
13 | setup(function() | 11 | lazy_setup(function() |
14 | test_env.setup_specs() | 12 | test_env.setup_specs() |
15 | end) | 13 | end) |
16 | 14 | ||
diff --git a/spec/install_spec.lua b/spec/install_spec.lua index 45979b9c..b4b064f0 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua | |||
@@ -7,8 +7,6 @@ local write_file = test_env.write_file | |||
7 | local git_repo = require("spec.util.git_repo") | 7 | local git_repo = require("spec.util.git_repo") |
8 | local V = test_env.V | 8 | local V = test_env.V |
9 | 9 | ||
10 | test_env.unload_luarocks() | ||
11 | |||
12 | local extra_rocks = { | 10 | local extra_rocks = { |
13 | "/cprint-${CPRINT}.src.rock", | 11 | "/cprint-${CPRINT}.src.rock", |
14 | "/cprint-${CPRINT}.rockspec", | 12 | "/cprint-${CPRINT}.rockspec", |
@@ -244,15 +242,15 @@ describe("luarocks install #integration", function() | |||
244 | test = "test.lua" | 242 | test = "test.lua" |
245 | } | 243 | } |
246 | } | 244 | } |
247 | ]], finally) | 245 | ]]) |
248 | write_file("test.lua", "return {}", finally) | 246 | write_file("test.lua", "return {}") |
249 | write_file("luarocks.lock", [[ | 247 | write_file("luarocks.lock", [[ |
250 | return { | 248 | return { |
251 | dependencies = { | 249 | dependencies = { |
252 | ["a_rock"] = "1.0-1", | 250 | ["a_rock"] = "1.0-1", |
253 | } | 251 | } |
254 | } | 252 | } |
255 | ]], finally) | 253 | ]]) |
256 | 254 | ||
257 | assert.is_true(run.luarocks_bool("make --pack-binary-rock --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec")) | 255 | assert.is_true(run.luarocks_bool("make --pack-binary-rock --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec")) |
258 | assert.is_true(os.remove("luarocks.lock")) | 256 | assert.is_true(os.remove("luarocks.lock")) |
@@ -268,17 +266,17 @@ describe("luarocks install #integration", function() | |||
268 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/luarocks.lock")) | 266 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/luarocks.lock")) |
269 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) | 267 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/1.0-1/a_rock-1.0-1.rockspec")) |
270 | assert.is.falsy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/2.0-1")) | 268 | assert.is.falsy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/2.0-1")) |
271 | end) | 269 | end, finally) |
272 | end) | 270 | end) |
273 | 271 | ||
274 | describe("#unix install runs build from #git", function() | 272 | describe("#unix install runs build from #git", function() |
275 | local git | 273 | local git |
276 | 274 | ||
277 | setup(function() | 275 | lazy_setup(function() |
278 | git = git_repo.start() | 276 | git = git_repo.start() |
279 | end) | 277 | end) |
280 | 278 | ||
281 | teardown(function() | 279 | lazy_teardown(function() |
282 | if git then | 280 | if git then |
283 | git:stop() | 281 | git:stop() |
284 | end | 282 | end |
diff --git a/spec/lint_spec.lua b/spec/lint_spec.lua index 847c9800..919e4e71 100644 --- a/spec/lint_spec.lua +++ b/spec/lint_spec.lua | |||
@@ -2,8 +2,6 @@ local test_env = require("spec.util.test_env") | |||
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | local get_tmp_path = test_env.get_tmp_path | 3 | local get_tmp_path = test_env.get_tmp_path |
4 | local write_file = test_env.write_file | 4 | local write_file = test_env.write_file |
5 | |||
6 | test_env.unload_luarocks() | ||
7 | local lfs = require("lfs") | 5 | local lfs = require("lfs") |
8 | 6 | ||
9 | local extra_rocks = { | 7 | local extra_rocks = { |
diff --git a/spec/list_spec.lua b/spec/list_spec.lua index 4c7fc776..eeeb79d2 100644 --- a/spec/list_spec.lua +++ b/spec/list_spec.lua | |||
@@ -3,8 +3,6 @@ local V = test_env.V | |||
3 | local run = test_env.run | 3 | local run = test_env.run |
4 | local testing_paths = test_env.testing_paths | 4 | local testing_paths = test_env.testing_paths |
5 | 5 | ||
6 | test_env.unload_luarocks() | ||
7 | |||
8 | local extra_rocks = { | 6 | local extra_rocks = { |
9 | "/say-1.0-1.src.rock", | 7 | "/say-1.0-1.src.rock", |
10 | "/say-1.2-1.src.rock" | 8 | "/say-1.2-1.src.rock" |
diff --git a/spec/loader_spec.lua b/spec/loader_spec.lua index c8526117..bd95a292 100644 --- a/spec/loader_spec.lua +++ b/spec/loader_spec.lua | |||
@@ -9,22 +9,10 @@ describe("luarocks.loader", function() | |||
9 | test_env.setup_specs() | 9 | test_env.setup_specs() |
10 | end) | 10 | end) |
11 | 11 | ||
12 | describe("#unit", function() | ||
13 | it("starts", function() | ||
14 | assert(run.lua_bool([[-e "require 'luarocks.loader'; print(package.loaded['luarocks.loaded'])"]])) | ||
15 | end) | ||
16 | |||
17 | describe("which", function() | ||
18 | it("finds modules using package.path", function() | ||
19 | assert(run.lua_bool([[-e "loader = require 'luarocks.loader'; local x,y,z,p = loader.which('luarocks.loader', 'p'); assert(p == 'p')"]])) | ||
20 | end) | ||
21 | end) | ||
22 | end) | ||
23 | |||
24 | describe("#integration", function() | 12 | describe("#integration", function() |
25 | it("respects version constraints", function() | 13 | it("respects version constraints", function() |
26 | test_env.run_in_tmp(function(tmpdir) | 14 | test_env.run_in_tmp(function(tmpdir) |
27 | write_file("rock_b_01.lua", "print('ROCK B 0.1'); return {}", finally) | 15 | write_file("rock_b_01.lua", "print('ROCK B 0.1'); return {}") |
28 | write_file("rock_b-0.1-1.rockspec", [[ | 16 | write_file("rock_b-0.1-1.rockspec", [[ |
29 | package = "rock_b" | 17 | package = "rock_b" |
30 | version = "0.1-1" | 18 | version = "0.1-1" |
@@ -37,9 +25,9 @@ describe("luarocks.loader", function() | |||
37 | rock_b = "rock_b_01.lua" | 25 | rock_b = "rock_b_01.lua" |
38 | } | 26 | } |
39 | } | 27 | } |
40 | ]], finally) | 28 | ]]) |
41 | 29 | ||
42 | write_file("rock_b_10.lua", "print('ROCK B 1.0'); return {}", finally) | 30 | write_file("rock_b_10.lua", "print('ROCK B 1.0'); return {}") |
43 | write_file("rock_b-1.0-1.rockspec", [[ | 31 | write_file("rock_b-1.0-1.rockspec", [[ |
44 | package = "rock_b" | 32 | package = "rock_b" |
45 | version = "1.0-1" | 33 | version = "1.0-1" |
@@ -52,9 +40,9 @@ describe("luarocks.loader", function() | |||
52 | rock_b = "rock_b_10.lua" | 40 | rock_b = "rock_b_10.lua" |
53 | } | 41 | } |
54 | } | 42 | } |
55 | ]], finally) | 43 | ]]) |
56 | 44 | ||
57 | write_file("rock_a.lua", "require('rock_b'); return {}", finally) | 45 | write_file("rock_a.lua", "require('rock_b'); return {}") |
58 | write_file("rock_a-2.0-1.rockspec", [[ | 46 | write_file("rock_a-2.0-1.rockspec", [[ |
59 | package = "rock_a" | 47 | package = "rock_a" |
60 | version = "2.0-1" | 48 | version = "2.0-1" |
@@ -70,7 +58,7 @@ describe("luarocks.loader", function() | |||
70 | rock_a = "rock_a.lua" | 58 | rock_a = "rock_a.lua" |
71 | } | 59 | } |
72 | } | 60 | } |
73 | ]], finally) | 61 | ]]) |
74 | 62 | ||
75 | print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=" .. testing_paths.testing_tree .. " ./rock_b-0.1-1.rockspec")) | 63 | print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=" .. testing_paths.testing_tree .. " ./rock_b-0.1-1.rockspec")) |
76 | print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=" .. testing_paths.testing_tree .. " ./rock_b-1.0-1.rockspec --keep")) | 64 | print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=" .. testing_paths.testing_tree .. " ./rock_b-1.0-1.rockspec --keep")) |
@@ -79,7 +67,7 @@ describe("luarocks.loader", function() | |||
79 | local output = run.lua([[-e "require 'luarocks.loader'; require('rock_a')"]]) | 67 | local output = run.lua([[-e "require 'luarocks.loader'; require('rock_a')"]]) |
80 | 68 | ||
81 | assert.matches("ROCK B 0.1", output, 1, true) | 69 | assert.matches("ROCK B 0.1", output, 1, true) |
82 | end) | 70 | end, finally) |
83 | end) | 71 | end) |
84 | end) | 72 | end) |
85 | end) | 73 | end) |
diff --git a/spec/make_manifest_spec.lua b/spec/make_manifest_spec.lua index a3d015c9..146b6178 100644 --- a/spec/make_manifest_spec.lua +++ b/spec/make_manifest_spec.lua | |||
@@ -1,8 +1,6 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | 3 | ||
4 | test_env.unload_luarocks() | ||
5 | |||
6 | describe("luarocks make_manifest #integration", function() | 4 | describe("luarocks make_manifest #integration", function() |
7 | 5 | ||
8 | before_each(function() | 6 | before_each(function() |
diff --git a/spec/make_spec.lua b/spec/make_spec.lua index 626d84df..6cce0543 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua | |||
@@ -5,8 +5,6 @@ local testing_paths = test_env.testing_paths | |||
5 | local env_variables = test_env.env_variables | 5 | local env_variables = test_env.env_variables |
6 | local write_file = test_env.write_file | 6 | local write_file = test_env.write_file |
7 | 7 | ||
8 | test_env.unload_luarocks() | ||
9 | |||
10 | local extra_rocks = { | 8 | local extra_rocks = { |
11 | "/luasocket-${LUASOCKET}.src.rock", | 9 | "/luasocket-${LUASOCKET}.src.rock", |
12 | "/luasocket-${LUASOCKET}.rockspec", | 10 | "/luasocket-${LUASOCKET}.rockspec", |
@@ -156,8 +154,8 @@ describe("luarocks make #integration", function() | |||
156 | test = "test.lua" | 154 | test = "test.lua" |
157 | } | 155 | } |
158 | } | 156 | } |
159 | ]], finally) | 157 | ]]) |
160 | write_file("test.lua", "return {}", finally) | 158 | write_file("test.lua", "return {}") |
161 | 159 | ||
162 | assert.is_true(run.luarocks_bool("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --pin --tree=lua_modules")) | 160 | assert.is_true(run.luarocks_bool("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --pin --tree=lua_modules")) |
163 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) | 161 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) |
@@ -171,7 +169,7 @@ describe("luarocks make #integration", function() | |||
171 | ["lua"] = test_env.lua_version .. "-1", | 169 | ["lua"] = test_env.lua_version .. "-1", |
172 | } | 170 | } |
173 | }, lockdata) | 171 | }, lockdata) |
174 | end) | 172 | end, finally) |
175 | end) | 173 | end) |
176 | 174 | ||
177 | it("respects luarocks.lock when present #pinning", function() | 175 | it("respects luarocks.lock when present #pinning", function() |
@@ -191,15 +189,15 @@ describe("luarocks make #integration", function() | |||
191 | test = "test.lua" | 189 | test = "test.lua" |
192 | } | 190 | } |
193 | } | 191 | } |
194 | ]], finally) | 192 | ]]) |
195 | write_file("test.lua", "return {}", finally) | 193 | write_file("test.lua", "return {}") |
196 | write_file("luarocks.lock", [[ | 194 | write_file("luarocks.lock", [[ |
197 | return { | 195 | return { |
198 | dependencies = { | 196 | dependencies = { |
199 | ["a_rock"] = "1.0-1", | 197 | ["a_rock"] = "1.0-1", |
200 | } | 198 | } |
201 | } | 199 | } |
202 | ]], finally) | 200 | ]]) |
203 | 201 | ||
204 | print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=lua_modules")) | 202 | print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=lua_modules")) |
205 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/2.0-1/test-2.0-1.rockspec")) | 203 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/2.0-1/test-2.0-1.rockspec")) |
@@ -212,7 +210,7 @@ describe("luarocks make #integration", function() | |||
212 | ["a_rock"] = "1.0-1", | 210 | ["a_rock"] = "1.0-1", |
213 | } | 211 | } |
214 | }, lockdata) | 212 | }, lockdata) |
215 | end) | 213 | end, finally) |
216 | end) | 214 | end) |
217 | 215 | ||
218 | it("overrides luarocks.lock with --pin #pinning", function() | 216 | it("overrides luarocks.lock with --pin #pinning", function() |
@@ -232,15 +230,15 @@ describe("luarocks make #integration", function() | |||
232 | test = "test.lua" | 230 | test = "test.lua" |
233 | } | 231 | } |
234 | } | 232 | } |
235 | ]], finally) | 233 | ]]) |
236 | write_file("test.lua", "return {}", finally) | 234 | write_file("test.lua", "return {}") |
237 | write_file("luarocks.lock", [[ | 235 | write_file("luarocks.lock", [[ |
238 | return { | 236 | return { |
239 | dependencies = { | 237 | dependencies = { |
240 | ["a_rock"] = "1.0-1", | 238 | ["a_rock"] = "1.0-1", |
241 | } | 239 | } |
242 | } | 240 | } |
243 | ]], finally) | 241 | ]]) |
244 | 242 | ||
245 | print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=lua_modules --pin")) | 243 | print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=lua_modules --pin")) |
246 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/2.0-1/test-2.0-1.rockspec")) | 244 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/2.0-1/test-2.0-1.rockspec")) |
@@ -254,7 +252,7 @@ describe("luarocks make #integration", function() | |||
254 | ["lua"] = test_env.lua_version .. "-1", | 252 | ["lua"] = test_env.lua_version .. "-1", |
255 | } | 253 | } |
256 | }, lockdata) | 254 | }, lockdata) |
257 | end) | 255 | end, finally) |
258 | end) | 256 | end) |
259 | 257 | ||
260 | describe("#ddt upgrading rockspecs with double deploy types", function() | 258 | describe("#ddt upgrading rockspecs with double deploy types", function() |
diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua index d47cfd05..18271176 100644 --- a/spec/new_version_spec.lua +++ b/spec/new_version_spec.lua | |||
@@ -3,8 +3,6 @@ local lfs = require("lfs") | |||
3 | local run = test_env.run | 3 | local run = test_env.run |
4 | local testing_paths = test_env.testing_paths | 4 | local testing_paths = test_env.testing_paths |
5 | 5 | ||
6 | test_env.unload_luarocks() | ||
7 | |||
8 | local extra_rocks = { | 6 | local extra_rocks = { |
9 | "/abelhas-1.1-1.rockspec", | 7 | "/abelhas-1.1-1.rockspec", |
10 | "/lpeg-${LPEG}.rockspec" | 8 | "/lpeg-${LPEG}.rockspec" |
@@ -12,7 +10,7 @@ local extra_rocks = { | |||
12 | 10 | ||
13 | describe("luarocks new_version #integration", function() | 11 | describe("luarocks new_version #integration", function() |
14 | 12 | ||
15 | setup(function() | 13 | lazy_setup(function() |
16 | test_env.setup_specs(extra_rocks) | 14 | test_env.setup_specs(extra_rocks) |
17 | end) | 15 | end) |
18 | 16 | ||
@@ -69,10 +67,11 @@ describe("luarocks new_version #integration", function() | |||
69 | end) | 67 | end) |
70 | 68 | ||
71 | describe("remote tests #mock", function() | 69 | describe("remote tests #mock", function() |
72 | setup(function() | 70 | lazy_setup(function() |
71 | test_env.setup_specs(extra_rocks, "mock") | ||
73 | test_env.mock_server_init() | 72 | test_env.mock_server_init() |
74 | end) | 73 | end) |
75 | teardown(function() | 74 | lazy_teardown(function() |
76 | test_env.mock_server_done() | 75 | test_env.mock_server_done() |
77 | end) | 76 | end) |
78 | it("with remote spec", function() | 77 | it("with remote spec", function() |
diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index 0a4e0d8a..20a2b3ef 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua | |||
@@ -4,8 +4,6 @@ local run = test_env.run | |||
4 | local testing_paths = test_env.testing_paths | 4 | local testing_paths = test_env.testing_paths |
5 | local write_file = test_env.write_file | 5 | local write_file = test_env.write_file |
6 | 6 | ||
7 | test_env.unload_luarocks() | ||
8 | |||
9 | local extra_rocks = { | 7 | local extra_rocks = { |
10 | "/luassert-1.7.0-1.src.rock", | 8 | "/luassert-1.7.0-1.src.rock", |
11 | "/luasocket-${LUASOCKET}.src.rock", | 9 | "/luasocket-${LUASOCKET}.src.rock", |
@@ -64,11 +62,12 @@ describe("luarocks pack #integration", function() | |||
64 | 62 | ||
65 | describe("#mock", function() | 63 | describe("#mock", function() |
66 | 64 | ||
67 | setup(function() | 65 | lazy_setup(function() |
66 | test_env.setup_specs(extra_rocks, "mock") | ||
68 | test_env.mock_server_init() | 67 | test_env.mock_server_init() |
69 | end) | 68 | end) |
70 | 69 | ||
71 | teardown(function() | 70 | lazy_teardown(function() |
72 | test_env.mock_server_done() | 71 | test_env.mock_server_done() |
73 | end) | 72 | end) |
74 | 73 | ||
diff --git a/spec/path_spec.lua b/spec/path_spec.lua index ba2ecdde..1ad6b3ac 100644 --- a/spec/path_spec.lua +++ b/spec/path_spec.lua | |||
@@ -1,8 +1,6 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | 3 | ||
4 | test_env.unload_luarocks() | ||
5 | |||
6 | describe("luarocks path #integration", function() | 4 | describe("luarocks path #integration", function() |
7 | before_each(function() | 5 | before_each(function() |
8 | test_env.setup_specs() | 6 | test_env.setup_specs() |
diff --git a/spec/purge_spec.lua b/spec/purge_spec.lua index ccd26bdf..7fdb74f4 100644 --- a/spec/purge_spec.lua +++ b/spec/purge_spec.lua | |||
@@ -2,8 +2,6 @@ local test_env = require("spec.util.test_env") | |||
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | local testing_paths = test_env.testing_paths | 3 | local testing_paths = test_env.testing_paths |
4 | 4 | ||
5 | test_env.unload_luarocks() | ||
6 | |||
7 | local extra_rocks = { | 5 | local extra_rocks = { |
8 | "/say-1.0-1.src.rock", | 6 | "/say-1.0-1.src.rock", |
9 | } | 7 | } |
diff --git a/spec/quick/path.q b/spec/quick/path.q new file mode 100644 index 00000000..77fc188b --- /dev/null +++ b/spec/quick/path.q | |||
@@ -0,0 +1,22 @@ | |||
1 | ================================================================================ | ||
2 | TEST: luarocks path: --project-tree | ||
3 | |||
4 | |||
5 | RUN: luarocks path --project-tree=foo | ||
6 | STDOUT: | ||
7 | -------------------------------------------------------------------------------- | ||
8 | %{path(foo/share/lua/%{lua_version}/?.lua)} | ||
9 | %{path(foo/share/lua/%{lua_version}/?/init.lua)} | ||
10 | -------------------------------------------------------------------------------- | ||
11 | |||
12 | RUN: luarocks path --project-tree=foo --tree=bar | ||
13 | NOT_STDOUT: | ||
14 | -------------------------------------------------------------------------------- | ||
15 | %{path(foo/share/lua/%{lua_version}/?.lua)} | ||
16 | %{path(foo/share/lua/%{lua_version}/?/init.lua)} | ||
17 | -------------------------------------------------------------------------------- | ||
18 | STDOUT: | ||
19 | -------------------------------------------------------------------------------- | ||
20 | %{path(bar/share/lua/%{lua_version}/?.lua)} | ||
21 | %{path(bar/share/lua/%{lua_version}/?/init.lua)} | ||
22 | -------------------------------------------------------------------------------- | ||
diff --git a/spec/refresh_cache_spec.lua b/spec/refresh_cache_spec.lua index c0877371..73ba9a91 100644 --- a/spec/refresh_cache_spec.lua +++ b/spec/refresh_cache_spec.lua | |||
@@ -1,8 +1,6 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | 3 | ||
4 | test_env.unload_luarocks() | ||
5 | |||
6 | describe("luarocks-admin refresh_cache #integration", function() | 4 | describe("luarocks-admin refresh_cache #integration", function() |
7 | 5 | ||
8 | before_each(function() | 6 | before_each(function() |
diff --git a/spec/remove_spec.lua b/spec/remove_spec.lua index ddeb0644..3bcfbb25 100644 --- a/spec/remove_spec.lua +++ b/spec/remove_spec.lua | |||
@@ -6,8 +6,6 @@ local env_variables = test_env.env_variables | |||
6 | local V = test_env.V | 6 | local V = test_env.V |
7 | local P = test_env.P | 7 | local P = test_env.P |
8 | 8 | ||
9 | test_env.unload_luarocks() | ||
10 | |||
11 | local extra_rocks = { | 9 | local extra_rocks = { |
12 | "/abelhas-1.1-1.src.rock", | 10 | "/abelhas-1.1-1.src.rock", |
13 | "/copas-${COPAS}.src.rock", | 11 | "/copas-${COPAS}.src.rock", |
diff --git a/spec/search_spec.lua b/spec/search_spec.lua index bb6adf3e..6d71e008 100644 --- a/spec/search_spec.lua +++ b/spec/search_spec.lua | |||
@@ -1,8 +1,6 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | 3 | ||
4 | test_env.unload_luarocks() | ||
5 | |||
6 | local extra_rocks = { | 4 | local extra_rocks = { |
7 | "/lzlib-0.4.1.53-1.src.rock" | 5 | "/lzlib-0.4.1.53-1.src.rock" |
8 | } | 6 | } |
diff --git a/spec/show_spec.lua b/spec/show_spec.lua index d07a8495..cd34b5a5 100644 --- a/spec/show_spec.lua +++ b/spec/show_spec.lua | |||
@@ -2,8 +2,6 @@ local test_env = require("spec.util.test_env") | |||
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | local testing_paths = test_env.testing_paths | 3 | local testing_paths = test_env.testing_paths |
4 | 4 | ||
5 | test_env.unload_luarocks() | ||
6 | |||
7 | describe("luarocks show #integration", function() | 5 | describe("luarocks show #integration", function() |
8 | 6 | ||
9 | before_each(function() | 7 | before_each(function() |
diff --git a/spec/test_spec.lua b/spec/test_spec.lua index 4be0567f..194dcfd1 100644 --- a/spec/test_spec.lua +++ b/spec/test_spec.lua | |||
@@ -1,12 +1,9 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local lfs = require("lfs") | 2 | local lfs = require("lfs") |
3 | local get_tmp_path = test_env.get_tmp_path | ||
4 | local run = test_env.run | 3 | local run = test_env.run |
5 | local testing_paths = test_env.testing_paths | 4 | local testing_paths = test_env.testing_paths |
6 | local write_file = test_env.write_file | 5 | local write_file = test_env.write_file |
7 | 6 | ||
8 | test_env.unload_luarocks() | ||
9 | |||
10 | local extra_rocks = { | 7 | local extra_rocks = { |
11 | "/busted-2.0.0-1.rockspec", | 8 | "/busted-2.0.0-1.rockspec", |
12 | "/lua_cliargs-3.0-1.src.rock", | 9 | "/lua_cliargs-3.0-1.src.rock", |
@@ -109,173 +106,3 @@ describe("luarocks test #integration", function() | |||
109 | end) | 106 | end) |
110 | end) | 107 | end) |
111 | 108 | ||
112 | test_env.unload_luarocks() | ||
113 | |||
114 | local fs = require("luarocks.fs") | ||
115 | local cfg = require("luarocks.core.cfg") | ||
116 | local path = require("luarocks.path") | ||
117 | local test = require("luarocks.test") | ||
118 | local test_busted = require("luarocks.test.busted") | ||
119 | local test_command = require("luarocks.test.command") | ||
120 | |||
121 | describe("LuaRocks test #unit", function() | ||
122 | local runner | ||
123 | |||
124 | lazy_setup(function() | ||
125 | cfg.init() | ||
126 | fs.init() | ||
127 | runner = require("luacov.runner") | ||
128 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | ||
129 | runner.tick = true | ||
130 | end) | ||
131 | |||
132 | lazy_teardown(function() | ||
133 | runner.shutdown() | ||
134 | end) | ||
135 | |||
136 | local tmpdir | ||
137 | local olddir | ||
138 | |||
139 | local create_tmp_dir = function() | ||
140 | tmpdir = get_tmp_path() | ||
141 | olddir = lfs.currentdir() | ||
142 | lfs.mkdir(tmpdir) | ||
143 | lfs.chdir(tmpdir) | ||
144 | fs.change_dir(tmpdir) | ||
145 | end | ||
146 | |||
147 | local destroy_tmp_dir = function() | ||
148 | if olddir then | ||
149 | lfs.chdir(olddir) | ||
150 | if tmpdir then | ||
151 | lfs.rmdir(tmpdir) | ||
152 | end | ||
153 | end | ||
154 | end | ||
155 | |||
156 | describe("test.command", function() | ||
157 | describe("command.detect_type", function() | ||
158 | before_each(function() | ||
159 | create_tmp_dir() | ||
160 | end) | ||
161 | |||
162 | after_each(function() | ||
163 | destroy_tmp_dir() | ||
164 | end) | ||
165 | |||
166 | it("returns true if test.lua exists", function() | ||
167 | write_file("test.lua", "", finally) | ||
168 | assert.truthy(test_command.detect_type()) | ||
169 | end) | ||
170 | |||
171 | it("returns false if test.lua doesn't exist", function() | ||
172 | assert.falsy(test_command.detect_type()) | ||
173 | end) | ||
174 | end) | ||
175 | |||
176 | describe("command.run_tests", function() | ||
177 | before_each(function() | ||
178 | create_tmp_dir() | ||
179 | end) | ||
180 | |||
181 | after_each(function() | ||
182 | destroy_tmp_dir() | ||
183 | end) | ||
184 | |||
185 | it("returns the result of the executed tests", function() | ||
186 | write_file("test.lua", "assert(1==1)", finally) | ||
187 | assert.truthy(test_command.run_tests(nil, {})) | ||
188 | |||
189 | write_file("test.lua", "assert(1==2)", finally) | ||
190 | assert.falsy(test_command.run_tests(nil, {})) | ||
191 | end) | ||
192 | |||
193 | it("returns the result of the executed tests with custom arguments and test command", function() | ||
194 | write_file("test.lua", "assert(1==1)", finally) | ||
195 | |||
196 | local test = { | ||
197 | script = "test.lua", | ||
198 | flags = { | ||
199 | arg1 = "1", | ||
200 | arg2 = "2" | ||
201 | }, | ||
202 | command = fs.Q(testing_paths.lua) | ||
203 | } | ||
204 | assert.truthy(test_command.run_tests(test, {})) | ||
205 | end) | ||
206 | |||
207 | it("returns false and does nothing if the test script doesn't exist", function() | ||
208 | assert.falsy(test_command.run_tests(nil, {})) | ||
209 | end) | ||
210 | end) | ||
211 | end) | ||
212 | |||
213 | describe("test.busted", function() | ||
214 | describe("busted.detect_type", function() | ||
215 | before_each(function() | ||
216 | create_tmp_dir() | ||
217 | end) | ||
218 | |||
219 | after_each(function() | ||
220 | destroy_tmp_dir() | ||
221 | end) | ||
222 | |||
223 | it("returns true if .busted exists", function() | ||
224 | write_file(".busted", "", finally) | ||
225 | assert.truthy(test_busted.detect_type()) | ||
226 | end) | ||
227 | |||
228 | it("returns false if .busted doesn't exist", function() | ||
229 | assert.falsy(test_busted.detect_type()) | ||
230 | end) | ||
231 | end) | ||
232 | |||
233 | describe("busted.run_tests", function() | ||
234 | before_each(function() | ||
235 | path.use_tree(testing_paths.testing_sys_tree) | ||
236 | create_tmp_dir() | ||
237 | end) | ||
238 | |||
239 | after_each(function() | ||
240 | destroy_tmp_dir() | ||
241 | end) | ||
242 | |||
243 | pending("returns the result of the executed tests", function() | ||
244 | -- FIXME: busted issue | ||
245 | write_file("test_spec.lua", "assert(1==1)", finally) | ||
246 | assert.truthy(test_busted.run_tests(nil, {})) | ||
247 | |||
248 | write_file("test_spec.lua", "assert(1==2)", finally) | ||
249 | assert.falsy(test_busted.run_tests()) | ||
250 | end) | ||
251 | end) | ||
252 | end) | ||
253 | |||
254 | describe("test", function() | ||
255 | describe("test.run_test_suite", function() | ||
256 | before_each(function() | ||
257 | create_tmp_dir() | ||
258 | end) | ||
259 | |||
260 | after_each(function() | ||
261 | destroy_tmp_dir() | ||
262 | end) | ||
263 | |||
264 | it("returns false if the given rockspec cannot be loaded", function() | ||
265 | assert.falsy(test.run_test_suite("invalid", nil, {})) | ||
266 | end) | ||
267 | |||
268 | it("returns false if no test type was detected", function() | ||
269 | assert.falsy(test.run_test_suite({ package = "test" }, nil, {})) | ||
270 | end) | ||
271 | |||
272 | it("returns the result of executing the tests specified in the given rockspec", function() | ||
273 | write_file("test.lua", "assert(1==1)", finally) | ||
274 | assert.truthy(test.run_test_suite({ test_dependencies = {} }, nil, {})) | ||
275 | |||
276 | write_file("test.lua", "assert(1==2)", finally) | ||
277 | assert.falsy(test.run_test_suite({ test_dependencies = {} }, nil, {})) | ||
278 | end) | ||
279 | end) | ||
280 | end) | ||
281 | end) | ||
diff --git a/spec/unit/build_spec.lua b/spec/unit/build_spec.lua index 6ab143c6..fb680858 100644 --- a/spec/unit/build_spec.lua +++ b/spec/unit/build_spec.lua | |||
@@ -6,9 +6,6 @@ local testing_paths = test_env.testing_paths | |||
6 | local write_file = test_env.write_file | 6 | local write_file = test_env.write_file |
7 | local P = test_env.P | 7 | local P = test_env.P |
8 | 8 | ||
9 | test_env.unload_luarocks() | ||
10 | |||
11 | test_env.unload_luarocks() | ||
12 | test_env.setup_specs() | 9 | test_env.setup_specs() |
13 | local cfg = require("luarocks.core.cfg") | 10 | local cfg = require("luarocks.core.cfg") |
14 | local deps = require("luarocks.deps") | 11 | local deps = require("luarocks.deps") |
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 @@ | |||
1 | local test_env = require("spec.util.test_env") | ||
2 | local testing_paths = test_env.testing_paths | ||
3 | |||
4 | local cfg = require("luarocks.core.cfg") | ||
5 | local deps = require("luarocks.deps") | ||
6 | local fs = require("luarocks.fs") | ||
7 | |||
8 | describe("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) | ||
144 | end) | ||
diff --git a/spec/unit/dir_spec.lua b/spec/unit/dir_spec.lua index b5dadda8..f340beea 100644 --- a/spec/unit/dir_spec.lua +++ b/spec/unit/dir_spec.lua | |||
@@ -2,7 +2,6 @@ local test_env = require("spec.util.test_env") | |||
2 | local testing_paths = test_env.testing_paths | 2 | local testing_paths = test_env.testing_paths |
3 | local P = test_env.P | 3 | local P = test_env.P |
4 | 4 | ||
5 | test_env.unload_luarocks() | ||
6 | test_env.setup_specs() | 5 | test_env.setup_specs() |
7 | local dir = require("luarocks.dir") | 6 | local dir = require("luarocks.dir") |
8 | 7 | ||
diff --git a/spec/unit/fetch_spec.lua b/spec/unit/fetch_spec.lua index 38da379e..c58e2cea 100644 --- a/spec/unit/fetch_spec.lua +++ b/spec/unit/fetch_spec.lua | |||
@@ -1,6 +1,5 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | 2 | ||
3 | test_env.unload_luarocks() | ||
4 | test_env.setup_specs() | 3 | test_env.setup_specs() |
5 | local cfg = require("luarocks.core.cfg") | 4 | local cfg = require("luarocks.core.cfg") |
6 | local fetch = require("luarocks.fetch") | 5 | local fetch = require("luarocks.fetch") |
diff --git a/spec/unit/fs_spec.lua b/spec/unit/fs_spec.lua index aea86af3..7643e9b5 100644 --- a/spec/unit/fs_spec.lua +++ b/spec/unit/fs_spec.lua | |||
@@ -1,6 +1,5 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | 2 | ||
3 | test_env.unload_luarocks() | ||
4 | test_env.setup_specs() | 3 | test_env.setup_specs() |
5 | local fs = require("luarocks.fs") | 4 | local fs = require("luarocks.fs") |
6 | local path = require("luarocks.path") | 5 | local path = require("luarocks.path") |
@@ -542,7 +541,7 @@ describe("luarocks.fs #unit", function() | |||
542 | if is_win then | 541 | if is_win then |
543 | assert.same(tmpdir, fs.current_dir()) | 542 | assert.same(tmpdir, fs.current_dir()) |
544 | else | 543 | else |
545 | assert.same(lfs.attributes(tmpdir).ino, lfs.attributes(fs.current_dir()).ino) | 544 | assert.same(lfs.attributes(tmpdir).ino, lfs.attributes((fs.current_dir())).ino) |
546 | end | 545 | end |
547 | end) | 546 | end) |
548 | end) | 547 | end) |
@@ -578,7 +577,7 @@ describe("luarocks.fs #unit", function() | |||
578 | if is_win then | 577 | if is_win then |
579 | assert.same(tmpdir, fs.current_dir()) | 578 | assert.same(tmpdir, fs.current_dir()) |
580 | else | 579 | else |
581 | assert.same(lfs.attributes(tmpdir).ino, lfs.attributes(lfs.currentdir()).ino) | 580 | assert.same(lfs.attributes(tmpdir).ino, lfs.attributes(fs.current_dir()).ino) |
582 | end | 581 | end |
583 | end) | 582 | end) |
584 | 583 | ||
@@ -1283,67 +1282,6 @@ describe("luarocks.fs #unit", function() | |||
1283 | end) | 1282 | end) |
1284 | end) | 1283 | end) |
1285 | 1284 | ||
1286 | describe("fs.download #mock", function() | ||
1287 | local tmpfile | ||
1288 | local tmpdir | ||
1289 | |||
1290 | setup(function() | ||
1291 | test_env.mock_server_init() | ||
1292 | end) | ||
1293 | |||
1294 | teardown(function() | ||
1295 | test_env.mock_server_done() | ||
1296 | end) | ||
1297 | |||
1298 | after_each(function() | ||
1299 | if tmpfile then | ||
1300 | os.remove(tmpfile) | ||
1301 | tmpfile = nil | ||
1302 | end | ||
1303 | if tmpdir then | ||
1304 | lfs.rmdir(tmpdir) | ||
1305 | tmpdir = nil | ||
1306 | end | ||
1307 | end) | ||
1308 | |||
1309 | it("returns true and fetches the url argument into the specified filename", function() | ||
1310 | tmpfile = get_tmp_path() | ||
1311 | assert.truthy(fs.download("http://localhost:8080/file/a_rock.lua", tmpfile)) | ||
1312 | local fd = assert(io.open(tmpfile, "r")) | ||
1313 | local downloadcontent = assert(fd:read("*a")) | ||
1314 | fd:close() | ||
1315 | fd = assert(io.open(testing_paths.fixtures_dir .. "/a_rock.lua", "r")) | ||
1316 | local originalcontent = assert(fd:read("*a")) | ||
1317 | fd:close() | ||
1318 | assert.same(downloadcontent, originalcontent) | ||
1319 | end) | ||
1320 | |||
1321 | it("returns true and fetches the url argument into a file whose name matches the basename of the url if the filename argument is not given", function() | ||
1322 | tmpdir = get_tmp_path() | ||
1323 | lfs.mkdir(tmpdir) | ||
1324 | fs.change_dir(tmpdir) | ||
1325 | assert.truthy(fs.download("http://localhost:8080/file/a_rock.lua")) | ||
1326 | tmpfile = tmpdir .. "/a_rock.lua" | ||
1327 | local fd = assert(io.open(tmpfile, "r")) | ||
1328 | local downloadcontent = assert(fd:read("*a")) | ||
1329 | fd:close() | ||
1330 | fd = assert(io.open(testing_paths.fixtures_dir .. "/a_rock.lua", "r")) | ||
1331 | local originalcontent = assert(fd:read("*a")) | ||
1332 | fd:close() | ||
1333 | assert.same(downloadcontent, originalcontent) | ||
1334 | fs.pop_dir() | ||
1335 | end) | ||
1336 | |||
1337 | it("returns false and does nothing if the url argument contains a nonexistent file", function() | ||
1338 | tmpfile = get_tmp_path() | ||
1339 | assert.falsy(fs.download("http://localhost:8080/file/nonexistent", tmpfile)) | ||
1340 | end) | ||
1341 | |||
1342 | it("returns false and does nothing if the url argument is invalid", function() | ||
1343 | assert.falsy(fs.download("invalidurl")) | ||
1344 | end) | ||
1345 | end) | ||
1346 | |||
1347 | describe("fs.zip", function() | 1285 | describe("fs.zip", function() |
1348 | local tmpdir | 1286 | local tmpdir |
1349 | local olddir | 1287 | local olddir |
diff --git a/spec/unit/fun_spec.lua b/spec/unit/fun_spec.lua index 9844ec27..c2b3e864 100644 --- a/spec/unit/fun_spec.lua +++ b/spec/unit/fun_spec.lua | |||
@@ -1,7 +1,6 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local testing_paths = test_env.testing_paths | 2 | local testing_paths = test_env.testing_paths |
3 | 3 | ||
4 | test_env.unload_luarocks() | ||
5 | local fun = require("luarocks.fun") | 4 | local fun = require("luarocks.fun") |
6 | 5 | ||
7 | describe("luarocks.fun #unit", function() | 6 | describe("luarocks.fun #unit", function() |
diff --git a/spec/unit/loader_spec.lua b/spec/unit/loader_spec.lua new file mode 100644 index 00000000..7650c80c --- /dev/null +++ b/spec/unit/loader_spec.lua | |||
@@ -0,0 +1,21 @@ | |||
1 | local test_env = require("spec.util.test_env") | ||
2 | local run = test_env.run | ||
3 | |||
4 | describe("luarocks.loader", function() | ||
5 | |||
6 | before_each(function() | ||
7 | test_env.setup_specs() | ||
8 | end) | ||
9 | |||
10 | describe("#unit", function() | ||
11 | it("starts", function() | ||
12 | assert(run.lua_bool([[-e "require 'luarocks.loader'; print(package.loaded['luarocks.loaded'])"]])) | ||
13 | end) | ||
14 | |||
15 | describe("which", function() | ||
16 | it("finds modules using package.path", function() | ||
17 | assert(run.lua_bool([[-e "loader = require 'luarocks.loader'; local x,y,z,p = loader.which('luarocks.loader', 'p'); assert(p == 'p')"]])) | ||
18 | end) | ||
19 | end) | ||
20 | end) | ||
21 | end) | ||
diff --git a/spec/unit/persist_spec.lua b/spec/unit/persist_spec.lua index f426fd83..ea5985aa 100644 --- a/spec/unit/persist_spec.lua +++ b/spec/unit/persist_spec.lua | |||
@@ -1,7 +1,6 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local testing_paths = test_env.testing_paths | 2 | local testing_paths = test_env.testing_paths |
3 | 3 | ||
4 | test_env.unload_luarocks() | ||
5 | local persist = require("luarocks.persist") | 4 | local persist = require("luarocks.persist") |
6 | 5 | ||
7 | describe("luarocks.persist #unit", function() | 6 | describe("luarocks.persist #unit", function() |
diff --git a/spec/unit/test_spec.lua b/spec/unit/test_spec.lua new file mode 100644 index 00000000..4d338984 --- /dev/null +++ b/spec/unit/test_spec.lua | |||
@@ -0,0 +1,174 @@ | |||
1 | local test_env = require("spec.util.test_env") | ||
2 | local lfs = require("lfs") | ||
3 | local get_tmp_path = test_env.get_tmp_path | ||
4 | local testing_paths = test_env.testing_paths | ||
5 | local write_file = test_env.write_file | ||
6 | |||
7 | local fs = require("luarocks.fs") | ||
8 | local cfg = require("luarocks.core.cfg") | ||
9 | local path = require("luarocks.path") | ||
10 | local test = require("luarocks.test") | ||
11 | local test_busted = require("luarocks.test.busted") | ||
12 | local test_command = require("luarocks.test.command") | ||
13 | |||
14 | describe("LuaRocks test #unit", function() | ||
15 | local runner | ||
16 | |||
17 | lazy_setup(function() | ||
18 | cfg.init() | ||
19 | fs.init() | ||
20 | runner = require("luacov.runner") | ||
21 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | ||
22 | runner.tick = true | ||
23 | end) | ||
24 | |||
25 | lazy_teardown(function() | ||
26 | runner.shutdown() | ||
27 | end) | ||
28 | |||
29 | local tmpdir | ||
30 | local olddir | ||
31 | |||
32 | local create_tmp_dir = function() | ||
33 | tmpdir = get_tmp_path() | ||
34 | olddir = lfs.currentdir() | ||
35 | lfs.mkdir(tmpdir) | ||
36 | lfs.chdir(tmpdir) | ||
37 | fs.change_dir(tmpdir) | ||
38 | end | ||
39 | |||
40 | local destroy_tmp_dir = function() | ||
41 | if olddir then | ||
42 | lfs.chdir(olddir) | ||
43 | if tmpdir then | ||
44 | lfs.rmdir(tmpdir) | ||
45 | end | ||
46 | end | ||
47 | end | ||
48 | |||
49 | describe("test.command", function() | ||
50 | describe("command.detect_type", function() | ||
51 | before_each(function() | ||
52 | create_tmp_dir() | ||
53 | end) | ||
54 | |||
55 | after_each(function() | ||
56 | destroy_tmp_dir() | ||
57 | end) | ||
58 | |||
59 | it("returns true if test.lua exists", function() | ||
60 | write_file("test.lua", "", finally) | ||
61 | assert.truthy(test_command.detect_type()) | ||
62 | end) | ||
63 | |||
64 | it("returns false if test.lua doesn't exist", function() | ||
65 | assert.falsy(test_command.detect_type()) | ||
66 | end) | ||
67 | end) | ||
68 | |||
69 | describe("command.run_tests", function() | ||
70 | before_each(function() | ||
71 | create_tmp_dir() | ||
72 | end) | ||
73 | |||
74 | after_each(function() | ||
75 | destroy_tmp_dir() | ||
76 | end) | ||
77 | |||
78 | it("returns the result of the executed tests", function() | ||
79 | write_file("test.lua", "assert(1==1)", finally) | ||
80 | assert.truthy(test_command.run_tests(nil, {})) | ||
81 | |||
82 | write_file("test.lua", "assert(1==2)", finally) | ||
83 | assert.falsy(test_command.run_tests(nil, {})) | ||
84 | end) | ||
85 | |||
86 | it("returns the result of the executed tests with custom arguments and test command", function() | ||
87 | write_file("test.lua", "assert(1==1)", finally) | ||
88 | |||
89 | local test = { | ||
90 | script = "test.lua", | ||
91 | flags = { | ||
92 | arg1 = "1", | ||
93 | arg2 = "2" | ||
94 | }, | ||
95 | command = fs.Q(testing_paths.lua) | ||
96 | } | ||
97 | assert.truthy(test_command.run_tests(test, {})) | ||
98 | end) | ||
99 | |||
100 | it("returns false and does nothing if the test script doesn't exist", function() | ||
101 | assert.falsy(test_command.run_tests(nil, {})) | ||
102 | end) | ||
103 | end) | ||
104 | end) | ||
105 | |||
106 | describe("test.busted", function() | ||
107 | describe("busted.detect_type", function() | ||
108 | before_each(function() | ||
109 | create_tmp_dir() | ||
110 | end) | ||
111 | |||
112 | after_each(function() | ||
113 | destroy_tmp_dir() | ||
114 | end) | ||
115 | |||
116 | it("returns true if .busted exists", function() | ||
117 | write_file(".busted", "", finally) | ||
118 | assert.truthy(test_busted.detect_type()) | ||
119 | end) | ||
120 | |||
121 | it("returns false if .busted doesn't exist", function() | ||
122 | assert.falsy(test_busted.detect_type()) | ||
123 | end) | ||
124 | end) | ||
125 | |||
126 | describe("busted.run_tests", function() | ||
127 | before_each(function() | ||
128 | path.use_tree(testing_paths.testing_sys_tree) | ||
129 | create_tmp_dir() | ||
130 | end) | ||
131 | |||
132 | after_each(function() | ||
133 | destroy_tmp_dir() | ||
134 | end) | ||
135 | |||
136 | pending("returns the result of the executed tests", function() | ||
137 | -- FIXME: busted issue | ||
138 | write_file("test_spec.lua", "assert(1==1)", finally) | ||
139 | assert.truthy(test_busted.run_tests(nil, {})) | ||
140 | |||
141 | write_file("test_spec.lua", "assert(1==2)", finally) | ||
142 | assert.falsy(test_busted.run_tests()) | ||
143 | end) | ||
144 | end) | ||
145 | end) | ||
146 | |||
147 | describe("test", function() | ||
148 | describe("test.run_test_suite", function() | ||
149 | before_each(function() | ||
150 | create_tmp_dir() | ||
151 | end) | ||
152 | |||
153 | after_each(function() | ||
154 | destroy_tmp_dir() | ||
155 | end) | ||
156 | |||
157 | it("returns false if the given rockspec cannot be loaded", function() | ||
158 | assert.falsy(test.run_test_suite("invalid", nil, {})) | ||
159 | end) | ||
160 | |||
161 | it("returns false if no test type was detected", function() | ||
162 | assert.falsy(test.run_test_suite({ package = "test" }, nil, {})) | ||
163 | end) | ||
164 | |||
165 | it("returns the result of executing the tests specified in the given rockspec", function() | ||
166 | write_file("test.lua", "assert(1==1)", finally) | ||
167 | assert.truthy(test.run_test_suite({ test_dependencies = {} }, nil, {})) | ||
168 | |||
169 | write_file("test.lua", "assert(1==2)", finally) | ||
170 | assert.falsy(test.run_test_suite({ test_dependencies = {} }, nil, {})) | ||
171 | end) | ||
172 | end) | ||
173 | end) | ||
174 | end) | ||
diff --git a/spec/unit/tools_spec.lua b/spec/unit/tools_spec.lua index 29e21740..0863c316 100644 --- a/spec/unit/tools_spec.lua +++ b/spec/unit/tools_spec.lua | |||
@@ -3,7 +3,6 @@ local get_tmp_path = test_env.get_tmp_path | |||
3 | local testing_paths = test_env.testing_paths | 3 | local testing_paths = test_env.testing_paths |
4 | local write_file = test_env.write_file | 4 | local write_file = test_env.write_file |
5 | 5 | ||
6 | test_env.unload_luarocks() | ||
7 | local fs = require("luarocks.fs") | 6 | local fs = require("luarocks.fs") |
8 | local cfg = require("luarocks.core.cfg") | 7 | local cfg = require("luarocks.core.cfg") |
9 | local patch = require("luarocks.tools.patch") | 8 | local patch = require("luarocks.tools.patch") |
diff --git a/spec/unit/util_spec.lua b/spec/unit/util_spec.lua new file mode 100644 index 00000000..0e380f2a --- /dev/null +++ b/spec/unit/util_spec.lua | |||
@@ -0,0 +1,161 @@ | |||
1 | local test_env = require("spec.util.test_env") | ||
2 | local testing_paths = test_env.testing_paths | ||
3 | local P = test_env.P | ||
4 | |||
5 | local util = require("luarocks.util") | ||
6 | local core_util = require("luarocks.core.util") | ||
7 | |||
8 | describe("luarocks.util #unit", function() | ||
9 | local runner | ||
10 | |||
11 | setup(function() | ||
12 | runner = require("luacov.runner") | ||
13 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | ||
14 | runner.tick = true | ||
15 | end) | ||
16 | |||
17 | teardown(function() | ||
18 | runner.shutdown() | ||
19 | end) | ||
20 | |||
21 | describe("util.variable_substitutions", function() | ||
22 | it("replaces variables", function() | ||
23 | local t = { | ||
24 | ["hello"] = "$(KIND) world", | ||
25 | } | ||
26 | util.variable_substitutions(t, { | ||
27 | ["KIND"] = "happy", | ||
28 | }) | ||
29 | assert.are.same({ | ||
30 | ["hello"] = "happy world", | ||
31 | }, t) | ||
32 | end) | ||
33 | |||
34 | it("missing variables are empty", function() | ||
35 | local t = { | ||
36 | ["hello"] = "$(KIND) world", | ||
37 | } | ||
38 | util.variable_substitutions(t, { | ||
39 | }) | ||
40 | assert.are.same({ | ||
41 | ["hello"] = " world", | ||
42 | }, t) | ||
43 | end) | ||
44 | end) | ||
45 | |||
46 | describe("util.sortedpairs", function() | ||
47 | local function collect(iter, state, var) | ||
48 | local collected = {} | ||
49 | |||
50 | while true do | ||
51 | local returns = {iter(state, var)} | ||
52 | |||
53 | if returns[1] == nil then | ||
54 | return collected | ||
55 | else | ||
56 | table.insert(collected, returns) | ||
57 | var = returns[1] | ||
58 | end | ||
59 | end | ||
60 | end | ||
61 | |||
62 | it("default sort", function() | ||
63 | assert.are.same({}, collect(util.sortedpairs({}))) | ||
64 | assert.are.same({ | ||
65 | {1, "v1"}, | ||
66 | {2, "v2"}, | ||
67 | {3, "v3"}, | ||
68 | {"bar", "v5"}, | ||
69 | {"foo", "v4"} | ||
70 | }, collect(util.sortedpairs({"v1", "v2", "v3", foo = "v4", bar = "v5"}))) | ||
71 | end) | ||
72 | |||
73 | it("sort by function", function() | ||
74 | local function compare(a, b) return a > b end | ||
75 | assert.are.same({}, collect(util.sortedpairs({}, compare))) | ||
76 | assert.are.same({ | ||
77 | {3, "v3"}, | ||
78 | {2, "v2"}, | ||
79 | {1, "v1"} | ||
80 | }, collect(util.sortedpairs({"v1", "v2", "v3"}, compare))) | ||
81 | end) | ||
82 | |||
83 | it("sort by priority table", function() | ||
84 | assert.are.same({}, collect(util.sortedpairs({}, {"k1", "k2"}))) | ||
85 | assert.are.same({ | ||
86 | {"k3", "v3"}, | ||
87 | {"k2", "v2", {"sub order"}}, | ||
88 | {"k1", "v1"}, | ||
89 | {"k4", "v4"}, | ||
90 | {"k5", "v5"}, | ||
91 | }, collect(util.sortedpairs({ | ||
92 | k1 = "v1", k2 = "v2", k3 = "v3", k4 = "v4", k5 = "v5" | ||
93 | }, {"k3", {"k2", {"sub order"}}, "k1"}))) | ||
94 | end) | ||
95 | end) | ||
96 | |||
97 | describe("core.util.show_table", function() | ||
98 | it("returns a pretty-printed string containing the representation of the given table", function() | ||
99 | local result | ||
100 | |||
101 | local t1 = {1, 2, 3} | ||
102 | result = core_util.show_table(t1) | ||
103 | assert.truthy(result:find("[1] = 1", 1, true)) | ||
104 | assert.truthy(result:find("[2] = 2", 1, true)) | ||
105 | assert.truthy(result:find("[3] = 3", 1, true)) | ||
106 | |||
107 | local t2 = {a = 1, b = 2, c = 3} | ||
108 | result = core_util.show_table(t2) | ||
109 | assert.truthy(result:find("[\"a\"] = 1", 1, true)) | ||
110 | assert.truthy(result:find("[\"b\"] = 2", 1, true)) | ||
111 | assert.truthy(result:find("[\"c\"] = 3", 1, true)) | ||
112 | |||
113 | local t3 = {a = 1, b = "2", c = {3}} | ||
114 | result = core_util.show_table(t3) | ||
115 | assert.truthy(result:find("[\"a\"] = 1", 1, true)) | ||
116 | assert.truthy(result:find("[\"b\"] = \"2\"", 1, true)) | ||
117 | assert.truthy(result:find("[\"c\"] = {", 1, true)) | ||
118 | assert.truthy(result:find("[1] = 3", 1, true)) | ||
119 | |||
120 | local t4 = {a = 1, b = {c = 2, d = {e = "4"}}} | ||
121 | result = core_util.show_table(t4) | ||
122 | assert.truthy(result:find("[\"a\"] = 1", 1, true)) | ||
123 | assert.truthy(result:find("[\"b\"] = {", 1, true)) | ||
124 | assert.truthy(result:find("[\"c\"] = 2", 1, true)) | ||
125 | assert.truthy(result:find("[\"d\"] = {", 1, true)) | ||
126 | assert.truthy(result:find("[\"e\"] = \"4\"", 1, true)) | ||
127 | end) | ||
128 | end) | ||
129 | |||
130 | describe("core.util.cleanup_path", function() | ||
131 | it("does not change order of existing items of prepended path", function() | ||
132 | local sys_path = P'/usr/local/bin;/usr/bin' | ||
133 | local lr_path = P'/home/user/.luarocks/bin;/usr/bin' | ||
134 | local path = lr_path .. ';' .. sys_path | ||
135 | |||
136 | local result = core_util.cleanup_path(path, ';', '5.3', false) | ||
137 | assert.are.equal(P'/home/user/.luarocks/bin;/usr/local/bin;/usr/bin', result) | ||
138 | end) | ||
139 | |||
140 | it("does not change order of existing items of appended path", function() | ||
141 | local sys_path = P'/usr/local/bin;/usr/bin' | ||
142 | local lr_path = P'/home/user/.luarocks/bin;/usr/bin' | ||
143 | local path = sys_path .. ';' .. lr_path | ||
144 | |||
145 | local result = core_util.cleanup_path(path, ';', '5.3', true) | ||
146 | assert.are.equal(P'/usr/local/bin;/usr/bin;/home/user/.luarocks/bin', result) | ||
147 | end) | ||
148 | |||
149 | it("rewrites versions that do not match the provided version", function() | ||
150 | local expected = P'a/b/lua/5.3/?.lua;a/b/c/lua/5.3/?.lua' | ||
151 | local result = core_util.cleanup_path(P'a/b/lua/5.2/?.lua;a/b/c/lua/5.3/?.lua', ';', '5.3') | ||
152 | assert.are.equal(expected, result) | ||
153 | end) | ||
154 | |||
155 | it("does not rewrite versions for which the provided version is a substring", function() | ||
156 | local expected = P'a/b/lua/5.3/?.lua;a/b/c/lua/5.3.4/?.lua' | ||
157 | local result = core_util.cleanup_path(P'a/b/lua/5.2/?.lua;a/b/c/lua/5.3.4/?.lua', ';', '5.3') | ||
158 | assert.are.equal(expected, result) | ||
159 | end) | ||
160 | end) | ||
161 | end) | ||
diff --git a/spec/unpack_spec.lua b/spec/unpack_spec.lua index 00d6781f..59f7eb0b 100644 --- a/spec/unpack_spec.lua +++ b/spec/unpack_spec.lua | |||
@@ -3,8 +3,6 @@ local lfs = require("lfs") | |||
3 | local run = test_env.run | 3 | local run = test_env.run |
4 | local testing_paths = test_env.testing_paths | 4 | local testing_paths = test_env.testing_paths |
5 | 5 | ||
6 | test_env.unload_luarocks() | ||
7 | |||
8 | local extra_rocks = { | 6 | local extra_rocks = { |
9 | "/cprint-${CPRINT}.src.rock", | 7 | "/cprint-${CPRINT}.src.rock", |
10 | "/cprint-${CPRINT}.rockspec", | 8 | "/cprint-${CPRINT}.rockspec", |
diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua index 119d34b6..cc0b606c 100644 --- a/spec/upload_spec.lua +++ b/spec/upload_spec.lua | |||
@@ -2,38 +2,41 @@ local test_env = require("spec.util.test_env") | |||
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | local testing_paths = test_env.testing_paths | 3 | local testing_paths = test_env.testing_paths |
4 | 4 | ||
5 | test_env.unload_luarocks() | ||
6 | |||
7 | describe("luarocks upload #integration", function() | 5 | describe("luarocks upload #integration", function() |
8 | 6 | ||
9 | before_each(function() | 7 | describe("general tests", function() |
10 | test_env.setup_specs() | 8 | before_each(function() |
11 | end) | 9 | test_env.setup_specs(nil) |
10 | end) | ||
12 | 11 | ||
13 | it("with no flags/arguments", function() | 12 | it("with no flags/arguments", function() |
14 | assert.is_false(run.luarocks_bool("upload")) | 13 | assert.is_false(run.luarocks_bool("upload")) |
15 | end) | 14 | end) |
16 | 15 | ||
17 | it("invalid rockspec", function() | 16 | it("invalid rockspec", function() |
18 | assert.is_false(run.luarocks_bool("upload invalid.rockspec")) | 17 | assert.is_false(run.luarocks_bool("upload invalid.rockspec")) |
19 | end) | 18 | end) |
20 | 19 | ||
21 | it("api key invalid", function() | 20 | it("api key invalid", function() |
22 | assert.is_false(run.luarocks_bool("upload --api-key=invalid invalid.rockspec")) | 21 | assert.is_false(run.luarocks_bool("upload --api-key=invalid invalid.rockspec")) |
23 | end) | 22 | end) |
24 | 23 | ||
25 | it("api key invalid and skip-pack", function() | 24 | it("api key invalid and skip-pack", function() |
26 | assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --skip-pack " .. testing_paths.testing_server .. "/luasocket-${LUASOCKET}.rockspec")) | 25 | assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --skip-pack " .. testing_paths.testing_server .. "/luasocket-${LUASOCKET}.rockspec")) |
27 | end) | 26 | end) |
28 | 27 | ||
29 | it("force #unix", function() | 28 | it("force #unix", function() |
30 | assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --force " .. testing_paths.testing_server .. "/luasocket-${LUASOCKET}.rockspec")) | 29 | assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --force " .. testing_paths.testing_server .. "/luasocket-${LUASOCKET}.rockspec")) |
30 | end) | ||
31 | end) | 31 | end) |
32 | 32 | ||
33 | describe("tests with Xavante server #mock", function() | 33 | describe("tests with Xavante server #mock", function() |
34 | before_each(test_env.mock_server_init) | 34 | lazy_setup(function() |
35 | test_env.setup_specs(nil, "mock") | ||
36 | test_env.mock_server_init() | ||
37 | end) | ||
35 | 38 | ||
36 | after_each(test_env.mock_server_done) | 39 | lazy_teardown(test_env.mock_server_done) |
37 | 40 | ||
38 | it("rockspec with api-key", function() | 41 | it("rockspec with api-key", function() |
39 | assert.is_true(run.luarocks_bool("upload " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.openssl_dirs .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"})) | 42 | assert.is_true(run.luarocks_bool("upload " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.openssl_dirs .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"})) |
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index f311a370..15aa554d 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua | |||
@@ -809,52 +809,6 @@ local function get_luarocks_platform(variables) | |||
809 | return execute_output(cmd, false, variables) | 809 | return execute_output(cmd, false, variables) |
810 | end | 810 | end |
811 | 811 | ||
812 | --- Function for initial setup of environment, variables, md5sums for spec files | ||
813 | function test_env.setup_specs(extra_rocks) | ||
814 | local testrun_dir = test_env.testing_paths.testrun_dir | ||
815 | local variables = test_env.env_variables | ||
816 | |||
817 | -- if global variable about successful creation of testing environment doesn't exist, build environment | ||
818 | if not test_env.setup_done then | ||
819 | if test_env.CI then | ||
820 | if not exists(os.getenv("HOME"), ".ssh/id_rsa.pub") then | ||
821 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") | ||
822 | execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") | ||
823 | execute_bool("chmod og-wx ~/.ssh/authorized_keys") | ||
824 | execute_bool("ssh-keyscan localhost >> ~/.ssh/known_hosts") | ||
825 | end | ||
826 | end | ||
827 | |||
828 | test_env.main() | ||
829 | |||
830 | -- preload before meddling with package.path | ||
831 | require("spec.util.git_repo") | ||
832 | require("spec.util.quick") | ||
833 | |||
834 | package.path = variables.LUA_PATH | ||
835 | package.cpath = variables.LUA_CPATH | ||
836 | |||
837 | test_env.platform = get_luarocks_platform(test_env.env_variables) | ||
838 | test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" | ||
839 | test_env.md5sums = create_md5sums(test_env.testing_paths) | ||
840 | test_env.setup_done = true | ||
841 | title("RUNNING TESTS") | ||
842 | end | ||
843 | |||
844 | if extra_rocks then | ||
845 | local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) | ||
846 | if make_manifest then | ||
847 | test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) | ||
848 | end | ||
849 | end | ||
850 | |||
851 | if test_env.RESET_ENV then | ||
852 | reset_environment(test_env.testing_paths, test_env.md5sums, variables) | ||
853 | end | ||
854 | |||
855 | lfs.chdir(testrun_dir) | ||
856 | end | ||
857 | |||
858 | --- Test if required rock is installed and if not, install it. | 812 | --- Test if required rock is installed and if not, install it. |
859 | -- Return `true` if the rock is already installed or has been installed successfully, | 813 | -- Return `true` if the rock is already installed or has been installed successfully, |
860 | -- `false` if installation failed. | 814 | -- `false` if installation failed. |
@@ -1024,10 +978,14 @@ local function setup_luarocks() | |||
1024 | end | 978 | end |
1025 | 979 | ||
1026 | local function mock_api_call(path) | 980 | local function mock_api_call(path) |
1027 | test_env.execute(C(tool("wget"), "--quiet --timeout=5 --tries=1 localhost:8080" .. path)) | 981 | return test_env.execute(C(tool("wget"), "--timeout=0.1 --quiet --tries=10 http://localhost:8080" .. path)) |
1028 | end | 982 | end |
1029 | 983 | ||
1030 | function test_env.mock_server_init() | 984 | function test_env.mock_server_init() |
985 | if not test_env.mock_prepared then | ||
986 | error("need to setup_specs with with_mock set to true") | ||
987 | end | ||
988 | |||
1031 | local testing_paths = test_env.testing_paths | 989 | local testing_paths = test_env.testing_paths |
1032 | assert(test_env.need_rock("restserver-xavante")) | 990 | assert(test_env.need_rock("restserver-xavante")) |
1033 | 991 | ||
@@ -1043,14 +1001,13 @@ function test_env.mock_server_init() | |||
1043 | 1001 | ||
1044 | os.execute(test_env.execute_helper(bg_cmd, true, test_env.env_variables)) | 1002 | os.execute(test_env.execute_helper(bg_cmd, true, test_env.env_variables)) |
1045 | 1003 | ||
1046 | for _ = 1, 10 do | 1004 | for _ = 1, 100 do |
1047 | if mock_api_call("/api/tool_version") then | 1005 | if mock_api_call("/api/tool_version") then |
1048 | break | 1006 | break |
1049 | end | 1007 | end |
1050 | |||
1051 | os.execute(test_env.TEST_TARGET_OS == "windows" | 1008 | os.execute(test_env.TEST_TARGET_OS == "windows" |
1052 | and "timeout 1 > NUL" | 1009 | and "ping 192.0.2.0 -n 1 -w 250 > NUL" |
1053 | or "sleep 1") | 1010 | or "sleep 0.1") |
1054 | end | 1011 | end |
1055 | 1012 | ||
1056 | end | 1013 | end |
@@ -1070,6 +1027,10 @@ local function find_binary_rock(src_rock, dirname) | |||
1070 | end | 1027 | end |
1071 | 1028 | ||
1072 | local function prepare_mock_server_binary_rocks() | 1029 | local function prepare_mock_server_binary_rocks() |
1030 | if test_env.mock_prepared then | ||
1031 | return | ||
1032 | end | ||
1033 | |||
1073 | local testing_paths = test_env.testing_paths | 1034 | local testing_paths = test_env.testing_paths |
1074 | 1035 | ||
1075 | local rocks = { | 1036 | local rocks = { |
@@ -1106,6 +1067,8 @@ local function prepare_mock_server_binary_rocks() | |||
1106 | if make_manifest then | 1067 | if make_manifest then |
1107 | test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_server))) | 1068 | test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_server))) |
1108 | end | 1069 | end |
1070 | |||
1071 | test_env.mock_prepared = true | ||
1109 | end | 1072 | end |
1110 | 1073 | ||
1111 | --- | 1074 | --- |
@@ -1169,8 +1132,58 @@ function test_env.main() | |||
1169 | download_rocks(urls, testing_paths.testing_server) | 1132 | download_rocks(urls, testing_paths.testing_server) |
1170 | 1133 | ||
1171 | build_environment(rocks, env_vars) | 1134 | build_environment(rocks, env_vars) |
1135 | end | ||
1136 | |||
1137 | --- Function for initial setup of environment, variables, md5sums for spec files | ||
1138 | function test_env.setup_specs(extra_rocks, use_mock) | ||
1139 | test_env.unload_luarocks() | ||
1140 | |||
1141 | local testrun_dir = test_env.testing_paths.testrun_dir | ||
1142 | local variables = test_env.env_variables | ||
1143 | |||
1144 | -- if global variable about successful creation of testing environment doesn't exist, build environment | ||
1145 | if not test_env.setup_done then | ||
1146 | if test_env.CI then | ||
1147 | if not exists(os.getenv("HOME"), ".ssh/id_rsa.pub") then | ||
1148 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") | ||
1149 | execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") | ||
1150 | execute_bool("chmod og-wx ~/.ssh/authorized_keys") | ||
1151 | execute_bool("ssh-keyscan localhost >> ~/.ssh/known_hosts") | ||
1152 | end | ||
1153 | end | ||
1154 | |||
1155 | test_env.main() | ||
1156 | |||
1157 | -- preload before meddling with package.path | ||
1158 | require("spec.util.git_repo") | ||
1159 | require("spec.util.quick") | ||
1172 | 1160 | ||
1173 | prepare_mock_server_binary_rocks() | 1161 | package.path = variables.LUA_PATH |
1162 | package.cpath = variables.LUA_CPATH | ||
1163 | |||
1164 | test_env.platform = get_luarocks_platform(test_env.env_variables) | ||
1165 | test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" | ||
1166 | test_env.md5sums = create_md5sums(test_env.testing_paths) | ||
1167 | test_env.setup_done = true | ||
1168 | title("RUNNING TESTS") | ||
1169 | end | ||
1170 | |||
1171 | if use_mock == "mock" then | ||
1172 | prepare_mock_server_binary_rocks() | ||
1173 | end | ||
1174 | |||
1175 | if extra_rocks then | ||
1176 | local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) | ||
1177 | if make_manifest then | ||
1178 | test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) | ||
1179 | end | ||
1180 | end | ||
1181 | |||
1182 | if test_env.RESET_ENV then | ||
1183 | reset_environment(test_env.testing_paths, test_env.md5sums, variables) | ||
1184 | end | ||
1185 | |||
1186 | lfs.chdir(testrun_dir) | ||
1174 | end | 1187 | end |
1175 | 1188 | ||
1176 | test_env.set_lua_version() | 1189 | test_env.set_lua_version() |
diff --git a/spec/util_spec.lua b/spec/util_spec.lua index abc0da57..0f199c9c 100644 --- a/spec/util_spec.lua +++ b/spec/util_spec.lua | |||
@@ -1,8 +1,6 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local lfs = require("lfs") | 2 | local lfs = require("lfs") |
3 | local run = test_env.run | 3 | local run = test_env.run |
4 | local testing_paths = test_env.testing_paths | ||
5 | local P = test_env.P | ||
6 | 4 | ||
7 | describe("Basic tests #integration", function() | 5 | describe("Basic tests #integration", function() |
8 | 6 | ||
@@ -55,162 +53,3 @@ describe("Basic tests #integration", function() | |||
55 | end) | 53 | end) |
56 | 54 | ||
57 | end) | 55 | end) |
58 | |||
59 | test_env.unload_luarocks() | ||
60 | local util = require("luarocks.util") | ||
61 | local core_util = require("luarocks.core.util") | ||
62 | |||
63 | describe("luarocks.util #unit", function() | ||
64 | local runner | ||
65 | |||
66 | setup(function() | ||
67 | runner = require("luacov.runner") | ||
68 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | ||
69 | runner.tick = true | ||
70 | end) | ||
71 | |||
72 | teardown(function() | ||
73 | runner.shutdown() | ||
74 | end) | ||
75 | |||
76 | describe("util.variable_substitutions", function() | ||
77 | it("replaces variables", function() | ||
78 | local t = { | ||
79 | ["hello"] = "$(KIND) world", | ||
80 | } | ||
81 | util.variable_substitutions(t, { | ||
82 | ["KIND"] = "happy", | ||
83 | }) | ||
84 | assert.are.same({ | ||
85 | ["hello"] = "happy world", | ||
86 | }, t) | ||
87 | end) | ||
88 | |||
89 | it("missing variables are empty", function() | ||
90 | local t = { | ||
91 | ["hello"] = "$(KIND) world", | ||
92 | } | ||
93 | util.variable_substitutions(t, { | ||
94 | }) | ||
95 | assert.are.same({ | ||
96 | ["hello"] = " world", | ||
97 | }, t) | ||
98 | end) | ||
99 | end) | ||
100 | |||
101 | describe("util.sortedpairs", function() | ||
102 | local function collect(iter, state, var) | ||
103 | local collected = {} | ||
104 | |||
105 | while true do | ||
106 | local returns = {iter(state, var)} | ||
107 | |||
108 | if returns[1] == nil then | ||
109 | return collected | ||
110 | else | ||
111 | table.insert(collected, returns) | ||
112 | var = returns[1] | ||
113 | end | ||
114 | end | ||
115 | end | ||
116 | |||
117 | it("default sort", function() | ||
118 | assert.are.same({}, collect(util.sortedpairs({}))) | ||
119 | assert.are.same({ | ||
120 | {1, "v1"}, | ||
121 | {2, "v2"}, | ||
122 | {3, "v3"}, | ||
123 | {"bar", "v5"}, | ||
124 | {"foo", "v4"} | ||
125 | }, collect(util.sortedpairs({"v1", "v2", "v3", foo = "v4", bar = "v5"}))) | ||
126 | end) | ||
127 | |||
128 | it("sort by function", function() | ||
129 | local function compare(a, b) return a > b end | ||
130 | assert.are.same({}, collect(util.sortedpairs({}, compare))) | ||
131 | assert.are.same({ | ||
132 | {3, "v3"}, | ||
133 | {2, "v2"}, | ||
134 | {1, "v1"} | ||
135 | }, collect(util.sortedpairs({"v1", "v2", "v3"}, compare))) | ||
136 | end) | ||
137 | |||
138 | it("sort by priority table", function() | ||
139 | assert.are.same({}, collect(util.sortedpairs({}, {"k1", "k2"}))) | ||
140 | assert.are.same({ | ||
141 | {"k3", "v3"}, | ||
142 | {"k2", "v2", {"sub order"}}, | ||
143 | {"k1", "v1"}, | ||
144 | {"k4", "v4"}, | ||
145 | {"k5", "v5"}, | ||
146 | }, collect(util.sortedpairs({ | ||
147 | k1 = "v1", k2 = "v2", k3 = "v3", k4 = "v4", k5 = "v5" | ||
148 | }, {"k3", {"k2", {"sub order"}}, "k1"}))) | ||
149 | end) | ||
150 | end) | ||
151 | |||
152 | describe("core.util.show_table", function() | ||
153 | it("returns a pretty-printed string containing the representation of the given table", function() | ||
154 | local result | ||
155 | |||
156 | local t1 = {1, 2, 3} | ||
157 | result = core_util.show_table(t1) | ||
158 | assert.truthy(result:find("[1] = 1", 1, true)) | ||
159 | assert.truthy(result:find("[2] = 2", 1, true)) | ||
160 | assert.truthy(result:find("[3] = 3", 1, true)) | ||
161 | |||
162 | local t2 = {a = 1, b = 2, c = 3} | ||
163 | result = core_util.show_table(t2) | ||
164 | assert.truthy(result:find("[\"a\"] = 1", 1, true)) | ||
165 | assert.truthy(result:find("[\"b\"] = 2", 1, true)) | ||
166 | assert.truthy(result:find("[\"c\"] = 3", 1, true)) | ||
167 | |||
168 | local t3 = {a = 1, b = "2", c = {3}} | ||
169 | result = core_util.show_table(t3) | ||
170 | assert.truthy(result:find("[\"a\"] = 1", 1, true)) | ||
171 | assert.truthy(result:find("[\"b\"] = \"2\"", 1, true)) | ||
172 | assert.truthy(result:find("[\"c\"] = {", 1, true)) | ||
173 | assert.truthy(result:find("[1] = 3", 1, true)) | ||
174 | |||
175 | local t4 = {a = 1, b = {c = 2, d = {e = "4"}}} | ||
176 | result = core_util.show_table(t4) | ||
177 | assert.truthy(result:find("[\"a\"] = 1", 1, true)) | ||
178 | assert.truthy(result:find("[\"b\"] = {", 1, true)) | ||
179 | assert.truthy(result:find("[\"c\"] = 2", 1, true)) | ||
180 | assert.truthy(result:find("[\"d\"] = {", 1, true)) | ||
181 | assert.truthy(result:find("[\"e\"] = \"4\"", 1, true)) | ||
182 | end) | ||
183 | end) | ||
184 | |||
185 | describe("core.util.cleanup_path", function() | ||
186 | it("does not change order of existing items of prepended path", function() | ||
187 | local sys_path = P'/usr/local/bin;/usr/bin' | ||
188 | local lr_path = P'/home/user/.luarocks/bin;/usr/bin' | ||
189 | local path = lr_path .. ';' .. sys_path | ||
190 | |||
191 | local result = core_util.cleanup_path(path, ';', '5.3', false) | ||
192 | assert.are.equal(P'/home/user/.luarocks/bin;/usr/local/bin;/usr/bin', result) | ||
193 | end) | ||
194 | |||
195 | it("does not change order of existing items of appended path", function() | ||
196 | local sys_path = P'/usr/local/bin;/usr/bin' | ||
197 | local lr_path = P'/home/user/.luarocks/bin;/usr/bin' | ||
198 | local path = sys_path .. ';' .. lr_path | ||
199 | |||
200 | local result = core_util.cleanup_path(path, ';', '5.3', true) | ||
201 | assert.are.equal(P'/usr/local/bin;/usr/bin;/home/user/.luarocks/bin', result) | ||
202 | end) | ||
203 | |||
204 | it("rewrites versions that do not match the provided version", function() | ||
205 | local expected = P'a/b/lua/5.3/?.lua;a/b/c/lua/5.3/?.lua' | ||
206 | local result = core_util.cleanup_path(P'a/b/lua/5.2/?.lua;a/b/c/lua/5.3/?.lua', ';', '5.3') | ||
207 | assert.are.equal(expected, result) | ||
208 | end) | ||
209 | |||
210 | it("does not rewrite versions for which the provided version is a substring", function() | ||
211 | local expected = P'a/b/lua/5.3/?.lua;a/b/c/lua/5.3.4/?.lua' | ||
212 | local result = core_util.cleanup_path(P'a/b/lua/5.2/?.lua;a/b/c/lua/5.3.4/?.lua', ';', '5.3') | ||
213 | assert.are.equal(expected, result) | ||
214 | end) | ||
215 | end) | ||
216 | end) | ||
diff --git a/spec/which_spec.lua b/spec/which_spec.lua index 9ccb1040..5712511b 100644 --- a/spec/which_spec.lua +++ b/spec/which_spec.lua | |||
@@ -2,17 +2,14 @@ local test_env = require("spec.util.test_env") | |||
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | local P = test_env.P | 3 | local P = test_env.P |
4 | 4 | ||
5 | test_env.unload_luarocks() | ||
6 | |||
7 | local extra_rocks = { | 5 | local extra_rocks = { |
8 | "/say-1.2-1.src.rock", | 6 | "/say-1.2-1.src.rock", |
9 | } | 7 | } |
10 | 8 | ||
11 | describe("luarocks which #integration", function() | 9 | describe("luarocks which #integration", function() |
12 | 10 | ||
13 | setup(function() | 11 | lazy_setup(function() |
14 | test_env.setup_specs(extra_rocks) | 12 | test_env.setup_specs(extra_rocks) |
15 | test_env.unload_luarocks() -- need to be required here, because hardcoded is created after first loading of specs | ||
16 | end) | 13 | end) |
17 | 14 | ||
18 | it("fails on missing arguments", function() | 15 | it("fails on missing arguments", function() |
diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua index 5f9faa6e..abd5c80b 100644 --- a/spec/write_rockspec_spec.lua +++ b/spec/write_rockspec_spec.lua | |||
@@ -5,7 +5,7 @@ local run = test_env.run | |||
5 | 5 | ||
6 | describe("luarocks write_rockspec tests #integration", function() | 6 | describe("luarocks write_rockspec tests #integration", function() |
7 | 7 | ||
8 | before_each(function() | 8 | lazy_setup(function() |
9 | test_env.setup_specs() | 9 | test_env.setup_specs() |
10 | end) | 10 | end) |
11 | 11 | ||
@@ -20,7 +20,7 @@ describe("luarocks write_rockspec tests #integration", function() | |||
20 | describe("from #git #unix", function() | 20 | describe("from #git #unix", function() |
21 | local git | 21 | local git |
22 | 22 | ||
23 | setup(function() | 23 | lazy_setup(function() |
24 | git = git_repo.start() | 24 | git = git_repo.start() |
25 | end) | 25 | end) |
26 | 26 | ||
@@ -79,10 +79,11 @@ describe("luarocks write_rockspec tests #integration", function() | |||
79 | 79 | ||
80 | describe("from tarball #mock", function() | 80 | describe("from tarball #mock", function() |
81 | 81 | ||
82 | setup(function() | 82 | lazy_setup(function() |
83 | test_env.setup_specs(nil, "mock") | ||
83 | test_env.mock_server_init() | 84 | test_env.mock_server_init() |
84 | end) | 85 | end) |
85 | teardown(function() | 86 | lazy_teardown(function() |
86 | test_env.mock_server_done() | 87 | test_env.mock_server_done() |
87 | end) | 88 | end) |
88 | 89 | ||