diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-18 15:05:38 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-04-19 16:50:11 -0300 |
| commit | 18b9a94491a80a1bbe62a92103b8d8ba1bb1487e (patch) | |
| tree | 7006ab781dd86cf70c0977ad71aaf3cc62931a72 | |
| parent | bb88566e070d3b69d87c345ba9118401c195a7ee (diff) | |
| download | luarocks-18b9a94491a80a1bbe62a92103b8d8ba1bb1487e.tar.gz luarocks-18b9a94491a80a1bbe62a92103b8d8ba1bb1487e.tar.bz2 luarocks-18b9a94491a80a1bbe62a92103b8d8ba1bb1487e.zip | |
Tests: add test for fs.wrap_script
| -rw-r--r-- | spec/fs_spec.lua | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua index a9a34a41..631d15c6 100644 --- a/spec/fs_spec.lua +++ b/spec/fs_spec.lua | |||
| @@ -3,6 +3,7 @@ local test_env = require("spec.util.test_env") | |||
| 3 | test_env.unload_luarocks() | 3 | test_env.unload_luarocks() |
| 4 | test_env.setup_specs() | 4 | test_env.setup_specs() |
| 5 | local fs = require("luarocks.fs") | 5 | local fs = require("luarocks.fs") |
| 6 | local path = require("luarocks.path") | ||
| 6 | local cfg = require("luarocks.core.cfg") | 7 | local cfg = require("luarocks.core.cfg") |
| 7 | local lfs = require("lfs") | 8 | local lfs = require("lfs") |
| 8 | local is_win = test_env.TEST_TARGET_OS == "windows" | 9 | local is_win = test_env.TEST_TARGET_OS == "windows" |
| @@ -11,6 +12,13 @@ local testing_paths = test_env.testing_paths | |||
| 11 | local get_tmp_path = test_env.get_tmp_path | 12 | local get_tmp_path = test_env.get_tmp_path |
| 12 | local write_file = test_env.write_file | 13 | local write_file = test_env.write_file |
| 13 | 14 | ||
| 15 | -- A chdir that works in both full and minimal mode, setting | ||
| 16 | -- both the real process current dir and the LuaRocks internal stack in minimal mode | ||
| 17 | local function chdir(d) | ||
| 18 | lfs.chdir(d) | ||
| 19 | fs.change_dir(d) | ||
| 20 | end | ||
| 21 | |||
| 14 | describe("Luarocks fs test #unit", function() | 22 | describe("Luarocks fs test #unit", function() |
| 15 | local exists_file = function(path) | 23 | local exists_file = function(path) |
| 16 | local ok, err, code = os.rename(path, path) | 24 | local ok, err, code = os.rename(path, path) |
| @@ -449,7 +457,7 @@ describe("Luarocks fs test #unit", function() | |||
| 449 | tmpdir = nil | 457 | tmpdir = nil |
| 450 | end | 458 | end |
| 451 | if olddir then | 459 | if olddir then |
| 452 | lfs.chdir(olddir) | 460 | chdir(olddir) |
| 453 | olddir = nil | 461 | olddir = nil |
| 454 | end | 462 | end |
| 455 | end) | 463 | end) |
| @@ -487,7 +495,7 @@ describe("Luarocks fs test #unit", function() | |||
| 487 | tmpdir = nil | 495 | tmpdir = nil |
| 488 | end | 496 | end |
| 489 | if olddir then | 497 | if olddir then |
| 490 | lfs.chdir(olddir) | 498 | chdir(olddir) |
| 491 | olddir = nil | 499 | olddir = nil |
| 492 | end | 500 | end |
| 493 | end) | 501 | end) |
| @@ -530,7 +538,7 @@ describe("Luarocks fs test #unit", function() | |||
| 530 | tmpdir = nil | 538 | tmpdir = nil |
| 531 | end | 539 | end |
| 532 | if olddir then | 540 | if olddir then |
| 533 | lfs.chdir(olddir) | 541 | chdir(olddir) |
| 534 | end | 542 | end |
| 535 | end) | 543 | end) |
| 536 | 544 | ||
| @@ -550,7 +558,7 @@ describe("Luarocks fs test #unit", function() | |||
| 550 | it("returns false and does nothing if the current directory is not valid #unix", function() | 558 | it("returns false and does nothing if the current directory is not valid #unix", function() |
| 551 | tmpdir = get_tmp_path() | 559 | tmpdir = get_tmp_path() |
| 552 | lfs.mkdir(tmpdir) | 560 | lfs.mkdir(tmpdir) |
| 553 | lfs.chdir(tmpdir) | 561 | chdir(tmpdir) |
| 554 | lfs.rmdir(tmpdir) | 562 | lfs.rmdir(tmpdir) |
| 555 | assert.falsy(fs.change_dir_to_root()) | 563 | assert.falsy(fs.change_dir_to_root()) |
| 556 | assert.is_not.same("/", lfs.currentdir()) | 564 | assert.is_not.same("/", lfs.currentdir()) |
| @@ -571,7 +579,7 @@ describe("Luarocks fs test #unit", function() | |||
| 571 | tmpdir = nil | 579 | tmpdir = nil |
| 572 | end | 580 | end |
| 573 | if olddir then | 581 | if olddir then |
| 574 | lfs.chdir(olddir) | 582 | chdir(olddir) |
| 575 | end | 583 | end |
| 576 | end) | 584 | end) |
| 577 | 585 | ||
| @@ -1271,7 +1279,7 @@ describe("Luarocks fs test #unit", function() | |||
| 1271 | olddir = lfs.currentdir() | 1279 | olddir = lfs.currentdir() |
| 1272 | tmpdir = get_tmp_path() | 1280 | tmpdir = get_tmp_path() |
| 1273 | lfs.mkdir(tmpdir) | 1281 | lfs.mkdir(tmpdir) |
| 1274 | lfs.chdir(tmpdir) | 1282 | chdir(tmpdir) |
| 1275 | 1283 | ||
| 1276 | write_file("file1", "content1", finally) | 1284 | write_file("file1", "content1", finally) |
| 1277 | write_file("file2", "content2", finally) | 1285 | write_file("file2", "content2", finally) |
| @@ -1281,7 +1289,7 @@ describe("Luarocks fs test #unit", function() | |||
| 1281 | 1289 | ||
| 1282 | after_each(function() | 1290 | after_each(function() |
| 1283 | if olddir then | 1291 | if olddir then |
| 1284 | lfs.chdir(olddir) | 1292 | chdir(olddir) |
| 1285 | if tmpdir then | 1293 | if tmpdir then |
| 1286 | lfs.rmdir(tmpdir .. "/dir") | 1294 | lfs.rmdir(tmpdir .. "/dir") |
| 1287 | lfs.rmdir(tmpdir) | 1295 | lfs.rmdir(tmpdir) |
| @@ -1324,7 +1332,7 @@ describe("Luarocks fs test #unit", function() | |||
| 1324 | olddir = lfs.currentdir() | 1332 | olddir = lfs.currentdir() |
| 1325 | tmpdir = get_tmp_path() | 1333 | tmpdir = get_tmp_path() |
| 1326 | lfs.mkdir(tmpdir) | 1334 | lfs.mkdir(tmpdir) |
| 1327 | lfs.chdir(tmpdir) | 1335 | chdir(tmpdir) |
| 1328 | 1336 | ||
| 1329 | write_file("file1", "content1", finally) | 1337 | write_file("file1", "content1", finally) |
| 1330 | write_file("file2", "content2", finally) | 1338 | write_file("file2", "content2", finally) |
| @@ -1334,7 +1342,7 @@ describe("Luarocks fs test #unit", function() | |||
| 1334 | 1342 | ||
| 1335 | after_each(function() | 1343 | after_each(function() |
| 1336 | if olddir then | 1344 | if olddir then |
| 1337 | lfs.chdir(olddir) | 1345 | chdir(olddir) |
| 1338 | if tmpdir then | 1346 | if tmpdir then |
| 1339 | lfs.rmdir(tmpdir .. "/dir") | 1347 | lfs.rmdir(tmpdir .. "/dir") |
| 1340 | lfs.rmdir(tmpdir) | 1348 | lfs.rmdir(tmpdir) |
| @@ -1372,6 +1380,38 @@ describe("Luarocks fs test #unit", function() | |||
| 1372 | assert.falsy(fs.unzip("archive.zip")) | 1380 | assert.falsy(fs.unzip("archive.zip")) |
| 1373 | end) | 1381 | end) |
| 1374 | end) | 1382 | end) |
| 1383 | |||
| 1384 | describe("fs.wrap_script", function() | ||
| 1385 | local tmpdir | ||
| 1386 | local olddir | ||
| 1387 | |||
| 1388 | before_each(function() | ||
| 1389 | olddir = lfs.currentdir() | ||
| 1390 | tmpdir = get_tmp_path() | ||
| 1391 | lfs.mkdir(tmpdir) | ||
| 1392 | chdir(tmpdir) | ||
| 1393 | end) | ||
| 1394 | |||
| 1395 | after_each(function() | ||
| 1396 | if olddir then | ||
| 1397 | chdir(olddir) | ||
| 1398 | if tmpdir then | ||
| 1399 | lfs.rmdir(tmpdir) | ||
| 1400 | end | ||
| 1401 | end | ||
| 1402 | end) | ||
| 1403 | |||
| 1404 | it("produces a wrapper for a Lua script", function() | ||
| 1405 | write_file("my_script", "io.write('Hello ' .. arg[1])", finally) | ||
| 1406 | path.use_tree(testing_paths.testing_tree) | ||
| 1407 | local wrapper_name = fs.absolute_name("wrapper") | ||
| 1408 | fs.wrap_script("my_script", wrapper_name, "one", nil, nil, "World") | ||
| 1409 | local pd = assert(io.popen(wrapper_name .. test_env.wrapper_extension)) | ||
| 1410 | local data = pd:read("*a") | ||
| 1411 | pd:close() | ||
| 1412 | assert.same("Hello World", data) | ||
| 1413 | end) | ||
| 1414 | end) | ||
| 1375 | 1415 | ||
| 1376 | describe("fs.copy_binary", function() | 1416 | describe("fs.copy_binary", function() |
| 1377 | local tmpdir | 1417 | local tmpdir |
| @@ -1381,14 +1421,14 @@ describe("Luarocks fs test #unit", function() | |||
| 1381 | olddir = lfs.currentdir() | 1421 | olddir = lfs.currentdir() |
| 1382 | tmpdir = get_tmp_path() | 1422 | tmpdir = get_tmp_path() |
| 1383 | lfs.mkdir(tmpdir) | 1423 | lfs.mkdir(tmpdir) |
| 1384 | lfs.chdir(tmpdir) | 1424 | chdir(tmpdir) |
| 1385 | 1425 | ||
| 1386 | write_file("test.exe", "", finally) | 1426 | write_file("test.exe", "", finally) |
| 1387 | end) | 1427 | end) |
| 1388 | 1428 | ||
| 1389 | after_each(function() | 1429 | after_each(function() |
| 1390 | if olddir then | 1430 | if olddir then |
| 1391 | lfs.chdir(olddir) | 1431 | chdir(olddir) |
| 1392 | if tmpdir then | 1432 | if tmpdir then |
| 1393 | lfs.rmdir(tmpdir) | 1433 | lfs.rmdir(tmpdir) |
| 1394 | end | 1434 | end |
| @@ -1422,7 +1462,7 @@ describe("Luarocks fs test #unit", function() | |||
| 1422 | olddir = lfs.currentdir() | 1462 | olddir = lfs.currentdir() |
| 1423 | tmpdir = get_tmp_path() | 1463 | tmpdir = get_tmp_path() |
| 1424 | lfs.mkdir(tmpdir) | 1464 | lfs.mkdir(tmpdir) |
| 1425 | lfs.chdir(tmpdir) | 1465 | chdir(tmpdir) |
| 1426 | lfs.mkdir("lib") | 1466 | lfs.mkdir("lib") |
| 1427 | write_file("lib/module1.lua", "", finally) | 1467 | write_file("lib/module1.lua", "", finally) |
| 1428 | write_file("lib/module2.lua", "", finally) | 1468 | write_file("lib/module2.lua", "", finally) |
| @@ -1438,7 +1478,7 @@ describe("Luarocks fs test #unit", function() | |||
| 1438 | 1478 | ||
| 1439 | after_each(function() | 1479 | after_each(function() |
| 1440 | if olddir then | 1480 | if olddir then |
| 1441 | lfs.chdir(olddir) | 1481 | chdir(olddir) |
| 1442 | if tmpdir then | 1482 | if tmpdir then |
| 1443 | lfs.rmdir(tmpdir .. "/lib/internal") | 1483 | lfs.rmdir(tmpdir .. "/lib/internal") |
| 1444 | lfs.rmdir(tmpdir .. "/lib") | 1484 | lfs.rmdir(tmpdir .. "/lib") |
