diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-20 13:43:44 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-23 20:47:09 -0300 |
| commit | 2c4ff5240bf298fec07749f5984de2f08b8736ec (patch) | |
| tree | f0b4dfec401fa1a132fc5786467fb8683d17bdcb /spec/util/test_env.lua | |
| parent | 79bd1739d8ca004ddd0b2fa5e24da4a6f4b776fa (diff) | |
| download | luarocks-2c4ff5240bf298fec07749f5984de2f08b8736ec.tar.gz luarocks-2c4ff5240bf298fec07749f5984de2f08b8736ec.tar.bz2 luarocks-2c4ff5240bf298fec07749f5984de2f08b8736ec.zip | |
fix: better normalization for paths and slashes
Fixes #1195.
Diffstat (limited to 'spec/util/test_env.lua')
| -rw-r--r-- | spec/util/test_env.lua | 398 |
1 files changed, 224 insertions, 174 deletions
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index dcda6311..41787cb7 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua | |||
| @@ -37,6 +37,19 @@ local function title(str) | |||
| 37 | print(("-"):rep(#str)) | 37 | print(("-"):rep(#str)) |
| 38 | end | 38 | end |
| 39 | 39 | ||
| 40 | local dir_sep = package.config:sub(1, 1) | ||
| 41 | local function P(p) | ||
| 42 | return (p:gsub("/", dir_sep)) | ||
| 43 | end | ||
| 44 | |||
| 45 | local function dir_path(...) | ||
| 46 | return P((table.concat({ ... }, "/"):gsub("\\", "/"):gsub("/+", "/"))) | ||
| 47 | end | ||
| 48 | |||
| 49 | local function C(...) | ||
| 50 | return table.concat({...}, " ") | ||
| 51 | end | ||
| 52 | |||
| 40 | --- Quote argument for shell processing. Fixes paths on Windows. | 53 | --- Quote argument for shell processing. Fixes paths on Windows. |
| 41 | -- Adds double quotes and escapes. Based on function in fs/win32.lua. | 54 | -- Adds double quotes and escapes. Based on function in fs/win32.lua. |
| 42 | -- @param arg string: Unquoted argument. | 55 | -- @param arg string: Unquoted argument. |
| @@ -46,7 +59,7 @@ local function Q(arg) | |||
| 46 | local drive_letter = "[%.a-zA-Z]?:?[\\/]" | 59 | local drive_letter = "[%.a-zA-Z]?:?[\\/]" |
| 47 | -- Quote DIR for Windows | 60 | -- Quote DIR for Windows |
| 48 | if arg:match("^"..drive_letter) then | 61 | if arg:match("^"..drive_letter) then |
| 49 | arg = arg:gsub("/", "\\") | 62 | arg = P(arg) |
| 50 | end | 63 | end |
| 51 | 64 | ||
| 52 | if arg == "\\" then | 65 | if arg == "\\" then |
| @@ -72,7 +85,7 @@ local function V(str) | |||
| 72 | elseif suffix == "v" then | 85 | elseif suffix == "v" then |
| 73 | return v | 86 | return v |
| 74 | elseif suffix == "r" then | 87 | elseif suffix == "r" then |
| 75 | return v | 88 | return r |
| 76 | else | 89 | else |
| 77 | print("Test error: invalid suffix " .. suffix .. " in variable " .. name) | 90 | print("Test error: invalid suffix " .. suffix .. " in variable " .. name) |
| 78 | os.exit(1) | 91 | os.exit(1) |
| @@ -87,6 +100,14 @@ local function V(str) | |||
| 87 | end)) | 100 | end)) |
| 88 | end | 101 | end |
| 89 | 102 | ||
| 103 | local function tool(name) | ||
| 104 | if test_env.TEST_TARGET_OS == "windows" then | ||
| 105 | return Q(dir_path(test_env.testing_paths.win_tools, name .. ".exe")) | ||
| 106 | else | ||
| 107 | return name | ||
| 108 | end | ||
| 109 | end | ||
| 110 | |||
| 90 | local os_remove = os.remove | 111 | local os_remove = os.remove |
| 91 | os.remove = function(f) -- luacheck: ignore | 112 | os.remove = function(f) -- luacheck: ignore |
| 92 | return os_remove(V(f)) | 113 | return os_remove(V(f)) |
| @@ -131,8 +152,18 @@ function test_env.copy(source, destination) | |||
| 131 | source = V(source) | 152 | source = V(source) |
| 132 | destination = V(destination) | 153 | destination = V(destination) |
| 133 | 154 | ||
| 134 | local r_source, err = io.open(source, "r") | 155 | local r_source, r_destination, err |
| 135 | local r_destination, err = io.open(destination, "w") | 156 | r_source, err = io.open(source, "r") |
| 157 | if err then | ||
| 158 | print(debug.traceback()) | ||
| 159 | os.exit(1) | ||
| 160 | end | ||
| 161 | |||
| 162 | r_destination, err = io.open(destination, "w") | ||
| 163 | if err then | ||
| 164 | print(debug.traceback()) | ||
| 165 | os.exit(1) | ||
| 166 | end | ||
| 136 | 167 | ||
| 137 | while true do | 168 | while true do |
| 138 | local block = r_source:read(8192) | 169 | local block = r_source:read(8192) |
| @@ -147,7 +178,7 @@ end | |||
| 147 | function test_env.get_tmp_path() | 178 | function test_env.get_tmp_path() |
| 148 | local path = os.tmpname() | 179 | local path = os.tmpname() |
| 149 | if test_env.TEST_TARGET_OS == "windows" and not path:find(":") then | 180 | if test_env.TEST_TARGET_OS == "windows" and not path:find(":") then |
| 150 | path = os.getenv("TEMP") .. path | 181 | path = dir_path(os.getenv("TEMP"), path) |
| 151 | end | 182 | end |
| 152 | os.remove(path) | 183 | os.remove(path) |
| 153 | return path | 184 | return path |
| @@ -234,8 +265,8 @@ local function execute_bool(command, print_command, env_variables) | |||
| 234 | local redirect_filename | 265 | local redirect_filename |
| 235 | local redirect = "" | 266 | local redirect = "" |
| 236 | if print_command ~= nil then | 267 | if print_command ~= nil then |
| 237 | redirect_filename = test_env.testing_paths.luarocks_tmp.."/output.txt" | 268 | redirect_filename = dir_path(test_env.testing_paths.luarocks_tmp, "output.txt") |
| 238 | redirect = " > "..redirect_filename | 269 | redirect = " > " .. redirect_filename |
| 239 | os.remove(redirect_filename) | 270 | os.remove(redirect_filename) |
| 240 | end | 271 | end |
| 241 | local ok = test_env.execute(command .. redirect) | 272 | local ok = test_env.execute(command .. redirect) |
| @@ -312,7 +343,7 @@ function test_env.set_args() | |||
| 312 | if not test_env.TEST_TARGET_OS then | 343 | if not test_env.TEST_TARGET_OS then |
| 313 | title("OS CHECK") | 344 | title("OS CHECK") |
| 314 | 345 | ||
| 315 | if package.config:sub(1,1) == "\\" then | 346 | if dir_sep == "\\" then |
| 316 | test_env.TEST_TARGET_OS = "windows" | 347 | test_env.TEST_TARGET_OS = "windows" |
| 317 | if test_env.APPVEYOR then | 348 | if test_env.APPVEYOR then |
| 318 | test_env.OPENSSL_INCDIR = "C:\\OpenSSL-v111-Win32\\include" | 349 | test_env.OPENSSL_INCDIR = "C:\\OpenSSL-v111-Win32\\include" |
| @@ -348,7 +379,8 @@ function test_env.set_args() | |||
| 348 | 379 | ||
| 349 | test_env.openssl_dirs = "" | 380 | test_env.openssl_dirs = "" |
| 350 | if test_env.OPENSSL_INCDIR then | 381 | if test_env.OPENSSL_INCDIR then |
| 351 | test_env.openssl_dirs = "OPENSSL_INCDIR=" .. test_env.OPENSSL_INCDIR .. " OPENSSL_LIBDIR=" .. test_env.OPENSSL_LIBDIR | 382 | test_env.openssl_dirs = C("OPENSSL_INCDIR=" .. test_env.OPENSSL_INCDIR, |
| 383 | "OPENSSL_LIBDIR=" .. test_env.OPENSSL_LIBDIR) | ||
| 352 | end | 384 | end |
| 353 | 385 | ||
| 354 | return true | 386 | return true |
| @@ -358,12 +390,8 @@ function test_env.copy_dir(source_path, target_path) | |||
| 358 | source_path = V(source_path) | 390 | source_path = V(source_path) |
| 359 | target_path = V(target_path) | 391 | target_path = V(target_path) |
| 360 | 392 | ||
| 361 | local testing_paths = test_env.testing_paths | 393 | local flag = test_env.TEST_TARGET_OS == "windows" and "-R" or "-a" |
| 362 | if test_env.TEST_TARGET_OS == "windows" then | 394 | os.execute(C(tool("cp"), flag, dir_path(source_path, "."), target_path)) |
| 363 | execute_bool(testing_paths.win_tools .. "/cp -R ".. source_path .. "/. " .. target_path) | ||
| 364 | else | ||
| 365 | execute_bool("cp -a ".. source_path .. "/. " .. target_path) | ||
| 366 | end | ||
| 367 | end | 395 | end |
| 368 | 396 | ||
| 369 | --- Remove directory recursively | 397 | --- Remove directory recursively |
| @@ -374,7 +402,7 @@ function test_env.remove_dir(path) | |||
| 374 | if exists(path) then | 402 | if exists(path) then |
| 375 | for file in lfs.dir(path) do | 403 | for file in lfs.dir(path) do |
| 376 | if file ~= "." and file ~= ".." then | 404 | if file ~= "." and file ~= ".." then |
| 377 | local full_path = path..'/'..file | 405 | local full_path = dir_path(path, file) |
| 378 | 406 | ||
| 379 | if lfs.attributes(full_path, "mode") == "directory" then | 407 | if lfs.attributes(full_path, "mode") == "directory" then |
| 380 | test_env.remove_dir(full_path) | 408 | test_env.remove_dir(full_path) |
| @@ -396,7 +424,7 @@ function test_env.remove_subdirs(path, pattern) | |||
| 396 | if exists(path) then | 424 | if exists(path) then |
| 397 | for file in lfs.dir(path) do | 425 | for file in lfs.dir(path) do |
| 398 | if file ~= "." and file ~= ".." then | 426 | if file ~= "." and file ~= ".." then |
| 399 | local full_path = path..'/'..file | 427 | local full_path = dir_path(path, file) |
| 400 | 428 | ||
| 401 | if lfs.attributes(full_path, "mode") == "directory" and file:find(pattern) then | 429 | if lfs.attributes(full_path, "mode") == "directory" and file:find(pattern) then |
| 402 | test_env.remove_dir(full_path) | 430 | test_env.remove_dir(full_path) |
| @@ -418,7 +446,7 @@ function test_env.remove_files(path, pattern) | |||
| 418 | for file in lfs.dir(path) do | 446 | for file in lfs.dir(path) do |
| 419 | if file ~= "." and file ~= ".." then | 447 | if file ~= "." and file ~= ".." then |
| 420 | if file:find(pattern) then | 448 | if file:find(pattern) then |
| 421 | if os.remove(path .. "/" .. file) then | 449 | if os.remove(dir_path(path, file)) then |
| 422 | result_check = true | 450 | result_check = true |
| 423 | end | 451 | end |
| 424 | end | 452 | end |
| @@ -442,27 +470,21 @@ local function download_rocks(urls, save_path) | |||
| 442 | url = V(url) | 470 | url = V(url) |
| 443 | 471 | ||
| 444 | if url:match("^spec/fixtures") then | 472 | if url:match("^spec/fixtures") then |
| 445 | table.insert(fixtures, (url:gsub("^spec/fixtures", test_env.testing_paths.fixtures_dir))) | 473 | table.insert(fixtures, P(url:gsub("^spec/fixtures", test_env.testing_paths.fixtures_dir))) |
| 446 | else | 474 | else |
| 447 | -- check if already downloaded | 475 | -- check if already downloaded |
| 448 | if not exists(save_path .. "/" .. url) then | 476 | if not exists(dir_path(save_path, url)) then |
| 449 | table.insert(to_download, ((luarocks_repo .. url):gsub("org//", "org/"))) | 477 | table.insert(to_download, ((luarocks_repo .. url):gsub("org//", "org/"))) |
| 450 | end | 478 | end |
| 451 | end | 479 | end |
| 452 | end | 480 | end |
| 453 | 481 | ||
| 454 | if #fixtures > 0 then | 482 | if #fixtures > 0 then |
| 455 | os.execute("cp " .. table.concat(fixtures, " ") .. " " .. save_path) | 483 | os.execute(C(tool("cp"), table.concat(fixtures, " "), save_path)) |
| 456 | end | 484 | end |
| 457 | 485 | ||
| 458 | if #to_download > 0 then | 486 | if #to_download > 0 then |
| 459 | local cmd | 487 | local ok = execute_bool(C(tool("wget"), "--no-check-certificate -cP", save_path, table.concat(to_download, " "))) |
| 460 | if test_env.TEST_TARGET_OS == "windows" then | ||
| 461 | cmd = test_env.testing_paths.win_tools .. "/wget --no-check-certificate -cP " .. save_path | ||
| 462 | else | ||
| 463 | cmd = "wget -cP " .. save_path | ||
| 464 | end | ||
| 465 | local ok = execute_bool(cmd.." "..table.concat(to_download, " ")) | ||
| 466 | if not ok then | 488 | if not ok then |
| 467 | os.exit(1) | 489 | os.exit(1) |
| 468 | end | 490 | end |
| @@ -492,12 +514,13 @@ end | |||
| 492 | -- @return md5sum string: md5sum of directory | 514 | -- @return md5sum string: md5sum of directory |
| 493 | local function hash_environment(path) | 515 | local function hash_environment(path) |
| 494 | if test_env.TEST_TARGET_OS == "linux" then | 516 | if test_env.TEST_TARGET_OS == "linux" then |
| 495 | return execute_output("cd " .. path .. " && find . -printf \"%s %p\n\"") | 517 | return execute_output(C("cd", path, "&& find . -printf \"%s %p\n\" | md5sum")) |
| 496 | elseif test_env.TEST_TARGET_OS == "osx" then | 518 | elseif test_env.TEST_TARGET_OS == "osx" then |
| 497 | return execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5") | 519 | return execute_output(C("find", path, "-type f -exec stat -f \"%z %N\" {} \\; | md5")) |
| 498 | elseif test_env.TEST_TARGET_OS == "windows" then | 520 | elseif test_env.TEST_TARGET_OS == "windows" then |
| 499 | return execute_output("\"" .. Q(test_env.testing_paths.win_tools .. "/find") .. " " .. Q(path) | 521 | return execute_output( |
| 500 | .. " -printf \"%s %p\"\" > temp_sum.txt && certUtil -hashfile temp_sum.txt && del temp_sum.txt") | 522 | "\"" .. C(tool("find"), Q(path), "-printf", "\"%s %p\"") .. "\"" .. |
| 523 | " > temp_sum.txt && certUtil -hashfile temp_sum.txt && del temp_sum.txt") | ||
| 501 | end | 524 | end |
| 502 | end | 525 | end |
| 503 | 526 | ||
| @@ -505,29 +528,44 @@ end | |||
| 505 | -- @param testing_paths table: table with paths to testing directory | 528 | -- @param testing_paths table: table with paths to testing directory |
| 506 | -- @return env_variables table: table with created environment variables | 529 | -- @return env_variables table: table with created environment variables |
| 507 | local function create_env(testing_paths) | 530 | local function create_env(testing_paths) |
| 508 | local luaversion_short = _VERSION:gsub("Lua ", "") | 531 | local lua_v = _VERSION:gsub("Lua ", "") |
| 532 | local testrun_dir = test_env.testing_paths.testrun_dir | ||
| 533 | local lrprefix = testing_paths.testing_lrprefix | ||
| 534 | local tree = testing_paths.testing_tree | ||
| 535 | local sys_tree = testing_paths.testing_sys_tree | ||
| 509 | 536 | ||
| 510 | if test_env.LUAJIT_V then | 537 | if test_env.LUAJIT_V then |
| 511 | luaversion_short="5.1" | 538 | lua_v="5.1" |
| 512 | end | 539 | end |
| 513 | 540 | ||
| 514 | local env_variables = {} | 541 | local env_variables = {} |
| 515 | env_variables.GNUPGHOME = testing_paths.gpg_dir | 542 | env_variables.GNUPGHOME = testing_paths.gpg_dir |
| 516 | env_variables.LUA_VERSION = luaversion_short | 543 | env_variables.LUA_VERSION = lua_v |
| 517 | env_variables.LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/testing_config.lua" | 544 | env_variables.LUAROCKS_CONFIG = dir_path(testrun_dir, "testing_config.lua") |
| 545 | |||
| 546 | local lua_path = {} | ||
| 518 | if test_env.TEST_TARGET_OS == "windows" then | 547 | if test_env.TEST_TARGET_OS == "windows" then |
| 519 | env_variables.LUA_PATH = testing_paths.testing_lrprefix .. "\\lua\\?.lua;" | 548 | table.insert(lua_path, dir_path(lrprefix, "lua", "?.lua")) |
| 520 | else | 549 | else |
| 521 | env_variables.LUA_PATH = testing_paths.testing_lrprefix .. "/share/lua/" .. luaversion_short .. "/?.lua;" | 550 | table.insert(lua_path, dir_path(lrprefix, "share", "lua", lua_v, "?.lua")) |
| 522 | end | 551 | end |
| 523 | env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" | 552 | table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?.lua")) |
| 524 | env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" | 553 | table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?", "init.lua")) |
| 525 | env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" | 554 | table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?.lua")) |
| 526 | env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" | 555 | table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?", "init.lua")) |
| 527 | env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;" | 556 | table.insert(lua_path, dir_path(testing_paths.src_dir, "?.lua")) |
| 528 | env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?." .. test_env.lib_extension .. ";" | 557 | env_variables.LUA_PATH = table.concat(lua_path, ";") .. ";" |
| 529 | .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?." .. test_env.lib_extension .. ";" | 558 | |
| 530 | env_variables.PATH = os.getenv("PATH") .. ";" .. testing_paths.testing_tree .. "/bin;" .. testing_paths.testing_sys_tree .. "/bin;" | 559 | local lua_cpath = {} |
| 560 | local lib_pattern = "?." .. test_env.lib_extension | ||
| 561 | table.insert(lua_cpath, dir_path(tree, "lib", "lua", lua_v, lib_pattern)) | ||
| 562 | table.insert(lua_cpath, dir_path(sys_tree, "lib", "lua", lua_v, lib_pattern)) | ||
| 563 | env_variables.LUA_CPATH = table.concat(lua_cpath, ";") .. ";" | ||
| 564 | |||
| 565 | local path = { os.getenv("PATH") } | ||
| 566 | table.insert(path, dir_path(tree, "bin")) | ||
| 567 | table.insert(path, dir_path(sys_tree, "bin")) | ||
| 568 | env_variables.PATH = table.concat(path, test_env.TARGET_OS == "windows" and ";" or ":") | ||
| 531 | 569 | ||
| 532 | return env_variables | 570 | return env_variables |
| 533 | end | 571 | end |
| @@ -544,16 +582,19 @@ local function create_md5sums(testing_paths) | |||
| 544 | end | 582 | end |
| 545 | 583 | ||
| 546 | local function make_run_function(cmd_name, exec_function, with_coverage, do_print) | 584 | local function make_run_function(cmd_name, exec_function, with_coverage, do_print) |
| 547 | local cmd_prefix = Q(test_env.testing_paths.lua) .. " " | 585 | local cmd_prefix = Q(test_env.testing_paths.lua) |
| 586 | local testrun_dir = test_env.testing_paths.testrun_dir | ||
| 548 | 587 | ||
| 549 | if with_coverage then | 588 | if with_coverage then |
| 550 | cmd_prefix = cmd_prefix .. "-e \"require('luacov.runner')('" .. test_env.testing_paths.testrun_dir .. "/luacov.config')\" " | 589 | cmd_prefix = C(cmd_prefix, "-e", "\"require('luacov.runner')([[" .. testrun_dir .. "/luacov.config]])\"") |
| 551 | end | 590 | end |
| 552 | 591 | ||
| 553 | if cmd_name then | 592 | if cmd_name then |
| 554 | cmd_prefix = cmd_prefix .. test_env.testing_paths.src_dir .. "/bin/" .. cmd_name .. " " | 593 | cmd_prefix = C(cmd_prefix, dir_path(test_env.testing_paths.src_dir, "bin", cmd_name)) |
| 555 | end | 594 | end |
| 556 | 595 | ||
| 596 | cmd_prefix = P(cmd_prefix) | ||
| 597 | |||
| 557 | return function(cmd, new_vars) | 598 | return function(cmd, new_vars) |
| 558 | cmd = V(cmd) | 599 | cmd = V(cmd) |
| 559 | local temp_vars = {} | 600 | local temp_vars = {} |
| @@ -565,34 +606,34 @@ local function make_run_function(cmd_name, exec_function, with_coverage, do_prin | |||
| 565 | temp_vars[k] = v | 606 | temp_vars[k] = v |
| 566 | end | 607 | end |
| 567 | end | 608 | end |
| 568 | return exec_function(cmd_prefix .. cmd, do_print, temp_vars) | 609 | return exec_function(C(cmd_prefix, cmd), do_print, temp_vars) |
| 569 | end | 610 | end |
| 570 | end | 611 | end |
| 571 | 612 | ||
| 572 | local function make_run_functions() | 613 | local function make_run_functions() |
| 573 | return { | 614 | local fns = {} |
| 574 | lua = make_run_function(nil, execute_output, true, true), | 615 | |
| 575 | lua_bool = make_run_function(nil, execute_bool, true, true), | 616 | local cmds = { |
| 576 | luarocks = make_run_function("luarocks", execute_output, true, true), | 617 | ["lua"] = nil, |
| 577 | luarocks_bool = make_run_function("luarocks", execute_bool, true, true), | 618 | ["luarocks"] = "luarocks", |
| 578 | luarocks_noprint = make_run_function("luarocks", execute_bool, true, false), | 619 | ["luarocks_admin"] = "luarocks-admin", |
| 579 | luarocks_nocov = make_run_function("luarocks", execute_bool, false, true), | ||
| 580 | luarocks_noprint_nocov = make_run_function("luarocks", execute_bool, false, false), | ||
| 581 | luarocks_admin = make_run_function("luarocks-admin", execute_output, true, true), | ||
| 582 | luarocks_admin_bool = make_run_function("luarocks-admin", execute_bool, true, true), | ||
| 583 | luarocks_admin_nocov = make_run_function("luarocks-admin", execute_bool, false, false) | ||
| 584 | } | 620 | } |
| 621 | |||
| 622 | for _, name in ipairs({"lua", "luarocks", "luarocks_admin"}) do | ||
| 623 | fns[name] = make_run_function(cmds[name], execute_output, true, true) | ||
| 624 | fns[name .. "_bool"] = make_run_function(cmds[name], execute_bool, true, true) | ||
| 625 | fns[name .. "_nocov"] = make_run_function(cmds[name], execute_bool, false, true) | ||
| 626 | fns[name .. "_noprint_nocov"] = make_run_function(cmds[name], execute_bool, false, false) | ||
| 627 | end | ||
| 628 | |||
| 629 | return fns | ||
| 585 | end | 630 | end |
| 586 | 631 | ||
| 587 | local function move_file(src, dst) | 632 | local function move_file(src, dst) |
| 588 | if test_env.TEST_TARGET_OS == "windows" then | 633 | local ok = execute_bool(C(tool("mv"), P(src), P(dst))) |
| 589 | execute_bool(test_env.testing_paths.win_tools .. "/mv " .. src .. " " .. dst) | 634 | if not ok then |
| 590 | else | 635 | print(debug.traceback()) |
| 591 | local ok = execute_bool("mv " .. src .. " " .. dst) | 636 | os.exit(1) |
| 592 | if not ok then | ||
| 593 | print(debug.traceback()) | ||
| 594 | os.exit(1) | ||
| 595 | end | ||
| 596 | end | 637 | end |
| 597 | end | 638 | end |
| 598 | 639 | ||
| @@ -610,13 +651,15 @@ local function build_environment(rocks, env_variables) | |||
| 610 | lfs.mkdir(testing_paths.testing_tree) | 651 | lfs.mkdir(testing_paths.testing_tree) |
| 611 | lfs.mkdir(testing_paths.testing_sys_tree) | 652 | lfs.mkdir(testing_paths.testing_sys_tree) |
| 612 | 653 | ||
| 613 | test_env.run.luarocks_admin_nocov("make_manifest " .. Q(testing_paths.testing_server)) | 654 | test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_server))) |
| 614 | test_env.run.luarocks_admin_nocov("make_manifest " .. Q(testing_paths.testing_cache)) | 655 | test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_cache))) |
| 615 | 656 | ||
| 616 | for _, rock in ipairs(rocks) do | 657 | for _, rock in ipairs(rocks) do |
| 617 | if not test_env.run.luarocks_nocov(test_env.quiet("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. Q(rock), env_variables)) then | 658 | local only_server = "--only-server=" .. testing_paths.testing_cache |
| 618 | assert(test_env.run.luarocks_nocov("build --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock), env_variables)) | 659 | local tree = "--tree=" .. testing_paths.testing_sys_tree |
| 619 | assert(test_env.run.luarocks_nocov("pack --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock), env_variables)) | 660 | if not test_env.run.luarocks_nocov(test_env.quiet(C("install", only_server, tree, Q(rock)), env_variables)) then |
| 661 | assert(test_env.run.luarocks_nocov(C("build", tree, Q(rock)), env_variables)) | ||
| 662 | assert(test_env.run.luarocks_nocov(C("pack", tree, Q(rock)), env_variables)) | ||
| 620 | move_file(rock .. "-*.rock", testing_paths.testing_cache) | 663 | move_file(rock .. "-*.rock", testing_paths.testing_cache) |
| 621 | end | 664 | end |
| 622 | end | 665 | end |
| @@ -641,16 +684,6 @@ local function reset_environment(testing_paths, md5sums) | |||
| 641 | end | 684 | end |
| 642 | end | 685 | end |
| 643 | 686 | ||
| 644 | local function found_interpreter(testing_paths, luadir, lua_bindir) | ||
| 645 | local location = lua_bindir .. "/" .. testing_paths.lua_exe | ||
| 646 | if exists(location) then | ||
| 647 | testing_paths.lua_bindir = lua_bindir | ||
| 648 | testing_paths.luadir = luadir | ||
| 649 | testing_paths.lua = location | ||
| 650 | return true | ||
| 651 | end | ||
| 652 | end | ||
| 653 | |||
| 654 | local function find_lua() | 687 | local function find_lua() |
| 655 | -- (1) LUA is a full path | 688 | -- (1) LUA is a full path |
| 656 | if test_env.LUA and test_env.LUA:match("[/\\]") then | 689 | if test_env.LUA and test_env.LUA:match("[/\\]") then |
| @@ -671,22 +704,22 @@ local function find_lua() | |||
| 671 | if test_env.LUA_DIR then | 704 | if test_env.LUA_DIR then |
| 672 | 705 | ||
| 673 | local luadir = test_env.LUA_DIR | 706 | local luadir = test_env.LUA_DIR |
| 674 | local lua_bindir = exists(luadir .. "/bin") | 707 | local lua_bindir = exists(dir_path(luadir, "bin")) |
| 675 | and luadir .. "/bin" | 708 | and dir_path(luadir, "bin") |
| 676 | or luadir | 709 | or luadir |
| 677 | local lua = lua_bindir .. "/" .. lua_exe | 710 | local lua = dir_path(lua_bindir, lua_exe) |
| 678 | 711 | ||
| 679 | return lua_bindir, luadir, lua | 712 | return lua_bindir, luadir, lua |
| 680 | end | 713 | end |
| 681 | 714 | ||
| 682 | -- (2.2) LUA_DIR was not given, try some default paths | 715 | -- (2.2) LUA_DIR was not given, try some default paths |
| 683 | local try_dirs = (test_env.TEST_TARGET_OS == "windows") | 716 | local try_dirs = (test_env.TEST_TARGET_OS == "windows") |
| 684 | and { os.getenv("ProgramFiles(x86)").."/LuaRocks" } | 717 | and { os.getenv("ProgramFiles(x86)").."\\LuaRocks" } |
| 685 | or { "/usr/local", "/usr" } | 718 | or { "/usr/local", "/usr" } |
| 686 | 719 | ||
| 687 | for _, luadir in ipairs(try_dirs) do | 720 | for _, luadir in ipairs(try_dirs) do |
| 688 | for _, lua_bindir in ipairs({ luadir, luadir .. "/bin" }) do | 721 | for _, lua_bindir in ipairs({ luadir, dir_path(luadir, "bin") }) do |
| 689 | local lua = lua_bindir .. "/" .. lua_exe | 722 | local lua = dir_path(lua_bindir, lua_exe) |
| 690 | if exists(lua) then | 723 | if exists(lua) then |
| 691 | return lua_bindir, luadir, lua | 724 | return lua_bindir, luadir, lua |
| 692 | end | 725 | end |
| @@ -694,50 +727,47 @@ local function find_lua() | |||
| 694 | end | 727 | end |
| 695 | end | 728 | end |
| 696 | 729 | ||
| 697 | local function create_paths(luaversion_full) | 730 | local function create_testing_paths(suffix) |
| 698 | 731 | local paths = {} | |
| 699 | local testing_paths = {} | ||
| 700 | 732 | ||
| 701 | testing_paths.lua_bindir, testing_paths.luadir, testing_paths.lua = find_lua() | 733 | paths.lua_bindir, paths.luadir, paths.lua = find_lua() |
| 702 | if (not testing_paths.lua) or (not exists(testing_paths.lua)) then | 734 | if (not paths.lua) or (not exists(paths.lua)) then |
| 703 | error("Lua interpreter not found! Run `busted -Xhelper help` for options") | 735 | error("Lua interpreter not found! Run `busted -Xhelper help` for options") |
| 704 | end | 736 | end |
| 705 | 737 | ||
| 706 | local base_dir = lfs.currentdir() | 738 | local base_dir = lfs.currentdir() |
| 739 | paths.src_dir = dir_path(base_dir, "src") | ||
| 740 | paths.spec_dir = dir_path(base_dir, "spec") | ||
| 741 | paths.util_dir = dir_path(base_dir, "spec", "util") | ||
| 742 | paths.fixtures_dir = dir_path(base_dir, "spec", "fixtures") | ||
| 743 | paths.fixtures_repo_dir = dir_path(base_dir, "spec", "fixtures", "a_repo") | ||
| 744 | paths.gpg_dir = dir_path(base_dir, "spec", "fixtures", "gpg") | ||
| 745 | |||
| 746 | local testrun_dir = dir_path(base_dir, "testrun") | ||
| 747 | paths.testrun_dir = testrun_dir | ||
| 748 | paths.testing_lrprefix = dir_path(testrun_dir, "testing_lrprefix-" .. suffix) | ||
| 749 | paths.testing_tree = dir_path(testrun_dir, "testing-" .. suffix) | ||
| 750 | paths.testing_tree_copy = dir_path(testrun_dir, "testing_copy-" .. suffix) | ||
| 751 | paths.testing_sys_tree = dir_path(testrun_dir, "testing_sys-" .. suffix) | ||
| 752 | paths.testing_sys_tree_copy = dir_path(testrun_dir, "testing_sys_copy-" .. suffix) | ||
| 753 | paths.testing_cache = dir_path(testrun_dir, "testing_cache-" .. suffix) | ||
| 754 | paths.testing_server = dir_path(testrun_dir, "testing_server-" .. suffix) | ||
| 755 | |||
| 756 | local rocks_v = "rocks-" .. test_env.lua_version | ||
| 757 | paths.testing_rocks = dir_path(paths.testing_tree, "lib", "luarocks", rocks_v) | ||
| 758 | paths.testing_sys_rocks = dir_path(paths.testing_sys_tree, "lib", "luarocks", rocks_v) | ||
| 707 | 759 | ||
| 708 | if test_env.TEST_TARGET_OS == "windows" then | 760 | if test_env.TEST_TARGET_OS == "windows" then |
| 709 | base_dir = base_dir:gsub("\\","/") | 761 | paths.luarocks_tmp = os.getenv("TEMP") |
| 710 | end | ||
| 711 | |||
| 712 | testing_paths.fixtures_dir = base_dir .. "/spec/fixtures" | ||
| 713 | testing_paths.gpg_dir = testing_paths.fixtures_dir .. "/gpg" | ||
| 714 | testing_paths.fixtures_repo_dir = base_dir .. "/spec/fixtures/a_repo" | ||
| 715 | testing_paths.util_dir = base_dir .. "/spec/util" | ||
| 716 | testing_paths.testrun_dir = base_dir .. "/testrun" | ||
| 717 | testing_paths.src_dir = base_dir .. "/src" | ||
| 718 | testing_paths.spec_dir = base_dir .. "/spec" | ||
| 719 | testing_paths.testing_lrprefix = testing_paths.testrun_dir .. "/testing_lrprefix-" .. luaversion_full | ||
| 720 | testing_paths.testing_tree = testing_paths.testrun_dir .. "/testing-" .. luaversion_full | ||
| 721 | testing_paths.testing_tree_copy = testing_paths.testrun_dir .. "/testing_copy-" .. luaversion_full | ||
| 722 | testing_paths.testing_sys_tree = testing_paths.testrun_dir .. "/testing_sys-" .. luaversion_full | ||
| 723 | testing_paths.testing_sys_tree_copy = testing_paths.testrun_dir .. "/testing_sys_copy-" .. luaversion_full | ||
| 724 | testing_paths.testing_cache = testing_paths.testrun_dir .. "/testing_cache-" .. luaversion_full | ||
| 725 | testing_paths.testing_server = testing_paths.testrun_dir .. "/testing_server-" .. luaversion_full | ||
| 726 | |||
| 727 | testing_paths.testing_rocks = testing_paths.testing_tree .. "/lib/luarocks/rocks-" .. test_env.lua_version | ||
| 728 | testing_paths.testing_sys_rocks = testing_paths.testing_sys_tree .. "/lib/luarocks/rocks-" .. test_env.lua_version | ||
| 729 | |||
| 730 | if test_env.TEST_TARGET_OS == "windows" then | ||
| 731 | testing_paths.luarocks_tmp = os.getenv("TEMP") | ||
| 732 | else | 762 | else |
| 733 | testing_paths.luarocks_tmp = "/tmp/luarocks_testing" | 763 | paths.luarocks_tmp = "/tmp/luarocks_testing" |
| 734 | end | 764 | end |
| 735 | 765 | ||
| 736 | if test_env.TEST_TARGET_OS == "windows" then | 766 | if test_env.TEST_TARGET_OS == "windows" then |
| 737 | testing_paths.win_tools = base_dir .. "/win32/tools" | 767 | paths.win_tools = dir_path(base_dir, "win32", "tools") |
| 738 | end | 768 | end |
| 739 | 769 | ||
| 740 | return testing_paths | 770 | return paths |
| 741 | end | 771 | end |
| 742 | 772 | ||
| 743 | --- Helper function to unload luarocks modules from global table package.loaded | 773 | --- Helper function to unload luarocks modules from global table package.loaded |
| @@ -748,7 +778,7 @@ function test_env.unload_luarocks() | |||
| 748 | package.loaded[modname] = nil | 778 | package.loaded[modname] = nil |
| 749 | end | 779 | end |
| 750 | end | 780 | end |
| 751 | local src_pattern = test_env.testing_paths.src_dir .. "/?.lua" | 781 | local src_pattern = dir_path(test_env.testing_paths.src_dir, "?.lua") |
| 752 | if not package.path:find(src_pattern, 1, true) then | 782 | if not package.path:find(src_pattern, 1, true) then |
| 753 | package.path = src_pattern .. ";" .. package.path | 783 | package.path = src_pattern .. ";" .. package.path |
| 754 | end | 784 | end |
| @@ -760,16 +790,19 @@ local function get_luarocks_platform(variables) | |||
| 760 | "cfg.init();" .. | 790 | "cfg.init();" .. |
| 761 | "print(cfg.arch)" .. | 791 | "print(cfg.arch)" .. |
| 762 | "\"" | 792 | "\"" |
| 763 | local cmd = test_env.testing_paths.lua .. " -e " .. print_arch_script | 793 | local cmd = C(test_env.testing_paths.lua, "-e", print_arch_script) |
| 764 | return execute_output(cmd, false, variables) | 794 | return execute_output(cmd, false, variables) |
| 765 | end | 795 | end |
| 766 | 796 | ||
| 767 | --- Function for initial setup of environment, variables, md5sums for spec files | 797 | --- Function for initial setup of environment, variables, md5sums for spec files |
| 768 | function test_env.setup_specs(extra_rocks) | 798 | function test_env.setup_specs(extra_rocks) |
| 799 | local testrun_dir = test_env.testing_paths.testrun_dir | ||
| 800 | local variables = test_env.env_variables | ||
| 801 | |||
| 769 | -- if global variable about successful creation of testing environment doesn't exist, build environment | 802 | -- if global variable about successful creation of testing environment doesn't exist, build environment |
| 770 | if not test_env.setup_done then | 803 | if not test_env.setup_done then |
| 771 | if test_env.CI then | 804 | if test_env.CI then |
| 772 | if not exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then | 805 | if not exists(os.getenv("HOME"), ".ssh/id_rsa.pub") then |
| 773 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") | 806 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") |
| 774 | execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") | 807 | execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") |
| 775 | execute_bool("chmod og-wx ~/.ssh/authorized_keys") | 808 | execute_bool("chmod og-wx ~/.ssh/authorized_keys") |
| @@ -783,8 +816,8 @@ function test_env.setup_specs(extra_rocks) | |||
| 783 | require("spec.util.git_repo") | 816 | require("spec.util.git_repo") |
| 784 | require("spec.util.quick") | 817 | require("spec.util.quick") |
| 785 | 818 | ||
| 786 | package.path = test_env.env_variables.LUA_PATH | 819 | package.path = variables.LUA_PATH |
| 787 | package.cpath = test_env.env_variables.LUA_CPATH | 820 | package.cpath = variables.LUA_CPATH |
| 788 | 821 | ||
| 789 | test_env.platform = get_luarocks_platform(test_env.env_variables) | 822 | test_env.platform = get_luarocks_platform(test_env.env_variables) |
| 790 | test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" | 823 | test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" |
| @@ -801,10 +834,10 @@ function test_env.setup_specs(extra_rocks) | |||
| 801 | end | 834 | end |
| 802 | 835 | ||
| 803 | if test_env.RESET_ENV then | 836 | if test_env.RESET_ENV then |
| 804 | reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables) | 837 | reset_environment(test_env.testing_paths, test_env.md5sums, variables) |
| 805 | end | 838 | end |
| 806 | 839 | ||
| 807 | lfs.chdir(test_env.testing_paths.testrun_dir) | 840 | lfs.chdir(testrun_dir) |
| 808 | end | 841 | end |
| 809 | 842 | ||
| 810 | --- Test if required rock is installed and if not, install it. | 843 | --- Test if required rock is installed and if not, install it. |
| @@ -829,7 +862,11 @@ end | |||
| 829 | -- replace %{key} in given string with value. | 862 | -- replace %{key} in given string with value. |
| 830 | local function substitute(str, replacements) | 863 | local function substitute(str, replacements) |
| 831 | return (str:gsub("%%%b{}", function(marker) | 864 | return (str:gsub("%%%b{}", function(marker) |
| 832 | return replacements[marker:sub(3, -2)] | 865 | local r = replacements[marker:sub(3, -2)] |
| 866 | if r then | ||
| 867 | r = r:gsub("\\", "\\\\") | ||
| 868 | end | ||
| 869 | return r | ||
| 833 | end)) | 870 | end)) |
| 834 | end | 871 | end |
| 835 | 872 | ||
| @@ -837,6 +874,8 @@ end | |||
| 837 | --- Create configs for luacov and several versions of Luarocks | 874 | --- Create configs for luacov and several versions of Luarocks |
| 838 | -- configs needed for some tests. | 875 | -- configs needed for some tests. |
| 839 | local function create_configs() | 876 | local function create_configs() |
| 877 | local testrun_dir = test_env.testing_paths.testrun_dir | ||
| 878 | |||
| 840 | -- testing_config.lua | 879 | -- testing_config.lua |
| 841 | -- testing_config_show_downloads.lua | 880 | -- testing_config_show_downloads.lua |
| 842 | -- testing_config_no_downloader.lua | 881 | -- testing_config_no_downloader.lua |
| @@ -857,17 +896,17 @@ local function create_configs() | |||
| 857 | }, | 896 | }, |
| 858 | } | 897 | } |
| 859 | ]], { | 898 | ]], { |
| 860 | user = os.getenv("USER"), | 899 | user = "testuser", |
| 861 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, | 900 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, |
| 862 | testing_tree = test_env.testing_paths.testing_tree, | 901 | testing_tree = test_env.testing_paths.testing_tree, |
| 863 | testing_server = test_env.testing_paths.testing_server, | 902 | testing_server = test_env.testing_paths.testing_server, |
| 864 | testing_cache = test_env.testing_paths.testing_cache | 903 | testing_cache = test_env.testing_paths.testing_cache |
| 865 | }) | 904 | }) |
| 866 | 905 | ||
| 867 | test_env.write_file(test_env.testing_paths.testrun_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") | 906 | test_env.write_file(dir_path(testrun_dir, "testing_config.lua"), config_content .. " \nweb_browser = \"true\"") |
| 868 | test_env.write_file(test_env.testing_paths.testrun_dir .. "/testing_config_show_downloads.lua", config_content | 907 | test_env.write_file(dir_path(testrun_dir, "testing_config_show_downloads.lua"), config_content |
| 869 | .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") | 908 | .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") |
| 870 | test_env.write_file(test_env.testing_paths.testrun_dir .. "/testing_config_no_downloader.lua", config_content | 909 | test_env.write_file(dir_path(testrun_dir, "testing_config_no_downloader.lua"), config_content |
| 871 | .. "variables = { WGET = 'invalid', CURL = 'invalid' }") | 910 | .. "variables = { WGET = 'invalid', CURL = 'invalid' }") |
| 872 | 911 | ||
| 873 | -- testing_config_sftp.lua | 912 | -- testing_config_sftp.lua |
| @@ -885,32 +924,35 @@ local function create_configs() | |||
| 885 | }, | 924 | }, |
| 886 | } | 925 | } |
| 887 | ]], { | 926 | ]], { |
| 888 | user = os.getenv("USER"), | 927 | user = "testuser", |
| 889 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, | 928 | testing_sys_tree = test_env.testing_paths.testing_sys_tree, |
| 890 | testing_tree = test_env.testing_paths.testing_tree, | 929 | testing_tree = test_env.testing_paths.testing_tree, |
| 891 | testing_cache = test_env.testing_paths.testing_cache | 930 | testing_cache = test_env.testing_paths.testing_cache |
| 892 | }) | 931 | }) |
| 893 | 932 | ||
| 894 | test_env.write_file(test_env.testing_paths.testrun_dir .. "/testing_config_sftp.lua", config_content) | 933 | test_env.write_file(dir_path(testrun_dir, "testing_config_sftp.lua"), config_content) |
| 895 | 934 | ||
| 896 | -- luacov.config | 935 | -- luacov.config |
| 897 | config_content = substitute([[ | 936 | config_content = substitute([[ |
| 898 | return { | 937 | return { |
| 899 | statsfile = "%{testrun_dir}/luacov.stats.out", | 938 | statsfile = "%{statsfile}", |
| 900 | reportfile = "%{testrun_dir}/luacov.report.out", | 939 | reportfile = "%{reportfile}", |
| 901 | modules = { | 940 | modules = { |
| 902 | ["luarocks"] = "src/bin/luarocks", | 941 | ["luarocks"] = "%{luarocks_path}", |
| 903 | ["luarocks-admin"] = "src/bin/luarocks-admin", | 942 | ["luarocks-admin"] = "%{luarocks_admin_path}", |
| 904 | ["luarocks.*"] = "src", | 943 | ["luarocks.*"] = "src", |
| 905 | ["luarocks.*.*"] = "src", | 944 | ["luarocks.*.*"] = "src", |
| 906 | ["luarocks.*.*.*"] = "src" | 945 | ["luarocks.*.*.*"] = "src" |
| 907 | } | 946 | } |
| 908 | } | 947 | } |
| 909 | ]], { | 948 | ]], { |
| 910 | testrun_dir = test_env.testing_paths.testrun_dir | 949 | statsfile = dir_path(testrun_dir, "luacov.stats.out"), |
| 950 | reportfile = dir_path(testrun_dir, "luacov.report.out"), | ||
| 951 | luarocks_path = dir_path("src", "bin", "luarocks"), | ||
| 952 | luarocks_admin_path = dir_path("src", "bin", "luarocks-admin"), | ||
| 911 | }) | 953 | }) |
| 912 | 954 | ||
| 913 | test_env.write_file(test_env.testing_paths.testrun_dir .. "/luacov.config", config_content) | 955 | test_env.write_file(dir_path(testrun_dir, "luacov.config"), config_content) |
| 914 | 956 | ||
| 915 | config_content = [[ | 957 | config_content = [[ |
| 916 | -- Config file of mock LuaRocks.org site for tests | 958 | -- Config file of mock LuaRocks.org site for tests |
| @@ -920,18 +962,20 @@ local function create_configs() | |||
| 920 | api_version = "1", | 962 | api_version = "1", |
| 921 | } | 963 | } |
| 922 | ]] | 964 | ]] |
| 923 | test_env.write_file(test_env.testing_paths.testrun_dir .. "/luarocks_site.lua", config_content) | 965 | test_env.write_file(dir_path(testrun_dir, "luarocks_site.lua"), config_content) |
| 924 | end | 966 | end |
| 925 | 967 | ||
| 926 | --- Remove testing directories. | 968 | --- Remove testing directories. |
| 927 | local function clean() | 969 | local function clean() |
| 970 | local testrun_dir = test_env.testing_paths.testrun_dir | ||
| 971 | |||
| 928 | print("Cleaning testing directory...") | 972 | print("Cleaning testing directory...") |
| 929 | test_env.remove_dir(test_env.testing_paths.luarocks_tmp) | 973 | test_env.remove_dir(test_env.testing_paths.luarocks_tmp) |
| 930 | test_env.remove_subdirs(test_env.testing_paths.testrun_dir, "testing[_%-]") | 974 | test_env.remove_subdirs(testrun_dir, "testing[_%-]") |
| 931 | test_env.remove_files(test_env.testing_paths.testrun_dir, "testing_") | 975 | test_env.remove_files(testrun_dir, "testing_") |
| 932 | test_env.remove_files(test_env.testing_paths.testrun_dir, "luacov") | 976 | test_env.remove_files(testrun_dir, "luacov") |
| 933 | test_env.remove_files(test_env.testing_paths.testrun_dir, "upload_config") | 977 | test_env.remove_files(testrun_dir, "upload_config") |
| 934 | test_env.remove_files(test_env.testing_paths.testrun_dir, "luarocks_site") | 978 | test_env.remove_files(testrun_dir, "luarocks_site") |
| 935 | print("Cleaning done!") | 979 | print("Cleaning done!") |
| 936 | end | 980 | end |
| 937 | 981 | ||
| @@ -942,7 +986,7 @@ local function setup_luarocks() | |||
| 942 | 986 | ||
| 943 | local lines = { | 987 | local lines = { |
| 944 | "return {", | 988 | "return {", |
| 945 | ("SYSCONFDIR = %q,"):format(testing_paths.testing_lrprefix .. "/etc/luarocks"), | 989 | ("SYSCONFDIR = %q,"):format(dir_path(testing_paths.testing_lrprefix, "etc/luarocks")), |
| 946 | ("LUA_DIR = %q,"):format(testing_paths.luadir), | 990 | ("LUA_DIR = %q,"):format(testing_paths.luadir), |
| 947 | ("LUA_BINDIR = %q,"):format(testing_paths.lua_bindir), | 991 | ("LUA_BINDIR = %q,"):format(testing_paths.lua_bindir), |
| 948 | ("LUA = %q,"):format(testing_paths.lua), | 992 | ("LUA = %q,"):format(testing_paths.lua), |
| @@ -965,33 +1009,33 @@ local function setup_luarocks() | |||
| 965 | end | 1009 | end |
| 966 | 1010 | ||
| 967 | local function mock_api_call(path) | 1011 | local function mock_api_call(path) |
| 968 | if test_env.TEST_TARGET_OS == "windows" then | 1012 | test_env.execute(C(tool("wget"), "--quiet --timeout=5 --tries=1 localhost:8080" .. path)) |
| 969 | return test_env.execute(Q(test_env.testing_paths.win_tools .. "/wget") .. " --quiet --timeout=5 --tries=1 localhost:8080" .. path) | ||
| 970 | else | ||
| 971 | return test_env.execute("curl -s localhost:8080" .. path) | ||
| 972 | end | ||
| 973 | end | 1013 | end |
| 974 | 1014 | ||
| 975 | function test_env.mock_server_init() | 1015 | function test_env.mock_server_init() |
| 976 | local testing_paths = test_env.testing_paths | 1016 | local testing_paths = test_env.testing_paths |
| 977 | assert(test_env.need_rock("restserver-xavante")) | 1017 | assert(test_env.need_rock("restserver-xavante")) |
| 978 | 1018 | ||
| 979 | if test_env.TEST_TARGET_OS == "windows" then | 1019 | local lua = Q(testing_paths.lua) |
| 980 | os.execute(test_env.execute_helper("start /b \"\" " .. Q(testing_paths.lua) .. " " .. Q(testing_paths.util_dir .. "/mock-server.lua") .. " " .. Q(testing_paths.fixtures_dir), true, test_env.env_variables)) | 1020 | local mock_server = Q(dir_path(testing_paths.util_dir, "mock-server.lua")) |
| 981 | else | 1021 | local fixtures_dir = Q(testing_paths.fixtures_dir) |
| 982 | os.execute(test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.util_dir .. "/mock-server.lua " .. testing_paths.fixtures_dir .. " &", true, test_env.env_variables)) | 1022 | |
| 983 | end | 1023 | local cmd = C(lua, mock_server, fixtures_dir) |
| 1024 | |||
| 1025 | local bg_cmd = test_env.TEST_TARGET_OS == "windows" | ||
| 1026 | and C("start", "/b", "\"\"", cmd) | ||
| 1027 | or C(cmd, "&") | ||
| 1028 | |||
| 1029 | os.execute(test_env.execute_helper(bg_cmd, true, test_env.env_variables)) | ||
| 984 | 1030 | ||
| 985 | for _ = 1, 10 do | 1031 | for _ = 1, 10 do |
| 986 | if mock_api_call("/api/tool_version") then | 1032 | if mock_api_call("/api/tool_version") then |
| 987 | break | 1033 | break |
| 988 | end | 1034 | end |
| 989 | 1035 | ||
| 990 | if test_env.TEST_TARGET_OS == "windows" then | 1036 | os.execute(test_env.TEST_TARGET_OS == "windows" |
| 991 | os.execute("timeout 1 > NUL") | 1037 | and "timeout 1 > NUL" |
| 992 | else | 1038 | or "sleep 1") |
| 993 | os.execute("sleep 1") | ||
| 994 | end | ||
| 995 | end | 1039 | end |
| 996 | 1040 | ||
| 997 | end | 1041 | end |
| @@ -1000,9 +1044,9 @@ function test_env.mock_server_done() | |||
| 1000 | mock_api_call("/shutdown") | 1044 | mock_api_call("/shutdown") |
| 1001 | end | 1045 | end |
| 1002 | 1046 | ||
| 1003 | local function find_binary_rock(src_rock, dir) | 1047 | local function find_binary_rock(src_rock, dirname) |
| 1004 | local patt = src_rock:gsub("([.-])", "%%%1"):gsub("src", ".*[^s][^r][^c]") | 1048 | local patt = src_rock:gsub("([.-])", "%%%1"):gsub("src", ".*[^s][^r][^c]") |
| 1005 | for name in lfs.dir(dir) do | 1049 | for name in lfs.dir(dirname) do |
| 1006 | if name:match(patt) then | 1050 | if name:match(patt) then |
| 1007 | return true | 1051 | return true |
| 1008 | end | 1052 | end |
| @@ -1034,14 +1078,18 @@ local function prepare_mock_server_binary_rocks() | |||
| 1034 | rock = V(rock) | 1078 | rock = V(rock) |
| 1035 | local rockname = rock:gsub("%-[^-]+%-%d+%.[%a.]+$", "") | 1079 | local rockname = rock:gsub("%-[^-]+%-%d+%.[%a.]+$", "") |
| 1036 | if not find_binary_rock(rock, testing_paths.testing_server) then | 1080 | if not find_binary_rock(rock, testing_paths.testing_server) then |
| 1037 | test_env.run.luarocks_nocov("build " .. Q(testing_paths.testing_server .. "/" .. rock) .. " --tree=" .. testing_paths.testing_cache) | 1081 | local rockpath = dir_path(testing_paths.testing_server, rock) |
| 1038 | test_env.run.luarocks_nocov("pack " .. rockname .. " --tree=" .. testing_paths.testing_cache) | 1082 | local tree = "--tree=" .. testing_paths.testing_cache |
| 1083 | |||
| 1084 | test_env.run.luarocks_nocov(C("build", Q(rockpath), tree)) | ||
| 1085 | test_env.run.luarocks_nocov(C("pack", rockname, tree)) | ||
| 1086 | |||
| 1039 | move_file(rockname .. "-*.rock", testing_paths.testing_server) | 1087 | move_file(rockname .. "-*.rock", testing_paths.testing_server) |
| 1040 | make_manifest = true | 1088 | make_manifest = true |
| 1041 | end | 1089 | end |
| 1042 | end | 1090 | end |
| 1043 | if make_manifest then | 1091 | if make_manifest then |
| 1044 | test_env.run.luarocks_admin_nocov("make_manifest " .. Q(testing_paths.testing_server)) | 1092 | test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_server))) |
| 1045 | end | 1093 | end |
| 1046 | end | 1094 | end |
| 1047 | 1095 | ||
| @@ -1049,13 +1097,14 @@ end | |||
| 1049 | -- Main function to create config files and testing environment | 1097 | -- Main function to create config files and testing environment |
| 1050 | function test_env.main() | 1098 | function test_env.main() |
| 1051 | local testing_paths = test_env.testing_paths | 1099 | local testing_paths = test_env.testing_paths |
| 1100 | local testrun_dir = test_env.testing_paths.testrun_dir | ||
| 1052 | 1101 | ||
| 1053 | if test_env.TEST_ENV_CLEAN then | 1102 | if test_env.TEST_ENV_CLEAN then |
| 1054 | clean() | 1103 | clean() |
| 1055 | end | 1104 | end |
| 1056 | 1105 | ||
| 1057 | lfs.mkdir(testing_paths.testrun_dir) | 1106 | lfs.mkdir(testrun_dir) |
| 1058 | test_env.write_file(testing_paths.testrun_dir .. "/.luarocks-no-project", "") | 1107 | test_env.write_file(dir_path(testrun_dir, ".luarocks-no-project"), "") |
| 1059 | lfs.mkdir(testing_paths.testing_cache) | 1108 | lfs.mkdir(testing_paths.testing_cache) |
| 1060 | lfs.mkdir(testing_paths.luarocks_tmp) | 1109 | lfs.mkdir(testing_paths.luarocks_tmp) |
| 1061 | 1110 | ||
| @@ -1068,7 +1117,7 @@ function test_env.main() | |||
| 1068 | local urls = {} -- names of rock and rockspec files to be downloaded | 1117 | local urls = {} -- names of rock and rockspec files to be downloaded |
| 1069 | 1118 | ||
| 1070 | local env_vars = { | 1119 | local env_vars = { |
| 1071 | LUAROCKS_CONFIG = test_env.testing_paths.testrun_dir .. "/testing_config.lua" | 1120 | LUAROCKS_CONFIG = dir_path(testrun_dir, "testing_config.lua") |
| 1072 | } | 1121 | } |
| 1073 | 1122 | ||
| 1074 | if test_env.TYPE_TEST_ENV == "full" then | 1123 | if test_env.TYPE_TEST_ENV == "full" then |
| @@ -1088,8 +1137,8 @@ function test_env.main() | |||
| 1088 | table.insert(urls, "/luaposix-${LUAPOSIX}.src.rock") | 1137 | table.insert(urls, "/luaposix-${LUAPOSIX}.src.rock") |
| 1089 | table.insert(rocks, "luaposix") | 1138 | table.insert(rocks, "luaposix") |
| 1090 | end | 1139 | end |
| 1091 | assert(test_env.run.luarocks_nocov("config variables.OPENSSL_INCDIR " .. Q(test_env.OPENSSL_INCDIR), env_vars)) | 1140 | assert(test_env.run.luarocks_nocov(C("config", "variables.OPENSSL_INCDIR", Q(test_env.OPENSSL_INCDIR)), env_vars)) |
| 1092 | assert(test_env.run.luarocks_nocov("config variables.OPENSSL_LIBDIR " .. Q(test_env.OPENSSL_LIBDIR), env_vars)) | 1141 | assert(test_env.run.luarocks_nocov(C("config", "variables.OPENSSL_LIBDIR", Q(test_env.OPENSSL_LIBDIR)), env_vars)) |
| 1093 | end | 1142 | end |
| 1094 | 1143 | ||
| 1095 | -- luacov is needed for both minimal or full environment | 1144 | -- luacov is needed for both minimal or full environment |
| @@ -1111,12 +1160,13 @@ end | |||
| 1111 | 1160 | ||
| 1112 | test_env.set_lua_version() | 1161 | test_env.set_lua_version() |
| 1113 | test_env.set_args() | 1162 | test_env.set_args() |
| 1114 | test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V) | 1163 | test_env.testing_paths = create_testing_paths(test_env.LUA_V or test_env.LUAJIT_V) |
| 1115 | test_env.env_variables = create_env(test_env.testing_paths) | 1164 | test_env.env_variables = create_env(test_env.testing_paths) |
| 1116 | test_env.run = make_run_functions() | 1165 | test_env.run = make_run_functions() |
| 1117 | test_env.exists = exists | 1166 | test_env.exists = exists |
| 1118 | test_env.V = V | 1167 | test_env.V = V |
| 1119 | test_env.Q = Q | 1168 | test_env.Q = Q |
| 1169 | test_env.P = P | ||
| 1120 | test_env.platform = get_luarocks_platform(test_env.env_variables) | 1170 | test_env.platform = get_luarocks_platform(test_env.env_variables) |
| 1121 | 1171 | ||
| 1122 | return test_env | 1172 | return test_env |
