aboutsummaryrefslogtreecommitdiff
path: root/spec/unit/fs_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/fs_spec.lua')
-rw-r--r--spec/unit/fs_spec.lua66
1 files changed, 2 insertions, 64 deletions
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 @@
1local test_env = require("spec.util.test_env") 1local test_env = require("spec.util.test_env")
2 2
3test_env.unload_luarocks()
4test_env.setup_specs() 3test_env.setup_specs()
5local fs = require("luarocks.fs") 4local fs = require("luarocks.fs")
6local path = require("luarocks.path") 5local 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