1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
local test_env = require("test/test_environment")
local lfs = require("lfs")
local run = test_env.run
local testing_paths = test_env.testing_paths
local env_variables = test_env.env_variables
describe("Basic tests #blackbox #b_util", function()
before_each(function()
test_env.setup_specs()
end)
it("LuaRocks version", function()
assert.is_true(run.luarocks_bool("--version"))
end)
it("LuaRocks unknown command", function()
assert.is_false(run.luarocks_bool("unknown_command"))
end)
it("LuaRocks arguments fail", function()
assert.is_false(run.luarocks_bool("--porcelain=invalid"))
assert.is_false(run.luarocks_bool("--invalid-flag"))
assert.is_false(run.luarocks_bool("--server"))
assert.is_false(run.luarocks_bool("--server --porcelain"))
assert.is_false(run.luarocks_bool("--invalid-flag=abc"))
assert.is_false(run.luarocks_bool("invalid=5"))
end)
it("LuaRocks execute from not existing directory", function()
local main_path = lfs.currentdir()
assert.is_true(lfs.mkdir("idontexist"))
assert.is_true(lfs.chdir("idontexist"))
local delete_path = lfs.currentdir()
assert.is_true(os.remove(delete_path))
local output = run.luarocks("")
assert.is.falsy(output:find("LuaRocks scm, a module deployment system for Lua"))
assert.is_true(lfs.chdir(main_path))
output = run.luarocks("")
assert.is.truthy(output:find("LuaRocks scm, a module deployment system for Lua"))
end)
it("LuaRocks timeout", function()
assert.is.truthy(run.luarocks("--timeout=10"))
end)
it("LuaRocks timeout invalid", function()
assert.is_false(run.luarocks_bool("--timeout=abc"))
end)
it("LuaRocks only server=testing", function()
assert.is.truthy(run.luarocks("--only-server=testing"))
end)
it("LuaRocks test site config", function()
assert.is.truthy(os.rename("src/luarocks/site_config.lua", "src/luarocks/site_config.lua.tmp"))
assert.is.falsy(lfs.attributes("src/luarocks/site_config.lua"))
assert.is.truthy(lfs.attributes("src/luarocks/site_config.lua.tmp"))
assert.is.truthy(run.luarocks(""))
assert.is.truthy(os.rename("src/luarocks/site_config.lua.tmp", "src/luarocks/site_config.lua"))
assert.is.falsy(lfs.attributes("src/luarocks/site_config.lua.tmp"))
assert.is.truthy(lfs.attributes("src/luarocks/site_config.lua"))
end)
describe("LuaRocks sysconfig fails", function()
local scdir = ""
before_each(function()
scdir = testing_paths.testing_lrprefix .. "/etc/luarocks/"
lfs.mkdir(testing_paths.testing_lrprefix)
lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/")
lfs.mkdir(scdir)
end)
after_each(function()
test_env.remove_dir(testing_paths.testing_lrprefix)
end)
it("LuaRocks sysconfig fail", function()
local sysconfig = io.open(scdir .. "/config.lua", "w+")
sysconfig:write("aoeui")
sysconfig:close()
assert.is_false(run.luarocks_bool("list"))
end)
it("LuaRocks sysconfig fail", function()
local sysconfig = io.open(scdir .. "/config-" .. env_variables.LUA_VERSION .. ".lua", "w+")
sysconfig:write("aoeui")
sysconfig:close()
assert.is_false(run.luarocks_bool("list"))
end)
end)
end)
|