aboutsummaryrefslogtreecommitdiff
path: root/spec/fs_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/fs_spec.lua')
-rw-r--r--spec/fs_spec.lua142
1 files changed, 71 insertions, 71 deletions
diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua
index cc36d277..5410cff7 100644
--- a/spec/fs_spec.lua
+++ b/spec/fs_spec.lua
@@ -62,7 +62,7 @@ describe("luarocks.fs #unit", function()
62 end 62 end
63 63
64 local runner 64 local runner
65 65
66 setup(function() 66 setup(function()
67 cfg.init() 67 cfg.init()
68 fs.init() 68 fs.init()
@@ -70,7 +70,7 @@ describe("luarocks.fs #unit", function()
70 runner.init(testing_paths.testrun_dir .. "/luacov.config") 70 runner.init(testing_paths.testrun_dir .. "/luacov.config")
71 runner.tick = true 71 runner.tick = true
72 end) 72 end)
73 73
74 teardown(function() 74 teardown(function()
75 runner.shutdown() 75 runner.shutdown()
76 end) 76 end)
@@ -122,10 +122,10 @@ describe("luarocks.fs #unit", function()
122 end 122 end
123 end) 123 end)
124 end) 124 end)
125 125
126 describe("fs.execute_string", function() 126 describe("fs.execute_string", function()
127 local tmpdir 127 local tmpdir
128 128
129 after_each(function() 129 after_each(function()
130 if tmpdir then 130 if tmpdir then
131 lfs.rmdir(tmpdir) 131 lfs.rmdir(tmpdir)
@@ -140,7 +140,7 @@ describe("luarocks.fs #unit", function()
140 assert.falsy(fs.execute_string("invalidcommand")) 140 assert.falsy(fs.execute_string("invalidcommand"))
141 end) 141 end)
142 end) 142 end)
143 143
144 describe("fs.dir_iterator", function() 144 describe("fs.dir_iterator", function()
145 local tmpfile1 145 local tmpfile1
146 local tmpfile2 146 local tmpfile2
@@ -218,7 +218,7 @@ describe("luarocks.fs #unit", function()
218 end 218 end
219 end) 219 end)
220 end) 220 end)
221 221
222 describe("fs.is_writable", function() 222 describe("fs.is_writable", function()
223 local tmpfile 223 local tmpfile
224 local tmpdir 224 local tmpdir
@@ -268,7 +268,7 @@ describe("luarocks.fs #unit", function()
268 assert.falsy(fs.is_writable("/nonexistent")) 268 assert.falsy(fs.is_writable("/nonexistent"))
269 end) 269 end)
270 end) 270 end)
271 271
272 describe("fs.set_time #unix", function() 272 describe("fs.set_time #unix", function()
273 local tmpfile 273 local tmpfile
274 local tmpdir 274 local tmpdir
@@ -787,13 +787,13 @@ describe("luarocks.fs #unit", function()
787 assert.truthy(exists_file(tmpdir)) 787 assert.truthy(exists_file(tmpdir))
788 end) 788 end)
789 end) 789 end)
790 790
791 describe("fs.list_dir", function() 791 describe("fs.list_dir", function()
792 local intfile1 792 local intfile1
793 local intfile2 793 local intfile2
794 local intdir 794 local intdir
795 local tmpdir 795 local tmpdir
796 796
797 before_each(function() 797 before_each(function()
798 if intfile1 then 798 if intfile1 then
799 os.remove(intfile1) 799 os.remove(intfile1)
@@ -812,7 +812,7 @@ describe("luarocks.fs #unit", function()
812 tmpdir = nil 812 tmpdir = nil
813 end 813 end
814 end) 814 end)
815 815
816 it("returns a table with the contents of the given directory", function() 816 it("returns a table with the contents of the given directory", function()
817 tmpdir = get_tmp_path() 817 tmpdir = get_tmp_path()
818 lfs.mkdir(tmpdir) 818 lfs.mkdir(tmpdir)
@@ -828,18 +828,18 @@ describe("luarocks.fs #unit", function()
828 assert.truthy(result[2] == "intfile1" or result[2] == "intdir") 828 assert.truthy(result[2] == "intfile1" or result[2] == "intdir")
829 assert.is_not.same(result[1], result[2]) 829 assert.is_not.same(result[1], result[2])
830 end) 830 end)
831 831
832 it("returns an empty table if the argument is a file", function() 832 it("returns an empty table if the argument is a file", function()
833 intfile1 = get_tmp_path() 833 intfile1 = get_tmp_path()
834 create_file(intfile1) 834 create_file(intfile1)
835 local result = fs.list_dir(intfile1) 835 local result = fs.list_dir(intfile1)
836 assert.same(#result, 0) 836 assert.same(#result, 0)
837 end) 837 end)
838 838
839 it("does nothing if the argument is nonexistent", function() 839 it("does nothing if the argument is nonexistent", function()
840 assert.same(fs.list_dir("/nonexistent"), {}) 840 assert.same(fs.list_dir("/nonexistent"), {})
841 end) 841 end)
842 842
843 it("does nothing if the argument doesn't have the proper permissions", function() 843 it("does nothing if the argument doesn't have the proper permissions", function()
844 tmpdir = get_tmp_path() 844 tmpdir = get_tmp_path()
845 lfs.mkdir(tmpdir) 845 lfs.mkdir(tmpdir)
@@ -1017,13 +1017,13 @@ describe("luarocks.fs #unit", function()
1017 assert.falsy(exists_file(dstdir .. "/internalfile")) 1017 assert.falsy(exists_file(dstdir .. "/internalfile"))
1018 end) 1018 end)
1019 end) 1019 end)
1020 1020
1021 describe("fs.find", function() 1021 describe("fs.find", function()
1022 local tmpdir 1022 local tmpdir
1023 local intdir 1023 local intdir
1024 local intfile1 1024 local intfile1
1025 local intfile2 1025 local intfile2
1026 1026
1027 after_each(function() 1027 after_each(function()
1028 if intfile1 then 1028 if intfile1 then
1029 os.remove(intfile1) 1029 os.remove(intfile1)
@@ -1042,7 +1042,7 @@ describe("luarocks.fs #unit", function()
1042 tmpdir = nil 1042 tmpdir = nil
1043 end 1043 end
1044 end) 1044 end)
1045 1045
1046 local create_dir_tree = function() 1046 local create_dir_tree = function()
1047 tmpdir = get_tmp_path() 1047 tmpdir = get_tmp_path()
1048 lfs.mkdir(tmpdir) 1048 lfs.mkdir(tmpdir)
@@ -1053,7 +1053,7 @@ describe("luarocks.fs #unit", function()
1053 intfile2 = intdir .. "/intfile2" 1053 intfile2 = intdir .. "/intfile2"
1054 create_file(intfile2) 1054 create_file(intfile2)
1055 end 1055 end
1056 1056
1057 it("returns a table of all the contents in the directory given as argument", function() 1057 it("returns a table of all the contents in the directory given as argument", function()
1058 create_dir_tree() 1058 create_dir_tree()
1059 local contents = {} 1059 local contents = {}
@@ -1068,7 +1068,7 @@ describe("luarocks.fs #unit", function()
1068 assert.same(contents["intdir"], true) 1068 assert.same(contents["intdir"], true)
1069 assert.same(contents["intdir/intfile2"], true) 1069 assert.same(contents["intdir/intfile2"], true)
1070 end) 1070 end)
1071 1071
1072 it("uses the current working directory if the argument is nil", function() 1072 it("uses the current working directory if the argument is nil", function()
1073 create_dir_tree() 1073 create_dir_tree()
1074 local olddir = fs.current_dir() 1074 local olddir = fs.current_dir()
@@ -1085,7 +1085,7 @@ describe("luarocks.fs #unit", function()
1085 assert.same(contents["intfile2"], true) 1085 assert.same(contents["intfile2"], true)
1086 fs.change_dir(olddir) 1086 fs.change_dir(olddir)
1087 end) 1087 end)
1088 1088
1089 it("returns an empty table if the argument is nonexistent", function() 1089 it("returns an empty table if the argument is nonexistent", function()
1090 local contents = fs.find("/nonexistent") 1090 local contents = fs.find("/nonexistent")
1091 local count = 0 1091 local count = 0
@@ -1094,7 +1094,7 @@ describe("luarocks.fs #unit", function()
1094 end 1094 end
1095 assert.same(count, 0) 1095 assert.same(count, 0)
1096 end) 1096 end)
1097 1097
1098 it("returns an empty table if the argument is a file", function() 1098 it("returns an empty table if the argument is a file", function()
1099 intfile1 = get_tmp_path() 1099 intfile1 = get_tmp_path()
1100 create_file(intfile1) 1100 create_file(intfile1)
@@ -1105,7 +1105,7 @@ describe("luarocks.fs #unit", function()
1105 end 1105 end
1106 assert.same(count, 0) 1106 assert.same(count, 0)
1107 end) 1107 end)
1108 1108
1109 it("does nothing if the argument doesn't have the proper permissions", function() 1109 it("does nothing if the argument doesn't have the proper permissions", function()
1110 tmpdir = get_tmp_path() 1110 tmpdir = get_tmp_path()
1111 lfs.mkdir(tmpdir) 1111 lfs.mkdir(tmpdir)
@@ -1113,12 +1113,12 @@ describe("luarocks.fs #unit", function()
1113 assert.same(fs.find(tmpdir), {}) 1113 assert.same(fs.find(tmpdir), {})
1114 end) 1114 end)
1115 end) 1115 end)
1116 1116
1117 describe("fs.move", function() 1117 describe("fs.move", function()
1118 local srcfile 1118 local srcfile
1119 local dstfile 1119 local dstfile
1120 local tmpdir 1120 local tmpdir
1121 1121
1122 after_each(function() 1122 after_each(function()
1123 if srcfile then 1123 if srcfile then
1124 os.remove(srcfile) 1124 os.remove(srcfile)
@@ -1133,7 +1133,7 @@ describe("luarocks.fs #unit", function()
1133 tmpdir = nil 1133 tmpdir = nil
1134 end 1134 end
1135 end) 1135 end)
1136 1136
1137 it("returns true and moves the source (together with its permissions) to the destination", function() 1137 it("returns true and moves the source (together with its permissions) to the destination", function()
1138 srcfile = get_tmp_path() 1138 srcfile = get_tmp_path()
1139 create_file(srcfile) 1139 create_file(srcfile)
@@ -1149,7 +1149,7 @@ describe("luarocks.fs #unit", function()
1149 assert.same(oldperms, lfs.attributes(dstfile, "permissions")) 1149 assert.same(oldperms, lfs.attributes(dstfile, "permissions"))
1150 end 1150 end
1151 end) 1151 end)
1152 1152
1153 it("returns true and moves the source (with custom permissions) to the destination", function() 1153 it("returns true and moves the source (with custom permissions) to the destination", function()
1154 srcfile = get_tmp_path() 1154 srcfile = get_tmp_path()
1155 create_file(srcfile) 1155 create_file(srcfile)
@@ -1161,13 +1161,13 @@ describe("luarocks.fs #unit", function()
1161 local dstcontents = assert(fd:read("*a")) 1161 local dstcontents = assert(fd:read("*a"))
1162 assert.same(dstcontents, "foo") 1162 assert.same(dstcontents, "foo")
1163 end) 1163 end)
1164 1164
1165 it("returns false and does nothing if the source doesn't exist", function() 1165 it("returns false and does nothing if the source doesn't exist", function()
1166 dstfile = get_tmp_path() 1166 dstfile = get_tmp_path()
1167 assert.falsy(fs.move("/nonexistent", dstfile)) 1167 assert.falsy(fs.move("/nonexistent", dstfile))
1168 assert.falsy(fs.exists(dstfile)) 1168 assert.falsy(fs.exists(dstfile))
1169 end) 1169 end)
1170 1170
1171 it("returns false and does nothing if the destination already exists", function() 1171 it("returns false and does nothing if the destination already exists", function()
1172 srcfile = get_tmp_path() 1172 srcfile = get_tmp_path()
1173 create_file(srcfile) 1173 create_file(srcfile)
@@ -1179,7 +1179,7 @@ describe("luarocks.fs #unit", function()
1179 local dstcontents = assert(fd:read("*a")) 1179 local dstcontents = assert(fd:read("*a"))
1180 assert.same(dstcontents, "bar") 1180 assert.same(dstcontents, "bar")
1181 end) 1181 end)
1182 1182
1183 it("returns false and does nothing if the destination path doesn't have the proper permissions", function() 1183 it("returns false and does nothing if the destination path doesn't have the proper permissions", function()
1184 srcfile = get_tmp_path() 1184 srcfile = get_tmp_path()
1185 create_file(srcfile) 1185 create_file(srcfile)
@@ -1190,17 +1190,17 @@ describe("luarocks.fs #unit", function()
1190 assert.falsy(fs.exists(tmpdir .. "/dstfile")) 1190 assert.falsy(fs.exists(tmpdir .. "/dstfile"))
1191 end) 1191 end)
1192 end) 1192 end)
1193 1193
1194 describe("fs.is_lua", function() 1194 describe("fs.is_lua", function()
1195 local tmpfile 1195 local tmpfile
1196 1196
1197 after_each(function() 1197 after_each(function()
1198 if tmpfile then 1198 if tmpfile then
1199 os.remove(tmpfile) 1199 os.remove(tmpfile)
1200 tmpfile = nil 1200 tmpfile = nil
1201 end 1201 end
1202 end) 1202 end)
1203 1203
1204 it("returns true if the argument is a valid lua script", function() 1204 it("returns true if the argument is a valid lua script", function()
1205 tmpfile = get_tmp_path() 1205 tmpfile = get_tmp_path()
1206 create_file(tmpfile, "print(\"foo\")") 1206 create_file(tmpfile, "print(\"foo\")")
@@ -1212,13 +1212,13 @@ describe("luarocks.fs #unit", function()
1212 create_file(tmpfile, "#!/usr/bin/env lua\n\nprint(\"foo\")") 1212 create_file(tmpfile, "#!/usr/bin/env lua\n\nprint(\"foo\")")
1213 assert.truthy(fs.is_lua(tmpfile)) 1213 assert.truthy(fs.is_lua(tmpfile))
1214 end) 1214 end)
1215 1215
1216 it("returns false if the argument is not a valid lua script", function() 1216 it("returns false if the argument is not a valid lua script", function()
1217 tmpfile = os.tmpname() 1217 tmpfile = os.tmpname()
1218 create_file(tmpfile) 1218 create_file(tmpfile)
1219 assert.falsy(fs.is_lua(tmpfile)) 1219 assert.falsy(fs.is_lua(tmpfile))
1220 end) 1220 end)
1221 1221
1222 it("returns false if the argument is a valid lua script but doesn't have the proper permissions", function() 1222 it("returns false if the argument is a valid lua script but doesn't have the proper permissions", function()
1223 tmpfile = get_tmp_path() 1223 tmpfile = get_tmp_path()
1224 create_file(tmpfile, "print(\"foo\")") 1224 create_file(tmpfile, "print(\"foo\")")
@@ -1281,15 +1281,15 @@ describe("luarocks.fs #unit", function()
1281 assert.falsy(exists_file(tmpdir)) 1281 assert.falsy(exists_file(tmpdir))
1282 end) 1282 end)
1283 end) 1283 end)
1284 1284
1285 describe("fs.download #mock", function() 1285 describe("fs.download #mock", function()
1286 local tmpfile 1286 local tmpfile
1287 local tmpdir 1287 local tmpdir
1288 1288
1289 setup(function() 1289 setup(function()
1290 test_env.mock_server_init() 1290 test_env.mock_server_init()
1291 end) 1291 end)
1292 1292
1293 teardown(function() 1293 teardown(function()
1294 test_env.mock_server_done() 1294 test_env.mock_server_done()
1295 end) 1295 end)
@@ -1304,7 +1304,7 @@ describe("luarocks.fs #unit", function()
1304 tmpdir = nil 1304 tmpdir = nil
1305 end 1305 end
1306 end) 1306 end)
1307 1307
1308 it("returns true and fetches the url argument into the specified filename", function() 1308 it("returns true and fetches the url argument into the specified filename", function()
1309 tmpfile = get_tmp_path() 1309 tmpfile = get_tmp_path()
1310 assert.truthy(fs.download("http://localhost:8080/file/a_rock.lua", tmpfile)) 1310 assert.truthy(fs.download("http://localhost:8080/file/a_rock.lua", tmpfile))
@@ -1316,7 +1316,7 @@ describe("luarocks.fs #unit", function()
1316 fd:close() 1316 fd:close()
1317 assert.same(downloadcontent, originalcontent) 1317 assert.same(downloadcontent, originalcontent)
1318 end) 1318 end)
1319 1319
1320 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() 1320 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()
1321 tmpdir = get_tmp_path() 1321 tmpdir = get_tmp_path()
1322 lfs.mkdir(tmpdir) 1322 lfs.mkdir(tmpdir)
@@ -1332,33 +1332,33 @@ describe("luarocks.fs #unit", function()
1332 assert.same(downloadcontent, originalcontent) 1332 assert.same(downloadcontent, originalcontent)
1333 fs.pop_dir() 1333 fs.pop_dir()
1334 end) 1334 end)
1335 1335
1336 it("returns false and does nothing if the url argument contains a nonexistent file", function() 1336 it("returns false and does nothing if the url argument contains a nonexistent file", function()
1337 tmpfile = get_tmp_path() 1337 tmpfile = get_tmp_path()
1338 assert.falsy(fs.download("http://localhost:8080/file/nonexistent", tmpfile)) 1338 assert.falsy(fs.download("http://localhost:8080/file/nonexistent", tmpfile))
1339 end) 1339 end)
1340 1340
1341 it("returns false and does nothing if the url argument is invalid", function() 1341 it("returns false and does nothing if the url argument is invalid", function()
1342 assert.falsy(fs.download("invalidurl")) 1342 assert.falsy(fs.download("invalidurl"))
1343 end) 1343 end)
1344 end) 1344 end)
1345 1345
1346 describe("fs.zip", function() 1346 describe("fs.zip", function()
1347 local tmpdir 1347 local tmpdir
1348 local olddir 1348 local olddir
1349 1349
1350 before_each(function() 1350 before_each(function()
1351 olddir = lfs.currentdir() 1351 olddir = lfs.currentdir()
1352 tmpdir = get_tmp_path() 1352 tmpdir = get_tmp_path()
1353 lfs.mkdir(tmpdir) 1353 lfs.mkdir(tmpdir)
1354 chdir(tmpdir) 1354 chdir(tmpdir)
1355 1355
1356 write_file("file1", "content1", finally) 1356 write_file("file1", "content1", finally)
1357 write_file("file2", "content2", finally) 1357 write_file("file2", "content2", finally)
1358 lfs.mkdir("dir") 1358 lfs.mkdir("dir")
1359 write_file("dir/file3", "content3", finally) 1359 write_file("dir/file3", "content3", finally)
1360 end) 1360 end)
1361 1361
1362 after_each(function() 1362 after_each(function()
1363 if olddir then 1363 if olddir then
1364 chdir(olddir) 1364 chdir(olddir)
@@ -1368,12 +1368,12 @@ describe("luarocks.fs #unit", function()
1368 end 1368 end
1369 end 1369 end
1370 end) 1370 end)
1371 1371
1372 it("returns true and creates a zip archive of the given files", function() 1372 it("returns true and creates a zip archive of the given files", function()
1373 assert.truthy(fs.zip("archive.zip", "file1", "file2", "dir")) 1373 assert.truthy(fs.zip("archive.zip", "file1", "file2", "dir"))
1374 assert.truthy(exists_file("archive.zip")) 1374 assert.truthy(exists_file("archive.zip"))
1375 end) 1375 end)
1376 1376
1377 it("returns false and does nothing if the files specified in the arguments are invalid", function() 1377 it("returns false and does nothing if the files specified in the arguments are invalid", function()
1378 assert.falsy(fs.zip("archive.zip", "nonexistent")) 1378 assert.falsy(fs.zip("archive.zip", "nonexistent"))
1379 assert.falsy(exists_file("nonexistent")) 1379 assert.falsy(exists_file("nonexistent"))
@@ -1381,7 +1381,7 @@ describe("luarocks.fs #unit", function()
1381 end) 1381 end)
1382 1382
1383 describe("fs.bunzip2", function() 1383 describe("fs.bunzip2", function()
1384 1384
1385 it("uncompresses a .bz2 file", function() 1385 it("uncompresses a .bz2 file", function()
1386 local input = testing_paths.fixtures_dir .. "/abc.bz2" 1386 local input = testing_paths.fixtures_dir .. "/abc.bz2"
1387 local output = os.tmpname() 1387 local output = os.tmpname()
@@ -1393,25 +1393,25 @@ describe("luarocks.fs #unit", function()
1393 local abc = ("a"):rep(100000)..("b"):rep(100000)..("c"):rep(100000) 1393 local abc = ("a"):rep(100000)..("b"):rep(100000)..("c"):rep(100000)
1394 assert.same(abc, content) 1394 assert.same(abc, content)
1395 end) 1395 end)
1396 1396
1397 end) 1397 end)
1398 1398
1399 describe("fs.unzip", function() 1399 describe("fs.unzip", function()
1400 local tmpdir 1400 local tmpdir
1401 local olddir 1401 local olddir
1402 1402
1403 before_each(function() 1403 before_each(function()
1404 olddir = lfs.currentdir() 1404 olddir = lfs.currentdir()
1405 tmpdir = get_tmp_path() 1405 tmpdir = get_tmp_path()
1406 lfs.mkdir(tmpdir) 1406 lfs.mkdir(tmpdir)
1407 chdir(tmpdir) 1407 chdir(tmpdir)
1408 1408
1409 write_file("file1", "content1", finally) 1409 write_file("file1", "content1", finally)
1410 write_file("file2", "content2", finally) 1410 write_file("file2", "content2", finally)
1411 lfs.mkdir("dir") 1411 lfs.mkdir("dir")
1412 write_file("dir/file3", "content3", finally) 1412 write_file("dir/file3", "content3", finally)
1413 end) 1413 end)
1414 1414
1415 after_each(function() 1415 after_each(function()
1416 if olddir then 1416 if olddir then
1417 chdir(olddir) 1417 chdir(olddir)
@@ -1421,33 +1421,33 @@ describe("luarocks.fs #unit", function()
1421 end 1421 end
1422 end 1422 end
1423 end) 1423 end)
1424 1424
1425 it("returns true and unzips the given zip archive", function() 1425 it("returns true and unzips the given zip archive", function()
1426 assert.truthy(fs.zip("archive.zip", "file1", "file2", "dir")) 1426 assert.truthy(fs.zip("archive.zip", "file1", "file2", "dir"))
1427 os.remove("file1") 1427 os.remove("file1")
1428 os.remove("file2") 1428 os.remove("file2")
1429 lfs.rmdir("dir") 1429 lfs.rmdir("dir")
1430 1430
1431 assert.truthy(fs.unzip("archive.zip")) 1431 assert.truthy(fs.unzip("archive.zip"))
1432 assert.truthy(exists_file("file1")) 1432 assert.truthy(exists_file("file1"))
1433 assert.truthy(exists_file("file2")) 1433 assert.truthy(exists_file("file2"))
1434 assert.truthy(exists_file("dir/file3")) 1434 assert.truthy(exists_file("dir/file3"))
1435 1435
1436 local fd 1436 local fd
1437 1437
1438 fd = assert(io.open("file1", "r")) 1438 fd = assert(io.open("file1", "r"))
1439 assert.same(fd:read("*a"), "content1") 1439 assert.same(fd:read("*a"), "content1")
1440 fd:close() 1440 fd:close()
1441 1441
1442 fd = assert(io.open("file2", "r")) 1442 fd = assert(io.open("file2", "r"))
1443 assert.same(fd:read("*a"), "content2") 1443 assert.same(fd:read("*a"), "content2")
1444 fd:close() 1444 fd:close()
1445 1445
1446 fd = assert(io.open("dir/file3", "r")) 1446 fd = assert(io.open("dir/file3", "r"))
1447 assert.same(fd:read("*a"), "content3") 1447 assert.same(fd:read("*a"), "content3")
1448 fd:close() 1448 fd:close()
1449 end) 1449 end)
1450 1450
1451 it("does nothing if the given archive is invalid", function() 1451 it("does nothing if the given archive is invalid", function()
1452 assert.falsy(fs.unzip("archive.zip")) 1452 assert.falsy(fs.unzip("archive.zip"))
1453 end) 1453 end)
@@ -1456,14 +1456,14 @@ describe("luarocks.fs #unit", function()
1456 describe("fs.wrap_script", function() 1456 describe("fs.wrap_script", function()
1457 local tmpdir 1457 local tmpdir
1458 local olddir 1458 local olddir
1459 1459
1460 before_each(function() 1460 before_each(function()
1461 olddir = lfs.currentdir() 1461 olddir = lfs.currentdir()
1462 tmpdir = get_tmp_path() 1462 tmpdir = get_tmp_path()
1463 lfs.mkdir(tmpdir) 1463 lfs.mkdir(tmpdir)
1464 chdir(tmpdir) 1464 chdir(tmpdir)
1465 end) 1465 end)
1466 1466
1467 after_each(function() 1467 after_each(function()
1468 if olddir then 1468 if olddir then
1469 chdir(olddir) 1469 chdir(olddir)
@@ -1484,20 +1484,20 @@ describe("luarocks.fs #unit", function()
1484 assert.same("Hello World", data) 1484 assert.same("Hello World", data)
1485 end) 1485 end)
1486 end) 1486 end)
1487 1487
1488 describe("fs.copy_binary", function() 1488 describe("fs.copy_binary", function()
1489 local tmpdir 1489 local tmpdir
1490 local olddir 1490 local olddir
1491 1491
1492 before_each(function() 1492 before_each(function()
1493 olddir = lfs.currentdir() 1493 olddir = lfs.currentdir()
1494 tmpdir = get_tmp_path() 1494 tmpdir = get_tmp_path()
1495 lfs.mkdir(tmpdir) 1495 lfs.mkdir(tmpdir)
1496 chdir(tmpdir) 1496 chdir(tmpdir)
1497 1497
1498 write_file("test.exe", "", finally) 1498 write_file("test.exe", "", finally)
1499 end) 1499 end)
1500 1500
1501 after_each(function() 1501 after_each(function()
1502 if olddir then 1502 if olddir then
1503 chdir(olddir) 1503 chdir(olddir)
@@ -1506,7 +1506,7 @@ describe("luarocks.fs #unit", function()
1506 end 1506 end
1507 end 1507 end
1508 end) 1508 end)
1509 1509
1510 it("returns true and copies the given binary file to the file specified in the dest argument", function() 1510 it("returns true and copies the given binary file to the file specified in the dest argument", function()
1511 assert.truthy(fs.copy_binary("test.exe", lfs.currentdir() .. "/copy.exe")) 1511 assert.truthy(fs.copy_binary("test.exe", lfs.currentdir() .. "/copy.exe"))
1512 assert.truthy(exists_file("copy.exe")) 1512 assert.truthy(exists_file("copy.exe"))
@@ -1519,17 +1519,17 @@ describe("luarocks.fs #unit", function()
1519 fd:close() 1519 fd:close()
1520 end 1520 end
1521 end) 1521 end)
1522 1522
1523 it("returns false and does nothing if the source file is invalid", function() 1523 it("returns false and does nothing if the source file is invalid", function()
1524 assert.falsy(fs.copy_binary("invalid.exe", "copy.exe")) 1524 assert.falsy(fs.copy_binary("invalid.exe", "copy.exe"))
1525 end) 1525 end)
1526 end) 1526 end)
1527 1527
1528 describe("fs.modules", function() 1528 describe("fs.modules", function()
1529 local tmpdir 1529 local tmpdir
1530 local olddir 1530 local olddir
1531 local oldpath 1531 local oldpath
1532 1532
1533 before_each(function() 1533 before_each(function()
1534 olddir = lfs.currentdir() 1534 olddir = lfs.currentdir()
1535 tmpdir = get_tmp_path() 1535 tmpdir = get_tmp_path()
@@ -1547,7 +1547,7 @@ describe("luarocks.fs #unit", function()
1547 oldpath = package.path 1547 oldpath = package.path
1548 package.path = package.path .. tmpdir .. "/?.lua;" 1548 package.path = package.path .. tmpdir .. "/?.lua;"
1549 end) 1549 end)
1550 1550
1551 after_each(function() 1551 after_each(function()
1552 if olddir then 1552 if olddir then
1553 chdir(olddir) 1553 chdir(olddir)
@@ -1583,7 +1583,7 @@ describe("luarocks.fs #unit", function()
1583 end) 1583 end)
1584 1584
1585 describe("#unix fs._unix_rwx_to_number", function() 1585 describe("#unix fs._unix_rwx_to_number", function()
1586 1586
1587 it("converts permissions in rwx notation to numeric ones", function() 1587 it("converts permissions in rwx notation to numeric ones", function()
1588 assert.same(tonumber("0644", 8), fs._unix_rwx_to_number("rw-r--r--")) 1588 assert.same(tonumber("0644", 8), fs._unix_rwx_to_number("rw-r--r--"))
1589 assert.same(tonumber("0755", 8), fs._unix_rwx_to_number("rwxr-xr-x")) 1589 assert.same(tonumber("0755", 8), fs._unix_rwx_to_number("rwxr-xr-x"))