aboutsummaryrefslogtreecommitdiff
path: root/spec/util/test_env.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/util/test_env.lua')
-rw-r--r--spec/util/test_env.lua24
1 files changed, 18 insertions, 6 deletions
diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua
index 2232de87..e318128e 100644
--- a/spec/util/test_env.lua
+++ b/spec/util/test_env.lua
@@ -1,6 +1,7 @@
1local lfs = require("lfs")
2local test_env = {} 1local test_env = {}
3 2
3local lfs = require("lfs")
4
4local help_message = [[ 5local help_message = [[
5LuaRocks test-suite 6LuaRocks test-suite
6 7
@@ -135,6 +136,11 @@ function test_env.execute_helper(command, print_command, env_variables)
135 return final_command 136 return final_command
136end 137end
137 138
139function test_env.execute(cmd)
140 local ok = os.execute(cmd)
141 return (ok == true or ok == 0) -- normalize Lua 5.1 output to boolean
142end
143
138--- Execute command and returns true/false 144--- Execute command and returns true/false
139-- @return true/false boolean: status of the command execution 145-- @return true/false boolean: status of the command execution
140local function execute_bool(command, print_command, env_variables) 146local function execute_bool(command, print_command, env_variables)
@@ -147,8 +153,7 @@ local function execute_bool(command, print_command, env_variables)
147 redirect = " > "..redirect_filename 153 redirect = " > "..redirect_filename
148 os.remove(redirect_filename) 154 os.remove(redirect_filename)
149 end 155 end
150 local ok = os.execute(command .. redirect) 156 local ok = test_env.execute(command .. redirect)
151 ok = (ok == true or ok == 0) -- normalize Lua 5.1 output to boolean
152 if redirect ~= "" then 157 if redirect ~= "" then
153 if not ok then 158 if not ok then
154 local fd = io.open(redirect_filename, "r") 159 local fd = io.open(redirect_filename, "r")
@@ -530,9 +535,13 @@ function test_env.unload_luarocks()
530 package.loaded[modname] = nil 535 package.loaded[modname] = nil
531 end 536 end
532 end 537 end
538 local src_pattern = test_env.testing_paths.src_dir .. "/?.lua"
539 if not package.path:find(src_pattern, 1, true) then
540 package.path = src_pattern .. ";" .. package.path
541 end
533end 542end
534 543
535--- Function for initially setup of environment, variables, md5sums for spec files 544--- Function for initial setup of environment, variables, md5sums for spec files
536function test_env.setup_specs(extra_rocks) 545function test_env.setup_specs(extra_rocks)
537 -- if global variable about successful creation of testing environment doesn't exist, build environment 546 -- if global variable about successful creation of testing environment doesn't exist, build environment
538 if not test_env.setup_done then 547 if not test_env.setup_done then
@@ -546,6 +555,10 @@ function test_env.setup_specs(extra_rocks)
546 end 555 end
547 556
548 test_env.main() 557 test_env.main()
558
559 -- preload before meddling with package.path
560 require("spec.util.git_repo")
561
549 package.path = test_env.env_variables.LUA_PATH 562 package.path = test_env.env_variables.LUA_PATH
550 563
551 test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').arch)\"", false, test_env.env_variables) 564 test_env.platform = execute_output(test_env.testing_paths.lua .. " -e \"print(require('luarocks.core.cfg').arch)\"", false, test_env.env_variables)
@@ -744,9 +757,8 @@ function test_env.mock_server_extra_rocks(more)
744end 757end
745 758
746function test_env.mock_server_init() 759function test_env.mock_server_init()
747 local assert = require("luassert")
748 local testing_paths = test_env.testing_paths 760 local testing_paths = test_env.testing_paths
749 assert.is_true(test_env.need_rock("restserver-xavante")) 761 assert(test_env.need_rock("restserver-xavante"))
750 local final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.util_dir .. "/mock-server.lua &", true, test_env.env_variables) 762 local final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.util_dir .. "/mock-server.lua &", true, test_env.env_variables)
751 os.execute(final_command) 763 os.execute(final_command)
752end 764end