aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHisham <hisham@gobolinux.org>2016-07-28 17:24:15 -0300
committerHisham <hisham@gobolinux.org>2016-07-28 17:24:15 -0300
commitaccce73cf90bde70baa3d8101b76ca56b0cb0720 (patch)
tree705bb1ba44cd07f9b701cb8d6cf969d7bb48fd72 /test
parent5f5b26206068ba597091bb6fc22d8d63c0fef408 (diff)
parent67a737310b31eed8d1c38eb0e34ff4b6fc411731 (diff)
downloadluarocks-accce73cf90bde70baa3d8101b76ca56b0cb0720.tar.gz
luarocks-accce73cf90bde70baa3d8101b76ca56b0cb0720.tar.bz2
luarocks-accce73cf90bde70baa3d8101b76ca56b0cb0720.zip
Merge branch 'master' into luarocks-3
Diffstat (limited to 'test')
-rw-r--r--test/README.md59
-rw-r--r--test/luarocks_site.lua6
-rw-r--r--test/mock-server.lua80
-rw-r--r--test/test_environment.lua617
-rw-r--r--test/testfiles/invalid_validate-args-1.5.4-1.rockspec35
-rw-r--r--test/testing.lua483
-rwxr-xr-xtest/testing.sh698
7 files changed, 797 insertions, 1181 deletions
diff --git a/test/README.md b/test/README.md
new file mode 100644
index 00000000..c374438f
--- /dev/null
+++ b/test/README.md
@@ -0,0 +1,59 @@
1#LuaRocks testsuite
2##Overview
3Test suite for LuaRocks project with Busted unit testing framework(http://olivinelabs.com/busted/).
4
5* Contains white-box & black-box tests
6* Easy setup for your purpose on command line or from configuration file
7
8
9## Dependencies
10* Lua >= 5.1
11* Busted with dependencies
12
13
14##Usage
15Running of tests is based on basic Busted usage. *-Xhelper* flag is mandatory for inserting arguments into testing (primary black-box). Flag *--tags=* or *-t* is mandatory for specifying which tests will run. Mandatory *-Xhelper* flag always needs version of Lua or LuaJIT (e.g. *lua=5.2.4* or *luajit=2.0.3*). Start tests inside LuaRocks folder or specify with *-C* flag.
16
17**Arguments for Busted helper script**
18
19```
20lua=<version>, !mandatory! type your full version of Lua (e.g. lua=5.2.4)
21OR
22luajit=<version>, !mandatory! type your full version of LuaJIT (e.g. luajit=5.2.4)
23
24env=<type>, (default:"minimal") type what kind of environment to use ["minimal", "full"]
25clean, remove existing testing environment
26travis, add just if running on TravisCI
27os=<version>, type your OS ["linux", "os x", "windows"]
28```
29---------------------------------------------------------------------------------------------
30####_**Tags** of tests are required and are in this format:_
31
32**whitebox** - run all whitebox tests
33
34**blackbox** - run all blackbox tests
35
36**ssh** - run all tests which require ssh
37
38**w**\_*name-of-command* - whitebox testing of command
39
40**b**\_*name-of-command* - blackbox testing of command
41
42for example: `b_install` or `w_help`
43
44###Examples
45To run white-box tests in LuaRocks directory type :
46
47`busted -t "whitebox"`
48
49To run black-box tests just of *install* command (we defined our OS, so OS check is skipped.):
50
51`busted -Xhelper lua=5.2.4,os=linux -t "b_install"`
52
53To run black-box tests of *install* command, whitebox of *help* command (using *full* type of environment):
54
55`busted -Xhelper lua=5.2.4,env=full -t "b_install", "w_help"`
56
57To run black-box tests without tests, which use ssh:
58
59`busted -Xhelper lua=5.2.4 -t "blackbox" --exclude-tags=ssh` \ No newline at end of file
diff --git a/test/luarocks_site.lua b/test/luarocks_site.lua
new file mode 100644
index 00000000..cfa77dca
--- /dev/null
+++ b/test/luarocks_site.lua
@@ -0,0 +1,6 @@
1-- Config file of LuaRocks site for tests
2upload = {
3 server = "http://localhost:8080",
4 tool_version = "1.0.0",
5 api_version = "1",
6} \ No newline at end of file
diff --git a/test/mock-server.lua b/test/mock-server.lua
new file mode 100644
index 00000000..797e2bc5
--- /dev/null
+++ b/test/mock-server.lua
@@ -0,0 +1,80 @@
1#!/usr/bin/env lua
2
3--- A simple LuaRocks mock-server for testing.
4local restserver = require("restserver")
5local server = restserver:new():port(8080)
6
7server:add_resource("api/tool_version", {
8 {
9 method = "GET",
10 path = "/",
11 produces = "application/json",
12 handler = function(query)
13 local json = { version = query.current }
14 return restserver.response():status(200):entity(json)
15 end
16 }
17})
18
19server:add_resource("api/1/{id:[0-9]+}/status", {
20 {
21 method = "GET",
22 path = "/",
23 produces = "application/json",
24 handler = function(query)
25 local json = { user_id = "123", created_at = "29.1.1993" }
26 return restserver.response():status(200):entity(json)
27 end
28 }
29})
30
31server:add_resource("/api/1/{id:[0-9]+}/check_rockspec", {
32 {
33 method = "GET",
34 path = "/",
35 produces = "application/json",
36 handler = function(query)
37 local json = {}
38 return restserver.response():status(200):entity(json)
39 end
40 }
41})
42
43server:add_resource("/api/1/{id:[0-9]+}/upload", {
44 {
45 method = "POST",
46 path = "/",
47 produces = "application/json",
48 handler = function(query)
49 local json = {module = "luasocket", version = {id = "1.0"}, module_url = "http://localhost/luasocket", manifests = "root", is_new = "is_new"}
50 return restserver.response():status(200):entity(json)
51 end
52 }
53})
54
55server:add_resource("/api/1/{id:[0-9]+}/upload_rock/{id:[0-9]+}", {
56 {
57 method = "POST",
58 path = "/",
59 produces = "application/json",
60 handler = function(query)
61 local json = {"rock","module_url"}
62 return restserver.response():status(200):entity(json)
63 end
64 }
65})
66
67-- SHUTDOWN this mock-server
68server:add_resource("/shutdown", {
69 {
70 method = "GET",
71 path = "/",
72 handler = function(query)
73 os.exit()
74 return restserver.response():status(200):entity()
75 end
76 }
77})
78
79-- This loads the restserver.xavante plugin
80server:enable("restserver.xavante"):start() \ No newline at end of file
diff --git a/test/test_environment.lua b/test/test_environment.lua
new file mode 100644
index 00000000..13e548f9
--- /dev/null
+++ b/test/test_environment.lua
@@ -0,0 +1,617 @@
1local lfs = require("lfs")
2local test_env = {}
3
4local help_message = [[
5LuaRocks test-suite
6
7INFORMATION
8 New test-suite for LuaRocks project, using unit testing framework Busted.
9REQUIREMENTS
10 Be sure sshd is running on your system, or use '--exclude-tags=ssh',
11 to not execute tests which require sshd.
12USAGE
13 busted [-Xhelper <arguments>]
14ARGUMENTS
15 env=<type> Set type of environment to use ("minimal" or "full",
16 default: "minimal").
17 noreset Don't reset environment after each test
18 clean Remove existing testing environment.
19 travis Add if running on TravisCI.
20 os=<type> Set OS ("linux", "osx", or "windows").
21]]
22
23local function help()
24 print(help_message)
25 os.exit(1)
26end
27
28local function title(str)
29 print()
30 print(("-"):rep(#str))
31 print(str)
32 print(("-"):rep(#str))
33end
34
35local function exists(path)
36 return lfs.attributes(path, "mode") ~= nil
37end
38
39function test_env.quiet(commad)
40 if not test_env.VERBOSE then
41 if test_env.TEST_TARGET_OS == "linux" or test_env.TEST_TARGET_OS == "osx" then
42 return commad .. " 1> /dev/null 2> /dev/null"
43 elseif test_env.TEST_TARGET_OS == "windows" then
44 return commad .. " 2> NUL 1> NUL"
45 end
46 else
47 return command
48 end
49end
50
51--- Helper function for execute_bool and execute_output
52-- @param command string: command to execute
53-- @param print_command boolean: print command if 'true'
54-- @param env_variables table: table of environment variables to export {FOO="bar", BAR="foo"}
55-- @return final_command string: concatenated command to execution
56function test_env.execute_helper(command, print_command, env_variables)
57 local final_command = ""
58
59 if print_command then
60 print("\n[EXECUTING]: " .. command)
61 end
62
63 if env_variables then
64 final_command = "export "
65 for k,v in pairs(env_variables) do
66 final_command = final_command .. k .. "='" .. v .. "' "
67 end
68 -- remove last space and add ';' to separate exporting variables from command
69 final_command = final_command:sub(1, -2) .. "; "
70 end
71
72 final_command = final_command .. command
73
74 return final_command
75end
76
77--- Execute command and returns true/false
78-- In Lua5.1 os.execute returns numeric value, but in Lua5.2+ returns boolean
79-- @return true/false boolean: status of the command execution
80local function execute_bool(command, print_command, env_variables)
81 command = test_env.execute_helper(command, print_command, env_variables)
82
83 local ok = os.execute(command)
84 return ok == true or ok == 0
85end
86
87--- Execute command and returns output of command
88-- @return output string: output the command execution
89local function execute_output(command, print_command, env_variables)
90 command = test_env.execute_helper(command, print_command, env_variables)
91
92 local file = assert(io.popen(command))
93 local output = file:read('*all')
94 file:close()
95 return output:gsub("\n","") -- output adding new line, need to be removed
96end
97
98--- Set test_env.LUA_V or test_env.LUAJIT_V based
99-- on version of Lua used to run this script.
100function test_env.set_lua_version()
101 if _G.jit then
102 test_env.LUAJIT_V = _G.jit.version:match("(2%.%d)%.%d")
103 else
104 test_env.LUA_V = _VERSION:match("5%.%d")
105 end
106end
107
108--- Set all arguments from input into global variables
109function test_env.set_args()
110 -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables
111 test_env.TYPE_TEST_ENV = "minimal"
112 test_env.RESET_ENV = true
113
114 for _, argument in ipairs(arg) do
115 if argument:find("^env=") then
116 test_env.TYPE_TEST_ENV = argument:match("^env=(.*)$")
117 elseif argument == "noreset" then
118 test_env.RESET_ENV = false
119 elseif argument == "clean" then
120 test_env.TEST_ENV_CLEAN = true
121 elseif argument == "verbose" then
122 test_env.VERBOSE = true
123 elseif argument == "travis" then
124 test_env.TRAVIS = true
125 elseif argument:find("^os=") then
126 test_env.TEST_TARGET_OS = argument:match("^os=(.*)$")
127 else
128 help()
129 end
130 end
131
132 if not test_env.TEST_TARGET_OS then
133 title("OS CHECK")
134
135 if execute_bool("sw_vers") then
136 test_env.TEST_TARGET_OS = "osx"
137 elseif execute_bool("uname -s") then
138 test_env.TEST_TARGET_OS = "linux"
139 else
140 test_env.TEST_TARGET_OS = "windows"
141 end
142 end
143 return true
144end
145
146--- Remove directory recursively
147-- @param path string: directory path to delete
148function test_env.remove_dir(path)
149 if exists(path) then
150 for file in lfs.dir(path) do
151 if file ~= "." and file ~= ".." then
152 local full_path = path..'/'..file
153
154 if lfs.attributes(full_path, "mode") == "directory" then
155 test_env.remove_dir(full_path)
156 else
157 os.remove(full_path)
158 end
159 end
160 end
161 end
162 os.remove(path)
163end
164
165--- Remove subdirectories of a directory that match a pattern
166-- @param path string: path to directory
167-- @param pattern string: pattern matching basenames of subdirectories to be removed
168function test_env.remove_subdirs(path, pattern)
169 if exists(path) then
170 for file in lfs.dir(path) do
171 if file ~= "." and file ~= ".." then
172 local full_path = path..'/'..file
173
174 if lfs.attributes(full_path, "mode") == "directory" and file:find(pattern) then
175 test_env.remove_dir(full_path)
176 end
177 end
178 end
179 end
180end
181
182--- Remove files matching a pattern
183-- @param path string: directory where to delete files
184-- @param pattern string: pattern matching basenames of files to be deleted
185-- @return result_check boolean: true if one or more files deleted
186function test_env.remove_files(path, pattern)
187 local result_check = false
188 if exists(path) then
189 for file in lfs.dir(path) do
190 if file ~= "." and file ~= ".." then
191 if file:find(pattern) then
192 if os.remove(path .. "/" .. file) then
193 result_check = true
194 end
195 end
196 end
197 end
198 end
199 return result_check
200end
201
202
203--- Function for downloading rocks and rockspecs
204-- @param urls table: array of full names of rocks/rockspecs to download
205-- @param save_path string: path to directory, where to download rocks/rockspecs
206-- @return make_manifest boolean: true if new rocks downloaded
207local function download_rocks(urls, save_path)
208 local luarocks_repo = "https://luarocks.org"
209 local make_manifest = false
210
211 for _, url in ipairs(urls) do
212 -- check if already downloaded
213 if not exists(save_path .. url) then
214 execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url)
215 make_manifest = true
216 end
217 end
218 return make_manifest
219end
220
221--- Create a file containing a string.
222-- @param path string: path to file.
223-- @param str string: content of the file.
224local function write_file(path, str)
225 local file = assert(io.open(path, "w"))
226 file:write(str)
227 file:close()
228end
229
230--- Create md5sum of directory structure recursively, based on filename and size
231-- @param path string: path to directory for generate md5sum
232-- @return md5sum string: md5sum of directory
233local function hash_environment(path)
234 if test_env.TEST_TARGET_OS == "linux" then
235 return execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum")
236 elseif test_env.TEST_TARGET_OS == "osx" then
237 return execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5")
238 else
239 -- TODO: Windows
240 return ""
241 end
242end
243
244--- Create environment variables needed for tests
245-- @param testing_paths table: table with paths to testing directory
246-- @return env_variables table: table with created environment variables
247local function create_env(testing_paths)
248 local luaversion_short = _VERSION:gsub("Lua ", "")
249
250 if test_env.LUAJIT_V then
251 luaversion_short="5.1"
252 end
253
254 local env_variables = {}
255 env_variables.LUA_VERSION = luaversion_short
256 env_variables.LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua"
257 env_variables.LUA_PATH = testing_paths.testing_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;"
258 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;"
259 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;"
260 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;"
261 env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;"
262 env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;"
263 .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;"
264 env_variables.PATH = os.getenv("PATH") .. ":" .. testing_paths.testing_tree .. "/bin:" .. testing_paths.testing_sys_tree .. "/bin"
265
266 return env_variables
267end
268
269--- Create md5sums of origin system and system-copy testing directory
270-- @param testing_paths table: table with paths to testing directory
271-- @return md5sums table: table of md5sums of system and system-copy testing directory
272local function create_md5sums(testing_paths)
273 local md5sums = {}
274 md5sums.testing_tree_copy_md5 = hash_environment(testing_paths.testing_tree_copy)
275 md5sums.testing_sys_tree_copy_md5 = hash_environment(testing_paths.testing_sys_tree_copy)
276
277 return md5sums
278end
279
280local function make_run_function(cmd_name, exec_function, with_coverage, do_print)
281 local cmd_prefix = test_env.testing_paths.lua .. " "
282
283 if with_coverage then
284 cmd_prefix = cmd_prefix .. "-e \"require('luacov.runner')('" .. test_env.testing_paths.testing_dir .. "/luacov.config')\" "
285 end
286
287 cmd_prefix = cmd_prefix .. test_env.testing_paths.src_dir .. "/bin/" .. cmd_name .. " "
288
289 return function(cmd, new_vars)
290 local temp_vars = {}
291 for k, v in pairs(test_env.env_variables) do
292 temp_vars[k] = v
293 end
294 if new_vars then
295 for k, v in pairs(new_vars) do
296 temp_vars[k] = v
297 end
298 end
299 return exec_function(cmd_prefix .. cmd, do_print, temp_vars)
300 end
301end
302
303local function make_run_functions()
304 return {
305 luarocks = make_run_function("luarocks", execute_output, true, true),
306 luarocks_bool = make_run_function("luarocks", execute_bool, true, true),
307 luarocks_noprint = make_run_function("luarocks", execute_bool, true, false),
308 luarocks_nocov = make_run_function("luarocks", execute_bool, false, true),
309 luarocks_noprint_nocov = make_run_function("luarocks", execute_bool, false, false),
310 luarocks_admin = make_run_function("luarocks-admin", execute_output, true, true),
311 luarocks_admin_bool = make_run_function("luarocks-admin", execute_bool, true, true),
312 luarocks_admin_nocov = make_run_function("luarocks-admin", execute_bool, false, false)
313 }
314end
315
316--- Rebuild environment.
317-- Remove old installed rocks and install new ones,
318-- updating manifests and tree copies.
319local function build_environment(rocks, env_variables)
320 title("BUILDING ENVIRONMENT")
321 local testing_paths = test_env.testing_paths
322 test_env.remove_dir(testing_paths.testing_tree)
323 test_env.remove_dir(testing_paths.testing_sys_tree)
324 test_env.remove_dir(testing_paths.testing_tree_copy)
325 test_env.remove_dir(testing_paths.testing_sys_tree_copy)
326
327 lfs.mkdir(testing_paths.testing_tree)
328 lfs.mkdir(testing_paths.testing_sys_tree)
329
330 test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server)
331 test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache)
332
333 for _, rock in ipairs(rocks) do
334 if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) then
335 test_env.run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables)
336 test_env.run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables)
337 execute_bool("mv " .. rock .. "-*.rock " .. testing_paths.testing_cache)
338 end
339 end
340
341 execute_bool("cp -a " .. testing_paths.testing_tree .. "/. " .. testing_paths.testing_tree_copy)
342 execute_bool("cp -a " .. testing_paths.testing_sys_tree .. "/. " .. testing_paths.testing_sys_tree_copy)
343end
344
345--- Reset testing environment
346local function reset_environment(testing_paths, md5sums)
347 local testing_tree_md5 = hash_environment(testing_paths.testing_tree)
348 local testing_sys_tree_md5 = hash_environment(testing_paths.testing_sys_tree)
349
350 if testing_tree_md5 ~= md5sums.testing_tree_copy_md5 then
351 test_env.remove_dir(testing_paths.testing_tree)
352 execute_bool("cp -a " .. testing_paths.testing_tree_copy .. "/. " .. testing_paths.testing_tree)
353 end
354
355 if testing_sys_tree_md5 ~= md5sums.testing_sys_tree_copy_md5 then
356 test_env.remove_dir(testing_paths.testing_sys_tree)
357 execute_bool("cp -a " .. testing_paths.testing_sys_tree_copy .. "/. " .. testing_paths.testing_sys_tree)
358 end
359
360 print("\n[ENVIRONMENT RESET]")
361end
362
363local function create_paths(luaversion_full)
364 local cfg = require("luarocks.cfg")
365
366 local testing_paths = {}
367 testing_paths.luadir = cfg.variables.LUA_BINDIR:gsub("/bin/?$", "")
368 testing_paths.lua = cfg.variables.LUA_BINDIR .. "/" .. cfg.lua_interpreter
369
370 testing_paths.luarocks_tmp = "/tmp/luarocks_testing" --windows?
371
372 testing_paths.luarocks_dir = lfs.currentdir()
373 testing_paths.testing_dir = testing_paths.luarocks_dir .. "/test"
374 testing_paths.src_dir = testing_paths.luarocks_dir .. "/src"
375 testing_paths.testing_lrprefix = testing_paths.testing_dir .. "/testing_lrprefix-" .. luaversion_full
376 testing_paths.testing_tree = testing_paths.testing_dir .. "/testing-" .. luaversion_full
377 testing_paths.testing_tree_copy = testing_paths.testing_dir .. "/testing_copy-" .. luaversion_full
378 testing_paths.testing_sys_tree = testing_paths.testing_dir .. "/testing_sys-" .. luaversion_full
379 testing_paths.testing_sys_tree_copy = testing_paths.testing_dir .. "/testing_sys_copy-" .. luaversion_full
380 testing_paths.testing_cache = testing_paths.testing_dir .. "/testing_cache-" .. luaversion_full
381 testing_paths.testing_server = testing_paths.testing_dir .. "/testing_server-" .. luaversion_full
382
383 return testing_paths
384end
385
386--- Helper function to unload luarocks modules from global table package.loaded
387-- Needed to load our local (testing) version of LuaRocks
388function test_env.unload_luarocks()
389 for modname, _ in pairs(package.loaded) do
390 if modname:match("^luarocks%.") then
391 package.loaded[modname] = nil
392 end
393 end
394end
395
396--- Function for initially setup of environment, variables, md5sums for spec files
397function test_env.setup_specs(extra_rocks)
398 -- if global variable about successful creation of testing environment doesn't exists, build environment
399 if not test_env.setup_done then
400 if test_env.TRAVIS then
401 if not exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then
402 execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa")
403 execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys")
404 execute_bool("chmod og-wx ~/.ssh/authorized_keys")
405 execute_bool("ssh-keyscan localhost >> ~/.ssh/known_hosts")
406 end
407 end
408
409 test_env.main()
410 package.path = test_env.env_variables.LUA_PATH
411
412 test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables)
413 test_env.md5sums = create_md5sums(test_env.testing_paths)
414 test_env.setup_done = true
415 title("RUNNING TESTS")
416 end
417
418 if extra_rocks then
419 local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server)
420 if make_manifest then
421 test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server)
422 end
423 end
424
425 if test_env.RESET_ENV then
426 reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables)
427 end
428end
429
430--- Test if required rock is installed if not, install it
431function test_env.need_rock(rock)
432 print("Check if " .. rock .. " is installed")
433 if test_env.run.luarocks_noprint_nocov(test_env.quiet("show " .. rock)) then
434 return true
435 else
436 return test_env.run.luarocks_noprint_nocov(test_env.quiet("install " .. rock))
437 end
438end
439
440--- For each key-value pair in replacements table
441-- replace %{key} in given string with value.
442local function substitute(str, replacements)
443 return (str:gsub("%%%b{}", function(marker)
444 return replacements[marker:sub(3, -2)]
445 end))
446end
447
448
449--- Create configs for luacov and several versions of Luarocks
450-- configs needed for some tests.
451local function create_configs()
452 -- testing_config.lua and testing_config_show_downloads.lua
453 local config_content = substitute([[
454 rocks_trees = {
455 "%{testing_tree}",
456 { name = "system", root = "%{testing_sys_tree}" },
457 }
458 rocks_servers = {
459 "%{testing_server}"
460 }
461 local_cache = "%{testing_cache}"
462 upload_server = "testing"
463 upload_user = "%{user}"
464 upload_servers = {
465 testing = {
466 rsync = "localhost/tmp/luarocks_testing",
467 },
468 }
469 external_deps_dirs = {
470 "/usr/local",
471 "/usr",
472 -- These are used for a test that fails, so it
473 -- can point to invalid paths:
474 {
475 prefix = "/opt",
476 bin = "bin",
477 include = "include",
478 lib = { "lib", "lib64" },
479 }
480 }
481 ]], {
482 user = os.getenv("USER"),
483 testing_sys_tree = test_env.testing_paths.testing_sys_tree,
484 testing_tree = test_env.testing_paths.testing_tree,
485 testing_server = test_env.testing_paths.testing_server,
486 testing_cache = test_env.testing_paths.testing_cache
487 })
488
489 write_file(test_env.testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"")
490 write_file(test_env.testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content
491 .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}")
492
493 -- testing_config_sftp.lua
494 config_content = substitute([[
495 rocks_trees = {
496 "%{testing_tree}",
497 "%{testing_sys_tree}",
498 }
499 local_cache = "%{testing_cache}"
500 upload_server = "testing"
501 upload_user = "%{user}"
502 upload_servers = {
503 testing = {
504 sftp = "localhost/tmp/luarocks_testing",
505 },
506 }
507 ]], {
508 user = os.getenv("USER"),
509 testing_sys_tree = test_env.testing_paths.testing_sys_tree,
510 testing_tree = test_env.testing_paths.testing_tree,
511 testing_cache = test_env.testing_paths.testing_cache
512 })
513
514 write_file(test_env.testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content)
515
516 -- luacov.config
517 config_content = substitute([[
518 return {
519 statsfile = "%{testing_dir}/luacov.stats.out",
520 reportfile = "%{testing_dir}/luacov.report.out",
521 modules = {
522 ["luarocks"] = "src/bin/luarocks",
523 ["luarocks-admin"] = "src/bin/luarocks-admin",
524 ["luarocks.*"] = "src",
525 ["luarocks.*.*"] = "src",
526 ["luarocks.*.*.*"] = "src"
527 }
528 }
529 ]], {
530 testing_dir = test_env.testing_paths.testing_dir
531 })
532
533 write_file(test_env.testing_paths.testing_dir .. "/luacov.config", config_content)
534end
535
536--- Remove testing directories.
537local function clean()
538 print("Cleaning testing directory...")
539 test_env.remove_dir(test_env.testing_paths.luarocks_tmp)
540 test_env.remove_subdirs(test_env.testing_paths.testing_dir, "testing[_%-]")
541 test_env.remove_files(test_env.testing_paths.testing_dir, "testing_")
542 test_env.remove_files(test_env.testing_paths.testing_dir, "luacov")
543 test_env.remove_files(test_env.testing_paths.testing_dir, "upload_config")
544 print("Cleaning done!")
545end
546
547--- Install luarocks into testing prefix.
548local function install_luarocks(install_env_vars)
549 -- Configure LuaRocks testing environment
550 title("Installing LuaRocks")
551 local configure_cmd = "./configure --with-lua=" .. test_env.testing_paths.luadir .. " --prefix=" .. test_env.testing_paths.testing_lrprefix
552 assert(execute_bool(test_env.quiet(configure_cmd), false, install_env_vars))
553 assert(execute_bool(test_env.quiet("make clean"), false, install_env_vars))
554 assert(execute_bool(test_env.quiet("make src/luarocks/site_config.lua"), false, install_env_vars))
555 assert(execute_bool(test_env.quiet("make dev"), false, install_env_vars))
556 print("LuaRocks installed correctly!")
557end
558
559---
560-- Main function to create config files and testing environment
561function test_env.main()
562 local testing_paths = test_env.testing_paths
563
564 if test_env.TEST_ENV_CLEAN then
565 clean()
566 end
567
568 lfs.mkdir(testing_paths.testing_cache)
569 lfs.mkdir(testing_paths.luarocks_tmp)
570
571 create_configs()
572
573 local install_env_vars = {
574 LUAROCKS_CONFIG = test_env.testing_paths.testing_dir .. "/testing_config.lua",
575 LUA_PATH = "",
576 LUA_CPATH = ""
577 }
578
579 install_luarocks(install_env_vars)
580
581 -- Preparation of rocks for building environment
582 local rocks = {} -- names of rocks, required for building environment
583 local urls = {} -- names of rock and rockspec files to be downloaded
584 table.insert(urls, "/luacov-0.11.0-1.rockspec")
585 table.insert(urls, "/luacov-0.11.0-1.src.rock")
586
587 if test_env.TYPE_TEST_ENV == "full" then
588 table.insert(urls, "/luafilesystem-1.6.3-1.src.rock")
589 table.insert(urls, "/luasocket-3.0rc1-1.src.rock")
590 table.insert(urls, "/luasocket-3.0rc1-1.rockspec")
591 table.insert(urls, "/luaposix-33.2.1-1.src.rock")
592 table.insert(urls, "/md5-1.2-1.src.rock")
593 table.insert(urls, "/lzlib-0.4.1.53-1.src.rock")
594 rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"}
595
596 if test_env.LUA_V ~= "5.1" then
597 table.insert(urls, "/luabitop-1.0.2-1.rockspec")
598 table.insert(urls, "/luabitop-1.0.2-1.src.rock")
599 table.insert(rocks, "luabitop")
600 end
601 end
602
603 table.insert(rocks, "luacov") -- luacov is needed for minimal or full environment
604
605 -- Download rocks needed for LuaRocks testing environment
606 lfs.mkdir(testing_paths.testing_server)
607 download_rocks(urls, testing_paths.testing_server)
608 build_environment(rocks, install_env_vars)
609end
610
611test_env.set_lua_version()
612test_env.set_args()
613test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V)
614test_env.env_variables = create_env(test_env.testing_paths)
615test_env.run = make_run_functions()
616
617return test_env
diff --git a/test/testfiles/invalid_validate-args-1.5.4-1.rockspec b/test/testfiles/invalid_validate-args-1.5.4-1.rockspec
new file mode 100644
index 00000000..0b4d807d
--- /dev/null
+++ b/test/testfiles/invalid_validate-args-1.5.4-1.rockspec
@@ -0,0 +1,35 @@
1package = 'validate-args'
2version = '1.5.4-1'
3source = {{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{++{
4 url = "https://bitbucket.org/djerius/validate.args/downloads/validate-args-1.5.4.tar.gz"
5}
6
7description = {
8 summary = "Function argument validation",
9 detailed = [[
10 validate.args is a Lua module that provides a framework for
11 validation of arguments to Lua functions as well as complex data
12 structures. The included validate.inplace module provides "live"
13 validation during assignment of values to elements in tables. ]],
14 license = "GPL-3",
15
16}
17
18dependencies = {
19 "lua >= 5.1"
20}
21
22build = {
23
24 type = "builtin",
25
26 modules = {
27 ["validate.args"] = "validate/args.lua",
28 ["validate.inplace"] = "validate/inplace.lua",
29 },
30
31 copy_directories = {
32 "doc", "tests"
33 }
34
35}
diff --git a/test/testing.lua b/test/testing.lua
deleted file mode 100644
index 1a837484..00000000
--- a/test/testing.lua
+++ /dev/null
@@ -1,483 +0,0 @@
1
2local variables = {}
3
4-- Expand variables in the format $foo or ${foo} according
5-- to the variables table.
6local function expand_variables(str)
7 return str:gsub("%$({?)([A-Za-z0-9_]+)(}?)", function(o, v, c)
8 return #o <= #c and (variables[v] or "") .. (#o < #c and c or "")
9 end)
10end
11
12-- @param cmd command to run
13-- @param envtable optional table of temporary environment variables
14local function run(cmd, envtable)
15 cmd = expand_variables(cmd)
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)
29end
30
31local function mkdir(dirname)
32 cmd = expand_variables(dirname)
33 -- TODO
34end
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
53local function touch(filename)
54 -- TODO
55end
56
57local function rm(...)
58 for _, filename in ipairs {...} do
59 filename = expand_variables(filename)
60 -- TODO
61 end
62 return true
63end
64
65local function file_set_contents(filename, contents)
66 filename = expand_variables(filename)
67
68 local fd, err = io.open(filename, "w")
69 if not fd then return nil, err end
70 fd:write(contents)
71 fd:close()
72 return true
73end
74
75local function need_luasocket()
76 -- TODO
77end
78
79local tests = {
80
81 test_version = function() return run "$luarocks --version" end,
82 fail_unknown_command = function() return run "$luarocks unknown_command" end,
83 fail_arg_boolean_parameter = function() return run "$luarocks --porcelain=invalid" end,
84 fail_arg_boolean_unknown = function() return run "$luarocks --invalid-flag" end,
85 fail_arg_string_no_parameter = function() return run "$luarocks --server" end,
86 fail_arg_string_followed_by_flag = function() return run "$luarocks --server --porcelain" end,
87 fail_arg_string_unknown = function() return run "$luarocks --invalid-flag=abc" end,
88 test_empty_list = function() return run "$luarocks list" end,
89 test_list_outdated = function () return run "$luarocks list --outdated" end,
90 fail_sysconfig_err = function()
91 mkdir "$testing_lrprefix/etc/luarocks"
92 file_set_contents("$testing_lrprefix/etc/luarocks/config.lua", "aoeui")
93 return run "$luarocks list"
94 and rm "$testing_lrprefix/etc/luarocks/config.lua"
95 end,
96 fail_sysconfig_default_err = function()
97 mkdir "$testing_lrprefix/etc/luarocks"
98 file_set_contents("$testing_lrprefix/etc/luarocks/config-$luashortversion.lua", "aoeui")
99 return run "$luarocks list"
100 and rm "$testing_lrprefix/etc/luarocks/config-$luashortversion.lua"
101 end,
102 fail_build_noarg = function() return run "$luarocks build" end,
103 fail_download_noarg = function() return run "$luarocks download" end,
104 fail_install_noarg = function() return run "$luarocks install" end,
105 fail_lint_noarg = function() return run "$luarocks lint" end,
106 fail_search_noarg = function() return run "$luarocks search" end,
107 fail_show_noarg = function() return run "$luarocks show" end,
108 fail_unpack_noarg = function() return run "$luarocks unpack" end,
109 fail_upload_noarg = function() return run "$luarocks upload" end,
110 fail_remove_noarg = function() return run "$luarocks remove" end,
111 fail_doc_noarg = function() return run "$luarocks doc" end,
112 fail_new_version_noarg = function() return run "$luarocks new_version" end,
113 fail_write_rockspec_noarg = function() return run "$luarocks write_rockspec" end,
114 fail_build_invalid = function() return run "$luarocks build invalid" end,
115 fail_download_invalid = function() return run "$luarocks download invalid" end,
116 fail_install_invalid = function() return run "$luarocks install invalid" end,
117 fail_lint_invalid = function() return run "$luarocks lint invalid" end,
118 fail_show_invalid = function() return run "$luarocks show invalid" end,
119 fail_new_version_invalid = function() return run "$luarocks new_version invalid" end,
120 test_list_invalidtree = function() return run "$luarocks --tree=/some/invalid/tree list" end,
121 fail_inexistent_dir = function()
122 -- Unix only?
123 return run "mkdir idontexist; cd idontexist; rmdir ../idontexist; $luarocks; err=$?; cd ..; return $err"
124 end,
125 fail_make_norockspec = function() return run "$luarocks make" end,
126 fail_build_permissions = function() return run "$luarocks build --tree=/usr lpeg" end,
127 fail_build_permissions_parent = function() return run "$luarocks build --tree=/usr/invalid lpeg" end,
128 test_build_verbose = function() return run "$luarocks build --verbose lpeg" end,
129 fail_build_blank_arg = function() return run "$luarocks build --tree="" lpeg" end,
130 test_build_withpatch = function() need_luasocket(); return run "$luarocks build luadoc" end,
131 test_build_diffversion = function() return run "$luarocks build luacov ${version_luacov}" end,
132 test_build_command = function() return run "$luarocks build stdlib" end,
133 test_build_install_bin = function() return run "$luarocks build luarepl" end,
134 test_build_nohttps = function()
135 need_luasocket()
136 return run "$luarocks download --rockspec validate-args ${verrev_validate_args}"
137 and run "$luarocks build ./validate-args-${version_validate_args}-1.rockspec"
138 and rm "./validate-args-${version_validate_args}-1.rockspec"
139 end,
140 test_build_https = function()
141 need_luasocket()
142 return run "$luarocks download --rockspec validate-args ${verrev_validate_args}"
143 and run "$luarocks install luasec"
144 and run "$luarocks build ./validate-args-${verrev_validate_args}.rockspec"
145 and rm "./validate-args-${verrev_validate_args}.rockspec"
146 end,
147 test_build_supported_platforms = function() return run "$luarocks build lpty" end,
148 test_build_only_deps_rockspec = function()
149 return run "$luarocks download --rockspec lxsh ${verrev_lxsh}"
150 and run "$luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps"
151 and (not run "$luarocks show lxsh")
152 end,
153 test_build_only_deps_src_rock = function()
154 return run "$luarocks download --source lxsh ${verrev_lxsh}"
155 and run "$luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps"
156 and (not run "$luarocks show lxsh")
157 end,
158 test_build_only_deps = function() return run "$luarocks build luasec --only-deps" and (not run "$luarocks show luasec") end,
159 test_install_only_deps = function() return run "$luarocks install lxsh ${verrev_lxsh} --only-deps" and (not run "$luarocks show lxsh") end,
160 fail_build_missing_external = function() return run '$luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"' end,
161 fail_build_invalidpatch = function()
162 need_luasocket()
163 return run '$luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"'
164 end,
165 test_build_deps_partial_match = function() return run "$luarocks build lmathx" end,
166 test_build_show_downloads = function()
167 return run("$luarocks build alien", { LUAROCKS_CONFIG="$testing_dir/testing_config_show_downloads.lua" })
168 end,
169 test_download_all = function()
170 return run "$luarocks download --all validate-args"
171 and rm(glob("validate-args-*"))
172 end,
173 test_download_rockspecversion = function()
174 return run "$luarocks download --rockspec validate-args ${verrev_validate_args}"
175 and rm(glob("validate-args-*"))
176 end,
177 test_help = function() return run "$luarocks help" end,
178 fail_help_invalid = function() return run "$luarocks help invalid" end,
179 test_install_binaryrock = function()
180 return run "$luarocks build --pack-binary-rock cprint"
181 and run "$luarocks install ./cprint-${verrev_cprint}.${platform}.rock"
182 and rm "./cprint-${verrev_cprint}.${platform}.rock"
183 end,
184 test_install_with_bin = function() return run "$luarocks install wsapi" end,
185 fail_install_notazipfile = function() return run '$luarocks install "$testing_dir/testfiles/not_a_zipfile-1.0-1.src.rock"' end,
186 fail_install_invalidpatch = function()
187 need_luasocket()
188 return run '$luarocks install "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"'
189 end,
190 fail_install_invalid_filename = function() return run '$luarocks install "invalid.rock"' end,
191 fail_install_invalid_arch = function() return run '$luarocks install "foo-1.0-1.impossible-x86.rock"' end,
192 test_install_reinstall = function()
193 return run '$luarocks install "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"'
194 and run '$luarocks install --deps-mode=none "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"'
195 end,
196 fail_local_root = function() return run("$luarocks install --local luasocket", { USER="root" }) end,
197 test_site_config = function()
198 mv("../src/luarocks/site_config.lua", "../src/luarocks/site_config.lua.tmp")
199 local ok = run "$luarocks"
200 mv("../src/luarocks/site_config.lua.tmp", "../src/luarocks/site_config.lua")
201 return ok
202 end,
203 test_lint_ok = function()
204 return run "$luarocks download --rockspec validate-args ${verrev_validate_args}"
205 and run "$luarocks lint ./validate-args-${verrev_validate_args}.rockspec"
206 and rm "./validate-args-${verrev_validate_args}.rockspec"
207 end,
208 fail_lint_type_mismatch_string = function() return run '$luarocks lint "$testing_dir/testfiles/type_mismatch_string-1.0-1.rockspec"' end,
209 fail_lint_type_mismatch_version = function() return run '$luarocks lint "$testing_dir/testfiles/type_mismatch_version-1.0-1.rockspec"' end,
210 fail_lint_type_mismatch_table = function() return run '$luarocks lint "$testing_dir/testfiles/type_mismatch_table-1.0-1.rockspec"' end,
211 fail_lint_no_build_table = function() return run '$luarocks lint "$testing_dir/testfiles/no_build_table-0.1-1.rockspec"' end,
212 test_list = function() return run "$luarocks list" end,
213 test_list_porcelain = function() return run "$luarocks list --porcelain" end,
214 test_make_with_rockspec = function()
215 return rm_rf "./luasocket-${verrev_luasocket}"
216 and run "$luarocks download --source luasocket"
217 and run "$luarocks unpack ./luasocket-${verrev_luasocket}.src.rock"
218 and cd_run("luasocket-${verrev_luasocket}/${srcdir_luasocket}", "$luarocks make luasocket-${verrev_luasocket}.rockspec")
219 and rm_rf "./luasocket-${verrev_luasocket}"
220 end,
221 test_make_default_rockspec = function()
222 return rm_rf "./lxsh-${verrev_lxsh}"
223 and run "$luarocks download --source lxsh ${verrev_lxsh}"
224 and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock"
225 and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", "$luarocks make")
226 and rm_rf "./lxsh-${verrev_lxsh}"
227 end,
228 test_make_pack_binary_rock = function()
229 return rm_rf "./lxsh-${verrev_lxsh}"
230 and run "$luarocks download --source lxsh ${verrev_lxsh}"
231 and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock"
232 and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", "$luarocks make --deps-mode=none --pack-binary-rock")
233 and exists "lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1/lxsh-${verrev_lxsh}.all.rock"
234 and rm_rf "./lxsh-${verrev_lxsh}"
235 end,
236 fail_make_which_rockspec = function()
237 rm_rf "./luasocket-${verrev_luasocket}"
238 run "$luarocks download --source luasocket"
239 run "$luarocks unpack ./luasocket-${verrev_luasocket}.src.rock"
240 local ok = cd_run("luasocket-${verrev_luasocket}/${srcdir_luasocket}", "$luarocks make")
241 rm_rf "./luasocket-${verrev_luasocket}"
242 return ok
243 end,
244 test_new_version = function()
245 return run "$luarocks download --rockspec luacov ${version_luacov}"
246 and run "$luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2"
247 and rm(glob("./luacov-0.*"))
248 end,
249 test_new_version_url = function()
250 return run "$luarocks download --rockspec abelhas 1.0"
251 and run "$luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz"
252 and rm(glob("./abelhas-*"))
253 end,
254 test_pack = function()
255 return run "$luarocks list"
256 and run "$luarocks pack luacov"
257 and rm(glob("./luacov-*.rock"))
258 end,
259 test_pack_src = function()
260 return run "$luarocks install luasec"
261 and run "$luarocks download --rockspec luasocket"
262 and run "$luarocks pack ./luasocket-${verrev_luasocket}.rockspec"
263 and rm(glob("./luasocket-${version_luasocket}-*.rock"))
264 end,
265 test_path = function() return run "$luarocks path --bin" end,
266 test_path_lr_path = function() return run "$luarocks path --lr-path" end,
267 test_path_lr_cpath = function() return run "$luarocks path --lr-cpath" end,
268 test_path_lr_bin = function() return run "$luarocks path --lr-bin" end,
269 test_path_with_tree = function() return run "$luarocks path --tree=lua_modules" end,
270 fail_purge_missing_tree = function() return run '$luarocks purge --tree="$testing_tree"' end,
271 test_purge = function() return run '$luarocks purge --tree="$testing_sys_tree"' end,
272 test_remove = function()
273 return run "$luarocks build abelhas ${version_abelhas}"
274 and run "$luarocks remove abelhas ${version_abelhas}"
275 end,
276 test_remove_force = function()
277 need_luasocket()
278 return run "$luarocks build lualogging"
279 and run "$luarocks remove --force luasocket"
280 end,
281 fail_remove_deps = function()
282 need_luasocket()
283 return run "$luarocks build lualogging"
284 and run "$luarocks remove luasocket"
285 end,
286 fail_remove_missing = function() return run "$luarocks remove missing_rock" end,
287 fail_remove_invalid_name = function() return run "$luarocks remove invalid.rock" end,
288 test_search_found = function() return run "$luarocks search zlib" end,
289 test_search_missing = function() return run "$luarocks search missing_rock" end,
290 test_show = function() return run "$luarocks show luacov" end,
291 test_show_modules = function() return run "$luarocks show --modules luacov" end,
292 test_show_home = function() return run "$luarocks show --home luacov" end,
293 test_show_depends = function()
294 need_luasocket()
295 return run "$luarocks install luasec"
296 and run "$luarocks show luasec"
297 end,
298 test_show_oldversion = function()
299 return run "$luarocks install luacov ${version_luacov}"
300 and run "$luarocks show luacov ${version_luacov}"
301 end,
302 test_unpack_download = function()
303 return rm_rf "./cprint-${verrev_cprint}"
304 and run "$luarocks unpack cprint"
305 and rm_rf "./cprint-${verrev_cprint}"
306 end,
307 test_unpack_src = function()
308 return rm_rf "./cprint-${verrev_cprint}"
309 and run "$luarocks download --source cprint"
310 and run "$luarocks unpack ./cprint-${verrev_cprint}.src.rock"
311 and rm_rf "./cprint-${verrev_cprint}"
312 end,
313 test_unpack_rockspec = function()
314 return rm_rf "./cprint-${verrev_cprint}"
315 and run "$luarocks download --rockspec cprint"
316 and run "$luarocks unpack ./cprint-${verrev_cprint}.rockspec"
317 and rm_rf "./cprint-${verrev_cprint}"
318 end,
319 test_unpack_binary = function()
320 return rm_rf "./cprint-${verrev_cprint}"
321 and run "$luarocks build cprint"
322 and run "$luarocks pack cprint"
323 and run "$luarocks unpack ./cprint-${verrev_cprint}.${platform}.rock"
324 and rm_rf "./cprint-${verrev_cprint}"
325 end,
326 fail_unpack_invalidpatch = function()
327 need_luasocket()
328 return run '$luarocks unpack "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"'
329 end,
330 fail_unpack_invalidrockspec = function()
331 need_luasocket()
332 return run '$luarocks unpack "invalid.rockspec"'
333 end,
334 fail_upload_invalidrockspec = function() return run '$luarocks upload "invalid.rockspec"' end,
335 fail_upload_invalidkey = function() return run '$luarocks upload --api-key="invalid" "invalid.rockspec"' end,
336 test_admin_help = function() return run "$luarocks_admin help" end,
337 test_admin_make_manifest = function() return run "$luarocks_admin make_manifest" end,
338 test_admin_add_rsync = function() return run '$luarocks_admin --server=testing add "$testing_server/luasocket-${verrev_luasocket}.src.rock"' end,
339 test_admin_add_sftp = function()
340 return run("$luarocks_admin --server=testing add ./luasocket-${verrev_luasocket}.src.rock", { LUAROCKS_CONFIG="$testing_dir/testing_config_sftp.lua" })
341 end,
342 fail_admin_add_missing = function() return run "$luarocks_admin --server=testing add" end,
343 fail_admin_invalidserver = function() return run '$luarocks_admin --server=invalid add "$testing_server/luasocket-${verrev_luasocket}.src.rock"' end,
344 fail_admin_invalidrock = function() return run "$luarocks_admin --server=testing add invalid" end,
345 test_admin_refresh_cache = function() return run "$luarocks_admin --server=testing refresh_cache" end,
346 test_admin_remove = function() return run "$luarocks_admin --server=testing remove luasocket-${verrev_luasocket}.src.rock" end,
347 fail_admin_remove_missing = function() return run "$luarocks_admin --server=testing remove" end,
348 fail_deps_mode_invalid_arg = function() return run "$luarocks remove luacov --deps-mode" end,
349
350 test_deps_mode_one = function()
351 return run '$luarocks build --tree="system" lpeg'
352 and run '$luarocks list'
353 and run '$luarocks build --deps-mode=one --tree="$testing_tree" lxsh'
354 and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' ~= ""
355 end,
356 test_deps_mode_order = function()
357 return run '$luarocks build --tree="system" lpeg'
358 and run '$luarocks build --deps-mode=order --tree="$testing_tree" lxsh'
359 and run '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg'
360 and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' == ""
361 end,
362 test_deps_mode_order_sys = function()
363 return run '$luarocks build --tree="$testing_tree" lpeg'
364 and run '$luarocks build --deps-mode=order --tree="$testing_sys_tree" lxsh'
365 and run_get_contents '$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg' ~= ""
366 end,
367 test_deps_mode_all_sys = function()
368 return run '$luarocks build --tree="$testing_tree" lpeg'
369 and run '$luarocks build --deps-mode=all --tree="$testing_sys_tree" lxsh'
370 and run_get_contents '$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg' == ""
371 end,
372
373 test_deps_mode_none = function()
374 return run '$luarocks build --tree="$testing_tree" --deps-mode=none lxsh'
375 and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' == ""
376 end,
377 test_deps_mode_nodeps_alias = function()
378 return run '$luarocks build --tree="$testing_tree" --nodeps lxsh'
379 and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' == ""
380 end,
381 test_deps_mode_make_order = function()
382 local ok = run '$luarocks build --tree="$testing_sys_tree" lpeg'
383 and rm_rf "./lxsh-${verrev_lxsh}"
384 and run "$luarocks download --source lxsh ${verrev_lxsh}"
385 and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock"
386 and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", '$luarocks make --tree="$testing_tree" --deps-mode=order')
387 if not ok then
388 return false
389 end
390 local found = run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg'
391 rm_rf "./lxsh-${verrev_lxsh}"
392 return found == ""
393 end,
394 test_deps_mode_make_order_sys = function()
395 local ok = run '$luarocks build --tree="$testing_tree" lpeg'
396 and rm_rf "./lxsh-${verrev_lxsh}"
397 and run "$luarocks download --source lxsh ${verrev_lxsh}"
398 and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock"
399 and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", '$luarocks make --tree="$testing_sys_tree" --deps-mode=order')
400 if not ok then
401 return false
402 end
403 local found = run_get_contents '$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg'
404 rm_rf "./lxsh-${verrev_lxsh}"
405 return found ~= ""
406 end,
407 test_write_rockspec = function() return run "$luarocks write_rockspec git://github.com/keplerproject/luarocks" end,
408 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,
409 test_write_rockspec_format = function() return run '$luarocks write_rockspec git://github.com/keplerproject/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2' end,
410 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,
411 fail_write_rockspec_args = function() return run "$luarocks write_rockspec invalid" end,
412 fail_write_rockspec_args_url = function() return run "$luarocks write_rockspec http://example.com/invalid.zip" end,
413 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,
414 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,
415
416 fail_config_noflags = function() return run "$luarocks config; " end,
417 test_config_lua_incdir = function() return run "$luarocks config --lua-incdir; " end,
418 test_config_lua_libdir = function() return run "$luarocks config --lua-libdir; " end,
419 test_config_lua_ver = function() return run "$luarocks config --lua-ver; " end,
420 fail_config_system_config = function()
421 return rm "$testing_lrprefix/etc/luarocks/config.lua"
422 and run "$luarocks config --system-config; "
423 end,
424 test_config_system_config = function()
425 local ok = mkdir "$testing_lrprefix/etc/luarocks"
426 and touch "$testing_lrprefix/etc/luarocks/config.lua"
427 and run "$luarocks config --system-config; "
428 rm "$testing_lrprefix/etc/luarocks/config.lua"
429 return ok
430 end,
431 fail_config_system_config_invalid = function()
432 local ok = mkdir "$testing_lrprefix/etc/luarocks"
433 and run "echo 'if if if' > '$testing_lrprefix/etc/luarocks/config.lua' ;"
434 and run "$luarocks config --system-config"
435 rm "$testing_lrprefix/etc/luarocks/config.lua"
436 return ok
437 end,
438 test_config_user_config = function() return run "$luarocks config --user-config; " end,
439 fail_config_user_config = function() return run "LUAROCKS_CONFIG='/missing_file.lua' $luarocks config --user-config; " end,
440 test_config_rock_trees = function() return run "$luarocks config --rock-trees;" end,
441 test_config_help = function() return run "$luarocks help config;" end,
442 test_doc = function()
443 return run "$luarocks install luarepl"
444 and run "$luarocks doc luarepl"
445 end,
446 test_doc_home = function()
447 return run "$luarocks install luacov"
448 and run "$luarocks doc luacov --home"
449 end,
450 fail_doc_invalid = function () return run "$luarocks doc invalid" end,
451
452 -- Tests for https://github.com/keplerproject/luarocks/issues/375
453 test_fetch_base_dir = function()
454 local fetch = require "luarocks.fetch"
455
456 return assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip"))
457 and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip"))
458 and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz"))
459 and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2"))
460 and assert("parser.moon" == fetch.url_to_base_dir("git://github.com/Cirru/parser.moon"))
461 and assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3"))
462 end,
463
464 -- Tests for https://github.com/keplerproject/luarocks/issues/552
465 test_install_break_dependencies_warning = function()
466 need_luasocket()
467 return run "$luarocks install say ${new_version_say}"
468 and run "$luarocks install luassert"
469 and run "$luarocks install say ${old_version_say}"
470 end,
471 test_install_break_dependencies_force = function()
472 need_luasocket()
473 return run "$luarocks install say ${new_version_say}"
474 and run "$luarocks install luassert"
475 and run "$luarocks install --force say ${old_version_say}"
476 end,
477 test_install_break_dependencies_force = function()
478 need_luasocket()
479 return run "$luarocks install say ${new_version_say}"
480 and run "$luarocks install luassert"
481 and run "$luarocks install --force-fast say ${old_version_say}"
482 end
483}
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