From 0e8089c20e43e92e9351a71e92396b83faf23632 Mon Sep 17 00:00:00 2001 From: George Roman <george.roman.99@gmail.com> Date: Thu, 24 May 2018 09:46:33 +0300 Subject: Make the mock server run on Windows --- appveyor.yml | 2 +- spec/util/mock-server.lua | 2 +- spec/util/test_env.lua | 26 +++++++++++++++++++++----- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 87e49122..33d1033b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -46,7 +46,7 @@ build_script: - luarocks install cluacov 1> NUL 2> NUL test_script: - - busted -o gtest -v --lpath=.//?.lua --exclude-tags=ssh,unix,mock -Xhelper lua_dir=%CD%\lua_install,appveyor,%COMPILER% + - busted -o gtest -v --lpath=.//?.lua --exclude-tags=ssh,unix -Xhelper lua_dir=%CD%\lua_install,appveyor,%COMPILER% after_test: - pip install codecov diff --git a/spec/util/mock-server.lua b/spec/util/mock-server.lua index ae41b964..8e498d57 100644 --- a/spec/util/mock-server.lua +++ b/spec/util/mock-server.lua @@ -71,7 +71,7 @@ server:add_resource("/file/{name:[^/]+}", { produces = "text/plain", handler = function(query, name) local basedir = arg[1] or "./spec/fixtures" - local fd = io.open(basedir .. "/" .. name, "r") + local fd = io.open(basedir .. "/" .. name, "rb") if not fd then return restserver.response():status(404) end diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index f55fb53a..48914311 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua @@ -380,8 +380,12 @@ local function create_env(testing_paths) env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;" - env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" - .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" + local lib_extension = "so" + if test_env.TEST_TARGET_OS == "windows" then + lib_extension = "dll" + end + env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?." .. lib_extension .. ";" + .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?." .. lib_extension .. ";" env_variables.PATH = os.getenv("PATH") .. ";" .. testing_paths.testing_tree .. "/bin;" .. testing_paths.testing_sys_tree .. "/bin;" return env_variables @@ -764,13 +768,25 @@ end function test_env.mock_server_init() local testing_paths = test_env.testing_paths assert(test_env.need_rock("restserver-xavante")) - local final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.util_dir .. "/mock-server.lua " .. testing_paths.fixtures_dir .. " &", true, test_env.env_variables) + local final_command + local sleep_command + if test_env.TEST_TARGET_OS == "windows" then + final_command = 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) + sleep_command = "timeout 1 > NUL" + else + final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.util_dir .. "/mock-server.lua " .. testing_paths.fixtures_dir .. " &", true, test_env.env_variables) + sleep_command = "sleep 1" + end os.execute(final_command) - os.execute("sleep 1") + os.execute(sleep_command) end function test_env.mock_server_done() - os.execute("curl localhost:8080/shutdown") + if test_env.TEST_TARGET_OS == "windows" then + os.execute(Q(test_env.testing_paths.win_tools .. "/wget") .. " --quiet --timeout=5 --tries=1 localhost:8080/shutdown") + else + os.execute("curl localhost:8080/shutdown") + end end --- -- cgit v1.2.3-55-g6feb