diff options
| author | Peter Melnichenko <mpeterval@gmail.com> | 2016-07-08 14:30:00 +0300 |
|---|---|---|
| committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-07-08 14:43:19 +0300 |
| commit | 8867f3324d97584ed24f3a1082144e9b1375d663 (patch) | |
| tree | 6d2ac6859128b94e02c7e9fb247cc505ab62d6c4 /test/test_environment.lua | |
| parent | 20a1baba59e7555b3140e0c2226948447fe8e62a (diff) | |
| download | luarocks-8867f3324d97584ed24f3a1082144e9b1375d663.tar.gz luarocks-8867f3324d97584ed24f3a1082144e9b1375d663.tar.bz2 luarocks-8867f3324d97584ed24f3a1082144e9b1375d663.zip | |
Make env vars, paths and run commands available on test env load
Diffstat (limited to 'test/test_environment.lua')
| -rw-r--r-- | test/test_environment.lua | 94 |
1 files changed, 42 insertions, 52 deletions
diff --git a/test/test_environment.lua b/test/test_environment.lua index bde43163..b3ac3b18 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua | |||
| @@ -254,44 +254,40 @@ local function create_md5sums(testing_paths) | |||
| 254 | return md5sums | 254 | return md5sums |
| 255 | end | 255 | end |
| 256 | 256 | ||
| 257 | local function run_luarocks(testing_paths, env_variables) | 257 | local function make_run_function(cmd_name, exec_function, with_coverage, do_print) |
| 258 | 258 | local cmd_prefix = test_env.testing_paths.lua .. " " | |
| 259 | local function make_command_function(exec_function, lua_cmd, do_print) | 259 | |
| 260 | return function(cmd, new_vars) | 260 | if with_coverage then |
| 261 | local temp_vars = {} | 261 | cmd_prefix = cmd_prefix .. "-e \"require('luacov.runner')('" .. test_env.testing_paths.testing_dir .. "/luacov.config')\" " |
| 262 | for k, v in pairs(env_variables) do | 262 | end |
| 263 | |||
| 264 | cmd_prefix = cmd_prefix .. test_env.testing_paths.src_dir .. "/bin/" .. cmd_name .. " " | ||
| 265 | |||
| 266 | return function(cmd, new_vars) | ||
| 267 | local temp_vars = {} | ||
| 268 | for k, v in pairs(test_env.env_variables) do | ||
| 269 | temp_vars[k] = v | ||
| 270 | end | ||
| 271 | if new_vars then | ||
| 272 | for k, v in pairs(new_vars) do | ||
| 263 | temp_vars[k] = v | 273 | temp_vars[k] = v |
| 264 | end | 274 | end |
| 265 | if new_vars then | ||
| 266 | for k, v in pairs(new_vars) do | ||
| 267 | temp_vars[k] = v | ||
| 268 | end | ||
| 269 | end | ||
| 270 | return exec_function(lua_cmd .. cmd, do_print, temp_vars) | ||
| 271 | end | 275 | end |
| 276 | return exec_function(cmd_prefix .. cmd, do_print, temp_vars) | ||
| 272 | end | 277 | end |
| 278 | end | ||
| 273 | 279 | ||
| 274 | local run = {} | 280 | local function make_run_functions() |
| 275 | 281 | return { | |
| 276 | local cov_str = testing_paths.lua .. " -e\"require('luacov.runner')('" .. testing_paths.testing_dir .. "/luacov.config')\" " | 282 | luarocks = make_run_function("luarocks", execute_output, true, true), |
| 277 | 283 | luarocks_bool = make_run_function("luarocks", execute_bool, true, true), | |
| 278 | local luarocks_cmd = cov_str .. testing_paths.src_dir .. "/bin/luarocks " | 284 | luarocks_noprint = make_run_function("luarocks", execute_bool, true, false), |
| 279 | run.luarocks = make_command_function(execute_output, luarocks_cmd, true) | 285 | luarocks_nocov = make_run_function("luarocks", execute_bool, false, true), |
| 280 | run.luarocks_bool = make_command_function(execute_bool, luarocks_cmd, true) | 286 | luarocks_noprint_nocov = make_run_function("luarocks", execute_bool, false, false), |
| 281 | run.luarocks_noprint = make_command_function(execute_bool, luarocks_cmd, false) | 287 | luarocks_admin = make_run_function("luarocks-admin", execute_output, true, true), |
| 282 | 288 | luarocks_admin_bool = make_run_function("luarocks-admin", execute_bool, true, true), | |
| 283 | local luarocks_nocov_cmd = testing_paths.lua .. " " .. testing_paths.src_dir .. "/bin/luarocks " | 289 | luarocks_admin_nocov = make_run_function("luarocks-admin", execute_bool, false, false) |
| 284 | run.luarocks_nocov = make_command_function(execute_bool, luarocks_nocov_cmd, true) | 290 | } |
| 285 | run.luarocks_noprint_nocov = make_command_function(execute_bool, luarocks_nocov_cmd, false) | ||
| 286 | |||
| 287 | local luarocks_admin_cmd = cov_str .. testing_paths.src_dir .. "/bin/luarocks-admin " | ||
| 288 | run.luarocks_admin = make_command_function(execute_output, luarocks_admin_cmd, true) | ||
| 289 | run.luarocks_admin_bool = make_command_function(execute_bool, luarocks_admin_cmd, true) | ||
| 290 | |||
| 291 | local luarocks_admin_nocov_cmd = testing_paths.lua .. " " .. testing_paths.src_dir .. "/bin/luarocks-admin " | ||
| 292 | run.luarocks_admin_nocov = make_command_function(execute_bool, luarocks_admin_nocov_cmd, false) | ||
| 293 | |||
| 294 | return run | ||
| 295 | end | 291 | end |
| 296 | 292 | ||
| 297 | --- Build environment for testing | 293 | --- Build environment for testing |
| @@ -307,14 +303,13 @@ local function build_environment(env_rocks, testing_paths, env_variables) | |||
| 307 | lfs.mkdir(testing_paths.testing_tree) | 303 | lfs.mkdir(testing_paths.testing_tree) |
| 308 | lfs.mkdir(testing_paths.testing_sys_tree) | 304 | lfs.mkdir(testing_paths.testing_sys_tree) |
| 309 | 305 | ||
| 310 | local run = run_luarocks(testing_paths, env_variables) | 306 | test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) |
| 311 | run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) | 307 | test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) |
| 312 | run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) | ||
| 313 | 308 | ||
| 314 | for _,package in ipairs(env_rocks) do | 309 | for _,package in ipairs(env_rocks) do |
| 315 | if not run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) then | 310 | if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) then |
| 316 | run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) | 311 | test_env.run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) |
| 317 | run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. package .. "; mv " .. package .. "-*.rock " .. testing_paths.testing_cache, env_variables) | 312 | test_env.run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. package .. "; mv " .. package .. "-*.rock " .. testing_paths.testing_cache, env_variables) |
| 318 | end | 313 | end |
| 319 | end | 314 | end |
| 320 | 315 | ||
| @@ -394,12 +389,9 @@ function test_env.unload_luarocks() | |||
| 394 | end | 389 | end |
| 395 | 390 | ||
| 396 | --- Function for initially setup of environment, variables, md5sums for spec files | 391 | --- Function for initially setup of environment, variables, md5sums for spec files |
| 397 | function test_env.setup_specs(extra_rocks, luaversion_full) | 392 | function test_env.setup_specs(extra_rocks) |
| 398 | -- if global variable about successful creation of testing environment doesn't exists, build environment | 393 | -- if global variable about successful creation of testing environment doesn't exists, build environment |
| 399 | if not test_env.setup_done then | 394 | if not test_env.setup_done then |
| 400 | test_env.set_lua_version() | ||
| 401 | test_env.set_args() | ||
| 402 | |||
| 403 | if test_env.TRAVIS then | 395 | if test_env.TRAVIS then |
| 404 | if not os.rename(os.getenv("HOME") .. "/.ssh/id_rsa.pub", os.getenv("HOME") .. "/.ssh/id_rsa.pub") then | 396 | if not os.rename(os.getenv("HOME") .. "/.ssh/id_rsa.pub", os.getenv("HOME") .. "/.ssh/id_rsa.pub") then |
| 405 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") | 397 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") |
| @@ -409,16 +401,9 @@ function test_env.setup_specs(extra_rocks, luaversion_full) | |||
| 409 | end | 401 | end |
| 410 | end | 402 | end |
| 411 | 403 | ||
| 412 | luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V | ||
| 413 | |||
| 414 | test_env.main() | 404 | test_env.main() |
| 415 | |||
| 416 | -- Set paths, env_vars and functions for specs | ||
| 417 | test_env.testing_paths = create_paths(luaversion_full) | ||
| 418 | test_env.env_variables = create_env(test_env.testing_paths) | ||
| 419 | package.path = test_env.env_variables.LUA_PATH | 405 | package.path = test_env.env_variables.LUA_PATH |
| 420 | 406 | ||
| 421 | test_env.run = run_luarocks(test_env.testing_paths, test_env.env_variables) | ||
| 422 | test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables) | 407 | test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables) |
| 423 | test_env.md5sums = create_md5sums(test_env.testing_paths) | 408 | test_env.md5sums = create_md5sums(test_env.testing_paths) |
| 424 | test_env.setup_done = true | 409 | test_env.setup_done = true |
| @@ -427,8 +412,7 @@ function test_env.setup_specs(extra_rocks, luaversion_full) | |||
| 427 | if extra_rocks then | 412 | if extra_rocks then |
| 428 | local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) | 413 | local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) |
| 429 | if make_manifest then | 414 | if make_manifest then |
| 430 | local run = run_luarocks(test_env.testing_paths, test_env.env_variables) | 415 | test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) |
| 431 | run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) | ||
| 432 | end | 416 | end |
| 433 | end | 417 | end |
| 434 | 418 | ||
| @@ -602,4 +586,10 @@ upload_servers = { | |||
| 602 | print("----------------") | 586 | print("----------------") |
| 603 | end | 587 | end |
| 604 | 588 | ||
| 589 | test_env.set_lua_version() | ||
| 590 | test_env.set_args() | ||
| 591 | test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V) | ||
| 592 | test_env.env_variables = create_env(test_env.testing_paths) | ||
| 593 | test_env.run = make_run_functions() | ||
| 594 | |||
| 605 | return test_env | 595 | return test_env |
