diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2021-03-16 13:36:26 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2021-03-16 16:32:45 -0300 |
commit | 8f3ce333e7a1abfc6bf0488817d9eff4a2fd443f (patch) | |
tree | f05d1a49995341a56e602ce2a3256b89372e9d04 /spec/fetch_spec.lua | |
parent | 2b56388e76952be52d849415b1ebae74b6dc4607 (diff) | |
download | luarocks-8f3ce333e7a1abfc6bf0488817d9eff4a2fd443f.tar.gz luarocks-8f3ce333e7a1abfc6bf0488817d9eff4a2fd443f.tar.bz2 luarocks-8f3ce333e7a1abfc6bf0488817d9eff4a2fd443f.zip |
editorconfig: trim trailing whitespace
Diffstat (limited to 'spec/fetch_spec.lua')
-rw-r--r-- | spec/fetch_spec.lua | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua index 6e23a8f2..8194a298 100644 --- a/spec/fetch_spec.lua +++ b/spec/fetch_spec.lua | |||
@@ -17,9 +17,9 @@ describe("luarocks fetch #unit #mock", function() | |||
17 | local are_same_files = function(file1, file2) | 17 | local are_same_files = function(file1, file2) |
18 | return file1 == file2 or lfs.attributes(file1).ino == lfs.attributes(file2).ino | 18 | return file1 == file2 or lfs.attributes(file1).ino == lfs.attributes(file2).ino |
19 | end | 19 | end |
20 | 20 | ||
21 | local runner | 21 | local runner |
22 | 22 | ||
23 | setup(function() | 23 | setup(function() |
24 | cfg.init() | 24 | cfg.init() |
25 | fs.init() | 25 | fs.init() |
@@ -29,15 +29,15 @@ describe("luarocks fetch #unit #mock", function() | |||
29 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | 29 | runner.init(testing_paths.testrun_dir .. "/luacov.config") |
30 | runner.tick = true | 30 | runner.tick = true |
31 | end) | 31 | end) |
32 | 32 | ||
33 | teardown(function() | 33 | teardown(function() |
34 | test_env.mock_server_done() | 34 | test_env.mock_server_done() |
35 | 35 | ||
36 | runner.shutdown() | 36 | runner.shutdown() |
37 | end) | 37 | end) |
38 | 38 | ||
39 | describe("fetch.fetch_url", function() | 39 | describe("fetch.fetch_url", function() |
40 | 40 | ||
41 | it("fetches the url argument and returns the absolute path of the fetched file", function() | 41 | it("fetches the url argument and returns the absolute path of the fetched file", function() |
42 | local fetchedfile = fetch.fetch_url("http://localhost:8080/file/a_rock.lua") | 42 | local fetchedfile = fetch.fetch_url("http://localhost:8080/file/a_rock.lua") |
43 | assert.truthy(are_same_files(fetchedfile, lfs.currentdir() .. "/a_rock.lua")) | 43 | assert.truthy(are_same_files(fetchedfile, lfs.currentdir() .. "/a_rock.lua")) |
@@ -50,25 +50,25 @@ describe("luarocks fetch #unit #mock", function() | |||
50 | assert.same(fetchedcontent, filecontent) | 50 | assert.same(fetchedcontent, filecontent) |
51 | os.remove(fetchedfile) | 51 | os.remove(fetchedfile) |
52 | end) | 52 | end) |
53 | 53 | ||
54 | it("returns the absolute path of the filename argument if the url represents a file", function() | 54 | it("returns the absolute path of the filename argument if the url represents a file", function() |
55 | local file = fetch.fetch_url("file://a_rock.lua") | 55 | local file = fetch.fetch_url("file://a_rock.lua") |
56 | assert.truthy(are_same_files(file, lfs.currentdir() .. "/a_rock.lua")) | 56 | assert.truthy(are_same_files(file, lfs.currentdir() .. "/a_rock.lua")) |
57 | end) | 57 | end) |
58 | 58 | ||
59 | it("returns false and does nothing if the url argument contains a nonexistent file", function() | 59 | it("returns false and does nothing if the url argument contains a nonexistent file", function() |
60 | assert.falsy(fetch.fetch_url("http://localhost:8080/file/nonexistent")) | 60 | assert.falsy(fetch.fetch_url("http://localhost:8080/file/nonexistent")) |
61 | end) | 61 | end) |
62 | 62 | ||
63 | it("returns false and does nothing if the url argument is invalid", function() | 63 | it("returns false and does nothing if the url argument is invalid", function() |
64 | assert.falsy(fetch.fetch_url("invalid://url", "file")) | 64 | assert.falsy(fetch.fetch_url("invalid://url", "file")) |
65 | end) | 65 | end) |
66 | end) | 66 | end) |
67 | 67 | ||
68 | describe("fetch.fetch_url_at_temp_dir", function() | 68 | describe("fetch.fetch_url_at_temp_dir", function() |
69 | local tmpfile | 69 | local tmpfile |
70 | local tmpdir | 70 | local tmpdir |
71 | 71 | ||
72 | after_each(function() | 72 | after_each(function() |
73 | if tmpfile then | 73 | if tmpfile then |
74 | os.remove(tmpfile) | 74 | os.remove(tmpfile) |
@@ -89,7 +89,7 @@ describe("luarocks fetch #unit #mock", function() | |||
89 | assert.truthy(are_same_files(tmpfile, pathname)) | 89 | assert.truthy(are_same_files(tmpfile, pathname)) |
90 | assert.truthy(are_same_files(tmpdir, dirname)) | 90 | assert.truthy(are_same_files(tmpdir, dirname)) |
91 | end) | 91 | end) |
92 | 92 | ||
93 | it("returns true and fetches the url into a temporary dir", function() | 93 | it("returns true and fetches the url into a temporary dir", function() |
94 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test") | 94 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test") |
95 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/a_rock.lua")) | 95 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/a_rock.lua")) |
@@ -101,7 +101,7 @@ describe("luarocks fetch #unit #mock", function() | |||
101 | fd:close() | 101 | fd:close() |
102 | assert.same(fetchedcontent, filecontent) | 102 | assert.same(fetchedcontent, filecontent) |
103 | end) | 103 | end) |
104 | 104 | ||
105 | it("returns true and fetches the url into a temporary dir with custom filename", function() | 105 | it("returns true and fetches the url into a temporary dir with custom filename", function() |
106 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test", "my_a_rock.lua") | 106 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test", "my_a_rock.lua") |
107 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/my_a_rock.lua")) | 107 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/my_a_rock.lua")) |
@@ -114,12 +114,12 @@ describe("luarocks fetch #unit #mock", function() | |||
114 | fd:close() | 114 | fd:close() |
115 | assert.same(fetchedcontent, filecontent) | 115 | assert.same(fetchedcontent, filecontent) |
116 | end) | 116 | end) |
117 | 117 | ||
118 | it("returns false and does nothing if the file specified in the url is nonexistent", function() | 118 | it("returns false and does nothing if the file specified in the url is nonexistent", function() |
119 | assert.falsy(fetch.fetch_url_at_temp_dir("file://nonexistent", "test")) | 119 | assert.falsy(fetch.fetch_url_at_temp_dir("file://nonexistent", "test")) |
120 | assert.falsy(fetch.fetch_url_at_temp_dir("http://localhost:8080/file/nonexistent", "test")) | 120 | assert.falsy(fetch.fetch_url_at_temp_dir("http://localhost:8080/file/nonexistent", "test")) |
121 | end) | 121 | end) |
122 | 122 | ||
123 | it("returns false and does nothing if the url is invalid", function() | 123 | it("returns false and does nothing if the url is invalid", function() |
124 | assert.falsy(fetch.fetch_url_at_temp_dir("url://invalid", "test")) | 124 | assert.falsy(fetch.fetch_url_at_temp_dir("url://invalid", "test")) |
125 | end) | 125 | end) |
@@ -133,7 +133,7 @@ describe("luarocks fetch #unit #mock", function() | |||
133 | assert.truthy(are_same_files(inferreddir, founddir)) | 133 | assert.truthy(are_same_files(inferreddir, founddir)) |
134 | assert.truthy(lfs.attributes(tmpdir .. "/" .. founddir)) | 134 | assert.truthy(lfs.attributes(tmpdir .. "/" .. founddir)) |
135 | end) | 135 | end) |
136 | 136 | ||
137 | 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() | 137 | 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() |
138 | local url = "http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz" | 138 | local url = "http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz" |
139 | local file, tmpdir = assert(fetch.fetch_url_at_temp_dir(url, "test")) | 139 | local file, tmpdir = assert(fetch.fetch_url_at_temp_dir(url, "test")) |
@@ -142,29 +142,29 @@ describe("luarocks fetch #unit #mock", function() | |||
142 | assert.truthy(are_same_files(founddir, "an_upstream_tarball-0.1")) | 142 | assert.truthy(are_same_files(founddir, "an_upstream_tarball-0.1")) |
143 | assert.truthy(lfs.attributes(tmpdir .. "/" .. founddir)) | 143 | assert.truthy(lfs.attributes(tmpdir .. "/" .. founddir)) |
144 | end) | 144 | end) |
145 | 145 | ||
146 | it("returns false and does nothing if the temporary directory doesn't exist", function() | 146 | it("returns false and does nothing if the temporary directory doesn't exist", function() |
147 | assert.falsy(fetch.find_base_dir("file", "nonexistent", "url")) | 147 | assert.falsy(fetch.find_base_dir("file", "nonexistent", "url")) |
148 | end) | 148 | end) |
149 | end) | 149 | end) |
150 | 150 | ||
151 | describe("fetch.fetch_and_unpack_rock", function() | 151 | describe("fetch.fetch_and_unpack_rock", function() |
152 | local tmpdir | 152 | local tmpdir |
153 | 153 | ||
154 | after_each(function() | 154 | after_each(function() |
155 | if tmpdir then | 155 | if tmpdir then |
156 | lfs.rmdir(tmpdir) | 156 | lfs.rmdir(tmpdir) |
157 | tmpdir = nil | 157 | tmpdir = nil |
158 | end | 158 | end |
159 | end) | 159 | end) |
160 | 160 | ||
161 | it("unpacks the rock file from the url and returns its resulting temporary parent directory", function() | 161 | it("unpacks the rock file from the url and returns its resulting temporary parent directory", function() |
162 | tmpdir = fetch.fetch_and_unpack_rock("http://localhost:8080/file/a_rock-1.0-1.src.rock") | 162 | tmpdir = fetch.fetch_and_unpack_rock("http://localhost:8080/file/a_rock-1.0-1.src.rock") |
163 | assert.truthy(string.find(tmpdir, "a_rock%-1%.0%-1")) | 163 | assert.truthy(string.find(tmpdir, "a_rock%-1%.0%-1")) |
164 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock-1.0-1.rockspec")) | 164 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock-1.0-1.rockspec")) |
165 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock.lua")) | 165 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock.lua")) |
166 | end) | 166 | end) |
167 | 167 | ||
168 | it("unpacks the rock file from the url with custom unpacking directory", function() | 168 | it("unpacks the rock file from the url with custom unpacking directory", function() |
169 | tmpdir = get_tmp_path() | 169 | tmpdir = get_tmp_path() |
170 | lfs.mkdir(tmpdir) | 170 | lfs.mkdir(tmpdir) |
@@ -173,15 +173,15 @@ describe("luarocks fetch #unit #mock", function() | |||
173 | assert.truthy(lfs.attributes(resultingdir .. "/a_rock-1.0-1.rockspec")) | 173 | assert.truthy(lfs.attributes(resultingdir .. "/a_rock-1.0-1.rockspec")) |
174 | assert.truthy(lfs.attributes(resultingdir .. "/a_rock.lua")) | 174 | assert.truthy(lfs.attributes(resultingdir .. "/a_rock.lua")) |
175 | end) | 175 | end) |
176 | 176 | ||
177 | it("does nothing if the url doesn't represent a rock file", function() | 177 | it("does nothing if the url doesn't represent a rock file", function() |
178 | assert.falsy(pcall(fetch.fetch_and_unpack_rock, "http://localhost:8080/file/a_rock.lua")) | 178 | assert.falsy(pcall(fetch.fetch_and_unpack_rock, "http://localhost:8080/file/a_rock.lua")) |
179 | end) | 179 | end) |
180 | 180 | ||
181 | it("does nothing if the rock file url is invalid", function() | 181 | it("does nothing if the rock file url is invalid", function() |
182 | assert.falsy(pcall(fetch.fetch_and_unpack_rock, "url://invalid")) | 182 | assert.falsy(pcall(fetch.fetch_and_unpack_rock, "url://invalid")) |
183 | end) | 183 | end) |
184 | 184 | ||
185 | it("does nothing if the rock file url represents a nonexistent file", function() | 185 | it("does nothing if the rock file url represents a nonexistent file", function() |
186 | assert.falsy(pcall(fetch.fetch_and_unpack_rock, "url://invalid")) | 186 | assert.falsy(pcall(fetch.fetch_and_unpack_rock, "url://invalid")) |
187 | assert.falsy(pcall(fetch.fetch_and_unpack_rock, "http://localhost:8080/file/nonexistent")) | 187 | assert.falsy(pcall(fetch.fetch_and_unpack_rock, "http://localhost:8080/file/nonexistent")) |
@@ -191,7 +191,7 @@ describe("luarocks fetch #unit #mock", function() | |||
191 | describe("fetch.load_local_rockspec", function() | 191 | describe("fetch.load_local_rockspec", function() |
192 | local tmpdir | 192 | local tmpdir |
193 | local olddir | 193 | local olddir |
194 | 194 | ||
195 | before_each(function() | 195 | before_each(function() |
196 | tmpdir = get_tmp_path() | 196 | tmpdir = get_tmp_path() |
197 | olddir = lfs.currentdir() | 197 | olddir = lfs.currentdir() |
@@ -199,7 +199,7 @@ describe("luarocks fetch #unit #mock", function() | |||
199 | lfs.chdir(tmpdir) | 199 | lfs.chdir(tmpdir) |
200 | fs.change_dir(tmpdir) | 200 | fs.change_dir(tmpdir) |
201 | end) | 201 | end) |
202 | 202 | ||
203 | after_each(function() | 203 | after_each(function() |
204 | if olddir then | 204 | if olddir then |
205 | lfs.chdir(olddir) | 205 | lfs.chdir(olddir) |
@@ -208,14 +208,14 @@ describe("luarocks fetch #unit #mock", function() | |||
208 | end | 208 | end |
209 | end | 209 | end |
210 | end) | 210 | end) |
211 | 211 | ||
212 | it("returns a table representing the rockspec from the given file skipping some checks if the quick argument is enabled", function() | 212 | it("returns a table representing the rockspec from the given file skipping some checks if the quick argument is enabled", function() |
213 | local rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec", true) | 213 | local rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec", true) |
214 | assert.same(rockspec.name, "a_rock") | 214 | assert.same(rockspec.name, "a_rock") |
215 | assert.same(rockspec.version, "1.0-1") | 215 | assert.same(rockspec.version, "1.0-1") |
216 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | 216 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") |
217 | assert.same(rockspec.description, { summary = "An example rockspec" }) | 217 | assert.same(rockspec.description, { summary = "An example rockspec" }) |
218 | 218 | ||
219 | write_file("missing_mandatory_field-1.0-1.rockspec", [[ | 219 | write_file("missing_mandatory_field-1.0-1.rockspec", [[ |
220 | package="missing_mandatory_field" | 220 | package="missing_mandatory_field" |
221 | version="1.0-1" | 221 | version="1.0-1" |
@@ -227,7 +227,7 @@ describe("luarocks fetch #unit #mock", function() | |||
227 | assert.same(rockspec.name, "missing_mandatory_field") | 227 | assert.same(rockspec.name, "missing_mandatory_field") |
228 | assert.same(rockspec.version, "1.0-1") | 228 | assert.same(rockspec.version, "1.0-1") |
229 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") | 229 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") |
230 | 230 | ||
231 | write_file("unknown_field-1.0-1.rockspec", [[ | 231 | write_file("unknown_field-1.0-1.rockspec", [[ |
232 | package="unknown_field" | 232 | package="unknown_field" |
233 | version="1.0-1" | 233 | version="1.0-1" |
@@ -246,7 +246,7 @@ describe("luarocks fetch #unit #mock", function() | |||
246 | assert.falsy(fetch.load_local_rockspec("missing_mandatory_field-1.0-1.rockspec")) | 246 | assert.falsy(fetch.load_local_rockspec("missing_mandatory_field-1.0-1.rockspec")) |
247 | assert.falsy(fetch.load_local_rockspec("unknown_field-1.0-1.rockspec")) | 247 | assert.falsy(fetch.load_local_rockspec("unknown_field-1.0-1.rockspec")) |
248 | end) | 248 | end) |
249 | 249 | ||
250 | it("returns a table representing the rockspec from the given file", function() | 250 | it("returns a table representing the rockspec from the given file", function() |
251 | path.use_tree(testing_paths.testing_tree) | 251 | path.use_tree(testing_paths.testing_tree) |
252 | local rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec") | 252 | local rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec") |
@@ -255,15 +255,15 @@ describe("luarocks fetch #unit #mock", function() | |||
255 | assert.same(rockspec.description, { summary = "An example rockspec" }) | 255 | assert.same(rockspec.description, { summary = "An example rockspec" }) |
256 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | 256 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") |
257 | end) | 257 | end) |
258 | 258 | ||
259 | it("returns false if the rockspec in invalid", function() | 259 | it("returns false if the rockspec in invalid", function() |
260 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/invalid_validate-args-1.5.4-1.rockspec")) | 260 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/invalid_validate-args-1.5.4-1.rockspec")) |
261 | end) | 261 | end) |
262 | 262 | ||
263 | it("returns false if the rockspec version is not supported", function() | 263 | it("returns false if the rockspec version is not supported", function() |
264 | assert.falsy(fetch.load_local_rockspec("invalid_version.rockspec")) | 264 | assert.falsy(fetch.load_local_rockspec("invalid_version.rockspec")) |
265 | end) | 265 | end) |
266 | 266 | ||
267 | it("returns false if the rockspec doesn't pass the type checking", function() | 267 | it("returns false if the rockspec doesn't pass the type checking", function() |
268 | write_file("type_mismatch_string-1.0-1.rockspec", [[ | 268 | write_file("type_mismatch_string-1.0-1.rockspec", [[ |
269 | package="type_mismatch_version" | 269 | package="type_mismatch_version" |
@@ -271,7 +271,7 @@ describe("luarocks fetch #unit #mock", function() | |||
271 | ]], finally) | 271 | ]], finally) |
272 | assert.falsy(fetch.load_local_rockspec("type_mismatch_string-1.0-1.rockspec")) | 272 | assert.falsy(fetch.load_local_rockspec("type_mismatch_string-1.0-1.rockspec")) |
273 | end) | 273 | end) |
274 | 274 | ||
275 | it("returns false if the rockspec file name is not right", function() | 275 | it("returns false if the rockspec file name is not right", function() |
276 | write_file("invalid_rockspec_name.rockspec", [[ | 276 | write_file("invalid_rockspec_name.rockspec", [[ |
277 | package="invalid_rockspec_name" | 277 | package="invalid_rockspec_name" |
@@ -280,12 +280,12 @@ describe("luarocks fetch #unit #mock", function() | |||
280 | url = "http://example.com/foo.tar.gz" | 280 | url = "http://example.com/foo.tar.gz" |
281 | } | 281 | } |
282 | build = { | 282 | build = { |
283 | 283 | ||
284 | } | 284 | } |
285 | ]], finally) | 285 | ]], finally) |
286 | assert.falsy(fetch.load_local_rockspec("invalid_rockspec_name.rockspec")) | 286 | assert.falsy(fetch.load_local_rockspec("invalid_rockspec_name.rockspec")) |
287 | end) | 287 | end) |
288 | 288 | ||
289 | it("returns false if the version in the rockspec file name doesn't match the version declared in the rockspec", function() | 289 | it("returns false if the version in the rockspec file name doesn't match the version declared in the rockspec", function() |
290 | write_file("inconsistent_versions-1.0-1.rockspec", [[ | 290 | write_file("inconsistent_versions-1.0-1.rockspec", [[ |
291 | package="inconsistent_versions" | 291 | package="inconsistent_versions" |
@@ -294,13 +294,13 @@ describe("luarocks fetch #unit #mock", function() | |||
294 | url = "http://example.com/foo.tar.gz" | 294 | url = "http://example.com/foo.tar.gz" |
295 | } | 295 | } |
296 | build = { | 296 | build = { |
297 | 297 | ||
298 | } | 298 | } |
299 | ]], finally) | 299 | ]], finally) |
300 | assert.falsy(fetch.load_local_rockspec("inconsistent_versions-1.0-1.rockspec")) | 300 | assert.falsy(fetch.load_local_rockspec("inconsistent_versions-1.0-1.rockspec")) |
301 | end) | 301 | end) |
302 | end) | 302 | end) |
303 | 303 | ||
304 | describe("fetch.load_rockspec", function() | 304 | describe("fetch.load_rockspec", function() |
305 | it("returns a table containing the requested rockspec by downloading it into a temporary directory", function() | 305 | it("returns a table containing the requested rockspec by downloading it into a temporary directory", function() |
306 | path.use_tree(testing_paths.testing_tree) | 306 | path.use_tree(testing_paths.testing_tree) |
@@ -315,11 +315,11 @@ describe("luarocks fetch #unit #mock", function() | |||
315 | assert.same(rockspec.description, { summary = "An example rockspec" }) | 315 | assert.same(rockspec.description, { summary = "An example rockspec" }) |
316 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | 316 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") |
317 | end) | 317 | end) |
318 | 318 | ||
319 | it("returns a table containing the requested rockspec by downloading it into a given directory", function() | 319 | it("returns a table containing the requested rockspec by downloading it into a given directory", function() |
320 | local tmpdir = get_tmp_path() | 320 | local tmpdir = get_tmp_path() |
321 | lfs.mkdir(tmpdir) | 321 | lfs.mkdir(tmpdir) |
322 | 322 | ||
323 | path.use_tree(testing_paths.testing_tree) | 323 | path.use_tree(testing_paths.testing_tree) |
324 | local rockspec = fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec", tmpdir) | 324 | local rockspec = fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec", tmpdir) |
325 | assert.same(rockspec.name, "a_rock") | 325 | assert.same(rockspec.name, "a_rock") |
@@ -327,23 +327,23 @@ describe("luarocks fetch #unit #mock", function() | |||
327 | assert.same(rockspec.description, { summary = "An example rockspec" }) | 327 | assert.same(rockspec.description, { summary = "An example rockspec" }) |
328 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | 328 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") |
329 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock-1.0-1.rockspec")) | 329 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock-1.0-1.rockspec")) |
330 | 330 | ||
331 | lfs.rmdir(tmpdir) | 331 | lfs.rmdir(tmpdir) |
332 | end) | 332 | end) |
333 | 333 | ||
334 | it("returns false if the given download directory doesn't exist", function() | 334 | it("returns false if the given download directory doesn't exist", function() |
335 | assert.falsy(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec", "nonexistent")) | 335 | assert.falsy(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec", "nonexistent")) |
336 | end) | 336 | end) |
337 | 337 | ||
338 | it("returns false if the given filename is not a valid rockspec name", function() | 338 | it("returns false if the given filename is not a valid rockspec name", function() |
339 | assert.falsy(fetch.load_rockspec("http://localhost:8080/file/a_rock.lua")) | 339 | assert.falsy(fetch.load_rockspec("http://localhost:8080/file/a_rock.lua")) |
340 | end) | 340 | end) |
341 | end) | 341 | end) |
342 | 342 | ||
343 | describe("fetch.get_sources", function() | 343 | describe("fetch.get_sources", function() |
344 | local tmpdir | 344 | local tmpdir |
345 | local olddir | 345 | local olddir |
346 | 346 | ||
347 | before_each(function() | 347 | before_each(function() |
348 | tmpdir = get_tmp_path() | 348 | tmpdir = get_tmp_path() |
349 | olddir = lfs.currentdir() | 349 | olddir = lfs.currentdir() |
@@ -351,7 +351,7 @@ describe("luarocks fetch #unit #mock", function() | |||
351 | lfs.chdir(tmpdir) | 351 | lfs.chdir(tmpdir) |
352 | fs.change_dir(tmpdir) | 352 | fs.change_dir(tmpdir) |
353 | end) | 353 | end) |
354 | 354 | ||
355 | after_each(function() | 355 | after_each(function() |
356 | if olddir then | 356 | if olddir then |
357 | lfs.chdir(olddir) | 357 | lfs.chdir(olddir) |
@@ -360,13 +360,13 @@ describe("luarocks fetch #unit #mock", function() | |||
360 | end | 360 | end |
361 | end | 361 | end |
362 | end) | 362 | end) |
363 | 363 | ||
364 | it("downloads the sources for building a rock and returns the resulting source filename and its parent directory", function() | 364 | it("downloads the sources for building a rock and returns the resulting source filename and its parent directory", function() |
365 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) | 365 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) |
366 | local file, dir = fetch.get_sources(rockspec, false) | 366 | local file, dir = fetch.get_sources(rockspec, false) |
367 | assert.truthy(are_same_files(dir .. "/a_rock.lua", file)) | 367 | assert.truthy(are_same_files(dir .. "/a_rock.lua", file)) |
368 | end) | 368 | end) |
369 | 369 | ||
370 | it("downloads the sources for building a rock into a given directory and returns the resulting source filename and its parent directory", function() | 370 | it("downloads the sources for building a rock into a given directory and returns the resulting source filename and its parent directory", function() |
371 | local tmpdir = get_tmp_path() | 371 | local tmpdir = get_tmp_path() |
372 | lfs.mkdir(tmpdir) | 372 | lfs.mkdir(tmpdir) |
@@ -376,7 +376,7 @@ describe("luarocks fetch #unit #mock", function() | |||
376 | assert.truthy(are_same_files(dir .. "/a_rock.lua", file)) | 376 | assert.truthy(are_same_files(dir .. "/a_rock.lua", file)) |
377 | lfs.rmdir(tmpdir) | 377 | lfs.rmdir(tmpdir) |
378 | end) | 378 | end) |
379 | 379 | ||
380 | it("downloads the sources for building a rock, extracts the downloaded tarball and returns the resulting source filename and its parent directory", function() | 380 | it("downloads the sources for building a rock, extracts the downloaded tarball and returns the resulting source filename and its parent directory", function() |
381 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/busted_project-0.1-1.rockspec")) | 381 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/busted_project-0.1-1.rockspec")) |
382 | local file, dir = fetch.get_sources(rockspec, true) | 382 | local file, dir = fetch.get_sources(rockspec, true) |
@@ -385,12 +385,12 @@ describe("luarocks fetch #unit #mock", function() | |||
385 | assert.truthy(lfs.attributes(dir .. "/busted_project/sum.lua")) | 385 | assert.truthy(lfs.attributes(dir .. "/busted_project/sum.lua")) |
386 | assert.truthy(lfs.attributes(dir .. "/busted_project/spec/sum_spec.lua")) | 386 | assert.truthy(lfs.attributes(dir .. "/busted_project/spec/sum_spec.lua")) |
387 | end) | 387 | end) |
388 | 388 | ||
389 | it("returns false and does nothing if the destination directory doesn't exist", function() | 389 | it("returns false and does nothing if the destination directory doesn't exist", function() |
390 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) | 390 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) |
391 | assert.falsy(fetch.get_sources(rockspec, false, "nonexistent")) | 391 | assert.falsy(fetch.get_sources(rockspec, false, "nonexistent")) |
392 | end) | 392 | end) |
393 | 393 | ||
394 | it("returns false and does nothing if the rockspec source url is invalid", function() | 394 | it("returns false and does nothing if the rockspec source url is invalid", function() |
395 | write_file("invalid_url-1.0-1.rockspec", [[ | 395 | write_file("invalid_url-1.0-1.rockspec", [[ |
396 | package="invalid_url" | 396 | package="invalid_url" |
@@ -399,13 +399,13 @@ describe("luarocks fetch #unit #mock", function() | |||
399 | url = "http://localhost:8080/file/nonexistent" | 399 | url = "http://localhost:8080/file/nonexistent" |
400 | } | 400 | } |
401 | build = { | 401 | build = { |
402 | 402 | ||
403 | } | 403 | } |
404 | ]], finally) | 404 | ]], finally) |
405 | local rockspec = assert(fetch.load_rockspec("invalid_url-1.0-1.rockspec")) | 405 | local rockspec = assert(fetch.load_rockspec("invalid_url-1.0-1.rockspec")) |
406 | assert.falsy(fetch.get_sources(rockspec, false)) | 406 | assert.falsy(fetch.get_sources(rockspec, false)) |
407 | end) | 407 | end) |
408 | 408 | ||
409 | it("returns false and does nothing if the downloaded rockspec has an invalid md5 checksum", function() | 409 | it("returns false and does nothing if the downloaded rockspec has an invalid md5 checksum", function() |
410 | write_file("invalid_checksum-1.0-1.rockspec", [[ | 410 | write_file("invalid_checksum-1.0-1.rockspec", [[ |
411 | package="invalid_checksum" | 411 | package="invalid_checksum" |
@@ -415,7 +415,7 @@ describe("luarocks fetch #unit #mock", function() | |||
415 | md5 = "invalid" | 415 | md5 = "invalid" |
416 | } | 416 | } |
417 | build = { | 417 | build = { |
418 | 418 | ||
419 | } | 419 | } |
420 | ]], finally) | 420 | ]], finally) |
421 | local rockspec = assert(fetch.load_rockspec("invalid_checksum-1.0-1.rockspec")) | 421 | local rockspec = assert(fetch.load_rockspec("invalid_checksum-1.0-1.rockspec")) |
@@ -429,7 +429,7 @@ describe("luarocks fetch #unit #mock", function() | |||
429 | setup(function() | 429 | setup(function() |
430 | git = git_repo.start() | 430 | git = git_repo.start() |
431 | end) | 431 | end) |
432 | 432 | ||
433 | teardown(function() | 433 | teardown(function() |
434 | if git then | 434 | if git then |
435 | git:stop() | 435 | git:stop() |