aboutsummaryrefslogtreecommitdiff
path: root/test/testing.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xtest/testing.sh651
1 files changed, 0 insertions, 651 deletions
diff --git a/test/testing.sh b/test/testing.sh
deleted file mode 100755
index cb10441c..00000000
--- a/test/testing.sh
+++ /dev/null
@@ -1,651 +0,0 @@
1#!/bin/bash -e
2
3# Setup #########################################
4
5[ -e ../configure ] || {
6 echo "Please run this from the test/ directory."
7 exit 1
8}
9
10if [ -z "$*" ]
11then
12 ps aux | grep -q '[s]shd' || {
13 echo "Run sudo /bin/sshd in order to perform all tests."
14 exit 1
15 }
16fi
17
18if [ "$1" == "--travis" ]
19then
20 travis=true
21 shift
22fi
23
24luaversion=5.1.5
25
26if [ "$1" == "--lua" ]
27then
28 shift
29 luaversion=$1
30 shift
31fi
32
33luashortversion=`echo $luaversion | cut -d. -f 1-2`
34
35testing_dir="$PWD"
36
37testing_lrprefix="$testing_dir/testing_lrprefix-$luaversion"
38testing_tree="$testing_dir/testing-$luaversion"
39testing_sys_tree="$testing_dir/testing_sys-$luaversion"
40testing_tree_copy="$testing_dir/testing_copy-$luaversion"
41testing_sys_tree_copy="$testing_dir/testing_sys_copy-$luaversion"
42testing_cache="$testing_dir/testing_cache-$luaversion"
43testing_server="$testing_dir/testing_server-$luaversion"
44
45if [ "$1" == "--clean" ]
46then
47 shift
48 rm -rf "$testing_cache"
49 rm -rf "$testing_server"
50fi
51
52[ "$1" ] || rm -f luacov.stats.out
53rm -f luacov.report.out
54rm -rf /tmp/luarocks_testing
55mkdir /tmp/luarocks_testing
56rm -rf "$testing_lrprefix"
57rm -rf "$testing_tree"
58rm -rf "$testing_sys_tree"
59rm -rf "$testing_tree_copy"
60rm -rf "$testing_sys_tree_copy"
61rm -rf "$testing_dir/testing_config.lua"
62rm -rf "$testing_dir/testing_config_show_downloads.lua"
63rm -rf "$testing_dir/testing_config_sftp.lua"
64rm -rf "$testing_dir/luacov.config"
65
66mkdir -p "$testing_cache"
67
68[ "$1" = "clean" ] && {
69 rm -f luacov.stats.out
70 exit 0
71}
72
73cat <<EOF > $testing_dir/testing_config.lua
74rocks_trees = {
75 "$testing_tree",
76 { name = "system", root = "$testing_sys_tree" },
77}
78rocks_servers = {
79 "$testing_server"
80}
81local_cache = "$testing_cache"
82upload_server = "testing"
83upload_user = "$USER"
84upload_servers = {
85 testing = {
86 rsync = "localhost/tmp/luarocks_testing",
87 },
88}
89external_deps_dirs = {
90 "/usr/local",
91 "/usr",
92 -- These are used for a test that fails, so it
93 -- can point to invalid paths:
94 {
95 prefix = "/opt",
96 bin = "bin",
97 include = "include",
98 lib = { "lib", "lib64" },
99 }
100}
101EOF
102(
103 cat $testing_dir/testing_config.lua
104 echo "show_downloads = true"
105) > $testing_dir/testing_config_show_downloads.lua
106cat <<EOF > $testing_dir/testing_config_sftp.lua
107rocks_trees = {
108 "$testing_tree",
109 "$testing_sys_tree",
110}
111local_cache = "$testing_cache"
112upload_server = "testing"
113upload_user = "$USER"
114upload_servers = {
115 testing = {
116 sftp = "localhost/tmp/luarocks_testing",
117 },
118}
119EOF
120cat <<EOF > $testing_dir/luacov.config
121return {
122 statsfile = "$testing_dir/luacov.stats.out",
123 reportfile = "$testing_dir/luacov.report.out",
124 modules = {
125 ["luarocks"] = "src/bin/luarocks",
126 ["luarocks-admin"] = "src/bin/luarocks-admin",
127 ["luarocks.*"] = "src",
128 ["luarocks.*.*"] = "src",
129 ["luarocks.*.*.*"] = "src"
130 }
131}
132EOF
133
134export LUAROCKS_CONFIG="$testing_dir/testing_config.lua"
135export LUA_PATH=
136export LUA_CPATH=
137
138if [ "$travis" ]
139then
140 luadir=/tmp/lua-$luaversion
141 pushd /tmp
142 if [ ! -e "$luadir/bin/lua" ]
143 then
144 mkdir -p lua
145 echo "Downloading lua $luaversion..."
146 wget "http://www.lua.org/ftp/lua-$luaversion.tar.gz" &> /dev/null
147 tar zxpf "lua-$luaversion.tar.gz"
148 cd "lua-$luaversion"
149 echo "Building lua $luaversion..."
150 make linux INSTALL_TOP="$luadir" &> /dev/null
151 make install INSTALL_TOP="$luadir" &> /dev/null
152 fi
153 popd
154 [ -e ~/.ssh/id_rsa.pub ] || ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa
155 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
156 chmod og-wx ~/.ssh/authorized_keys
157 ssh-keyscan localhost >> ~/.ssh/known_hosts
158else
159 luadir="/Programs/Lua/Current"
160 if [ ! -e "$luadir" ]
161 then
162 luadir="/usr/local"
163 fi
164fi
165
166if [ `uname -m` = i686 ]
167then
168 platform="linux-x86"
169else
170 platform="linux-x86_64"
171fi
172
173lua="$luadir/bin/lua"
174
175version_luasocket=3.0rc1
176verrev_luasocket=${version_luasocket}-1
177srcdir_luasocket=luasocket-3.0-rc1
178
179version_cprint=0.1
180verrev_cprint=0.1-2
181
182new_version_say=1.2-1
183old_version_say=1.0-1
184
185version_luacov=0.11.0
186verrev_luacov=${version_luacov}-1
187version_lxsh=0.8.6
188version_validate_args=1.5.4
189verrev_validate_args=1.5.4-1
190verrev_lxsh=${version_lxsh}-2
191version_abelhas=1.0
192verrev_abelhas=${version_abelhas}-1
193
194luasec=luasec
195
196cd ..
197./configure --with-lua="$luadir" --prefix="$testing_lrprefix"
198make clean
199make src/luarocks/site_config.lua
200make dev
201cd src
202basedir=$PWD
203run_lua() {
204 if [ "$1" = "--noecho" ]; then shift; noecho=1; else noecho=0; fi
205 if [ "$1" = "--nocov" ]; then shift; nocov=1; else nocov=0; fi
206 if [ "$noecho" = 0 ]
207 then
208 echo $*
209 fi
210 cmd=$1
211 shift
212 if [ "$nocov" = 0 ]
213 then
214 "$lua" -e"require('luacov.runner')('$testing_dir/luacov.config')" "$basedir/bin/$cmd" "$@"
215 else
216 "$lua" "$basedir/bin/$cmd" "$@"
217 fi
218}
219luarocks="run_lua luarocks"
220luarocks_nocov="run_lua --nocov luarocks"
221luarocks_noecho="run_lua --noecho luarocks"
222luarocks_noecho_nocov="run_lua --noecho --nocov luarocks"
223luarocks_admin="run_lua luarocks-admin"
224luarocks_admin_nocov="run_lua --nocov luarocks-admin"
225
226###################################################
227
228mkdir -p "$testing_server"
229(
230 cd "$testing_server"
231 luarocks_repo="https://luarocks.org"
232 get() { [ -e `basename "$1"` ] || wget -c "$1"; }
233 get "$luarocks_repo/luacov-${verrev_luacov}.src.rock"
234 get "$luarocks_repo/luacov-${verrev_luacov}.rockspec"
235 get "$luarocks_repo/luadoc-3.0.1-1.src.rock"
236 get "$luarocks_repo/lualogging-1.3.0-1.src.rock"
237 get "$luarocks_repo/luasocket-${verrev_luasocket}.src.rock"
238 get "$luarocks_repo/luasocket-${verrev_luasocket}.rockspec"
239 get "$luarocks_repo/luafilesystem-1.6.3-1.src.rock"
240 get "$luarocks_repo/stdlib-41.0.0-1.src.rock"
241 get "$luarocks_repo/luarepl-0.4-1.src.rock"
242 get "$luarocks_repo/validate-args-1.5.4-1.rockspec"
243 get "$luarocks_repo/luasec-0.6-1.rockspec"
244 get "$luarocks_repo/luabitop-1.0.2-1.rockspec"
245 get "$luarocks_repo/luabitop-1.0.2-1.src.rock"
246 get "$luarocks_repo/lpty-1.0.1-1.src.rock"
247 get "$luarocks_repo/cprint-${verrev_cprint}.src.rock"
248 get "$luarocks_repo/cprint-${verrev_cprint}.rockspec"
249 get "$luarocks_repo/wsapi-1.6-1.src.rock"
250 get "$luarocks_repo/lxsh-${verrev_lxsh}.src.rock"
251 get "$luarocks_repo/lxsh-${verrev_lxsh}.rockspec"
252 get "$luarocks_repo/abelhas-${verrev_abelhas}.rockspec"
253 get "$luarocks_repo/lzlib-0.4.1.53-1.src.rock"
254 get "$luarocks_repo/lpeg-0.12-1.src.rock"
255 get "$luarocks_repo/luaposix-33.2.1-1.src.rock"
256 get "$luarocks_repo/md5-1.2-1.src.rock"
257 get "$luarocks_repo/lmathx-20120430.51-1.src.rock"
258 get "$luarocks_repo/lmathx-20120430.51-1.rockspec"
259 get "$luarocks_repo/lmathx-20120430.52-1.src.rock"
260 get "$luarocks_repo/lmathx-20120430.52-1.rockspec"
261 get "$luarocks_repo/lmathx-20150505-1.src.rock"
262 get "$luarocks_repo/lmathx-20150505-1.rockspec"
263 get "$luarocks_repo/lua-path-0.2.3-1.src.rock"
264 get "$luarocks_repo/lua-cjson-2.1.0-1.src.rock"
265 get "$luarocks_repo/luacov-coveralls-0.1.1-1.src.rock"
266 get "$luarocks_repo/say-1.2-1.src.rock"
267 get "$luarocks_repo/say-1.0-1.src.rock"
268 get "$luarocks_repo/luassert-1.7.0-1.src.rock"
269)
270$luarocks_admin_nocov make_manifest "$testing_server"
271
272###################################################
273
274checksum_path() {
275 ( cd "$1"; find . -printf "%s %p\n" | md5sum )
276}
277
278build_environment() {
279 rm -rf "$testing_tree"
280 rm -rf "$testing_sys_tree"
281 rm -rf "$testing_tree_copy"
282 rm -rf "$testing_sys_tree_copy"
283 mkdir -p "$testing_tree"
284 mkdir -p "$testing_sys_tree"
285 $luarocks_admin_nocov make_manifest "$testing_cache"
286 for package in "$@"
287 do
288 $luarocks_nocov install --only-server="$testing_cache" --tree="$testing_sys_tree" $package || {
289 $luarocks_nocov build --tree="$testing_sys_tree" $package
290 $luarocks_nocov pack --tree="$testing_sys_tree" $package; mv $package-*.rock "$testing_cache"
291 }
292 done
293 export LUA_PATH=
294 export LUA_CPATH=
295 eval `$luarocks_noecho_nocov path --bin`
296 cp -a "$testing_tree" "$testing_tree_copy"
297 cp -a "$testing_sys_tree" "$testing_sys_tree_copy"
298 testing_tree_copy_md5=`checksum_path "$testing_tree_copy"`
299 testing_sys_tree_copy_md5=`checksum_path "$testing_sys_tree_copy"`
300}
301
302reset_environment() {
303 testing_tree_md5=`checksum_path "$testing_tree"`
304 testing_sys_tree_md5=`checksum_path "$testing_sys_tree"`
305 if [ "$testing_tree_md5" != "$testing_tree_copy_md5" ]
306 then
307 rm -rf "$testing_tree"
308 cp -a "$testing_tree_copy" "$testing_tree"
309 fi
310 if [ "$testing_sys_tree_md5" != "$testing_sys_tree_copy_md5" ]
311 then
312 rm -rf "$testing_sys_tree"
313 cp -a "$testing_sys_tree_copy" "$testing_sys_tree"
314 fi
315}
316
317need() {
318 echo "Obtaining $1 $2..."
319 if $luarocks show $1 &> /dev/null
320 then
321 echo "Already available"
322 return
323 fi
324 platrock="$1-$2.$platform.rock"
325 if [ ! -e "$testing_cache/$platrock" ]
326 then
327 echo "Building $1 $2..."
328 $luarocks_nocov build --pack-binary-rock $1 $2
329 mv "$platrock" "$testing_cache"
330 fi
331 echo "Installing $1 $2..."
332 $luarocks_nocov install "$testing_cache/$platrock"
333 return
334}
335need_luasocket() { need luasocket $verrev_luasocket; }
336
337# Tests #########################################
338test_version() { $luarocks --version; }
339
340fail_unknown_command() { $luarocks unknown_command; }
341
342fail_arg_boolean_parameter() { $luarocks --porcelain=invalid; }
343fail_arg_boolean_unknown() { $luarocks --invalid-flag; }
344fail_arg_string_no_parameter() { $luarocks --server; }
345fail_arg_string_followed_by_flag() { $luarocks --server --porcelain; }
346fail_arg_string_unknown() { $luarocks --invalid-flag=abc; }
347
348fail_invalid_assignment() { $luarocks invalid=5; }
349
350test_empty_list() { $luarocks list; }
351test_list_outdated() { $luarocks list --outdated; }
352
353fail_sysconfig_err() { local err=0; local scdir="$testing_lrprefix/etc/luarocks/"; mkdir -p "$scdir"; local sysconfig="$scdir/config.lua"; echo "aoeui" > "$sysconfig"; echo $sysconfig; $luarocks list; err=$?; rm "$sysconfig"; return "$err"; }
354fail_sysconfig_default_err() { local err=0; local scdir="$testing_lrprefix/etc/luarocks/"; mkdir -p "$scdir"; local sysconfig="$scdir/config-$luashortversion.lua"; echo "aoeui" > "$sysconfig"; echo $sysconfig; $luarocks list; err=$?; rm "$sysconfig"; return "$err"; }
355
356fail_build_noarg() { $luarocks build; }
357fail_download_noarg() { $luarocks download; }
358fail_install_noarg() { $luarocks install; }
359fail_lint_noarg() { $luarocks lint; }
360fail_search_noarg() { $luarocks search; }
361fail_show_noarg() { $luarocks show; }
362fail_unpack_noarg() { $luarocks unpack; }
363fail_upload_noarg() { $luarocks upload; }
364fail_remove_noarg() { $luarocks remove; }
365fail_doc_noarg() { $luarocks doc; }
366
367fail_build_invalid() { $luarocks build invalid; }
368fail_download_invalid() { $luarocks download invalid; }
369fail_install_invalid() { $luarocks install invalid; }
370fail_lint_invalid() { $luarocks lint invalid; }
371fail_show_invalid() { $luarocks show invalid; }
372fail_new_version_invalid() { $luarocks new_version invalid; }
373
374test_list_invalidtree() { $luarocks --tree=/some/invalid/tree list; }
375
376fail_inexistent_dir() { mkdir idontexist; cd idontexist; rmdir ../idontexist; $luarocks; err=$?; cd ..; return $err; }
377
378fail_make_norockspec() { $luarocks make; }
379
380fail_build_permissions() { $luarocks build --tree=/usr lpeg; }
381fail_build_permissions_parent() { $luarocks build --tree=/usr/invalid lpeg; }
382
383test_build_verbose() { $luarocks build --verbose lpeg; }
384test_build_timeout() { $luarocks --timeout=10; }
385fail_build_timeout_invalid() { $luarocks --timeout=abc; }
386test_build_branch() { $luarocks build --branch=master lpeg; }
387fail_build_invalid_entry_deps_mode() { $luarocks build --deps-mode=123 lpeg; }
388test_build_only_server() { $luarocks --only-server=testing; }
389test_build_only_sources() { $luarocks build --only-sources="http://example.com" lpeg; }
390fail_build_blank_arg() { $luarocks build --tree="" lpeg; }
391test_build_withpatch() { need_luasocket; $luarocks build luadoc; }
392test_build_diffversion() { $luarocks build luacov ${version_luacov}; }
393test_build_command() { $luarocks build stdlib; }
394test_build_install_bin() { $luarocks build luarepl; }
395test_build_nohttps() { need_luasocket; $luarocks download --rockspec validate-args ${verrev_validate_args} && $luarocks build ./validate-args-${version_validate_args}-1.rockspec && rm ./validate-args-${version_validate_args}-1.rockspec; }
396test_build_https() { need_luasocket; $luarocks download --rockspec validate-args ${verrev_validate_args} && $luarocks install $luasec && $luarocks build ./validate-args-${verrev_validate_args}.rockspec && rm ./validate-args-${verrev_validate_args}.rockspec; }
397test_build_supported_platforms() { $luarocks build lpty; }
398test_build_only_deps_rockspec() { $luarocks download --rockspec lxsh ${verrev_lxsh} && $luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; }
399test_build_only_deps_src_rock() { $luarocks download --source lxsh ${verrev_lxsh} && $luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; }
400test_build_only_deps() { $luarocks build luasec --only-deps && { $luarocks show luasec; [ $? -ne 0 ]; }; }
401test_install_only_deps() { $luarocks install lxsh ${verrev_lxsh} --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; }
402test_build_no_deps() { $luarocks build luasec --nodeps; }
403test_install_no_deps() { $luarocks install luasec --nodeps; }
404fail_build_missing_external() { $luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"; }
405fail_build_invalidpatch() { need_luasocket; $luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; }
406
407test_build_deps_partial_match() { $luarocks build lmathx; }
408test_build_show_downloads() { export LUAROCKS_CONFIG="$testing_dir/testing_config_show_downloads.lua" && $luarocks build alien; export LUAROCKS_CONFIG="$testing_dir/testing_config.lua"; }
409
410test_download_all() { $luarocks download --all validate-args && rm validate-args-*; }
411test_download_rockspecversion() { $luarocks download --rockspec validate-args ${verrev_validate_args} && rm validate-args-*; }
412
413test_help() { $luarocks help; }
414fail_help_invalid() { $luarocks help invalid; }
415
416test_install_only_deps() { $luarocks install --only-deps "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"; }
417test_install_binaryrock() { $luarocks build --pack-binary-rock cprint && $luarocks install ./cprint-${verrev_cprint}.${platform}.rock && rm ./cprint-${verrev_cprint}.${platform}.rock; }
418test_install_with_bin() { $luarocks install wsapi; }
419fail_install_notazipfile() { $luarocks install "$testing_dir/testfiles/not_a_zipfile-1.0-1.src.rock"; }
420fail_install_invalidpatch() { need_luasocket; $luarocks install "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; }
421fail_install_invalid_filename() { $luarocks install "invalid.rock"; }
422fail_install_invalid_arch() { $luarocks install "foo-1.0-1.impossible-x86.rock"; }
423test_install_reinstall() { $luarocks install "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"; $luarocks install --deps-mode=none "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"; }
424
425fail_local_root() { USER=root $luarocks install --local luasocket; }
426
427test_site_config() { mv ../src/luarocks/site_config.lua ../src/luarocks/site_config.lua.tmp; $luarocks; mv ../src/luarocks/site_config.lua.tmp ../src/luarocks/site_config.lua; }
428
429test_lint_ok() { $luarocks download --rockspec validate-args ${verrev_validate_args} && $luarocks lint ./validate-args-${verrev_validate_args}.rockspec && rm ./validate-args-${verrev_validate_args}.rockspec; }
430fail_lint_type_mismatch_string() { $luarocks lint "$testing_dir/testfiles/type_mismatch_string-1.0-1.rockspec"; }
431fail_lint_type_mismatch_version() { $luarocks lint "$testing_dir/testfiles/type_mismatch_version-1.0-1.rockspec"; }
432fail_lint_type_mismatch_table() { $luarocks lint "$testing_dir/testfiles/type_mismatch_table-1.0-1.rockspec"; }
433fail_lint_no_build_table() { $luarocks lint "$testing_dir/testfiles/no_build_table-0.1-1.rockspec"; }
434
435test_list() { $luarocks list; }
436test_list_porcelain() { $luarocks list --porcelain; }
437
438test_make_with_rockspec() { rm -rf ./luasocket-${verrev_luasocket} && $luarocks download --source luasocket && $luarocks unpack ./luasocket-${verrev_luasocket}.src.rock && cd luasocket-${verrev_luasocket}/${srcdir_luasocket} && $luarocks make luasocket-${verrev_luasocket}.rockspec && cd ../.. && rm -rf ./luasocket-${verrev_luasocket}; }
439test_make_default_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks new_version lxsh-${verrev_lxsh}.rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; }
440test_make_unnamed_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && cp lxsh-${verrev_lxsh}.rockspec rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; }
441fail_make_ambiguous_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && cp lxsh-${verrev_lxsh}.rockspec lxsh2-${verrev_lxsh}.rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; }
442fail_make_ambiguous_unnamed_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && mv lxsh-${verrev_lxsh}.rockspec 1_rockspec && cp 1_rockspec 2_rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; }
443test_make_pack_binary_rock() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --deps-mode=none --pack-binary-rock && [ -e ./lxsh-${verrev_lxsh}.all.rock ] && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; }
444
445test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; }
446test_new_version_url() { $luarocks download --rockspec abelhas 1.0 && $luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz && rm ./abelhas-*; }
447test_new_version_tag() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec --tag v0.3 && rm ./luacov-0.3-1.rockspec; }
448test_new_version_tag_without_arg() { rm -rf ./*rockspec && $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version --tag v0.3 && rm ./luacov-0.3-1.rockspec; }
449
450test_pack() { $luarocks list && $luarocks pack luacov && rm ./luacov-*.rock; }
451test_pack_src() { $luarocks install $luasec && $luarocks download --rockspec luasocket && $luarocks pack ./luasocket-${verrev_luasocket}.rockspec && rm ./luasocket-${version_luasocket}-*.rock; }
452
453test_path() { $luarocks path --bin; }
454test_path_lr_path() { $luarocks path --lr-path; }
455test_path_lr_cpath() { $luarocks path --lr-cpath; }
456test_path_lr_bin() { $luarocks path --lr-bin; }
457test_path_with_tree() { $luarocks path --tree=lua_modules; }
458
459fail_purge_missing_tree() { $luarocks purge --tree="$testing_tree"; }
460fail_purge_tree_notstring() { $luarocks purge --tree=1; }
461test_purge() { $luarocks purge --tree="$testing_sys_tree"; }
462test_purge_oldversions() { $luarocks purge --old-versions --tree="$testing_sys_tree"; }
463
464test_remove() { $luarocks build abelhas ${version_abelhas} && $luarocks remove abelhas ${version_abelhas}; }
465test_remove_force() { need_luasocket; $luarocks build lualogging && $luarocks remove --force luasocket; }
466test_remove_force_fast() { need_luasocket; $luarocks build lualogging && $luarocks remove --force-fast luasocket; }
467fail_remove_deps() { need_luasocket; $luarocks build lualogging && $luarocks remove luasocket; }
468fail_remove_missing() { $luarocks remove missing_rock; }
469fail_remove_invalid_name() { $luarocks remove invalid.rock; }
470
471test_search_found() { $luarocks search zlib; }
472test_search_missing() { $luarocks search missing_rock; }
473test_search_version() { $luarocks search zlib 1.1; }
474test_search_all() { $luarocks search --all; }
475fail_search_nostring() { $var=123; $luarocks search $var; }
476
477test_show() { $luarocks show luacov; }
478test_show_modules() { $luarocks show --modules luacov; }
479test_show_home() { $luarocks show --home luacov; }
480test_show_deps() { $luarocks show --deps luacov; }
481test_show_rockspec() { $luarocks show --rockspec luacov; }
482test_show_mversion() { $luarocks show --mversion luacov; }
483test_show_rocktree() { $luarocks show --rock-tree luacov; }
484test_show_rockdir() { $luarocks show --rock-dir luacov; }
485test_show_depends() { need_luasocket; $luarocks install $luasec && $luarocks show luasec; }
486test_show_oldversion() { $luarocks install luacov ${version_luacov} && $luarocks show luacov ${version_luacov}; }
487
488test_unpack_download() { rm -rf ./cprint-${verrev_cprint} && $luarocks unpack cprint && rm -rf ./cprint-${verrev_cprint}; }
489test_unpack_src() { rm -rf ./cprint-${verrev_cprint} && $luarocks download --source cprint && $luarocks unpack ./cprint-${verrev_cprint}.src.rock && rm -rf ./cprint-${verrev_cprint}; }
490test_unpack_rockspec() { rm -rf ./cprint-${verrev_cprint} && $luarocks download --rockspec cprint && $luarocks unpack ./cprint-${verrev_cprint}.rockspec && rm -rf ./cprint-${verrev_cprint}; }
491test_unpack_binary() { rm -rf ./cprint-${verrev_cprint} && $luarocks build cprint && $luarocks pack cprint && $luarocks unpack ./cprint-${verrev_cprint}.${platform}.rock && rm -rf ./cprint-${verrev_cprint}; }
492fail_unpack_invalidpatch() { need_luasocket; $luarocks unpack "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; }
493fail_unpack_invalidrockspec() { need_luasocket; $luarocks unpack "invalid.rockspec"; }
494
495fail_upload_invalidrockspec() { $luarocks upload "invalid.rockspec"; }
496fail_upload_invalidkey() { $luarocks upload --api-key="invalid" "invalid.rockspec"; }
497fail_upload_skippack() { $luarocks upload --api-key="invalid" --skip-pack "luacov-${verrev_luacov}.rockspec"; }
498fail_upload_force() { $luarocks install lua-cjson && $luarocks upload --api-key="invalid" --force "luacov-${verrev_luacov}.rockspec" && $luarocks remove lua-cjson; }
499
500
501test_admin_help() { $luarocks_admin help; }
502
503test_admin_make_manifest() { $luarocks_admin make_manifest; }
504test_admin_add_rsync() { $luarocks_admin --server=testing add "$testing_server/luasocket-${verrev_luasocket}.src.rock"; }
505test_admin_add_sftp() { export LUAROCKS_CONFIG="$testing_dir/testing_config_sftp.lua" && $luarocks_admin --server=testing add ./luasocket-${verrev_luasocket}.src.rock; export LUAROCKS_CONFIG="$testing_dir/testing_config.lua"; }
506fail_admin_add_missing() { $luarocks_admin --server=testing add; }
507fail_admin_invalidserver() { $luarocks_admin --server=invalid add "$testing_server/luasocket-${verrev_luasocket}.src.rock"; }
508fail_admin_invalidrock() { $luarocks_admin --server=testing add invalid; }
509test_admin_refresh_cache() { $luarocks_admin --server=testing refresh_cache; }
510test_admin_remove() { $luarocks_admin --server=testing remove luasocket-${verrev_luasocket}.src.rock; }
511fail_admin_remove_missing() { $luarocks_admin --server=testing remove; }
512fail_admin_split_server_url() { $luarocks_admin --server="localhost@/tmp/luarocks_testing" add "$testing_server/luasocket-${verrev_luasocket}.src.rock"; }
513
514fail_deps_mode_invalid_arg() { $luarocks remove luacov --deps-mode; }
515test_deps_mode_one() { $luarocks build --tree="system" lpeg && $luarocks list && $luarocks build --deps-mode=one --tree="$testing_tree" lxsh && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 1 ]; }
516test_deps_mode_order() { $luarocks build --tree="system" lpeg && $luarocks build --deps-mode=order --tree="$testing_tree" lxsh && $luarocks_noecho list --tree="$testing_tree" --porcelain lpeg && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ]; }
517test_deps_mode_order_sys() { $luarocks build --tree="$testing_tree" lpeg && $luarocks build --deps-mode=order --tree="$testing_sys_tree" lxsh && [ `$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg | wc -l` = 1 ]; }
518test_deps_mode_all_sys() { $luarocks build --tree="$testing_tree" lpeg && $luarocks build --deps-mode=all --tree="$testing_sys_tree" lxsh && [ `$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg | wc -l` = 0 ]; }
519test_deps_mode_none() { $luarocks build --tree="$testing_tree" --deps-mode=none lxsh; [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ]; }
520test_deps_mode_nodeps_alias() { $luarocks build --tree="$testing_tree" --nodeps lxsh; [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ]; }
521test_deps_mode_make_order() { $luarocks build --tree="$testing_sys_tree" lpeg && rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --tree="$testing_tree" --deps-mode=order && cd ../.. && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ] && rm -rf ./lxsh-${verrev_lxsh}; }
522test_deps_mode_make_order_sys() { $luarocks build --tree="$testing_tree" lpeg && rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --tree="$testing_sys_tree" --deps-mode=order && cd ../.. && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 1 ] && rm -rf ./lxsh-${verrev_lxsh}; }
523
524test_write_rockspec() { $luarocks write_rockspec git://github.com/keplerproject/luarocks; }
525test_write_rockspec_name() { $luarocks write_rockspec luarocks git://github.com/keplerproject/luarocks; }
526test_write_rockspec_name_version() { $luarocks write_rockspec luarocks 7.8.9 git://github.com/keplerproject/luarocks; }
527test_write_rockspec_current_dir() { $luarocks write_rockspec; }
528test_write_rockspec_tag() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --tag=v2.3.0; }
529test_write_rockspec_lib() { $luarocks write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license="3-clause BSD" --lua-version=5.1,5.2; }
530test_write_rockspec_format() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2; }
531test_write_rockspec_fullargs() { $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"; }
532fail_write_rockspec_args() { $luarocks write_rockspec invalid; }
533fail_write_rockspec_args_url() { $luarocks write_rockspec http://example.com/invalid.zip; }
534test_write_rockspec_http() { $luarocks write_rockspec http://luarocks.org/releases/luarocks-2.1.0.tar.gz --lua-version=5.1; }
535test_write_rockspec_basedir() { $luarocks write_rockspec https://github.com/downloads/Olivine-Labs/luassert/luassert-1.2.tar.gz --lua-version=5.1; }
536
537fail_config_noflags() { $luarocks config; }
538test_config_lua_incdir() { $luarocks config --lua-incdir; }
539test_config_lua_libdir() { $luarocks config --lua-libdir; }
540test_config_lua_ver() { $luarocks config --lua-ver; }
541fail_config_system_config() { rm -f "$testing_lrprefix/etc/luarocks/config.lua"; $luarocks config --system-config; }
542test_config_system_config() { mkdir -p "$testing_lrprefix/etc/luarocks"; touch "$testing_lrprefix/etc/luarocks/config.lua"; $luarocks config --system-config; err=$?; rm -f "$testing_lrprefix/etc/luarocks/config.lua"; return $err; }
543fail_config_system_config_invalid() { mkdir -p "$testing_lrprefix/etc/luarocks"; echo "if if if" > "$testing_lrprefix/etc/luarocks/config.lua"; $luarocks config --system-config; err=$?; rm -f "$testing_lrprefix/etc/luarocks/config.lua"; return $err; }
544test_config_user_config() { $luarocks config --user-config; }
545fail_config_user_config() { LUAROCKS_CONFIG="/missing_file.lua" $luarocks config --user-config; }
546test_config_rock_trees() { $luarocks config --rock-trees; }
547test_config_help() { $luarocks help config; }
548
549# Tests for https://github.com/keplerproject/luarocks/issues/375
550test_fetch_base_dir() { $lua <<EOF
551 local fetch = require "luarocks.fetch"
552
553 assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip"))
554 assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip"))
555 assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz"))
556 assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2"))
557 assert("parser.moon" == fetch.url_to_base_dir("git://github.com/Cirru/parser.moon"))
558 assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3"))
559EOF
560}
561
562test_doc() { $luarocks install luarepl; $luarocks doc luarepl; }
563test_doc_home() { $luarocks install luacov; $luarocks doc luacov --home; }
564fail_doc_invalid() { $luarocks doc invalid; }
565test_doc_list() { $luarocks install luacov; $luarocks doc luacov --list; }
566test_doc_local() { $luarocks install luacov; $luarocks doc luacov --local; }
567test_doc_porcelain() { $luarocks install luacov; $luarocks doc luacov --porcelain; }
568
569# Tests for https://github.com/keplerproject/luarocks/pull/552
570test_install_break_dependencies_warning() { need_luasocket; $luarocks install say ${new_version_say} && $luarocks install luassert && $luarocks install say ${old_version_say}; }
571test_install_break_dependencies_force() { need_luasocket; $luarocks install say ${new_version_say} && $luarocks install luassert && $luarocks install --force say ${old_version_say}; }
572test_install_break_dependencies_forcefast() { need_luasocket; $luarocks install say ${new_version_say} && $luarocks install luassert && $luarocks install --force-fast say ${old_version_say}; }
573
574# Driver #########################################
575run_tests() {
576 grep "^test_$1.*(" < $testing_dir/testing.sh | cut -d'(' -f1 | while read test
577 do
578 echo "-------------------------------------------"
579 echo "$test"
580 echo "-------------------------------------------"
581 reset_environment
582 if $test
583 then
584 echo "OK: Expected success."
585 else
586 if [ $? = 99 ]
587 then echo "FAIL: Unexpected crash!"; exit 99
588 fi
589 echo "FAIL: Unexpected failure."; exit 1
590 fi
591 done
592 grep "^fail_$1.*(" < $testing_dir/testing.sh | cut -d'(' -f1 | while read test
593 do
594 echo "-------------------------------------------"
595 echo "$test"
596 echo "-------------------------------------------"
597 reset_environment
598 if $test
599 then echo "FAIL: Unexpected success."; exit 1
600 else
601 if [ $? = 99 ]
602 then echo "FAIL: Unexpected crash!"; exit 99
603 fi
604 echo "OK: Expected failure."
605 fi
606 done
607}
608
609run_with_minimal_environment() {
610 echo "==========================================="
611 echo "Running with minimal environment"
612 echo "==========================================="
613 build_environment luacov
614 run_tests $1
615}
616
617run_with_full_environment() {
618 echo "==========================================="
619 echo "Running with full environment"
620 echo "==========================================="
621
622 local bitop=
623 [ "$luaversion" = "5.1.5" ] && bitop=luabitop
624
625 build_environment luacov luafilesystem luasocket $bitop luaposix md5 lzlib
626 run_tests $1
627}
628
629run_all_tests() {
630 run_with_minimal_environment $1
631 run_with_full_environment $1
632}
633
634run_all_tests $1
635#run_with_minimal_environment $1
636
637cd "$testing_dir/.."
638
639if [ "$travis" ]
640then
641 if [ "$TRAVIS" ]
642 then
643 build_environment luacov luafilesystem luacov-coveralls
644 $testing_sys_tree/bin/luacov-coveralls -c "$testing_dir/luacov.config" || echo "ok"
645 fi
646 $testing_sys_tree/bin/luacov -c "$testing_dir/luacov.config"
647 grep "Summary" -B1 -A1000 "$testing_dir/luacov.report.out"
648else
649 $testing_sys_tree/bin/luacov -c "$testing_dir/luacov.config"
650 cat "$testing_dir/luacov.report.out"
651fi