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