aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/cmd_spec.lua70
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 @@
1local test_env = require("spec.util.test_env") 1local test_env = require("spec.util.test_env")
2local lfs = require("lfs")
2local run = test_env.run 3local run = test_env.run
3 4
4test_env.unload_luarocks() 5test_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
34end) 104end)