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