aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2015-04-07 23:13:13 -0300
committerHisham Muhammad <hisham@gobolinux.org>2015-04-07 23:13:13 -0300
commit79addc7fb60a0f84c37fedfc6fa945c483be7b9a (patch)
treeda1cdc0d730156528d614e2db70787d75e4bc627 /test
parent58fb6b92bc488660ebacf4312801b0a9e3ba86bf (diff)
downloadluarocks-79addc7fb60a0f84c37fedfc6fa945c483be7b9a.tar.gz
luarocks-79addc7fb60a0f84c37fedfc6fa945c483be7b9a.tar.bz2
luarocks-79addc7fb60a0f84c37fedfc6fa945c483be7b9a.zip
Continuing slowly. Distracted by code golf. :)
Diffstat (limited to 'test')
-rw-r--r--test/testing.lua86
1 files changed, 59 insertions, 27 deletions
diff --git a/test/testing.lua b/test/testing.lua
index 1572c130..9103c19a 100644
--- a/test/testing.lua
+++ b/test/testing.lua
@@ -1,14 +1,31 @@
1 1
2local variables = {}
3
4-- Expand variables in the format $foo or ${foo} according
5-- to the variables table.
2local function expand_variables(str) 6local function expand_variables(str)
3 -- TODO 7 return str:gsub("%$({?)([A-Za-z0-9_]+)(}?)", function(o, v, c)
4 return str 8 return #o <= #c and (variables[v] or "") .. (#o < #c and c or "")
9 end)
5end 10end
6 11
7-- @param cmd command to run 12-- @param cmd command to run
8-- @param envtable optional table of temporary environment variables 13-- @param envtable optional table of temporary environment variables
9local function run(cmd, envtable) 14local function run(cmd, envtable)
10 cmd = expand_variables(cmd) 15 cmd = expand_variables(cmd)
11 -- TODO 16 local env = {}
17 for var, val in pairs(envtable) do
18 table.insert(env, var.."='"..expand_variables(val).."' ")
19 end
20 local code = os.execute(table.concat(env)..cmd)
21 return (code == 0 or code == true)
22end
23
24local function cd_run(dir, cmd, envtable)
25 return run("cd "..dir.." && "..cmd, envtable)
26end
27
28local function run_get_contents(cmd)
12end 29end
13 30
14local function mkdir(dirname) 31local function mkdir(dirname)
@@ -16,10 +33,26 @@ local function mkdir(dirname)
16 -- TODO 33 -- TODO
17end 34end
18 35
36local function rm_rf(...)
37 -- TODO
38end
39
40local function mv(src, dst)
41 -- TODO
42end
43
44local function exists(filename)
45 filename = expand_variables(filename)
46 -- TODO
47end
48
49local function glob(patt)
50 -- TODO
51end
52
19local function rm(...) 53local function rm(...)
20 for _, filename in ipairs {...} do 54 for _, filename in ipairs {...} do
21 filename = expand_variables(filename) 55 filename = expand_variables(filename)
22 -- TODO globbing
23 -- TODO 56 -- TODO
24 end 57 end
25 return true 58 return true
@@ -35,6 +68,10 @@ local function file_set_contents(filename, contents)
35 return true 68 return true
36end 69end
37 70
71local function need_luasocket()
72 -- TODO
73end
74
38local tests = { 75local tests = {
39 76
40 test_version = function() return run "$luarocks --version" end, 77 test_version = function() return run "$luarocks --version" end,
@@ -46,14 +83,10 @@ local tests = {
46 fail_arg_string_unknown = function() return run "$luarocks --invalid-flag=abc" end, 83 fail_arg_string_unknown = function() return run "$luarocks --invalid-flag=abc" end,
47 test_empty_list = function() return run "$luarocks list" end, 84 test_empty_list = function() return run "$luarocks list" end,
48 fail_bad_sysconfig = function() 85 fail_bad_sysconfig = function()
49 local err=0 86 mkdir "$testing_lrprefix/etc/luarocks"
50 local scdir=testing_lrprefix.."/etc/luarocks/" 87 file_set_contents("$testing_lrprefix/etc/luarocks/config.lua", "aoeui")
51 mkdir(scdir) 88 return run "$luarocks list"
52 local sysconfig=scdir.."/config.lua" 89 and rm "$testing_lrprefix/etc/luarocks/config.lua"
53 file_set_contents(sysconfig, "aoeui")
54 local err = run "$luarocks list"
55 rm(sysconfig)
56 return err
57 end, 90 end,
58 fail_build_noarg = function() return run "$luarocks build" end, 91 fail_build_noarg = function() return run "$luarocks build" end,
59 fail_download_noarg = function() return run "$luarocks download" end, 92 fail_download_noarg = function() return run "$luarocks download" end,
@@ -88,16 +121,16 @@ local tests = {
88 test_build_install_bin = function() return run "$luarocks build luarepl" end, 121 test_build_install_bin = function() return run "$luarocks build luarepl" end,
89 test_build_nohttps = function() 122 test_build_nohttps = function()
90 need_luasocket() 123 need_luasocket()
91 return (run "$luarocks download --rockspec validate-args ${verrev_validate_args}") 124 return run "$luarocks download --rockspec validate-args ${verrev_validate_args}"
92 and (run "$luarocks build ./validate-args-${version_validate_args}-1.rockspec") 125 and run "$luarocks build ./validate-args-${version_validate_args}-1.rockspec"
93 and (rm "./validate-args-${version_validate_args}-1.rockspec") 126 and rm "./validate-args-${version_validate_args}-1.rockspec"
94 end, 127 end,
95 test_build_https = function() 128 test_build_https = function()
96 need_luasocket() 129 need_luasocket()
97 return (run "$luarocks download --rockspec validate-args ${verrev_validate_args}") 130 return run "$luarocks download --rockspec validate-args ${verrev_validate_args}"
98 and (run "$luarocks install luasec") 131 and run "$luarocks install luasec"
99 and (run "$luarocks build ./validate-args-${verrev_validate_args}.rockspec") 132 and run "$luarocks build ./validate-args-${verrev_validate_args}.rockspec"
100 and (rm "./validate-args-${verrev_validate_args}.rockspec") 133 and rm "./validate-args-${verrev_validate_args}.rockspec"
101 end, 134 end,
102 test_build_supported_platforms = function() return run "$luarocks build lpty" end, 135 test_build_supported_platforms = function() return run "$luarocks build lpty" end,
103 fail_build_missing_external = function() return run '$luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"' end, 136 fail_build_missing_external = function() return run '$luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"' end,
@@ -111,11 +144,11 @@ local tests = {
111 end, 144 end,
112 test_download_all = function() 145 test_download_all = function()
113 return run "$luarocks download --all validate-args" 146 return run "$luarocks download --all validate-args"
114 and rm "validate-args-*" 147 and rm(glob("validate-args-*"))
115 end, 148 end,
116 test_download_rockspecversion = function() 149 test_download_rockspecversion = function()
117 return run "$luarocks download --rockspec validate-args ${verrev_validate_args}" 150 return run "$luarocks download --rockspec validate-args ${verrev_validate_args}"
118 and rm "validate-args-*" 151 and rm(glob("validate-args-*"))
119 end, 152 end,
120 test_help = function() return run "$luarocks help" end, 153 test_help = function() return run "$luarocks help" end,
121 fail_help_invalid = function() return run "$luarocks help invalid" end, 154 fail_help_invalid = function() return run "$luarocks help invalid" end,
@@ -179,30 +212,30 @@ local tests = {
179 rm_rf "./luasocket-${verrev_luasocket}" 212 rm_rf "./luasocket-${verrev_luasocket}"
180 run "$luarocks download --source luasocket" 213 run "$luarocks download --source luasocket"
181 run "$luarocks unpack ./luasocket-${verrev_luasocket}.src.rock" 214 run "$luarocks unpack ./luasocket-${verrev_luasocket}.src.rock"
182 local ok = at_run("luasocket-${verrev_luasocket}/${srcdir_luasocket}", "$luarocks make") 215 local ok = cd_run("luasocket-${verrev_luasocket}/${srcdir_luasocket}", "$luarocks make")
183 rm_rf "./luasocket-${verrev_luasocket}" 216 rm_rf "./luasocket-${verrev_luasocket}"
184 return ok 217 return ok
185 end, 218 end,
186 test_new_version = function() 219 test_new_version = function()
187 return run "$luarocks download --rockspec luacov ${version_luacov}" 220 return run "$luarocks download --rockspec luacov ${version_luacov}"
188 and run "$luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2" 221 and run "$luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2"
189 and rm "./luacov-0.*" 222 and rm(glob("./luacov-0.*"))
190 end, 223 end,
191 test_new_version_url = function() 224 test_new_version_url = function()
192 return run "$luarocks download --rockspec abelhas 1.0" 225 return run "$luarocks download --rockspec abelhas 1.0"
193 and run "$luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz" 226 and run "$luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz"
194 and rm "./abelhas-*" 227 and rm(glob("./abelhas-*"))
195 end, 228 end,
196 test_pack = function() 229 test_pack = function()
197 return run "$luarocks list" 230 return run "$luarocks list"
198 and run "$luarocks pack luacov" 231 and run "$luarocks pack luacov"
199 and rm "./luacov-*.rock" 232 and rm(glob("./luacov-*.rock"))
200 end, 233 end,
201 test_pack_src = function() 234 test_pack_src = function()
202 return run "$luarocks install luasec" 235 return run "$luarocks install luasec"
203 and run "$luarocks download --rockspec luasocket" 236 and run "$luarocks download --rockspec luasocket"
204 and run "$luarocks pack ./luasocket-${verrev_luasocket}.rockspec" 237 and run "$luarocks pack ./luasocket-${verrev_luasocket}.rockspec"
205 and rm "./luasocket-${version_luasocket}-*.rock" 238 and rm(glob("./luasocket-${version_luasocket}-*.rock"))
206 end, 239 end,
207 test_path = function() return run "$luarocks path --bin" end, 240 test_path = function() return run "$luarocks path --bin" end,
208 test_path_lr_path = function() return run "$luarocks path --lr-path" end, 241 test_path_lr_path = function() return run "$luarocks path --lr-path" end,
@@ -288,7 +321,6 @@ local tests = {
288 fail_admin_remove_missing = function() return run "$luarocks_admin --server=testing remove" end, 321 fail_admin_remove_missing = function() return run "$luarocks_admin --server=testing remove" end,
289 fail_deps_mode_invalid_arg = function() return run "$luarocks remove luacov --deps-mode" end, 322 fail_deps_mode_invalid_arg = function() return run "$luarocks remove luacov --deps-mode" end,
290 323
291 -- TODO:
292 test_deps_mode_one = function() 324 test_deps_mode_one = function()
293 return run '$luarocks build --tree="system" lpeg' 325 return run '$luarocks build --tree="system" lpeg'
294 and run '$luarocks list' 326 and run '$luarocks list'