diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/util/test_env.lua | 96 |
1 files changed, 58 insertions, 38 deletions
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index ca520459..f9f83b8c 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua | |||
@@ -22,7 +22,7 @@ ARGUMENTS | |||
22 | appveyor Add if running on Appveyor. | 22 | appveyor Add if running on Appveyor. |
23 | os=<type> Set OS ("linux", "osx", or "windows"). | 23 | os=<type> Set OS ("linux", "osx", or "windows"). |
24 | lua_dir=<path> Path of Lua installation (default "/usr/local") | 24 | lua_dir=<path> Path of Lua installation (default "/usr/local") |
25 | lua_interpreter=<lua> Name of the interpreter (default "lua") | 25 | lua=<lua> Name of the interpreter, may be full path (default "lua") |
26 | ]] | 26 | ]] |
27 | 27 | ||
28 | local function help() | 28 | local function help() |
@@ -107,7 +107,7 @@ lfs.attributes = function(f, ...) -- luacheck: ignore | |||
107 | return lfs_attributes(V(f), ...) | 107 | return lfs_attributes(V(f), ...) |
108 | end | 108 | end |
109 | 109 | ||
110 | function test_env.exists(path) | 110 | local function exists(path) |
111 | return lfs.attributes(path, "mode") ~= nil | 111 | return lfs.attributes(path, "mode") ~= nil |
112 | end | 112 | end |
113 | 113 | ||
@@ -302,8 +302,8 @@ function test_env.set_args() | |||
302 | test_env.MINGW = false | 302 | test_env.MINGW = false |
303 | elseif argument:find("^lua_dir=") then | 303 | elseif argument:find("^lua_dir=") then |
304 | test_env.LUA_DIR = argument:match("^lua_dir=(.*)$") | 304 | test_env.LUA_DIR = argument:match("^lua_dir=(.*)$") |
305 | elseif argument:find("^lua_interpreter=") then | 305 | elseif argument:find("^lua=") then |
306 | test_env.LUA_INTERPRETER = argument:match("^lua_interpreter=(.*)$") | 306 | test_env.LUA = argument:match("^lua=(.*)$") |
307 | else | 307 | else |
308 | help() | 308 | help() |
309 | end | 309 | end |
@@ -371,7 +371,7 @@ end | |||
371 | function test_env.remove_dir(path) | 371 | function test_env.remove_dir(path) |
372 | path = V(path) | 372 | path = V(path) |
373 | 373 | ||
374 | if test_env.exists(path) then | 374 | if exists(path) then |
375 | for file in lfs.dir(path) do | 375 | for file in lfs.dir(path) do |
376 | if file ~= "." and file ~= ".." then | 376 | if file ~= "." and file ~= ".." then |
377 | local full_path = path..'/'..file | 377 | local full_path = path..'/'..file |
@@ -393,7 +393,7 @@ end | |||
393 | function test_env.remove_subdirs(path, pattern) | 393 | function test_env.remove_subdirs(path, pattern) |
394 | path = V(path) | 394 | path = V(path) |
395 | 395 | ||
396 | if test_env.exists(path) then | 396 | if exists(path) then |
397 | for file in lfs.dir(path) do | 397 | for file in lfs.dir(path) do |
398 | if file ~= "." and file ~= ".." then | 398 | if file ~= "." and file ~= ".." then |
399 | local full_path = path..'/'..file | 399 | local full_path = path..'/'..file |
@@ -414,7 +414,7 @@ function test_env.remove_files(path, pattern) | |||
414 | path = V(path) | 414 | path = V(path) |
415 | 415 | ||
416 | local result_check = false | 416 | local result_check = false |
417 | if test_env.exists(path) then | 417 | if exists(path) then |
418 | for file in lfs.dir(path) do | 418 | for file in lfs.dir(path) do |
419 | if file ~= "." and file ~= ".." then | 419 | if file ~= "." and file ~= ".." then |
420 | if file:find(pattern) then | 420 | if file:find(pattern) then |
@@ -445,7 +445,7 @@ local function download_rocks(urls, save_path) | |||
445 | table.insert(fixtures, (url:gsub("^spec/fixtures", test_env.testing_paths.fixtures_dir))) | 445 | table.insert(fixtures, (url:gsub("^spec/fixtures", test_env.testing_paths.fixtures_dir))) |
446 | else | 446 | else |
447 | -- check if already downloaded | 447 | -- check if already downloaded |
448 | if not test_env.exists(save_path .. "/" .. url) then | 448 | if not exists(save_path .. "/" .. url) then |
449 | table.insert(to_download, ((luarocks_repo .. url):gsub("org//", "org/"))) | 449 | table.insert(to_download, ((luarocks_repo .. url):gsub("org//", "org/"))) |
450 | end | 450 | end |
451 | end | 451 | end |
@@ -642,8 +642,8 @@ local function reset_environment(testing_paths, md5sums) | |||
642 | end | 642 | end |
643 | 643 | ||
644 | local function found_interpreter(testing_paths, luadir, lua_bindir) | 644 | local function found_interpreter(testing_paths, luadir, lua_bindir) |
645 | local location = lua_bindir .. "/" .. testing_paths.lua_interpreter | 645 | local location = lua_bindir .. "/" .. testing_paths.lua_exe |
646 | if test_env.exists(location) then | 646 | if exists(location) then |
647 | testing_paths.lua_bindir = lua_bindir | 647 | testing_paths.lua_bindir = lua_bindir |
648 | testing_paths.luadir = luadir | 648 | testing_paths.luadir = luadir |
649 | testing_paths.lua = location | 649 | testing_paths.lua = location |
@@ -651,44 +651,57 @@ local function found_interpreter(testing_paths, luadir, lua_bindir) | |||
651 | end | 651 | end |
652 | end | 652 | end |
653 | 653 | ||
654 | local function create_paths(luaversion_full) | 654 | local function find_lua() |
655 | -- (1) LUA is a full path | ||
656 | if test_env.LUA and test_env.LUA:match("[/\\]") then | ||
655 | 657 | ||
656 | local testing_paths = {} | 658 | local lua_bindir = test_env.LUA:match("^(.-)[/\\][^/\\]*$") |
657 | local try_dirs | 659 | local luadir = test_env.LUA_DIR or lua_bindir:gsub("[/\\]bin$") |
660 | local lua = test_env.LUA | ||
658 | 661 | ||
659 | if test_env.TEST_TARGET_OS == "windows" then | 662 | return lua_bindir, luadir, lua |
660 | try_dirs = { os.getenv("ProgramFiles(x86)").."/LuaRocks" } | ||
661 | testing_paths.luarocks_tmp = os.getenv("TEMP") | ||
662 | testing_paths.lua_interpreter = "lua.exe" | ||
663 | else | ||
664 | try_dirs = { "/usr/local", "/usr" } | ||
665 | testing_paths.luarocks_tmp = "/tmp/luarocks_testing" | ||
666 | testing_paths.lua_interpreter = "lua" | ||
667 | end | 663 | end |
668 | 664 | ||
665 | -- (2) LUA is just the interpreter name | ||
666 | local lua_exe = test_env.LUA | ||
667 | or ((test_env.TEST_TARGET_OS == "windows") and "lua.exe") | ||
668 | or "lua" | ||
669 | |||
670 | -- (2.1) LUA_DIR was given | ||
669 | if test_env.LUA_DIR then | 671 | if test_env.LUA_DIR then |
670 | table.insert(try_dirs, 1, test_env.LUA_DIR) | ||
671 | end | ||
672 | 672 | ||
673 | if test_env.LUA_INTERPRETER then | 673 | local luadir = test_env.LUA_DIR |
674 | testing_paths.lua_interpreter = test_env.LUA_INTERPRETER | 674 | local lua_bindir = exists(luadir .. "/bin") |
675 | end | 675 | and luadir .. "/bin" |
676 | or luadir | ||
677 | local lua = lua_bindir .. "/" .. lua_exe | ||
676 | 678 | ||
677 | local bindir, interp = testing_paths.lua_interpreter:match("^(.-)[/\\]([^/\\]*)$") | 679 | return lua_bindir, luadir, lua |
678 | if bindir and interp then | ||
679 | testing_paths.lua_interpreter = interp | ||
680 | try_dirs = { bindir } | ||
681 | end | 680 | end |
682 | 681 | ||
683 | for _, try_dir in ipairs(try_dirs) do | 682 | -- (2.2) LUA_DIR was not given, try some default paths |
684 | if found_interpreter(testing_paths, try_dir, try_dir) | 683 | local try_dirs = (test_env.TEST_TARGET_OS == "windows") |
685 | or found_interpreter(testing_paths, try_dir, try_dir .. "/bin") | 684 | and { os.getenv("ProgramFiles(x86)").."/LuaRocks" } |
686 | then | 685 | or { "/usr/local", "/usr" } |
687 | break | 686 | |
687 | for _, luadir in ipairs(try_dirs) do | ||
688 | for _, lua_bindir in ipairs({ luadir, luadir .. "/bin" }) do | ||
689 | local lua = lua_bindir .. "/" .. lua_exe | ||
690 | if exists(lua) then | ||
691 | return lua_bindir, luadir, lua | ||
692 | end | ||
688 | end | 693 | end |
689 | end | 694 | end |
695 | end | ||
696 | |||
697 | local function create_paths(luaversion_full) | ||
690 | 698 | ||
691 | assert(testing_paths.lua, "Lua interpreter not found! Run `busted -Xhelper help` for options") | 699 | local testing_paths = {} |
700 | |||
701 | testing_paths.lua_bindir, testing_paths.luadir, testing_paths.lua = find_lua() | ||
702 | if (not testing_paths.lua) or (not exists(testing_paths.lua)) then | ||
703 | error("Lua interpreter not found! Run `busted -Xhelper help` for options") | ||
704 | end | ||
692 | 705 | ||
693 | local base_dir = lfs.currentdir() | 706 | local base_dir = lfs.currentdir() |
694 | 707 | ||
@@ -714,6 +727,12 @@ local function create_paths(luaversion_full) | |||
714 | testing_paths.testing_sys_rocks = testing_paths.testing_sys_tree .. "/lib/luarocks/rocks-" .. test_env.lua_version | 727 | testing_paths.testing_sys_rocks = testing_paths.testing_sys_tree .. "/lib/luarocks/rocks-" .. test_env.lua_version |
715 | 728 | ||
716 | if test_env.TEST_TARGET_OS == "windows" then | 729 | if test_env.TEST_TARGET_OS == "windows" then |
730 | testing_paths.luarocks_tmp = os.getenv("TEMP") | ||
731 | else | ||
732 | testing_paths.luarocks_tmp = "/tmp/luarocks_testing" | ||
733 | end | ||
734 | |||
735 | if test_env.TEST_TARGET_OS == "windows" then | ||
717 | testing_paths.win_tools = base_dir .. "/win32/tools" | 736 | testing_paths.win_tools = base_dir .. "/win32/tools" |
718 | end | 737 | end |
719 | 738 | ||
@@ -739,7 +758,7 @@ function test_env.setup_specs(extra_rocks) | |||
739 | -- if global variable about successful creation of testing environment doesn't exist, build environment | 758 | -- if global variable about successful creation of testing environment doesn't exist, build environment |
740 | if not test_env.setup_done then | 759 | if not test_env.setup_done then |
741 | if test_env.CI then | 760 | if test_env.CI then |
742 | if not test_env.exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then | 761 | if not exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then |
743 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") | 762 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") |
744 | execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") | 763 | execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") |
745 | execute_bool("chmod og-wx ~/.ssh/authorized_keys") | 764 | execute_bool("chmod og-wx ~/.ssh/authorized_keys") |
@@ -914,7 +933,7 @@ local function setup_luarocks() | |||
914 | ("SYSCONFDIR = %q,"):format(testing_paths.testing_lrprefix .. "/etc/luarocks"), | 933 | ("SYSCONFDIR = %q,"):format(testing_paths.testing_lrprefix .. "/etc/luarocks"), |
915 | ("LUA_DIR = %q,"):format(testing_paths.luadir), | 934 | ("LUA_DIR = %q,"):format(testing_paths.luadir), |
916 | ("LUA_BINDIR = %q,"):format(testing_paths.lua_bindir), | 935 | ("LUA_BINDIR = %q,"):format(testing_paths.lua_bindir), |
917 | ("LUA_INTERPRETER = %q,"):format(testing_paths.lua_interpreter), | 936 | ("LUA = %q,"):format(testing_paths.lua), |
918 | } | 937 | } |
919 | 938 | ||
920 | if test_env.TEST_TARGET_OS == "windows" then | 939 | if test_env.TEST_TARGET_OS == "windows" then |
@@ -1083,6 +1102,7 @@ test_env.set_args() | |||
1083 | test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V) | 1102 | test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V) |
1084 | test_env.env_variables = create_env(test_env.testing_paths) | 1103 | test_env.env_variables = create_env(test_env.testing_paths) |
1085 | test_env.run = make_run_functions() | 1104 | test_env.run = make_run_functions() |
1105 | test_env.exists = exists | ||
1086 | test_env.V = V | 1106 | test_env.V = V |
1087 | 1107 | ||
1088 | return test_env | 1108 | return test_env |