diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2019-06-03 15:59:29 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2019-06-03 18:48:42 -0300 |
| commit | daf7e7e5f5ede8c3a5a00e2edaf8246209712781 (patch) | |
| tree | b6435881ad91881de672f0281e59e0913d51c576 /spec/cmd_spec.lua | |
| parent | f7eb8df5363430a2b5ac288da5710ff382c632fe (diff) | |
| download | luarocks-daf7e7e5f5ede8c3a5a00e2edaf8246209712781.tar.gz luarocks-daf7e7e5f5ede8c3a5a00e2edaf8246209712781.tar.bz2 luarocks-daf7e7e5f5ede8c3a5a00e2edaf8246209712781.zip | |
Fix and reorganize Lua version detection
Make it more robust when detecting the Lua version when working inside a
project, and hopefully make the detection logic easier to track in the
code. Reorganized code so that the `detected` table becomes internal
to the `init_config` operation and only the regular `cfg` global table
is used after that.
Includes regression tests.
Diffstat (limited to 'spec/cmd_spec.lua')
| -rw-r--r-- | spec/cmd_spec.lua | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/spec/cmd_spec.lua b/spec/cmd_spec.lua index 70b9625d..21b25fe5 100644 --- a/spec/cmd_spec.lua +++ b/spec/cmd_spec.lua | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | local test_env = require("spec.util.test_env") | 1 | local test_env = require("spec.util.test_env") |
| 2 | local lfs = require("lfs") | ||
| 2 | local run = test_env.run | 3 | local run = test_env.run |
| 3 | 4 | ||
| 4 | test_env.unload_luarocks() | 5 | test_env.unload_luarocks() |
| @@ -31,4 +32,73 @@ describe("LuaRocks command line #integration", function() | |||
| 31 | end) | 32 | end) |
| 32 | end) | 33 | end) |
| 33 | 34 | ||
| 35 | describe("--lua-dir", function() | ||
| 36 | it("fails if given an invalid path", function() | ||
| 37 | local output = run.luarocks("--lua-dir=/bad/lua/path") | ||
| 38 | assert.match("Lua interpreter not found at /bad/lua/path", output, 1, true) | ||
| 39 | end) | ||
| 40 | |||
| 41 | it("fails if given a valid path without Lua", function() | ||
| 42 | local output = run.luarocks("--lua-dir=.") | ||
| 43 | assert.match("Lua interpreter not found at .", output, 1, true) | ||
| 44 | end) | ||
| 45 | |||
| 46 | it("passes if given a valid path with Lua", function() | ||
| 47 | assert.truthy(run.luarocks("--lua-dir=" .. test_env.testing_paths.luadir)) | ||
| 48 | end) | ||
| 49 | end) | ||
| 50 | |||
| 51 | describe("--lua-version", function() | ||
| 52 | it("warns but continues if given an invalid version", function() | ||
| 53 | local output = run.luarocks("--lua-version=1.0") | ||
| 54 | assert.match("Warning: Could not find a Lua 1.0 interpreter", output, 1, true) | ||
| 55 | assert.match("Lua version: 1.0", output, 1, true) | ||
| 56 | end) | ||
| 57 | |||
| 58 | it("sets the version independently of project tree", function() | ||
| 59 | test_env.run_in_tmp(function(tmpdir) | ||
| 60 | assert.truthy(run.luarocks_bool("init --lua-version=" .. test_env.lua_version .. " --lua-versions=" .. test_env.lua_version)) | ||
| 61 | |||
| 62 | local output = run.luarocks("--lua-version=1.0") | ||
| 63 | assert.match("Lua version: 1.0", output, 1, true) | ||
| 64 | |||
| 65 | output = run.luarocks("--lua-version=1.0 --project-tree=.") | ||
| 66 | assert.match("Lua version: 1.0", output, 1, true) | ||
| 67 | end, finally) | ||
| 68 | end) | ||
| 69 | end) | ||
| 70 | |||
| 71 | it("detects version based on project tree", function() | ||
| 72 | test_env.run_in_tmp(function(tmpdir) | ||
| 73 | assert.truthy(run.luarocks_bool("init --lua-version=" .. test_env.lua_version)) | ||
| 74 | assert.truthy(run.luarocks_bool("config lua_version 1.0 --project-tree=" .. tmpdir .. "/lua_modules")) | ||
| 75 | |||
| 76 | lfs.mkdir("aaa") | ||
| 77 | lfs.chdir("aaa") | ||
| 78 | lfs.mkdir("bbb") | ||
| 79 | lfs.chdir("bbb") | ||
| 80 | |||
| 81 | local output = run.luarocks("") | ||
| 82 | assert.match("Lua version: 1.0", output, 1, true) | ||
| 83 | end, finally) | ||
| 84 | end) | ||
| 85 | |||
| 86 | -- for backward compatibility | ||
| 87 | it("detects version of a project based on config", function() | ||
| 88 | test_env.run_in_tmp(function(tmpdir) | ||
| 89 | assert.truthy(run.luarocks_bool("init --lua-version=" .. test_env.lua_version)) | ||
| 90 | os.remove(".luarocks/config-" .. test_env.lua_version .. ".lua") | ||
| 91 | os.remove(".luarocks/default-lua-version.lua") | ||
| 92 | test_env.write_file(".luarocks/config-5.2.lua", [[ ]], finally) | ||
| 93 | |||
| 94 | lfs.mkdir("aaa") | ||
| 95 | lfs.chdir("aaa") | ||
| 96 | lfs.mkdir("bbb") | ||
| 97 | lfs.chdir("bbb") | ||
| 98 | |||
| 99 | local output = run.luarocks("") | ||
| 100 | assert.match("Lua version: 5.2", output, 1, true) | ||
| 101 | end, finally) | ||
| 102 | end) | ||
| 103 | |||
| 34 | end) | 104 | end) |
