diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-26 14:11:37 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-27 13:28:33 -0300 |
commit | 6bc6ede826843c3692971c14c27c3d27714b2126 (patch) | |
tree | a15196f6617c6cd6d683b69c51a26f57940d55bd /spec | |
parent | e0aa47df12c9b9beb05d380aac7d90a28a081a7b (diff) | |
download | luarocks-6bc6ede826843c3692971c14c27c3d27714b2126.tar.gz luarocks-6bc6ede826843c3692971c14c27c3d27714b2126.tar.bz2 luarocks-6bc6ede826843c3692971c14c27c3d27714b2126.zip |
tests(fetch): do not use restserver
Diffstat (limited to 'spec')
-rw-r--r-- | spec/build_spec.lua | 34 | ||||
-rw-r--r-- | spec/fetch_spec.lua | 540 | ||||
-rw-r--r-- | spec/util/quick.lua | 2 | ||||
-rw-r--r-- | spec/util/test_env.lua | 15 |
4 files changed, 309 insertions, 282 deletions
diff --git a/spec/build_spec.lua b/spec/build_spec.lua index 9b34ec54..a2c09119 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua | |||
@@ -64,8 +64,8 @@ describe("LuaRocks build #integration", function() | |||
64 | test = "test.lua" | 64 | test = "test.lua" |
65 | } | 65 | } |
66 | } | 66 | } |
67 | ]], finally) | 67 | ]]) |
68 | write_file("test.lua", "return {}", finally) | 68 | write_file("test.lua", "return {}") |
69 | 69 | ||
70 | assert.is_true(run.luarocks_bool("build --verbose test-1.0-1.rockspec")) | 70 | assert.is_true(run.luarocks_bool("build --verbose test-1.0-1.rockspec")) |
71 | assert.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) | 71 | assert.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) |
@@ -119,8 +119,8 @@ describe("LuaRocks build #integration", function() | |||
119 | test = "test.lua" | 119 | test = "test.lua" |
120 | } | 120 | } |
121 | } | 121 | } |
122 | ]], finally) | 122 | ]]) |
123 | write_file("test.lua", "return {}", finally) | 123 | write_file("test.lua", "return {}") |
124 | 124 | ||
125 | if test_env.TEST_TARGET_OS == "windows" then | 125 | if test_env.TEST_TARGET_OS == "windows" then |
126 | assert.is_false(run.luarocks_bool("build test-1.0-1.rockspec")) -- Error: This rockspec does not support windows platforms | 126 | assert.is_false(run.luarocks_bool("build test-1.0-1.rockspec")) -- Error: This rockspec does not support windows platforms |
@@ -149,8 +149,8 @@ describe("LuaRocks build #integration", function() | |||
149 | test = "test.lua" | 149 | test = "test.lua" |
150 | } | 150 | } |
151 | } | 151 | } |
152 | ]], finally) | 152 | ]]) |
153 | write_file("test.lua", "return {}", finally) | 153 | write_file("test.lua", "return {}") |
154 | 154 | ||
155 | assert.is_true(run.luarocks_bool("build test-1.0-1.rockspec --deps-mode=none")) | 155 | 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")) | 156 | assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) |
@@ -174,8 +174,8 @@ describe("LuaRocks build #integration", function() | |||
174 | test = "test.lua" | 174 | test = "test.lua" |
175 | } | 175 | } |
176 | } | 176 | } |
177 | ]], finally) | 177 | ]]) |
178 | write_file("test.lua", "return {}", finally) | 178 | write_file("test.lua", "return {}") |
179 | 179 | ||
180 | assert.is_true(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --pin --tree=lua_modules")) | 180 | assert.is_true(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --pin --tree=lua_modules")) |
181 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) | 181 | assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) |
@@ -189,7 +189,7 @@ describe("LuaRocks build #integration", function() | |||
189 | ["lua"] = test_env.lua_version .. "-1", | 189 | ["lua"] = test_env.lua_version .. "-1", |
190 | } | 190 | } |
191 | }, lockdata) | 191 | }, lockdata) |
192 | end) | 192 | end, finally) |
193 | end) | 193 | end) |
194 | 194 | ||
195 | it("supports --pin --only-deps #pinning", function() | 195 | it("supports --pin --only-deps #pinning", function() |
@@ -209,8 +209,8 @@ describe("LuaRocks build #integration", function() | |||
209 | test = "test.lua" | 209 | test = "test.lua" |
210 | } | 210 | } |
211 | } | 211 | } |
212 | ]], finally) | 212 | ]]) |
213 | write_file("test.lua", "return {}", finally) | 213 | write_file("test.lua", "return {}") |
214 | 214 | ||
215 | assert.is_true(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --pin --only-deps --tree=lua_modules")) | 215 | assert.is_true(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --pin --only-deps --tree=lua_modules")) |
216 | assert.is.falsy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) | 216 | assert.is.falsy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) |
@@ -225,7 +225,7 @@ describe("LuaRocks build #integration", function() | |||
225 | ["lua"] = test_env.lua_version .. "-1", | 225 | ["lua"] = test_env.lua_version .. "-1", |
226 | } | 226 | } |
227 | }, lockdata) | 227 | }, lockdata) |
228 | end) | 228 | end, finally) |
229 | end) | 229 | end) |
230 | 230 | ||
231 | it("lmathx deps partial match", function() | 231 | it("lmathx deps partial match", function() |
@@ -316,8 +316,8 @@ describe("LuaRocks build #integration", function() | |||
316 | test = "test.lua" | 316 | test = "test.lua" |
317 | } | 317 | } |
318 | } | 318 | } |
319 | ]], finally) | 319 | ]]) |
320 | write_file("test.lua", "return {}", finally) | 320 | write_file("test.lua", "return {}") |
321 | 321 | ||
322 | assert.is.truthy(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --only-deps")) | 322 | assert.is.truthy(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --only-deps")) |
323 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) | 323 | assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/test/1.0-1/test-1.0-1.rockspec")) |
@@ -342,8 +342,8 @@ describe("LuaRocks build #integration", function() | |||
342 | test = "test.lua" | 342 | test = "test.lua" |
343 | } | 343 | } |
344 | } | 344 | } |
345 | ]], finally) | 345 | ]]) |
346 | write_file("test.lua", "return {}", finally) | 346 | write_file("test.lua", "return {}") |
347 | 347 | ||
348 | assert.is.truthy(run.luarocks_bool("pack test-1.0-1.rockspec")) | 348 | assert.is.truthy(run.luarocks_bool("pack test-1.0-1.rockspec")) |
349 | assert.is.truthy(lfs.attributes("test-1.0-1.src.rock")) | 349 | assert.is.truthy(lfs.attributes("test-1.0-1.src.rock")) |
@@ -489,7 +489,7 @@ describe("LuaRocks build #integration", function() | |||
489 | build = "build.lua" | 489 | build = "build.lua" |
490 | } | 490 | } |
491 | } | 491 | } |
492 | ]], finally) | 492 | ]]) |
493 | assert.is_false(run.luarocks_bool("build missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\"")) | 493 | assert.is_false(run.luarocks_bool("build missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\"")) |
494 | end, finally) | 494 | end, finally) |
495 | end) | 495 | end) |
diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua index 046d7b7b..38da379e 100644 --- a/spec/fetch_spec.lua +++ b/spec/fetch_spec.lua | |||
@@ -1,19 +1,20 @@ | |||
1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
2 | local git_repo = require("spec.util.git_repo") | ||
3 | 2 | ||
4 | test_env.unload_luarocks() | 3 | test_env.unload_luarocks() |
5 | test_env.setup_specs() | 4 | test_env.setup_specs() |
6 | local cfg = require("luarocks.core.cfg") | 5 | local cfg = require("luarocks.core.cfg") |
7 | local fetch = require("luarocks.fetch") | 6 | local fetch = require("luarocks.fetch") |
8 | local fs = require("luarocks.fs") | 7 | local fs = require("luarocks.fs") |
8 | local dir = require("luarocks.dir") | ||
9 | local path = require("luarocks.path") | 9 | local path = require("luarocks.path") |
10 | local rockspecs = require("luarocks.rockspecs") | 10 | local rockspecs = require("luarocks.rockspecs") |
11 | local lfs = require("lfs") | 11 | local lfs = require("lfs") |
12 | local get_tmp_path = test_env.get_tmp_path | 12 | local get_tmp_path = test_env.get_tmp_path |
13 | local testing_paths = test_env.testing_paths | 13 | local testing_paths = test_env.testing_paths |
14 | local write_file = test_env.write_file | 14 | local write_file = test_env.write_file |
15 | local P = test_env.P | ||
15 | 16 | ||
16 | describe("luarocks fetch #unit #mock", function() | 17 | describe("luarocks fetch #unit", function() |
17 | local are_same_files = function(file1, file2) | 18 | local are_same_files = function(file1, file2) |
18 | return file1 == file2 or lfs.attributes(file1).ino == lfs.attributes(file2).ino | 19 | return file1 == file2 or lfs.attributes(file1).ino == lfs.attributes(file2).ino |
19 | end | 20 | end |
@@ -23,7 +24,40 @@ describe("luarocks fetch #unit #mock", function() | |||
23 | setup(function() | 24 | setup(function() |
24 | cfg.init() | 25 | cfg.init() |
25 | fs.init() | 26 | fs.init() |
26 | test_env.mock_server_init() | 27 | |
28 | -- mock network access | ||
29 | fs.download = function(url, destfile) | ||
30 | local mockfile = P(url:gsub("http://localhost:8080/file", testing_paths.fixtures_dir)) | ||
31 | if not destfile then | ||
32 | destfile = dir.base_name(mockfile) | ||
33 | end | ||
34 | destfile = fs.absolute_name(destfile) | ||
35 | |||
36 | local fdr = io.open(mockfile, "rb") | ||
37 | if not fdr then | ||
38 | return nil, "mock failed opening for reading" | ||
39 | end | ||
40 | |||
41 | local fdw = io.open(destfile, "wb") | ||
42 | if not fdr then | ||
43 | return nil, "mock failed opening for writing" | ||
44 | end | ||
45 | |||
46 | local data = fdr:read("*a") | ||
47 | if not data then | ||
48 | return nil, "mock failed reading" | ||
49 | end | ||
50 | |||
51 | local ok = fdw:write(data) | ||
52 | if not ok then | ||
53 | return nil, "mock failed writing" | ||
54 | end | ||
55 | |||
56 | fdr:close() | ||
57 | fdw:close() | ||
58 | |||
59 | return true, destfile | ||
60 | end | ||
27 | 61 | ||
28 | runner = require("luacov.runner") | 62 | runner = require("luacov.runner") |
29 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | 63 | runner.init(testing_paths.testrun_dir .. "/luacov.config") |
@@ -31,32 +65,31 @@ describe("luarocks fetch #unit #mock", function() | |||
31 | end) | 65 | end) |
32 | 66 | ||
33 | teardown(function() | 67 | teardown(function() |
34 | test_env.mock_server_done() | ||
35 | |||
36 | runner.shutdown() | 68 | runner.shutdown() |
37 | end) | 69 | end) |
38 | 70 | ||
71 | |||
39 | describe("fetch.fetch_url", function() | 72 | describe("fetch.fetch_url", function() |
40 | 73 | ||
41 | it("fetches the url argument and returns the absolute path of the fetched file", function() | 74 | it("fetches the url argument and returns the absolute path of the fetched file", function() |
42 | local fetchedfile, err = fetch.fetch_url("http://localhost:8080/file/a_rock.lua") | 75 | test_env.run_in_tmp(function() |
43 | assert(fetchedfile, err) | 76 | local fetchedfile, err = fetch.fetch_url("http://localhost:8080/file/a_rock.lua") |
44 | assert.truthy(are_same_files(fetchedfile, lfs.currentdir() .. "/a_rock.lua")) | 77 | assert(fetchedfile, err) |
45 | local fd = assert(io.open(fetchedfile, "r")) | 78 | assert.truthy(are_same_files(fetchedfile, lfs.currentdir() .. "/a_rock.lua")) |
46 | local fetchedcontent = assert(fd:read("*a")) | 79 | local fd = assert(io.open(fetchedfile, "r")) |
47 | fd:close() | 80 | local fetchedcontent = assert(fd:read("*a")) |
48 | fd = assert(io.open(testing_paths.fixtures_dir .. "/a_rock.lua", "r")) | 81 | fd:close() |
49 | local filecontent = assert(fd:read("*a")) | 82 | fd = assert(io.open(testing_paths.fixtures_dir .. "/a_rock.lua", "r")) |
50 | fd:close() | 83 | local filecontent = assert(fd:read("*a")) |
51 | assert.same(fetchedcontent, filecontent) | 84 | fd:close() |
52 | os.remove(fetchedfile) | 85 | assert.same(fetchedcontent, filecontent) |
86 | end, finally) | ||
53 | end) | 87 | end) |
54 | 88 | ||
55 | it("returns the absolute path of the filename argument if the url represents a file", function() | 89 | it("returns the absolute path of the filename argument if the url represents a file", function() |
56 | test_env.run_in_tmp(function(tmpdir) | 90 | test_env.run_in_tmp(function() |
57 | write_file("test.lua", "return {}", finally) | 91 | write_file("test.lua", "return {}") |
58 | 92 | ||
59 | fs.change_dir(tmpdir) | ||
60 | local file, err = fetch.fetch_url("file://test.lua") | 93 | local file, err = fetch.fetch_url("file://test.lua") |
61 | assert.truthy(file, err) | 94 | assert.truthy(file, err) |
62 | assert.truthy(are_same_files(file, lfs.currentdir() .. "/test.lua")) | 95 | assert.truthy(are_same_files(file, lfs.currentdir() .. "/test.lua")) |
@@ -65,9 +98,7 @@ describe("luarocks fetch #unit #mock", function() | |||
65 | end) | 98 | end) |
66 | 99 | ||
67 | it("fails if local path is invalid and returns a helpful hint for relative paths", function() | 100 | it("fails if local path is invalid and returns a helpful hint for relative paths", function() |
68 | test_env.run_in_tmp(function(tmpdir) | 101 | test_env.run_in_tmp(function() |
69 | write_file("test.lua", "return {}", finally) | ||
70 | |||
71 | local ok, err = fetch.fetch_url("file://boo.lua") | 102 | local ok, err = fetch.fetch_url("file://boo.lua") |
72 | assert.falsy(ok) | 103 | assert.falsy(ok) |
73 | assert.match("note that given path in rockspec is not absolute: file://boo.lua", err) | 104 | assert.match("note that given path in rockspec is not absolute: file://boo.lua", err) |
@@ -84,55 +115,46 @@ describe("luarocks fetch #unit #mock", function() | |||
84 | end) | 115 | end) |
85 | 116 | ||
86 | describe("fetch.fetch_url_at_temp_dir", function() | 117 | describe("fetch.fetch_url_at_temp_dir", function() |
87 | local tmpfile | ||
88 | local tmpdir | ||
89 | |||
90 | after_each(function() | ||
91 | if tmpfile then | ||
92 | os.remove(tmpfile) | ||
93 | tmpfile = nil | ||
94 | end | ||
95 | if tmpdir then | ||
96 | lfs.rmdir(tmpdir) | ||
97 | tmpdir = nil | ||
98 | end | ||
99 | end) | ||
100 | 118 | ||
101 | it("returns the absolute path and the parent directory of the file specified by the url", function() | 119 | it("returns the absolute path and the parent directory of the file specified by the url", function() |
102 | tmpdir = get_tmp_path() | 120 | test_env.run_in_tmp(function(tmpdir) |
103 | lfs.mkdir(tmpdir) | 121 | local tmpfile = tmpdir .. "/tmpfile" |
104 | tmpfile = tmpdir .. "/tmpfile" | 122 | assert(io.open(tmpfile, "w")) |
105 | local fd = assert(io.open(tmpfile, "w")) | 123 | local pathname, dirname = fetch.fetch_url_at_temp_dir("file://" .. tmpfile, "test") |
106 | local pathname, dirname = fetch.fetch_url_at_temp_dir("file://" .. tmpfile, "test") | 124 | assert.truthy(are_same_files(tmpfile, pathname)) |
107 | assert.truthy(are_same_files(tmpfile, pathname)) | 125 | assert.truthy(are_same_files(tmpdir, dirname)) |
108 | assert.truthy(are_same_files(tmpdir, dirname)) | 126 | end, finally) |
109 | end) | 127 | end) |
110 | 128 | ||
111 | it("returns true and fetches the url into a temporary dir", function() | 129 | it("returns true and fetches the url into a temporary dir", function() |
112 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test") | 130 | test_env.run_in_tmp(function() |
113 | assert(fetchedfile, tmpdir) | 131 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test") |
114 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/a_rock.lua")) | 132 | assert(fetchedfile, tmpdir) |
115 | local fd = assert(io.open(fetchedfile, "r")) | 133 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/a_rock.lua")) |
116 | local fetchedcontent = assert(fd:read("*a")) | 134 | local fd = assert(io.open(fetchedfile, "r")) |
117 | fd:close() | 135 | local fetchedcontent = assert(fd:read("*a")) |
118 | fd = assert(io.open(testing_paths.fixtures_dir .. "/a_rock.lua", "r")) | 136 | fd:close() |
119 | local filecontent = assert(fd:read("*a")) | 137 | fd = assert(io.open(testing_paths.fixtures_dir .. "/a_rock.lua", "r")) |
120 | fd:close() | 138 | local filecontent = assert(fd:read("*a")) |
121 | assert.same(fetchedcontent, filecontent) | 139 | fd:close() |
140 | assert.same(fetchedcontent, filecontent) | ||
141 | end, finally) | ||
122 | end) | 142 | end) |
123 | 143 | ||
124 | it("returns true and fetches the url into a temporary dir with custom filename", function() | 144 | it("returns true and fetches the url into a temporary dir with custom filename", function() |
125 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test", "my_a_rock.lua") | 145 | test_env.run_in_tmp(function() |
126 | assert(fetchedfile, tmpdir) | 146 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test", "my_a_rock.lua") |
127 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/my_a_rock.lua")) | 147 | assert(fetchedfile, tmpdir) |
128 | assert.truthy(string.find(tmpdir, "test")) | 148 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/my_a_rock.lua")) |
129 | local fd = assert(io.open(fetchedfile, "r")) | 149 | assert.truthy(string.find(tmpdir, "test")) |
130 | local fetchedcontent = assert(fd:read("*a")) | 150 | local fd = assert(io.open(fetchedfile, "r")) |
131 | fd:close() | 151 | local fetchedcontent = assert(fd:read("*a")) |
132 | fd = assert(io.open(testing_paths.fixtures_dir .. "/a_rock.lua", "r")) | 152 | fd:close() |
133 | local filecontent = assert(fd:read("*a")) | 153 | fd = assert(io.open(testing_paths.fixtures_dir .. "/a_rock.lua", "r")) |
134 | fd:close() | 154 | local filecontent = assert(fd:read("*a")) |
135 | assert.same(fetchedcontent, filecontent) | 155 | fd:close() |
156 | assert.same(fetchedcontent, filecontent) | ||
157 | end, finally) | ||
136 | end) | 158 | end) |
137 | 159 | ||
138 | it("returns false and does nothing if the file specified in the url is nonexistent", function() | 160 | it("returns false and does nothing if the file specified in the url is nonexistent", function() |
@@ -147,20 +169,24 @@ describe("luarocks fetch #unit #mock", function() | |||
147 | 169 | ||
148 | describe("fetch.find_base_dir", function() | 170 | describe("fetch.find_base_dir", function() |
149 | it("extracts the archive given by the file argument and returns the inferred and the actual root directory in the archive", function() | 171 | it("extracts the archive given by the file argument and returns the inferred and the actual root directory in the archive", function() |
150 | local url = "http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz" | 172 | test_env.run_in_tmp(function() |
151 | local file, tmpdir = assert(fetch.fetch_url_at_temp_dir(url, "test")) | 173 | local url = "http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz" |
152 | local inferreddir, founddir = fetch.find_base_dir(file, tmpdir, url) | 174 | local file, tmpdir = assert(fetch.fetch_url_at_temp_dir(url, "test")) |
153 | assert.truthy(are_same_files(inferreddir, founddir)) | 175 | local inferreddir, founddir = fetch.find_base_dir(file, tmpdir, url) |
154 | assert.truthy(lfs.attributes(tmpdir .. "/" .. founddir)) | 176 | assert.truthy(are_same_files(inferreddir, founddir)) |
177 | assert.truthy(lfs.attributes(tmpdir .. "/" .. founddir)) | ||
178 | end, finally) | ||
155 | end) | 179 | end) |
156 | 180 | ||
157 | it("extracts the archive given by the file argument with given base directory and returns the inferred and the actual root directory in the archive", function() | 181 | it("extracts the archive given by the file argument with given base directory and returns the inferred and the actual root directory in the archive", function() |
158 | local url = "http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz" | 182 | test_env.run_in_tmp(function() |
159 | local file, tmpdir = assert(fetch.fetch_url_at_temp_dir(url, "test")) | 183 | local url = "http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz" |
160 | local inferreddir, founddir = fetch.find_base_dir(file, tmpdir, url, "basedir") | 184 | local file, tmpdir = assert(fetch.fetch_url_at_temp_dir(url, "test")) |
161 | assert.truthy(are_same_files(inferreddir, "basedir")) | 185 | local inferreddir, founddir = fetch.find_base_dir(file, tmpdir, url, "basedir") |
162 | assert.truthy(are_same_files(founddir, "an_upstream_tarball-0.1")) | 186 | assert.truthy(are_same_files(inferreddir, "basedir")) |
163 | assert.truthy(lfs.attributes(tmpdir .. "/" .. founddir)) | 187 | assert.truthy(are_same_files(founddir, "an_upstream_tarball-0.1")) |
188 | assert.truthy(lfs.attributes(tmpdir .. "/" .. founddir)) | ||
189 | end, finally) | ||
164 | end) | 190 | end) |
165 | 191 | ||
166 | it("returns false and does nothing if the temporary directory doesn't exist", function() | 192 | it("returns false and does nothing if the temporary directory doesn't exist", function() |
@@ -169,29 +195,25 @@ describe("luarocks fetch #unit #mock", function() | |||
169 | end) | 195 | end) |
170 | 196 | ||
171 | describe("fetch.fetch_and_unpack_rock", function() | 197 | describe("fetch.fetch_and_unpack_rock", function() |
172 | local tmpdir | ||
173 | |||
174 | after_each(function() | ||
175 | if tmpdir then | ||
176 | lfs.rmdir(tmpdir) | ||
177 | tmpdir = nil | ||
178 | end | ||
179 | end) | ||
180 | 198 | ||
181 | it("unpacks the rock file from the url and returns its resulting temporary parent directory", function() | 199 | it("unpacks the rock file from the url and returns its resulting temporary parent directory", function() |
182 | tmpdir = fetch.fetch_and_unpack_rock("http://localhost:8080/file/a_rock-1.0-1.src.rock") | 200 | test_env.run_in_tmp(function() |
183 | assert.truthy(string.find(tmpdir, "a_rock%-1%.0%-1")) | 201 | local tmpdir = fetch.fetch_and_unpack_rock("http://localhost:8080/file/a_rock-1.0-1.src.rock") |
184 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock-1.0-1.rockspec")) | 202 | assert.truthy(string.find(tmpdir, "a_rock%-1%.0%-1")) |
185 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock.lua")) | 203 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock-1.0-1.rockspec")) |
204 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock.lua")) | ||
205 | end, finally) | ||
186 | end) | 206 | end) |
187 | 207 | ||
188 | it("unpacks the rock file from the url with custom unpacking directory", function() | 208 | it("unpacks the rock file from the url with custom unpacking directory", function() |
189 | tmpdir = get_tmp_path() | 209 | test_env.run_in_tmp(function() |
190 | lfs.mkdir(tmpdir) | 210 | local tmpdir = get_tmp_path() |
191 | local resultingdir = fetch.fetch_and_unpack_rock("http://localhost:8080/file/a_rock-1.0-1.src.rock", tmpdir) | 211 | lfs.mkdir(tmpdir) |
192 | assert.truthy(are_same_files(resultingdir, tmpdir)) | 212 | local resultingdir = fetch.fetch_and_unpack_rock("http://localhost:8080/file/a_rock-1.0-1.src.rock", tmpdir) |
193 | assert.truthy(lfs.attributes(resultingdir .. "/a_rock-1.0-1.rockspec")) | 213 | assert.truthy(are_same_files(resultingdir, tmpdir)) |
194 | assert.truthy(lfs.attributes(resultingdir .. "/a_rock.lua")) | 214 | assert.truthy(lfs.attributes(resultingdir .. "/a_rock-1.0-1.rockspec")) |
215 | assert.truthy(lfs.attributes(resultingdir .. "/a_rock.lua")) | ||
216 | end, finally) | ||
195 | end) | 217 | end) |
196 | 218 | ||
197 | it("does nothing if the url doesn't represent a rock file", function() | 219 | it("does nothing if the url doesn't represent a rock file", function() |
@@ -209,71 +231,55 @@ describe("luarocks fetch #unit #mock", function() | |||
209 | end) | 231 | end) |
210 | 232 | ||
211 | describe("fetch.load_local_rockspec", function() | 233 | describe("fetch.load_local_rockspec", function() |
212 | local tmpdir | ||
213 | local olddir | ||
214 | |||
215 | before_each(function() | ||
216 | tmpdir = get_tmp_path() | ||
217 | olddir = lfs.currentdir() | ||
218 | lfs.mkdir(tmpdir) | ||
219 | lfs.chdir(tmpdir) | ||
220 | fs.change_dir(tmpdir) | ||
221 | end) | ||
222 | |||
223 | after_each(function() | ||
224 | if olddir then | ||
225 | lfs.chdir(olddir) | ||
226 | if tmpdir then | ||
227 | lfs.rmdir(tmpdir) | ||
228 | end | ||
229 | end | ||
230 | end) | ||
231 | |||
232 | it("returns a table representing the rockspec from the given file skipping some checks if the quick argument is enabled", function() | 234 | it("returns a table representing the rockspec from the given file skipping some checks if the quick argument is enabled", function() |
233 | local rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec", true) | 235 | test_env.run_in_tmp(function() |
234 | assert.same(rockspec.name, "a_rock") | 236 | local rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec", true) |
235 | assert.same(rockspec.version, "1.0-1") | 237 | assert.same(rockspec.name, "a_rock") |
236 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | 238 | assert.same(rockspec.version, "1.0-1") |
237 | assert.same(rockspec.description, { summary = "An example rockspec" }) | 239 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") |
238 | 240 | assert.same(rockspec.description, { summary = "An example rockspec" }) | |
239 | write_file("missing_mandatory_field-1.0-1.rockspec", [[ | 241 | |
240 | package="missing_mandatory_field" | 242 | write_file("missing_mandatory_field-1.0-1.rockspec", [[ |
241 | version="1.0-1" | 243 | package="missing_mandatory_field" |
242 | source = { | 244 | version="1.0-1" |
243 | url = "http://example.com/foo.tar.gz" | 245 | source = { |
244 | } | 246 | url = "http://example.com/foo.tar.gz" |
245 | ]], finally) | 247 | } |
246 | rockspec = fetch.load_local_rockspec("missing_mandatory_field-1.0-1.rockspec", true) | 248 | ]]) |
247 | assert.same(rockspec.name, "missing_mandatory_field") | 249 | rockspec = fetch.load_local_rockspec("missing_mandatory_field-1.0-1.rockspec", true) |
248 | assert.same(rockspec.version, "1.0-1") | 250 | assert.same(rockspec.name, "missing_mandatory_field") |
249 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") | 251 | assert.same(rockspec.version, "1.0-1") |
250 | 252 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") | |
251 | write_file("unknown_field-1.0-1.rockspec", [[ | 253 | |
252 | package="unknown_field" | 254 | write_file("unknown_field-1.0-1.rockspec", [[ |
253 | version="1.0-1" | 255 | package="unknown_field" |
254 | source = { | 256 | version="1.0-1" |
255 | url = "http://example.com/foo.tar.gz" | 257 | source = { |
256 | } | 258 | url = "http://example.com/foo.tar.gz" |
257 | unknown="foo" | 259 | } |
258 | ]], finally) | 260 | unknown="foo" |
259 | rockspec = fetch.load_local_rockspec("unknown_field-1.0-1.rockspec", true) | 261 | ]]) |
260 | assert.same(rockspec.name, "unknown_field") | 262 | rockspec = fetch.load_local_rockspec("unknown_field-1.0-1.rockspec", true) |
261 | assert.same(rockspec.version, "1.0-1") | 263 | assert.same(rockspec.name, "unknown_field") |
262 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") | 264 | assert.same(rockspec.version, "1.0-1") |
263 | 265 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") | |
264 | -- The previous calls fail if the detailed checking is done | 266 | |
265 | path.use_tree(testing_paths.testing_tree) | 267 | -- The previous calls fail if the detailed checking is done |
266 | assert.falsy(fetch.load_local_rockspec("missing_mandatory_field-1.0-1.rockspec")) | 268 | path.use_tree(testing_paths.testing_tree) |
267 | assert.falsy(fetch.load_local_rockspec("unknown_field-1.0-1.rockspec")) | 269 | assert.falsy(fetch.load_local_rockspec("missing_mandatory_field-1.0-1.rockspec")) |
270 | assert.falsy(fetch.load_local_rockspec("unknown_field-1.0-1.rockspec")) | ||
271 | end, finally) | ||
268 | end) | 272 | end) |
269 | 273 | ||
270 | it("returns a table representing the rockspec from the given file", function() | 274 | it("returns a table representing the rockspec from the given file", function() |
271 | path.use_tree(testing_paths.testing_tree) | 275 | test_env.run_in_tmp(function() |
272 | local rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec") | 276 | path.use_tree(testing_paths.testing_tree) |
273 | assert.same(rockspec.name, "a_rock") | 277 | local rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec") |
274 | assert.same(rockspec.version, "1.0-1") | 278 | assert.same(rockspec.name, "a_rock") |
275 | assert.same(rockspec.description, { summary = "An example rockspec" }) | 279 | assert.same(rockspec.version, "1.0-1") |
276 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | 280 | assert.same(rockspec.description, { summary = "An example rockspec" }) |
281 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | ||
282 | end, finally) | ||
277 | end) | 283 | end) |
278 | 284 | ||
279 | it("returns false if the rockspec in invalid", function() | 285 | it("returns false if the rockspec in invalid", function() |
@@ -285,70 +291,81 @@ describe("luarocks fetch #unit #mock", function() | |||
285 | end) | 291 | end) |
286 | 292 | ||
287 | it("returns false if the rockspec doesn't pass the type checking", function() | 293 | it("returns false if the rockspec doesn't pass the type checking", function() |
288 | write_file("type_mismatch_string-1.0-1.rockspec", [[ | 294 | test_env.run_in_tmp(function() |
289 | package="type_mismatch_version" | 295 | write_file("type_mismatch_string-1.0-1.rockspec", [[ |
290 | version=1.0 | 296 | package="type_mismatch_version" |
291 | ]], finally) | 297 | version=1.0 |
292 | assert.falsy(fetch.load_local_rockspec("type_mismatch_string-1.0-1.rockspec")) | 298 | ]]) |
299 | assert.falsy(fetch.load_local_rockspec("type_mismatch_string-1.0-1.rockspec")) | ||
300 | end, finally) | ||
293 | end) | 301 | end) |
294 | 302 | ||
295 | it("returns false if the rockspec file name is not right", function() | 303 | it("returns false if the rockspec file name is not right", function() |
296 | write_file("invalid_rockspec_name.rockspec", [[ | 304 | test_env.run_in_tmp(function() |
297 | package="invalid_rockspec_name" | 305 | write_file("invalid_rockspec_name.rockspec", [[ |
298 | version="1.0-1" | 306 | package="invalid_rockspec_name" |
299 | source = { | 307 | version="1.0-1" |
300 | url = "http://example.com/foo.tar.gz" | 308 | source = { |
301 | } | 309 | url = "http://example.com/foo.tar.gz" |
302 | build = { | 310 | } |
303 | 311 | build = { | |
304 | } | 312 | |
305 | ]], finally) | 313 | } |
306 | assert.falsy(fetch.load_local_rockspec("invalid_rockspec_name.rockspec")) | 314 | ]]) |
315 | assert.falsy(fetch.load_local_rockspec("invalid_rockspec_name.rockspec")) | ||
316 | end, finally) | ||
307 | end) | 317 | end) |
308 | 318 | ||
309 | it("returns false if the version in the rockspec file name doesn't match the version declared in the rockspec", function() | 319 | it("returns false if the version in the rockspec file name doesn't match the version declared in the rockspec", function() |
310 | write_file("inconsistent_versions-1.0-1.rockspec", [[ | 320 | test_env.run_in_tmp(function() |
311 | package="inconsistent_versions" | 321 | write_file("inconsistent_versions-1.0-1.rockspec", [[ |
312 | version="1.0-2" | 322 | package="inconsistent_versions" |
313 | source = { | 323 | version="1.0-2" |
314 | url = "http://example.com/foo.tar.gz" | 324 | source = { |
315 | } | 325 | url = "http://example.com/foo.tar.gz" |
316 | build = { | 326 | } |
317 | 327 | build = { | |
318 | } | 328 | |
319 | ]], finally) | 329 | } |
320 | assert.falsy(fetch.load_local_rockspec("inconsistent_versions-1.0-1.rockspec")) | 330 | ]]) |
331 | assert.falsy(fetch.load_local_rockspec("inconsistent_versions-1.0-1.rockspec")) | ||
332 | end, finally) | ||
321 | end) | 333 | end) |
322 | end) | 334 | end) |
323 | 335 | ||
324 | describe("fetch.load_rockspec", function() | 336 | describe("fetch.load_rockspec", function() |
337 | |||
325 | it("returns a table containing the requested rockspec by downloading it into a temporary directory", function() | 338 | it("returns a table containing the requested rockspec by downloading it into a temporary directory", function() |
326 | path.use_tree(testing_paths.testing_tree) | 339 | test_env.run_in_tmp(function() |
327 | local rockspec = fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec") | 340 | path.use_tree(testing_paths.testing_tree) |
328 | assert.same(rockspec.name, "a_rock") | 341 | local rockspec = fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec") |
329 | assert.same(rockspec.version, "1.0-1") | 342 | assert.same(rockspec.name, "a_rock") |
330 | assert.same(rockspec.description, { summary = "An example rockspec" }) | 343 | assert.same(rockspec.version, "1.0-1") |
331 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | 344 | assert.same(rockspec.description, { summary = "An example rockspec" }) |
332 | rockspec = fetch.load_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec") | 345 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") |
333 | assert.same(rockspec.name, "a_rock") | 346 | rockspec = fetch.load_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec") |
334 | assert.same(rockspec.version, "1.0-1") | 347 | assert.same(rockspec.name, "a_rock") |
335 | assert.same(rockspec.description, { summary = "An example rockspec" }) | 348 | assert.same(rockspec.version, "1.0-1") |
336 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | 349 | assert.same(rockspec.description, { summary = "An example rockspec" }) |
350 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | ||
351 | end, finally) | ||
337 | end) | 352 | end) |
338 | 353 | ||
339 | it("returns a table containing the requested rockspec by downloading it into a given directory", function() | 354 | it("returns a table containing the requested rockspec by downloading it into a given directory", function() |
340 | local tmpdir = get_tmp_path() | 355 | test_env.run_in_tmp(function() |
341 | lfs.mkdir(tmpdir) | 356 | local tmpdir = get_tmp_path() |
342 | 357 | lfs.mkdir(tmpdir) | |
343 | path.use_tree(testing_paths.testing_tree) | 358 | |
344 | local rockspec = fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec", tmpdir) | 359 | path.use_tree(testing_paths.testing_tree) |
345 | assert.same(rockspec.name, "a_rock") | 360 | local rockspec = fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec", tmpdir) |
346 | assert.same(rockspec.version, "1.0-1") | 361 | assert.same(rockspec.name, "a_rock") |
347 | assert.same(rockspec.description, { summary = "An example rockspec" }) | 362 | assert.same(rockspec.version, "1.0-1") |
348 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | 363 | assert.same(rockspec.description, { summary = "An example rockspec" }) |
349 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock-1.0-1.rockspec")) | 364 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") |
365 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock-1.0-1.rockspec")) | ||
350 | 366 | ||
351 | lfs.rmdir(tmpdir) | 367 | lfs.rmdir(tmpdir) |
368 | end, finally) | ||
352 | end) | 369 | end) |
353 | 370 | ||
354 | it("returns false if the given download directory doesn't exist", function() | 371 | it("returns false if the given download directory doesn't exist", function() |
@@ -361,89 +378,84 @@ describe("luarocks fetch #unit #mock", function() | |||
361 | end) | 378 | end) |
362 | 379 | ||
363 | describe("fetch.get_sources", function() | 380 | describe("fetch.get_sources", function() |
364 | local tmpdir | ||
365 | local olddir | ||
366 | |||
367 | before_each(function() | ||
368 | tmpdir = get_tmp_path() | ||
369 | olddir = lfs.currentdir() | ||
370 | lfs.mkdir(tmpdir) | ||
371 | lfs.chdir(tmpdir) | ||
372 | fs.change_dir(tmpdir) | ||
373 | end) | ||
374 | |||
375 | after_each(function() | ||
376 | if olddir then | ||
377 | lfs.chdir(olddir) | ||
378 | if tmpdir then | ||
379 | lfs.rmdir(tmpdir) | ||
380 | end | ||
381 | end | ||
382 | end) | ||
383 | 381 | ||
384 | it("downloads the sources for building a rock and returns the resulting source filename and its parent directory", function() | 382 | it("downloads the sources for building a rock and returns the resulting source filename and its parent directory", function() |
385 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) | 383 | test_env.run_in_tmp(function() |
386 | local file, dir = fetch.get_sources(rockspec, false) | 384 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) |
387 | assert.truthy(are_same_files(dir .. "/a_rock.lua", file)) | 385 | local file, dirname = fetch.get_sources(rockspec, false) |
386 | assert.truthy(are_same_files(dirname .. "/a_rock.lua", file)) | ||
387 | end, finally) | ||
388 | end) | 388 | end) |
389 | 389 | ||
390 | it("downloads the sources for building a rock into a given directory and returns the resulting source filename and its parent directory", function() | 390 | it("downloads the sources for building a rock into a given directory and returns the resulting source filename and its parent directory", function() |
391 | local tmpdir = get_tmp_path() | 391 | test_env.run_in_tmp(function() |
392 | lfs.mkdir(tmpdir) | 392 | local tmpdir = get_tmp_path() |
393 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) | 393 | lfs.mkdir(tmpdir) |
394 | local file, dir = fetch.get_sources(rockspec, false, tmpdir) | 394 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) |
395 | assert.truthy(are_same_files(tmpdir, dir)) | 395 | local file, dirname = fetch.get_sources(rockspec, false, tmpdir) |
396 | assert.truthy(are_same_files(dir .. "/a_rock.lua", file)) | 396 | assert.truthy(are_same_files(tmpdir, dirname)) |
397 | lfs.rmdir(tmpdir) | 397 | assert.truthy(are_same_files(dirname .. "/a_rock.lua", file)) |
398 | lfs.rmdir(tmpdir) | ||
399 | end, finally) | ||
398 | end) | 400 | end) |
399 | 401 | ||
400 | it("downloads the sources for building a rock, extracts the downloaded tarball and returns the resulting source filename and its parent directory", function() | 402 | it("downloads the sources for building a rock, extracts the downloaded tarball and returns the resulting source filename and its parent directory", function() |
401 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/busted_project-0.1-1.rockspec")) | 403 | test_env.run_in_tmp(function() |
402 | local file, dir = fetch.get_sources(rockspec, true) | 404 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/busted_project-0.1-1.rockspec")) |
403 | assert.truthy(are_same_files(dir .. "/busted_project-0.1.tar.gz", file)) | 405 | local file, dirname = fetch.get_sources(rockspec, true) |
404 | assert.truthy(lfs.attributes(dir .. "/busted_project")) | 406 | assert.truthy(are_same_files(dirname .. "/busted_project-0.1.tar.gz", file)) |
405 | assert.truthy(lfs.attributes(dir .. "/busted_project/sum.lua")) | 407 | assert.truthy(lfs.attributes(dirname .. "/busted_project")) |
406 | assert.truthy(lfs.attributes(dir .. "/busted_project/spec/sum_spec.lua")) | 408 | assert.truthy(lfs.attributes(dirname .. "/busted_project/sum.lua")) |
409 | assert.truthy(lfs.attributes(dirname .. "/busted_project/spec/sum_spec.lua")) | ||
410 | end, finally) | ||
407 | end) | 411 | end) |
408 | 412 | ||
409 | it("returns false and does nothing if the destination directory doesn't exist", function() | 413 | it("returns false and does nothing if the destination directory doesn't exist", function() |
410 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) | 414 | test_env.run_in_tmp(function() |
411 | assert.falsy(fetch.get_sources(rockspec, false, "nonexistent")) | 415 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) |
416 | assert.falsy(fetch.get_sources(rockspec, false, "nonexistent")) | ||
417 | end, finally) | ||
412 | end) | 418 | end) |
413 | 419 | ||
414 | it("returns false and does nothing if the rockspec source url is invalid", function() | 420 | it("returns false and does nothing if the rockspec source url is invalid", function() |
415 | write_file("invalid_url-1.0-1.rockspec", [[ | 421 | test_env.run_in_tmp(function(tmpdir) |
416 | package="invalid_url" | 422 | write_file(tmpdir .. "/invalid_url-1.0-1.rockspec", [[ |
417 | version="1.0-1" | 423 | package="invalid_url" |
418 | source = { | 424 | version="1.0-1" |
419 | url = "http://localhost:8080/file/nonexistent" | 425 | source = { |
420 | } | 426 | url = "http://localhost:8080/file/nonexistent" |
421 | build = { | 427 | } |
422 | 428 | build = { | |
423 | } | 429 | |
424 | ]], finally) | 430 | } |
425 | local rockspec = assert(fetch.load_rockspec("invalid_url-1.0-1.rockspec")) | 431 | ]]) |
426 | assert.falsy(fetch.get_sources(rockspec, false)) | 432 | local rockspec = assert(fetch.load_rockspec(tmpdir .. "/invalid_url-1.0-1.rockspec")) |
433 | assert.falsy(fetch.get_sources(rockspec, false)) | ||
434 | end, finally) | ||
427 | end) | 435 | end) |
428 | 436 | ||
429 | it("returns false and does nothing if the downloaded rockspec has an invalid md5 checksum", function() | 437 | it("returns false and does nothing if the downloaded rockspec has an invalid md5 checksum", function() |
430 | write_file("invalid_checksum-1.0-1.rockspec", [[ | 438 | test_env.run_in_tmp(function() |
431 | package="invalid_checksum" | 439 | write_file("invalid_checksum-1.0-1.rockspec", [[ |
432 | version="1.0-1" | 440 | package="invalid_checksum" |
433 | source = { | 441 | version="1.0-1" |
434 | url = "http://localhost:8080/file/a_rock.lua", | 442 | source = { |
435 | md5 = "invalid" | 443 | url = "http://localhost:8080/file/a_rock.lua", |
436 | } | 444 | md5 = "invalid" |
437 | build = { | 445 | } |
438 | 446 | build = { | |
439 | } | 447 | |
440 | ]], finally) | 448 | } |
441 | local rockspec = assert(fetch.load_rockspec("invalid_checksum-1.0-1.rockspec")) | 449 | ]]) |
442 | assert.falsy(fetch.get_sources(rockspec, false)) | 450 | local rockspec = assert(fetch.load_rockspec("invalid_checksum-1.0-1.rockspec")) |
451 | assert.falsy(fetch.get_sources(rockspec, false)) | ||
452 | end, finally) | ||
443 | end) | 453 | end) |
444 | end) | 454 | end) |
445 | 455 | ||
446 | describe("fetch_sources #unix #git", function() | 456 | describe("fetch_sources #unix #git", function() |
457 | local git_repo = require("spec.util.git_repo") | ||
458 | |||
447 | local git | 459 | local git |
448 | 460 | ||
449 | setup(function() | 461 | setup(function() |
diff --git a/spec/util/quick.lua b/spec/util/quick.lua index 6b86bfa9..cb4bb4cf 100644 --- a/spec/util/quick.lua +++ b/spec/util/quick.lua | |||
@@ -429,7 +429,7 @@ function quick.compile(filename, env) | |||
429 | end | 429 | end |
430 | end | 430 | end |
431 | end | 431 | end |
432 | write([=[ end) ]=]) | 432 | write([=[ end, finally) ]=]) |
433 | write([=[ end ]=]) | 433 | write([=[ end ]=]) |
434 | 434 | ||
435 | local program = table.concat(code, "\n") | 435 | local program = table.concat(code, "\n") |
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index 41787cb7..f311a370 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua | |||
@@ -193,10 +193,25 @@ function test_env.run_in_tmp(f, finally) | |||
193 | lfs.mkdir(tmpdir) | 193 | lfs.mkdir(tmpdir) |
194 | lfs.chdir(tmpdir) | 194 | lfs.chdir(tmpdir) |
195 | 195 | ||
196 | if not finally then | ||
197 | error("run_in_tmp needs a finally argument") | ||
198 | end | ||
199 | |||
200 | -- for unit tests, so that current dir known by luarocks.fs (when running with non-lfs) | ||
201 | -- is synchronized with actual lfs (system) current dir | ||
202 | local fs = require("luarocks.fs") | ||
203 | if not fs.change_dir then | ||
204 | local cfg = require("luarocks.core.cfg") | ||
205 | cfg.init() | ||
206 | fs.init() | ||
207 | end | ||
208 | fs.change_dir(tmpdir) | ||
209 | |||
196 | if finally then | 210 | if finally then |
197 | finally(function() | 211 | finally(function() |
198 | lfs.chdir(olddir) | 212 | lfs.chdir(olddir) |
199 | lfs.rmdir(tmpdir) | 213 | lfs.rmdir(tmpdir) |
214 | fs.change_dir(olddir) | ||
200 | end) | 215 | end) |
201 | end | 216 | end |
202 | 217 | ||