diff options
Diffstat (limited to 'test/test_environment.lua')
-rw-r--r-- | test/test_environment.lua | 624 |
1 files changed, 299 insertions, 325 deletions
diff --git a/test/test_environment.lua b/test/test_environment.lua index 6de501fb..6de7a4e2 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua | |||
@@ -1,26 +1,38 @@ | |||
1 | local lfs = require("lfs") | 1 | local lfs = require("lfs") |
2 | local test_env = {} | 2 | local test_env = {} |
3 | local arg = arg or { ... } | 3 | |
4 | local help_message = [[ | ||
5 | LuaRocks test-suite | ||
6 | |||
7 | INFORMATION | ||
8 | New test-suite for LuaRocks project, using unit testing framework Busted. | ||
9 | REQUIREMENTS | ||
10 | Be sure sshd is running on your system, or use '--exclude-tags=ssh', | ||
11 | to not execute tests which require sshd. | ||
12 | USAGE | ||
13 | busted [-Xhelper <arguments>] | ||
14 | ARGUMENTS | ||
15 | env=<type> Set type of environment to use ("minimal" or "full", | ||
16 | default: "minimal"). | ||
17 | clean Remove existing testing environment. | ||
18 | travis Add if running on TravisCI. | ||
19 | os=<type> Set OS ("linux", "osx", or "windows"). | ||
20 | ]] | ||
4 | 21 | ||
5 | local function help() | 22 | local function help() |
6 | print("LuaRocks test-suite\n\n".. | 23 | print(help_message) |
7 | [[ | 24 | os.exit(1) |
8 | INFORMATION | 25 | end |
9 | New test-suite for LuaRocks project, using unit testing framework Busted. | 26 | |
10 | REQUIREMENTS | 27 | local function title(str) |
11 | Tests require to have Lua installed and added to PATH. Be sure sshd is runnig on your system, or | 28 | print() |
12 | use '--exclude-tags=ssh', to not execute tests which require sshd. | 29 | print(("-"):rep(#str)) |
13 | USAGE -Xhelper <arguments> | 30 | print(str) |
14 | lua=<version> (mandatory) type your full version of Lua (e.g. --lua 5.2.4) | 31 | print(("-"):rep(#str)) |
15 | OR | 32 | end |
16 | luajit=<version> (mandatory) type your full version of LuaJIT (e.g. --luajit 2.0.3) | 33 | |
17 | 34 | local function exists(path) | |
18 | env=<type> (default:"minimal") type what kind of environment to use ["minimal", "full"] | 35 | return lfs.attributes(path, "mode") ~= nil |
19 | clean remove existing testing environment | ||
20 | travis add just if running on TravisCI | ||
21 | os=<version> type your OS ["linux", "osx", "windows"] | ||
22 | ]]); | ||
23 | os.exit(1) | ||
24 | end | 36 | end |
25 | 37 | ||
26 | --- Helper function for execute_bool and execute_output | 38 | --- Helper function for execute_bool and execute_output |
@@ -70,54 +82,38 @@ local function execute_output(command, print_command, env_variables) | |||
70 | return output:gsub("\n","") -- output adding new line, need to be removed | 82 | return output:gsub("\n","") -- output adding new line, need to be removed |
71 | end | 83 | end |
72 | 84 | ||
73 | --- Set all arguments from input into global variables | 85 | --- Set test_env.LUA_V or test_env.LUAJIT_V based |
74 | function test_env.set_args() | 86 | -- on version of Lua used to run this script. |
75 | if arg[1] == nil then | 87 | function test_env.set_lua_version() |
76 | help() | 88 | if _G.jit then |
77 | end | 89 | test_env.LUAJIT_V = _G.jit.version:match("(2%.%d)%.%d") |
78 | 90 | else | |
79 | local args_position | 91 | test_env.LUA_V = _VERSION:match("5%.%d") |
80 | |||
81 | for i=1, #arg do | ||
82 | if arg[i]:find("-Xhelper") and arg[i+1]:find("lua=") and not arg[i+1]:find("luajit=") then | ||
83 | args_position = i+1 | ||
84 | test_env.LUA_V = arg[args_position]:gsub("(.*)lua=([^%,]+)(.*)","%2") | ||
85 | break | ||
86 | elseif arg[i]:find("-Xhelper") and not arg[i+1]:find("lua=") and arg[i+1]:find("luajit=") then | ||
87 | args_position = i+1 | ||
88 | test_env.LUAJIT_V = arg[args_position]:gsub("(.*)luajit=([^%,]+)(.*)","%2") | ||
89 | break | ||
90 | elseif arg[i]:find("-Xhelper") and arg[i+1]:find("lua=") and arg[i+1]:find("luajit=") then | ||
91 | print("Please specify just Lua or LuaJIT version for testing in format 'lua=X.X.X' or 'luajit=X.X.X', for -Xhelper flag") | ||
92 | os.exit(1) | ||
93 | elseif arg[i]:find("-Xhelper") and not arg[i+1]:find("lua=") and not arg[i+1]:find("luajit=") then | ||
94 | print("Please add mandatory argument - version of Lua or LuaJIT in format 'lua=X.X.X' or 'luajit=X.X.X', for -Xhelper flag") | ||
95 | os.exit(1) | ||
96 | end | ||
97 | end | ||
98 | |||
99 | if not args_position then | ||
100 | help() | ||
101 | end | 92 | end |
93 | end | ||
102 | 94 | ||
95 | --- Set all arguments from input into global variables | ||
96 | function test_env.set_args() | ||
103 | -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables | 97 | -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables |
104 | test_env.TYPE_TEST_ENV = "minimal" | 98 | test_env.TYPE_TEST_ENV = "minimal" |
105 | 99 | ||
106 | if arg[args_position]:find("env=") then | 100 | for _, argument in ipairs(arg) do |
107 | test_env.TYPE_TEST_ENV = arg[args_position]:gsub("(.*)env=([^%,]+)(.*)","%2") | 101 | if argument:find("^env=") then |
108 | end | 102 | test_env.TYPE_TEST_ENV = argument:match("^env=(.*)$") |
109 | if arg[args_position]:find("clean") then | 103 | elseif argument == "clean" then |
110 | test_env.TEST_ENV_CLEAN = true | 104 | test_env.TEST_ENV_CLEAN = true |
111 | end | 105 | elseif argument == "travis" then |
112 | if arg[args_position]:find("travis") then | 106 | test_env.TRAVIS = true |
113 | test_env.TRAVIS = true | 107 | elseif argument:find("^os=") then |
114 | end | 108 | test_env.TEST_TARGET_OS = argument:match("^os=(.*)$") |
115 | if arg[args_position]:find("os=") then | 109 | else |
116 | test_env.TEST_TARGET_OS = arg[args_position]:gsub("(.*)os=([^%,]+)(.*)","%2") | 110 | help() |
111 | end | ||
117 | end | 112 | end |
118 | 113 | ||
119 | if not test_env.TEST_TARGET_OS then | 114 | if not test_env.TEST_TARGET_OS then |
120 | print("[OS CHECK]") | 115 | title("OS CHECK") |
116 | |||
121 | if execute_bool("sw_vers") then | 117 | if execute_bool("sw_vers") then |
122 | test_env.TEST_TARGET_OS = "osx" | 118 | test_env.TEST_TARGET_OS = "osx" |
123 | elseif execute_bool("uname -s") then | 119 | elseif execute_bool("uname -s") then |
@@ -125,7 +121,6 @@ function test_env.set_args() | |||
125 | else | 121 | else |
126 | test_env.TEST_TARGET_OS = "windows" | 122 | test_env.TEST_TARGET_OS = "windows" |
127 | end | 123 | end |
128 | print("--------------") | ||
129 | end | 124 | end |
130 | return true | 125 | return true |
131 | end | 126 | end |
@@ -133,15 +128,13 @@ end | |||
133 | --- Remove directory recursively | 128 | --- Remove directory recursively |
134 | -- @param path string: directory path to delete | 129 | -- @param path string: directory path to delete |
135 | function test_env.remove_dir(path) | 130 | function test_env.remove_dir(path) |
136 | if lfs.attributes(path) then | 131 | if exists(path) then |
137 | for file in lfs.dir(path) do | 132 | for file in lfs.dir(path) do |
138 | if file ~= "." and file ~= ".." then | 133 | if file ~= "." and file ~= ".." then |
139 | local full_path = path..'/'..file | 134 | local full_path = path..'/'..file |
140 | local attr = lfs.attributes(full_path) | ||
141 | 135 | ||
142 | if attr.mode == "directory" then | 136 | if lfs.attributes(full_path, "mode") == "directory" then |
143 | test_env.remove_dir(full_path) | 137 | test_env.remove_dir(full_path) |
144 | os.remove(full_path) | ||
145 | else | 138 | else |
146 | os.remove(full_path) | 139 | os.remove(full_path) |
147 | end | 140 | end |
@@ -151,32 +144,30 @@ function test_env.remove_dir(path) | |||
151 | os.remove(path) | 144 | os.remove(path) |
152 | end | 145 | end |
153 | 146 | ||
154 | --- Remove directory recursively | 147 | --- Remove subdirectories of a directory that match a pattern |
155 | -- @param path string: directory path to delete | 148 | -- @param path string: path to directory |
156 | -- @param pattern string: pattern in directories | 149 | -- @param pattern string: pattern matching basenames of subdirectories to be removed |
157 | function test_env.remove_dir_pattern(path, pattern) | 150 | function test_env.remove_subdirs(path, pattern) |
158 | if lfs.attributes(path) then | 151 | if exists(path) then |
159 | for file in lfs.dir(path) do | 152 | for file in lfs.dir(path) do |
160 | if file ~= "." and file ~= ".." then | 153 | if file ~= "." and file ~= ".." then |
161 | local full_path = path..'/'..file | 154 | local full_path = path..'/'..file |
162 | local attr = lfs.attributes(full_path) | ||
163 | 155 | ||
164 | if attr.mode == "directory" and file:find(pattern) then | 156 | if lfs.attributes(full_path, "mode") == "directory" and file:find(pattern) then |
165 | test_env.remove_dir(full_path) | 157 | test_env.remove_dir(full_path) |
166 | os.remove(full_path) | ||
167 | end | 158 | end |
168 | end | 159 | end |
169 | end | 160 | end |
170 | end | 161 | end |
171 | end | 162 | end |
172 | 163 | ||
173 | --- Remove files based on filename | 164 | --- Remove files matching a pattern |
174 | -- @param path string: directory where to delete files | 165 | -- @param path string: directory where to delete files |
175 | -- @param pattern string: pattern in filenames | 166 | -- @param pattern string: pattern matching basenames of files to be deleted |
176 | -- @return result_check boolean: true if one or more files deleted | 167 | -- @return result_check boolean: true if one or more files deleted |
177 | function test_env.remove_files(path, pattern) | 168 | function test_env.remove_files(path, pattern) |
178 | local result_check = false | 169 | local result_check = false |
179 | if lfs.attributes(path) then | 170 | if exists(path) then |
180 | for file in lfs.dir(path) do | 171 | for file in lfs.dir(path) do |
181 | if file ~= "." and file ~= ".." then | 172 | if file ~= "." and file ~= ".." then |
182 | if file:find(pattern) then | 173 | if file:find(pattern) then |
@@ -192,51 +183,44 @@ end | |||
192 | 183 | ||
193 | 184 | ||
194 | --- Function for downloading rocks and rockspecs | 185 | --- Function for downloading rocks and rockspecs |
195 | -- @param rocks table: table with full name of rocks/rockspecs to download | 186 | -- @param urls table: array of full names of rocks/rockspecs to download |
196 | -- @param save_path string: path to directory, where to download rocks/rockspecs | 187 | -- @param save_path string: path to directory, where to download rocks/rockspecs |
197 | -- @return make_manifest boolean: true if new rocks downloaded | 188 | -- @return make_manifest boolean: true if new rocks downloaded |
198 | local function download_rocks(rocks, save_path) | 189 | local function download_rocks(urls, save_path) |
199 | local luarocks_repo = "https://luarocks.org" | 190 | local luarocks_repo = "https://luarocks.org" |
200 | local make_manifest = false | 191 | local make_manifest = false |
201 | 192 | ||
202 | for _,rock in ipairs(rocks) do | 193 | for _, url in ipairs(urls) do |
203 | -- check if already downloaded | 194 | -- check if already downloaded |
204 | if not os.rename( save_path .. rock, save_path .. rock) then | 195 | if not exists(save_path .. url) then |
205 | execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. rock) | 196 | execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url) |
206 | make_manifest = true | 197 | make_manifest = true |
207 | end | 198 | end |
208 | end | 199 | end |
209 | return make_manifest | 200 | return make_manifest |
210 | end | 201 | end |
211 | 202 | ||
212 | --- Create config files for testing | 203 | --- Create a file containing a string. |
213 | -- @param config_path string: path where to save config file | 204 | -- @param path string: path to file. |
214 | -- @param config_content string: content of this config file | 205 | -- @param str string: content of the file. |
215 | local function create_config(config_path, config_content) | 206 | local function write_file(path, str) |
216 | local file, err = io.open(config_path, "w+") | 207 | local file = assert(io.open(path, "w")) |
217 | if not file then return nil, err end | 208 | file:write(str) |
218 | file:write(config_content) | ||
219 | file:close() | 209 | file:close() |
220 | end | 210 | end |
221 | 211 | ||
222 | --- Create md5sum of directory structure recursively, based on filename and size | 212 | --- Create md5sum of directory structure recursively, based on filename and size |
223 | -- @param path string: path to directory for generate md5sum | 213 | -- @param path string: path to directory for generate md5sum |
224 | -- @param testing_os string(optional): version of PC OS | ||
225 | -- @return md5sum string: md5sum of directory | 214 | -- @return md5sum string: md5sum of directory |
226 | local function hash_environment(path, testing_os) | 215 | local function hash_environment(path) |
227 | local md5sum = "" | 216 | if test_env.TEST_TARGET_OS == "linux" then |
228 | testing_os = testing_os or test_env.TEST_TARGET_OS | 217 | return execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum") |
229 | 218 | elseif test_env.TEST_TARGET_OS == "osx" then | |
230 | if testing_os == "linux" then | 219 | return execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5") |
231 | md5sum = execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum") | 220 | else |
232 | end | 221 | -- TODO: Windows |
233 | if testing_os == "osx" then | 222 | return "" |
234 | md5sum = execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5") | ||
235 | end | 223 | end |
236 | --TODO if testing_os == "windows" then | ||
237 | -- md5sum = execute_output("find . -printf \"%s %p\n\" | md5sum") | ||
238 | -- end | ||
239 | return md5sum | ||
240 | end | 224 | end |
241 | 225 | ||
242 | --- Create environment variables needed for tests | 226 | --- Create environment variables needed for tests |
@@ -275,51 +259,48 @@ local function create_md5sums(testing_paths) | |||
275 | return md5sums | 259 | return md5sums |
276 | end | 260 | end |
277 | 261 | ||
278 | local function run_luarocks(testing_paths, env_variables) | 262 | local function make_run_function(cmd_name, exec_function, with_coverage, do_print) |
279 | 263 | local cmd_prefix = test_env.testing_paths.lua .. " " | |
280 | local function make_command_function(exec_function, lua_cmd, do_print) | 264 | |
281 | return function(cmd, new_vars) | 265 | if with_coverage then |
282 | local temp_vars = {} | 266 | cmd_prefix = cmd_prefix .. "-e \"require('luacov.runner')('" .. test_env.testing_paths.testing_dir .. "/luacov.config')\" " |
283 | for k, v in pairs(env_variables) do | 267 | end |
268 | |||
269 | cmd_prefix = cmd_prefix .. test_env.testing_paths.src_dir .. "/bin/" .. cmd_name .. " " | ||
270 | |||
271 | return function(cmd, new_vars) | ||
272 | local temp_vars = {} | ||
273 | for k, v in pairs(test_env.env_variables) do | ||
274 | temp_vars[k] = v | ||
275 | end | ||
276 | if new_vars then | ||
277 | for k, v in pairs(new_vars) do | ||
284 | temp_vars[k] = v | 278 | temp_vars[k] = v |
285 | end | 279 | end |
286 | if new_vars then | ||
287 | for k, v in pairs(new_vars) do | ||
288 | temp_vars[k] = v | ||
289 | end | ||
290 | end | ||
291 | return exec_function(lua_cmd .. cmd, do_print, temp_vars) | ||
292 | end | 280 | end |
281 | return exec_function(cmd_prefix .. cmd, do_print, temp_vars) | ||
293 | end | 282 | end |
283 | end | ||
294 | 284 | ||
295 | local run = {} | 285 | local function make_run_functions() |
296 | 286 | return { | |
297 | local cov_str = testing_paths.lua .. " -e\"require('luacov.runner')('" .. testing_paths.testing_dir .. "/luacov.config')\" " | 287 | luarocks = make_run_function("luarocks", execute_output, true, true), |
298 | 288 | luarocks_bool = make_run_function("luarocks", execute_bool, true, true), | |
299 | local luarocks_cmd = cov_str .. testing_paths.src_dir .. "/bin/luarocks " | 289 | luarocks_noprint = make_run_function("luarocks", execute_bool, true, false), |
300 | run.luarocks = make_command_function(execute_output, luarocks_cmd, true) | 290 | luarocks_nocov = make_run_function("luarocks", execute_bool, false, true), |
301 | run.luarocks_bool = make_command_function(execute_bool, luarocks_cmd, true) | 291 | luarocks_noprint_nocov = make_run_function("luarocks", execute_bool, false, false), |
302 | run.luarocks_noprint = make_command_function(execute_bool, luarocks_cmd, false) | 292 | luarocks_admin = make_run_function("luarocks-admin", execute_output, true, true), |
303 | 293 | luarocks_admin_bool = make_run_function("luarocks-admin", execute_bool, true, true), | |
304 | local luarocks_nocov_cmd = testing_paths.lua .. " " .. testing_paths.src_dir .. "/bin/luarocks " | 294 | luarocks_admin_nocov = make_run_function("luarocks-admin", execute_bool, false, false) |
305 | run.luarocks_nocov = make_command_function(execute_bool, luarocks_nocov_cmd, true) | 295 | } |
306 | run.luarocks_noprint_nocov = make_command_function(execute_bool, luarocks_nocov_cmd, false) | ||
307 | |||
308 | local luarocks_admin_cmd = cov_str .. testing_paths.src_dir .. "/bin/luarocks-admin " | ||
309 | run.luarocks_admin = make_command_function(execute_output, luarocks_admin_cmd, true) | ||
310 | run.luarocks_admin_bool = make_command_function(execute_bool, luarocks_admin_cmd, true) | ||
311 | |||
312 | local luarocks_admin_nocov_cmd = testing_paths.lua .. " " .. testing_paths.src_dir .. "/bin/luarocks-admin " | ||
313 | run.luarocks_admin_nocov = make_command_function(execute_bool, luarocks_admin_nocov_cmd, false) | ||
314 | |||
315 | return run | ||
316 | end | 296 | end |
317 | 297 | ||
318 | --- Build environment for testing | 298 | --- Rebuild environment. |
319 | local function build_environment(env_rocks, testing_paths, env_variables) | 299 | -- Remove old installed rocks and install new ones, |
320 | print("\n--------------------") | 300 | -- updating manifests and tree copies. |
321 | print("BUILDING ENVIRONMENT") | 301 | local function build_environment(rocks, env_variables) |
322 | print("--------------------") | 302 | title("BUILDING ENVIRONMENT") |
303 | local testing_paths = test_env.testing_paths | ||
323 | test_env.remove_dir(testing_paths.testing_tree) | 304 | test_env.remove_dir(testing_paths.testing_tree) |
324 | test_env.remove_dir(testing_paths.testing_sys_tree) | 305 | test_env.remove_dir(testing_paths.testing_sys_tree) |
325 | test_env.remove_dir(testing_paths.testing_tree_copy) | 306 | test_env.remove_dir(testing_paths.testing_tree_copy) |
@@ -328,14 +309,14 @@ local function build_environment(env_rocks, testing_paths, env_variables) | |||
328 | lfs.mkdir(testing_paths.testing_tree) | 309 | lfs.mkdir(testing_paths.testing_tree) |
329 | lfs.mkdir(testing_paths.testing_sys_tree) | 310 | lfs.mkdir(testing_paths.testing_sys_tree) |
330 | 311 | ||
331 | local run = run_luarocks(testing_paths, env_variables) | 312 | test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) |
332 | run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) | 313 | test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) |
333 | run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) | ||
334 | 314 | ||
335 | for _,package in ipairs(env_rocks) do | 315 | for _, rock in ipairs(rocks) do |
336 | if not run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) then | 316 | if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) then |
337 | run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) | 317 | test_env.run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) |
338 | run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. package .. "; mv " .. package .. "-*.rock " .. testing_paths.testing_cache, env_variables) | 318 | test_env.run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) |
319 | execute_bool("mv " .. rock .. "-*.rock " .. testing_paths.testing_cache) | ||
339 | end | 320 | end |
340 | end | 321 | end |
341 | 322 | ||
@@ -361,32 +342,11 @@ local function reset_environment(testing_paths, md5sums) | |||
361 | end | 342 | end |
362 | 343 | ||
363 | local function create_paths(luaversion_full) | 344 | local function create_paths(luaversion_full) |
364 | local testing_paths = {} | 345 | local cfg = require("luarocks.cfg") |
365 | |||
366 | testing_paths.luadir = "" | ||
367 | |||
368 | if test_env.TRAVIS then | ||
369 | testing_paths.luadir = lfs.currentdir() .. "/lua_install" | ||
370 | testing_paths.lua = testing_paths.luadir .. "/bin/lua" | ||
371 | end | ||
372 | 346 | ||
373 | if test_env.LUA_V and not test_env.TRAVIS then | 347 | local testing_paths = {} |
374 | if lfs.attributes("/usr/bin/lua") then | 348 | testing_paths.luadir = cfg.variables.LUA_BINDIR:gsub("/bin/?$", "") |
375 | testing_paths.luadir = "/usr" | 349 | testing_paths.lua = cfg.variables.LUA_BINDIR .. "/" .. cfg.lua_interpreter |
376 | testing_paths.lua = testing_paths.luadir .. "/bin/lua" | ||
377 | elseif lfs.attributes("/usr/local/bin/lua") then | ||
378 | testing_paths.luadir = "/usr/local" | ||
379 | testing_paths.lua = testing_paths.luadir .. "/bin/lua" | ||
380 | end | ||
381 | elseif test_env.LUAJIT_V and not test_env.TRAVIS then | ||
382 | if lfs.attributes("/usr/bin/luajit") then | ||
383 | testing_paths.luadir = "/usr" | ||
384 | testing_paths.lua = testing_paths.luadir .. "/bin/luajit" | ||
385 | elseif lfs.attributes("/usr/local/bin/luajit") then | ||
386 | testing_paths.luadir = "/usr/local" | ||
387 | testing_paths.lua = testing_paths.luadir .. "/bin/luajit" | ||
388 | end | ||
389 | end | ||
390 | 350 | ||
391 | testing_paths.luarocks_tmp = "/tmp/luarocks_testing" --windows? | 351 | testing_paths.luarocks_tmp = "/tmp/luarocks_testing" --windows? |
392 | 352 | ||
@@ -415,13 +375,11 @@ function test_env.unload_luarocks() | |||
415 | end | 375 | end |
416 | 376 | ||
417 | --- Function for initially setup of environment, variables, md5sums for spec files | 377 | --- Function for initially setup of environment, variables, md5sums for spec files |
418 | function test_env.setup_specs(extra_rocks, luaversion_full) | 378 | function test_env.setup_specs(extra_rocks) |
419 | -- if global variable about successful creation of testing environment doesn't exists, build environment | 379 | -- if global variable about successful creation of testing environment doesn't exists, build environment |
420 | if not test_env.setup_done then | 380 | if not test_env.setup_done then |
421 | test_env.set_args() | ||
422 | |||
423 | if test_env.TRAVIS then | 381 | if test_env.TRAVIS then |
424 | if not os.rename(os.getenv("HOME") .. "/.ssh/id_rsa.pub", os.getenv("HOME") .. "/.ssh/id_rsa.pub") then | 382 | if not exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then |
425 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") | 383 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") |
426 | execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") | 384 | execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") |
427 | execute_bool("chmod og-wx ~/.ssh/authorized_keys") | 385 | execute_bool("chmod og-wx ~/.ssh/authorized_keys") |
@@ -429,197 +387,213 @@ function test_env.setup_specs(extra_rocks, luaversion_full) | |||
429 | end | 387 | end |
430 | end | 388 | end |
431 | 389 | ||
432 | luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V | ||
433 | |||
434 | test_env.main() | 390 | test_env.main() |
435 | |||
436 | -- Set paths, env_vars and functions for specs | ||
437 | test_env.testing_paths = create_paths(luaversion_full) | ||
438 | test_env.env_variables = create_env(test_env.testing_paths) | ||
439 | package.path = test_env.env_variables.LUA_PATH | 391 | package.path = test_env.env_variables.LUA_PATH |
440 | 392 | ||
441 | test_env.run = run_luarocks(test_env.testing_paths, test_env.env_variables) | ||
442 | test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables) | 393 | test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables) |
443 | test_env.md5sums = create_md5sums(test_env.testing_paths) | 394 | test_env.md5sums = create_md5sums(test_env.testing_paths) |
444 | test_env.setup_done = true | 395 | test_env.setup_done = true |
396 | title("RUNNING TESTS") | ||
445 | end | 397 | end |
446 | 398 | ||
447 | if extra_rocks then | 399 | if extra_rocks then |
448 | local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) | 400 | local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) |
449 | if make_manifest then | 401 | if make_manifest then |
450 | local run = run_luarocks(test_env.testing_paths, test_env.env_variables) | 402 | test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) |
451 | run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) | ||
452 | end | 403 | end |
453 | end | 404 | end |
454 | 405 | ||
455 | reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables) | 406 | reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables) |
456 | |||
457 | return true | ||
458 | end | 407 | end |
459 | 408 | ||
460 | --- Helper function for tests which needs luasocket installed | 409 | --- Helper function for tests which needs luasocket installed |
461 | function test_env.need_luasocket(luarocks_nocov, testing_cache, platform) | 410 | function test_env.need_luasocket() |
462 | luarocks_nocov = luarocks_nocov or test_env.run.luarocks_nocov | 411 | if test_env.run.luarocks_nocov("show luasocket") then |
463 | testing_cache = testing_cache or test_env.testing_paths.testing_cache | ||
464 | platform = platform or test_env.platform | ||
465 | |||
466 | if luarocks_nocov("show luasocket") then | ||
467 | return true | 412 | return true |
468 | else | 413 | else |
469 | testing_cache = testing_cache .. "/" | 414 | local testing_cache = test_env.testing_paths.testing_cache .. "/" |
470 | local luasocket_rock = "luasocket-3.0rc1-1." .. platform .. ".rock" | 415 | local luasocket_rock = "luasocket-3.0rc1-1." .. test_env.platform .. ".rock" |
471 | if not os.rename( testing_cache .. luasocket_rock, testing_cache .. luasocket_rock) then | 416 | if not exists(testing_cache .. luasocket_rock) then |
472 | luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1") | 417 | test_env.run.luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1") |
473 | os.rename(luasocket_rock, testing_cache .. luasocket_rock) | 418 | os.rename(luasocket_rock, testing_cache .. luasocket_rock) |
474 | end | 419 | end |
475 | luarocks_nocov("install " .. testing_cache .. luasocket_rock) | 420 | return test_env.run.luarocks_nocov("install " .. testing_cache .. luasocket_rock) |
476 | end | 421 | end |
477 | return true | 422 | end |
423 | |||
424 | --- For each key-value pair in replacements table | ||
425 | -- replace %{key} in given string with value. | ||
426 | local function substitute(str, replacements) | ||
427 | return (str:gsub("%%%b{}", function(marker) | ||
428 | return replacements[marker:sub(3, -2)] | ||
429 | end)) | ||
430 | end | ||
431 | |||
432 | |||
433 | --- Create configs for luacov and several versions of Luarocks | ||
434 | -- configs needed for some tests. | ||
435 | local function create_configs() | ||
436 | -- testing_config.lua and testing_config_show_downloads.lua | ||
437 | local config_content = substitute([[ | ||
438 | rocks_trees = { | ||
439 | "%{testing_tree}", | ||
440 | { name = "system", root = "%{testing_sys_tree}" }, | ||
441 | } | ||
442 | rocks_servers = { | ||
443 | "%{testing_server}" | ||
444 | } | ||
445 | local_cache = "%{testing_cache}" | ||
446 | upload_server = "testing" | ||
447 | upload_user = "%{user}" | ||
448 | upload_servers = { | ||
449 | testing = { | ||
450 | rsync = "localhost/tmp/luarocks_testing", | ||
451 | }, | ||
452 | } | ||
453 | external_deps_dirs = { | ||
454 | "/usr/local", | ||
455 | "/usr", | ||
456 | -- These are used for a test that fails, so it | ||
457 | -- can point to invalid paths: | ||
458 | { | ||
459 | prefix = "/opt", | ||
460 | bin = "bin", | ||
461 | include = "include", | ||
462 | lib = { "lib", "lib64" }, | ||
463 | } | ||
464 | } | ||
465 | ]], { | ||
466 | user = os.getenv("USER"), | ||
467 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, | ||
468 | testing_tree = test_env.testing_paths.testing_tree, | ||
469 | testing_server = test_env.testing_paths.testing_server, | ||
470 | testing_cache = test_env.testing_paths.testing_cache | ||
471 | }) | ||
472 | |||
473 | write_file(test_env.testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") | ||
474 | write_file(test_env.testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content | ||
475 | .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") | ||
476 | |||
477 | -- testing_config_sftp.lua | ||
478 | config_content = substitute([[ | ||
479 | rocks_trees = { | ||
480 | "%{testing_tree}", | ||
481 | "%{testing_sys_tree}", | ||
482 | } | ||
483 | local_cache = "%{testing_cache}" | ||
484 | upload_server = "testing" | ||
485 | upload_user = "%{user}" | ||
486 | upload_servers = { | ||
487 | testing = { | ||
488 | sftp = "localhost/tmp/luarocks_testing", | ||
489 | }, | ||
490 | } | ||
491 | ]], { | ||
492 | user = os.getenv("USER"), | ||
493 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, | ||
494 | testing_tree = test_env.testing_paths.testing_tree, | ||
495 | testing_cache = test_env.testing_paths.testing_cache | ||
496 | }) | ||
497 | |||
498 | write_file(test_env.testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) | ||
499 | |||
500 | -- luacov.config | ||
501 | config_content = substitute([[ | ||
502 | return { | ||
503 | statsfile = "%{testing_dir}/luacov.stats.out", | ||
504 | reportfile = "%{testing_dir}/luacov.report.out", | ||
505 | modules = { | ||
506 | ["luarocks"] = "src/bin/luarocks", | ||
507 | ["luarocks-admin"] = "src/bin/luarocks-admin", | ||
508 | ["luarocks.*"] = "src", | ||
509 | ["luarocks.*.*"] = "src", | ||
510 | ["luarocks.*.*.*"] = "src" | ||
511 | } | ||
512 | } | ||
513 | ]], { | ||
514 | testing_dir = test_env.testing_paths.testing_dir | ||
515 | }) | ||
516 | |||
517 | write_file(test_env.testing_paths.testing_dir .. "/luacov.config", config_content) | ||
518 | end | ||
519 | |||
520 | --- Remove testing directories. | ||
521 | local function clean() | ||
522 | print("Cleaning testing directory...") | ||
523 | test_env.remove_dir(test_env.testing_paths.luarocks_tmp) | ||
524 | test_env.remove_subdirs(test_env.testing_paths.testing_dir, "testing[_%-]") | ||
525 | test_env.remove_files(test_env.testing_paths.testing_dir, "testing_") | ||
526 | test_env.remove_files(test_env.testing_paths.testing_dir, "luacov") | ||
527 | print("Cleaning done!") | ||
528 | end | ||
529 | |||
530 | --- Install luarocks into testing prefix. | ||
531 | local function install_luarocks(install_env_vars) | ||
532 | -- Configure LuaRocks testing environment | ||
533 | local configure_cmd = "./configure --with-lua=" .. test_env.testing_paths.luadir .. | ||
534 | " --prefix=" .. test_env.testing_paths.testing_lrprefix .. | ||
535 | " && make clean" | ||
536 | |||
537 | assert(execute_bool(configure_cmd, false, install_env_vars)) | ||
538 | assert(execute_bool("make src/luarocks/site_config.lua && make dev", false, install_env_vars)) | ||
478 | end | 539 | end |
479 | 540 | ||
480 | --- | 541 | --- |
481 | -- Main function to create config files and testing environment | 542 | -- Main function to create config files and testing environment |
482 | function test_env.main(luaversion_full, env_type, env_clean) | 543 | function test_env.main() |
483 | luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V | 544 | local testing_paths = test_env.testing_paths |
484 | local testing_paths = create_paths(luaversion_full) | 545 | |
485 | 546 | if test_env.TEST_ENV_CLEAN then | |
486 | env_clean = env_clean or test_env.TEST_ENV_CLEAN | 547 | clean() |
487 | if env_clean then | ||
488 | print("Cleaning testing directory...") | ||
489 | test_env.remove_dir(testing_paths.luarocks_tmp) | ||
490 | test_env.remove_dir_pattern(testing_paths.testing_dir, "testing_") | ||
491 | test_env.remove_dir_pattern(testing_paths.testing_dir, "testing-") | ||
492 | test_env.remove_files(testing_paths.testing_dir, "testing_") | ||
493 | test_env.remove_files(testing_paths.testing_dir, "luacov") | ||
494 | print("Cleaning done!") | ||
495 | end | 548 | end |
496 | 549 | ||
497 | lfs.mkdir(testing_paths.testing_cache) | 550 | lfs.mkdir(testing_paths.testing_cache) |
498 | lfs.mkdir(testing_paths.luarocks_tmp) | 551 | lfs.mkdir(testing_paths.luarocks_tmp) |
499 | 552 | ||
500 | --- CONFIG FILES | 553 | create_configs() |
501 | -- testing_config.lua and testing_config_show_downloads.lua | ||
502 | local config_content = ([[rocks_trees = { | ||
503 | "%{testing_tree}", | ||
504 | { name = "system", root = "%{testing_sys_tree}" }, | ||
505 | } | ||
506 | rocks_servers = { | ||
507 | "%{testing_server}" | ||
508 | } | ||
509 | local_cache = "%{testing_cache}" | ||
510 | upload_server = "testing" | ||
511 | upload_user = "%{user}" | ||
512 | upload_servers = { | ||
513 | testing = { | ||
514 | rsync = "localhost/tmp/luarocks_testing", | ||
515 | }, | ||
516 | } | ||
517 | external_deps_dirs = { | ||
518 | "/usr/local", | ||
519 | "/usr", | ||
520 | -- These are used for a test that fails, so it | ||
521 | -- can point to invalid paths: | ||
522 | { | ||
523 | prefix = "/opt", | ||
524 | bin = "bin", | ||
525 | include = "include", | ||
526 | lib = { "lib", "lib64" }, | ||
527 | } | ||
528 | }]]):gsub("%%%b{}", { | ||
529 | ["%{user}"] = os.getenv("USER"), | ||
530 | ["%{testing_sys_tree}"] = testing_paths.testing_sys_tree, | ||
531 | ["%{testing_tree}"] = testing_paths.testing_tree, | ||
532 | ["%{testing_server}"] = testing_paths.testing_server, | ||
533 | ["%{testing_cache}"] = testing_paths.testing_cache}) | ||
534 | |||
535 | create_config(testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") | ||
536 | create_config(testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content | ||
537 | .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") | ||
538 | 554 | ||
539 | -- testing_config_sftp.lua | 555 | local install_env_vars = { |
540 | config_content=([[rocks_trees = { | 556 | LUAROCKS_CONFIG = test_env.testing_paths.testing_dir .. "/testing_config.lua", |
541 | "%{testing_tree}", | 557 | LUA_PATH = "", |
542 | "%{testing_sys_tree}", | 558 | LUA_CPATH = "" |
543 | } | ||
544 | local_cache = "%{testing_cache}" | ||
545 | upload_server = "testing" | ||
546 | upload_user = "%{user}" | ||
547 | upload_servers = { | ||
548 | testing = { | ||
549 | sftp = "localhost/tmp/luarocks_testing", | ||
550 | }, | ||
551 | }]]):gsub("%%%b{}", { | ||
552 | ["%{user}"] = os.getenv("USER"), | ||
553 | ["%{testing_sys_tree}"] = testing_paths.testing_sys_tree, | ||
554 | ["%{testing_tree}"] = testing_paths.testing_tree, | ||
555 | ["%{testing_cache}"] = testing_paths.testing_cache}) | ||
556 | |||
557 | create_config(testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) | ||
558 | |||
559 | -- luacov.config | ||
560 | config_content=([[return { | ||
561 | statsfile = "%{testing_dir}/luacov.stats.out", | ||
562 | reportfile = "%{testing_dir}/luacov.report.out", | ||
563 | modules = { | ||
564 | ["luarocks"] = "src/bin/luarocks", | ||
565 | ["luarocks-admin"] = "src/bin/luarocks-admin", | ||
566 | ["luarocks.*"] = "src", | ||
567 | ["luarocks.*.*"] = "src", | ||
568 | ["luarocks.*.*.*"] = "src" | ||
569 | } | 559 | } |
570 | }]]):gsub("%%%b{}", { | ||
571 | ["%{testing_dir}"] = testing_paths.testing_dir}) | ||
572 | |||
573 | create_config(testing_paths.testing_dir .. "/luacov.config", config_content) | ||
574 | 560 | ||
575 | -- Create environment variables for configuration | 561 | install_luarocks(install_env_vars) |
576 | local temp_env_variables = {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua",LUA_PATH="",LUA_CPATH=""} | ||
577 | |||
578 | -- Configure LuaRocks testing environment | ||
579 | local configure_cmd = "./configure --with-lua=" .. testing_paths.luadir .. " --prefix=" .. testing_paths.testing_lrprefix | ||
580 | configure_cmd = configure_cmd .. " && make clean" | ||
581 | |||
582 | if not execute_bool(configure_cmd, false, temp_env_variables) then | ||
583 | os.exit(1) | ||
584 | end | ||
585 | if not execute_bool("make src/luarocks/site_config.lua && make dev", false, temp_env_variables) then | ||
586 | os.exit(1) | ||
587 | end | ||
588 | 562 | ||
589 | -- Preparation of rocks for building environment | 563 | -- Preparation of rocks for building environment |
590 | env_type = env_type or test_env.TYPE_TEST_ENV | 564 | local rocks = {} -- names of rocks, required for building environment |
591 | 565 | local urls = {} -- names of rock and rockspec files to be downloaded | |
592 | local env_rocks = {} -- short names of rocks, required for building environment | 566 | table.insert(urls, "/luacov-0.11.0-1.rockspec") |
593 | local rocks = {} -- full names of rocks required for download | 567 | table.insert(urls, "/luacov-0.11.0-1.src.rock") |
594 | rocks[#rocks+1] = "/luacov-0.11.0-1.rockspec" | 568 | |
595 | rocks[#rocks+1] = "/luacov-0.11.0-1.src.rock" | 569 | if test_env.TYPE_TEST_ENV == "full" then |
596 | 570 | table.insert(urls, "/luafilesystem-1.6.3-1.src.rock") | |
597 | if env_type == "full" then | 571 | table.insert(urls, "/luasocket-3.0rc1-1.src.rock") |
598 | rocks[#rocks+1] = "/luafilesystem-1.6.3-1.src.rock" | 572 | table.insert(urls, "/luasocket-3.0rc1-1.rockspec") |
599 | rocks[#rocks+1] = "/luasocket-3.0rc1-1.src.rock" | 573 | table.insert(urls, "/luaposix-33.2.1-1.src.rock") |
600 | rocks[#rocks+1] = "/luasocket-3.0rc1-1.rockspec" | 574 | table.insert(urls, "/md5-1.2-1.src.rock") |
601 | rocks[#rocks+1] = "/luaposix-33.2.1-1.src.rock" | 575 | table.insert(urls, "/lzlib-0.4.1.53-1.src.rock") |
602 | rocks[#rocks+1] = "/md5-1.2-1.src.rock" | 576 | rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} |
603 | rocks[#rocks+1] = "/lzlib-0.4.1.53-1.src.rock" | 577 | |
604 | env_rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} | 578 | if test_env.LUA_V ~= "5.1" then |
605 | end | 579 | table.insert(urls, "/luabitop-1.0.2-1.rockspec") |
606 | if env_type == "full" and luaversion_full ~= "5.1.5" then | 580 | table.insert(urls, "/luabitop-1.0.2-1.src.rock") |
607 | rocks[#rocks+1] = "/luabitop-1.0.2-1.rockspec" | 581 | table.insert(rocks, "luabitop") |
608 | rocks[#rocks+1] = "/luabitop-1.0.2-1.src.rock" | 582 | end |
609 | table.insert(env_rocks, "luabitop") | ||
610 | end | 583 | end |
611 | 584 | ||
612 | table.insert(env_rocks, "luacov") -- luacov is needed for minimal or full environment | 585 | table.insert(rocks, "luacov") -- luacov is needed for minimal or full environment |
613 | 586 | ||
614 | -- Download rocks needed for LuaRocks testing environment | 587 | -- Download rocks needed for LuaRocks testing environment |
615 | lfs.mkdir(testing_paths.testing_server) | 588 | lfs.mkdir(testing_paths.testing_server) |
616 | download_rocks(rocks, testing_paths.testing_server) | 589 | download_rocks(urls, testing_paths.testing_server) |
617 | 590 | build_environment(rocks, install_env_vars) | |
618 | build_environment(env_rocks, testing_paths, temp_env_variables) | ||
619 | |||
620 | print("----------------") | ||
621 | print(" RUNNING TESTS") | ||
622 | print("----------------") | ||
623 | end | 591 | end |
624 | 592 | ||
593 | test_env.set_lua_version() | ||
594 | test_env.set_args() | ||
595 | test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V) | ||
596 | test_env.env_variables = create_env(test_env.testing_paths) | ||
597 | test_env.run = make_run_functions() | ||
598 | |||
625 | return test_env | 599 | return test_env |