diff options
| author | George Roman <george.roman.99@gmail.com> | 2018-07-12 15:52:24 +0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-16 16:14:44 -0300 |
| commit | f2772aee0d4ee5012d9b1be65f685b535d7380bd (patch) | |
| tree | 4c3298d3ee735c3e824b4d4d2cfd7ab056af31a5 | |
| parent | 74352926fd13834b5b369a70aff3481357483833 (diff) | |
| download | luarocks-f2772aee0d4ee5012d9b1be65f685b535d7380bd.tar.gz luarocks-f2772aee0d4ee5012d9b1be65f685b535d7380bd.tar.bz2 luarocks-f2772aee0d4ee5012d9b1be65f685b535d7380bd.zip | |
Tests: add tests for the dynamic commands
| -rw-r--r-- | spec/fs_spec.lua | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/fs_spec.lua b/spec/fs_spec.lua index 08923f37..3b4e6bac 100644 --- a/spec/fs_spec.lua +++ b/spec/fs_spec.lua | |||
| @@ -1388,4 +1388,61 @@ describe("Luarocks fs test #unit", function() | |||
| 1388 | assert.falsy(fs.copy_binary("invalid.exe", "copy.exe")) | 1388 | assert.falsy(fs.copy_binary("invalid.exe", "copy.exe")) |
| 1389 | end) | 1389 | end) |
| 1390 | end) | 1390 | end) |
| 1391 | |||
| 1392 | describe("fs.modules", function() | ||
| 1393 | local tmpdir | ||
| 1394 | local olddir | ||
| 1395 | local oldpath | ||
| 1396 | |||
| 1397 | before_each(function() | ||
| 1398 | olddir = lfs.currentdir() | ||
| 1399 | tmpdir = get_tmp_path() | ||
| 1400 | lfs.mkdir(tmpdir) | ||
| 1401 | lfs.chdir(tmpdir) | ||
| 1402 | lfs.mkdir("lib") | ||
| 1403 | write_file("lib/module1.lua", "", finally) | ||
| 1404 | write_file("lib/module2.lua", "", finally) | ||
| 1405 | write_file("lib/module1.LuA", "", finally) | ||
| 1406 | write_file("lib/non_lua", "", finally) | ||
| 1407 | lfs.mkdir("lib/internal") | ||
| 1408 | write_file("lib/internal/module11.lua", "", finally) | ||
| 1409 | write_file("lib/internal/module22.lua", "", finally) | ||
| 1410 | |||
| 1411 | oldpath = package.path | ||
| 1412 | package.path = package.path .. tmpdir .. "/?.lua;" | ||
| 1413 | end) | ||
| 1414 | |||
| 1415 | after_each(function() | ||
| 1416 | if olddir then | ||
| 1417 | lfs.chdir(olddir) | ||
| 1418 | if tmpdir then | ||
| 1419 | lfs.rmdir(tmpdir .. "/lib/internal") | ||
| 1420 | lfs.rmdir(tmpdir .. "/lib") | ||
| 1421 | lfs.rmdir(tmpdir) | ||
| 1422 | end | ||
| 1423 | end | ||
| 1424 | if oldpath then | ||
| 1425 | package.path = oldpath | ||
| 1426 | end | ||
| 1427 | end) | ||
| 1428 | |||
| 1429 | it("returns a table of the lua modules at a specific require path", function() | ||
| 1430 | local result | ||
| 1431 | |||
| 1432 | result = fs.modules("lib") | ||
| 1433 | assert.same(#result, 2) | ||
| 1434 | assert.truthy(result[1] == "module1" or result[2] == "module1") | ||
| 1435 | assert.truthy(result[1] == "module2" or result[2] == "module2") | ||
| 1436 | |||
| 1437 | result = fs.modules("lib.internal") | ||
| 1438 | assert.same(#result, 2) | ||
| 1439 | assert.truthy(result[1] == "module11" or result[2] == "module11") | ||
| 1440 | assert.truthy(result[1] == "module22" or result[2] == "module22") | ||
| 1441 | end) | ||
| 1442 | |||
| 1443 | it("returns an empty table if the modules couldn't be found in package.path", function() | ||
| 1444 | package.path = "" | ||
| 1445 | assert.same(fs.modules("lib"), {}) | ||
| 1446 | end) | ||
| 1447 | end) | ||
| 1391 | end) | 1448 | end) |
