aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2015-04-03 16:24:23 -0300
committerHisham Muhammad <hisham@gobolinux.org>2015-04-03 16:24:23 -0300
commited1f9160473870481d2614f2faa06746fc447cc2 (patch)
treebf68ad49c6de4ef1eff68e110cd56a38c7b7c555 /test
parent5cb4aa78f7a3ebcb760c1f47df6d86b567f1f640 (diff)
downloadluarocks-ed1f9160473870481d2614f2faa06746fc447cc2.tar.gz
luarocks-ed1f9160473870481d2614f2faa06746fc447cc2.tar.bz2
luarocks-ed1f9160473870481d2614f2faa06746fc447cc2.zip
Starting to port test suite from Unix shell to Lua.
Diffstat (limited to 'test')
-rw-r--r--test/testing.lua361
1 files changed, 361 insertions, 0 deletions
diff --git a/test/testing.lua b/test/testing.lua
new file mode 100644
index 00000000..1572c130
--- /dev/null
+++ b/test/testing.lua
@@ -0,0 +1,361 @@
1
2local function expand_variables(str)
3 -- TODO
4 return str
5end
6
7-- @param cmd command to run
8-- @param envtable optional table of temporary environment variables
9local function run(cmd, envtable)
10 cmd = expand_variables(cmd)
11 -- TODO
12end
13
14local function mkdir(dirname)
15 cmd = expand_variables(dirname)
16 -- TODO
17end
18
19local function rm(...)
20 for _, filename in ipairs {...} do
21 filename = expand_variables(filename)
22 -- TODO globbing
23 -- TODO
24 end
25 return true
26end
27
28local function file_set_contents(filename, contents)
29 filename = expand_variables(filename)
30
31 local fd, err = io.open(filename, "w")
32 if not fd then return nil, err end
33 fd:write(contents)
34 fd:close()
35 return true
36end
37
38local tests = {
39
40 test_version = function() return run "$luarocks --version" end,
41 fail_unknown_command = function() return run "$luarocks unknown_command" end,
42 fail_arg_boolean_parameter = function() return run "$luarocks --porcelain=invalid" end,
43 fail_arg_boolean_unknown = function() return run "$luarocks --invalid-flag" end,
44 fail_arg_string_no_parameter = function() return run "$luarocks --server" end,
45 fail_arg_string_followed_by_flag = function() return run "$luarocks --server --porcelain" end,
46 fail_arg_string_unknown = function() return run "$luarocks --invalid-flag=abc" end,
47 test_empty_list = function() return run "$luarocks list" end,
48 fail_bad_sysconfig = function()
49 local err=0
50 local scdir=testing_lrprefix.."/etc/luarocks/"
51 mkdir(scdir)
52 local sysconfig=scdir.."/config.lua"
53 file_set_contents(sysconfig, "aoeui")
54 local err = run "$luarocks list"
55 rm(sysconfig)
56 return err
57 end,
58 fail_build_noarg = function() return run "$luarocks build" end,
59 fail_download_noarg = function() return run "$luarocks download" end,
60 fail_install_noarg = function() return run "$luarocks install" end,
61 fail_lint_noarg = function() return run "$luarocks lint" end,
62 fail_search_noarg = function() return run "$luarocks search" end,
63 fail_show_noarg = function() return run "$luarocks show" end,
64 fail_unpack_noarg = function() return run "$luarocks unpack" end,
65 fail_upload_noarg = function() return run "$luarocks upload" end,
66 fail_remove_noarg = function() return run "$luarocks remove" end,
67 fail_doc_noarg = function() return run "$luarocks doc" end,
68 fail_new_version_noarg = function() return run "$luarocks new_version" end,
69 fail_write_rockspec_noarg = function() return run "$luarocks write_rockspec" end,
70 fail_build_invalid = function() return run "$luarocks build invalid" end,
71 fail_download_invalid = function() return run "$luarocks download invalid" end,
72 fail_install_invalid = function() return run "$luarocks install invalid" end,
73 fail_lint_invalid = function() return run "$luarocks lint invalid" end,
74 fail_show_invalid = function() return run "$luarocks show invalid" end,
75 fail_new_version_invalid = function() return run "$luarocks new_version invalid" end,
76 fail_inexistent_dir = function()
77 -- Unix only?
78 return run "mkdir idontexist; cd idontexist; rmdir ../idontexist; $luarocks; err=$?; cd ..; return $err"
79 end,
80 fail_make_norockspec = function() return run "$luarocks make" end,
81 fail_build_permissions = function() return run "$luarocks build --tree=/usr lpeg" end,
82 fail_build_permissions_parent = function() return run "$luarocks build --tree=/usr/invalid lpeg" end,
83 test_build_verbose = function() return run "$luarocks build --verbose lpeg" end,
84 fail_build_blank_arg = function() return run "$luarocks build --tree="" lpeg" end,
85 test_build_withpatch = function() need_luasocket(); return run "$luarocks build luadoc" end,
86 test_build_diffversion = function() return run "$luarocks build luacov ${version_luacov}" end,
87 test_build_command = function() return run "$luarocks build stdlib" end,
88 test_build_install_bin = function() return run "$luarocks build luarepl" end,
89 test_build_nohttps = function()
90 need_luasocket()
91 return (run "$luarocks download --rockspec validate-args ${verrev_validate_args}")
92 and (run "$luarocks build ./validate-args-${version_validate_args}-1.rockspec")
93 and (rm "./validate-args-${version_validate_args}-1.rockspec")
94 end,
95 test_build_https = function()
96 need_luasocket()
97 return (run "$luarocks download --rockspec validate-args ${verrev_validate_args}")
98 and (run "$luarocks install luasec")
99 and (run "$luarocks build ./validate-args-${verrev_validate_args}.rockspec")
100 and (rm "./validate-args-${verrev_validate_args}.rockspec")
101 end,
102 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,
104 fail_build_invalidpatch = function()
105 need_luasocket()
106 return run '$luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"'
107 end,
108 test_build_deps_partial_match = function() return run "$luarocks build lmathx" end,
109 test_build_show_downloads = function()
110 return run("$luarocks build alien", { LUAROCKS_CONFIG="$testing_dir/testing_config_show_downloads.lua" })
111 end,
112 test_download_all = function()
113 return run "$luarocks download --all validate-args"
114 and rm "validate-args-*"
115 end,
116 test_download_rockspecversion = function()
117 return run "$luarocks download --rockspec validate-args ${verrev_validate_args}"
118 and rm "validate-args-*"
119 end,
120 test_help = function() return run "$luarocks help" end,
121 fail_help_invalid = function() return run "$luarocks help invalid" end,
122 test_install_binaryrock = function()
123 return run "$luarocks build --pack-binary-rock cprint"
124 and run "$luarocks install ./cprint-${verrev_cprint}.${platform}.rock"
125 and rm "./cprint-${verrev_cprint}.${platform}.rock"
126 end,
127 test_install_with_bin = function() return run "$luarocks install wsapi" end,
128 fail_install_notazipfile = function() return run '$luarocks install "$testing_dir/testfiles/not_a_zipfile-1.0-1.src.rock"' end,
129 fail_install_invalidpatch = function()
130 need_luasocket()
131 return run '$luarocks install "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"'
132 end,
133 fail_install_invalid_filename = function() return run '$luarocks install "invalid.rock"' end,
134 fail_install_invalid_arch = function() return run '$luarocks install "foo-1.0-1.impossible-x86.rock"' end,
135 test_install_reinstall = function()
136 return run '$luarocks install "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"'
137 and run '$luarocks install --deps-mode=none "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"'
138 end,
139 fail_local_root = function() return run("$luarocks install --local luasocket", { USER="root" }) end,
140 test_site_config = function()
141 mv("../src/luarocks/site_config.lua", "../src/luarocks/site_config.lua.tmp")
142 local ok = run "$luarocks"
143 mv("../src/luarocks/site_config.lua.tmp", "../src/luarocks/site_config.lua")
144 return ok
145 end,
146 test_lint_ok = function()
147 return run "$luarocks download --rockspec validate-args ${verrev_validate_args}"
148 and run "$luarocks lint ./validate-args-${verrev_validate_args}.rockspec"
149 and rm "./validate-args-${verrev_validate_args}.rockspec"
150 end,
151 fail_lint_type_mismatch_string = function() return run '$luarocks lint "$testing_dir/testfiles/type_mismatch_string-1.0-1.rockspec"' end,
152 fail_lint_type_mismatch_version = function() return run '$luarocks lint "$testing_dir/testfiles/type_mismatch_version-1.0-1.rockspec"' end,
153 fail_lint_type_mismatch_table = function() return run '$luarocks lint "$testing_dir/testfiles/type_mismatch_table-1.0-1.rockspec"' end,
154 test_list = function() return run "$luarocks list" end,
155 test_list_porcelain = function() return run "$luarocks list --porcelain" end,
156 test_make_with_rockspec = function()
157 return rm_rf "./luasocket-${verrev_luasocket}"
158 and run "$luarocks download --source luasocket"
159 and run "$luarocks unpack ./luasocket-${verrev_luasocket}.src.rock"
160 and cd_run("luasocket-${verrev_luasocket}/${srcdir_luasocket}", "$luarocks make luasocket-${verrev_luasocket}.rockspec")
161 and rm_rf "./luasocket-${verrev_luasocket}"
162 end,
163 test_make_default_rockspec = function()
164 return rm_rf "./lxsh-${verrev_lxsh}"
165 and run "$luarocks download --source lxsh ${verrev_lxsh}"
166 and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock"
167 and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", "$luarocks make")
168 and rm_rf "./lxsh-${verrev_lxsh}"
169 end,
170 test_make_pack_binary_rock = function()
171 return rm_rf "./lxsh-${verrev_lxsh}"
172 and run "$luarocks download --source lxsh ${verrev_lxsh}"
173 and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock"
174 and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", "$luarocks make --deps-mode=none --pack-binary-rock")
175 and exists "lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1/lxsh-${verrev_lxsh}.all.rock"
176 and rm_rf "./lxsh-${verrev_lxsh}"
177 end,
178 fail_make_which_rockspec = function()
179 rm_rf "./luasocket-${verrev_luasocket}"
180 run "$luarocks download --source luasocket"
181 run "$luarocks unpack ./luasocket-${verrev_luasocket}.src.rock"
182 local ok = at_run("luasocket-${verrev_luasocket}/${srcdir_luasocket}", "$luarocks make")
183 rm_rf "./luasocket-${verrev_luasocket}"
184 return ok
185 end,
186 test_new_version = function()
187 return run "$luarocks download --rockspec luacov ${version_luacov}"
188 and run "$luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2"
189 and rm "./luacov-0.*"
190 end,
191 test_new_version_url = function()
192 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"
194 and rm "./abelhas-*"
195 end,
196 test_pack = function()
197 return run "$luarocks list"
198 and run "$luarocks pack luacov"
199 and rm "./luacov-*.rock"
200 end,
201 test_pack_src = function()
202 return run "$luarocks install luasec"
203 and run "$luarocks download --rockspec luasocket"
204 and run "$luarocks pack ./luasocket-${verrev_luasocket}.rockspec"
205 and rm "./luasocket-${version_luasocket}-*.rock"
206 end,
207 test_path = function() return run "$luarocks path --bin" end,
208 test_path_lr_path = function() return run "$luarocks path --lr-path" end,
209 test_path_lr_cpath = function() return run "$luarocks path --lr-cpath" end,
210 test_path_lr_bin = function() return run "$luarocks path --lr-bin" end,
211 fail_purge_missing_tree = function() return run '$luarocks purge --tree="$testing_tree"' end,
212 test_purge = function() return run '$luarocks purge --tree="$testing_sys_tree"' end,
213 test_remove = function()
214 return run "$luarocks build abelhas ${version_abelhas}"
215 and run "$luarocks remove abelhas ${version_abelhas}"
216 end,
217 test_remove_force = function()
218 need_luasocket()
219 return run "$luarocks build lualogging"
220 and run "$luarocks remove --force luasocket"
221 end,
222 fail_remove_deps = function()
223 need_luasocket()
224 return run "$luarocks build lualogging"
225 and run "$luarocks remove luasocket"
226 end,
227 fail_remove_missing = function() return run "$luarocks remove missing_rock" end,
228 fail_remove_invalid_name = function() return run "$luarocks remove invalid.rock" end,
229 test_search_found = function() return run "$luarocks search zlib" end,
230 test_search_missing = function() return run "$luarocks search missing_rock" end,
231 test_show = function() return run "$luarocks show luacov" end,
232 test_show_modules = function() return run "$luarocks show --modules luacov" end,
233 test_show_home = function() return run "$luarocks show --home luacov" end,
234 test_show_depends = function()
235 need_luasocket()
236 return run "$luarocks install luasec"
237 and run "$luarocks show luasec"
238 end,
239 test_show_oldversion = function()
240 return run "$luarocks install luacov ${version_luacov}"
241 and run "$luarocks show luacov ${version_luacov}"
242 end,
243 test_unpack_download = function()
244 return rm_rf "./cprint-${verrev_cprint}"
245 and run "$luarocks unpack cprint"
246 and rm_rf "./cprint-${verrev_cprint}"
247 end,
248 test_unpack_src = function()
249 return rm_rf "./cprint-${verrev_cprint}"
250 and run "$luarocks download --source cprint"
251 and run "$luarocks unpack ./cprint-${verrev_cprint}.src.rock"
252 and rm_rf "./cprint-${verrev_cprint}"
253 end,
254 test_unpack_rockspec = function()
255 return rm_rf "./cprint-${verrev_cprint}"
256 and run "$luarocks download --rockspec cprint"
257 and run "$luarocks unpack ./cprint-${verrev_cprint}.rockspec"
258 and rm_rf "./cprint-${verrev_cprint}"
259 end,
260 test_unpack_binary = function()
261 return rm_rf "./cprint-${verrev_cprint}"
262 and run "$luarocks build cprint"
263 and run "$luarocks pack cprint"
264 and run "$luarocks unpack ./cprint-${verrev_cprint}.${platform}.rock"
265 and rm_rf "./cprint-${verrev_cprint}"
266 end,
267 fail_unpack_invalidpatch = function()
268 need_luasocket()
269 return run '$luarocks unpack "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"'
270 end,
271 fail_unpack_invalidrockspec = function()
272 need_luasocket()
273 return run '$luarocks unpack "invalid.rockspec"'
274 end,
275 fail_upload_invalidrockspec = function() return run '$luarocks upload "invalid.rockspec"' end,
276 fail_upload_invalidkey = function() return run '$luarocks upload --api-key="invalid" "invalid.rockspec"' end,
277 test_admin_help = function() return run "$luarocks_admin help" end,
278 test_admin_make_manifest = function() return run "$luarocks_admin make_manifest" end,
279 test_admin_add_rsync = function() return run '$luarocks_admin --server=testing add "$testing_server/luasocket-${verrev_luasocket}.src.rock"' end,
280 test_admin_add_sftp = function()
281 return run("$luarocks_admin --server=testing add ./luasocket-${verrev_luasocket}.src.rock", { LUAROCKS_CONFIG="$testing_dir/testing_config_sftp.lua" })
282 end,
283 fail_admin_add_missing = function() return run "$luarocks_admin --server=testing add" end,
284 fail_admin_invalidserver = function() return run '$luarocks_admin --server=invalid add "$testing_server/luasocket-${verrev_luasocket}.src.rock"' end,
285 fail_admin_invalidrock = function() return run "$luarocks_admin --server=testing add invalid" end,
286 test_admin_refresh_cache = function() return run "$luarocks_admin --server=testing refresh_cache" end,
287 test_admin_remove = function() return run "$luarocks_admin --server=testing remove luasocket-${verrev_luasocket}.src.rock" end,
288 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,
290
291 -- TODO:
292 test_deps_mode_one = function()
293 return run '$luarocks build --tree="system" lpeg'
294 and run '$luarocks list'
295 and run '$luarocks build --deps-mode=one --tree="$testing_tree" lxsh'
296 and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' ~= ""
297 end,
298 test_deps_mode_order = function()
299 return run '$luarocks build --tree="system" lpeg'
300 and run '$luarocks build --deps-mode=order --tree="$testing_tree" lxsh'
301 and run '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg'
302 and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' == ""
303 end,
304 test_deps_mode_order_sys = function()
305 return run '$luarocks build --tree="$testing_tree" lpeg'
306 and run '$luarocks build --deps-mode=order --tree="$testing_sys_tree" lxsh'
307 and run_get_contents '$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg' ~= ""
308 end,
309 test_deps_mode_all_sys = function()
310 return run '$luarocks build --tree="$testing_tree" lpeg'
311 and run '$luarocks build --deps-mode=all --tree="$testing_sys_tree" lxsh'
312 and run_get_contents '$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg' == ""
313 end,
314
315 test_deps_mode_none = function()
316 return run '$luarocks build --tree="$testing_tree" --deps-mode=none lxsh'
317 and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' == ""
318 end,
319 test_deps_mode_nodeps_alias = function()
320 return run '$luarocks build --tree="$testing_tree" --nodeps lxsh'
321 and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' == ""
322 end,
323 test_deps_mode_make_order = function()
324 local ok = run '$luarocks build --tree="$testing_sys_tree" lpeg'
325 and rm_rf "./lxsh-${verrev_lxsh}"
326 and run "$luarocks download --source lxsh ${verrev_lxsh}"
327 and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock"
328 and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", '$luarocks make --tree="$testing_tree" --deps-mode=order')
329 if not ok then
330 return false
331 end
332 local found = run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg'
333 rm_rf "./lxsh-${verrev_lxsh}"
334 return found == ""
335 end,
336 test_deps_mode_make_order_sys = function()
337 local ok = run '$luarocks build --tree="$testing_tree" lpeg'
338 and rm_rf "./lxsh-${verrev_lxsh}"
339 and run "$luarocks download --source lxsh ${verrev_lxsh}"
340 and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock"
341 and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", '$luarocks make --tree="$testing_sys_tree" --deps-mode=order')
342 if not ok then
343 return false
344 end
345 local found = run_get_contents '$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg'
346 rm_rf "./lxsh-${verrev_lxsh}"
347 return found ~= ""
348 end,
349 test_write_rockspec = function() return run "$luarocks write_rockspec git://github.com/keplerproject/luarocks" end,
350 test_write_rockspec_lib = function() return run '$luarocks write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license="3-clause BSD" --lua-version=5.1,5.2' end,
351 test_write_rockspec_fullargs = function() return run '$luarocks write_rockspec git://github.com/keplerproject/luarocks --lua-version=5.1,5.2 --license="MIT/X11" --homepage="http://www.luarocks.org" --summary="A package manager for Lua modules"' end,
352 fail_write_rockspec_args = function() return run "$luarocks write_rockspec invalid" end,
353 fail_write_rockspec_args_url = function() return run "$luarocks write_rockspec http://example.com/invalid.zip" end,
354 test_write_rockspec_http = function() return run "$luarocks write_rockspec http://luarocks.org/releases/luarocks-2.1.0.tar.gz --lua-version=5.1" end,
355 test_write_rockspec_basedir = function() return run "$luarocks write_rockspec https://github.com/downloads/Olivine-Labs/luassert/luassert-1.2.tar.gz --lua-version=5.1" end,
356 test_doc = function()
357 return run "$luarocks install luarepl"
358 and run "$luarocks doc luarepl"
359 end,
360
361}