From 54cf8ad4d527b0585f364b3d6cbe2c9eae58c3da Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 13:36:24 +0300 Subject: Test suite: use test/test_environment as busted helper When parsing test options, instead of directly looking for '-Xhelper' in arguments and splitting the next arguments on commas add .busted config to set test/test_environment as busted helper. Then busted will do the splitting on its own and set global arg to split options. --- .busted | 5 +++++ test/test_environment.lua | 42 +++++++++++++----------------------------- 2 files changed, 18 insertions(+), 29 deletions(-) create mode 100644 .busted diff --git a/.busted b/.busted new file mode 100644 index 00000000..7c67e719 --- /dev/null +++ b/.busted @@ -0,0 +1,5 @@ +return { + default = { + helper = "test/test_environment" + } +} diff --git a/test/test_environment.lua b/test/test_environment.lua index fad862ce..bde43163 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -1,6 +1,6 @@ local lfs = require("lfs") local test_env = {} -local arg = arg or { ... } +local arg = arg local function help() print("LuaRocks test-suite\n\n".. @@ -78,37 +78,21 @@ end --- Set all arguments from input into global variables function test_env.set_args() - if arg[1] == nil then - help() - end - - local helper_arg - - for i=1, #arg do - if arg[i] == "-Xhelper" then - helper_arg = arg[i+1] - break - end - end - - if not helper_arg then - help() - end - -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables test_env.TYPE_TEST_ENV = "minimal" - if helper_arg:find("env=") then - test_env.TYPE_TEST_ENV = helper_arg:gsub("(.*)env=([^%,]+)(.*)","%2") - end - if helper_arg:find("clean") then - test_env.TEST_ENV_CLEAN = true - end - if helper_arg:find("travis") then - test_env.TRAVIS = true - end - if helper_arg:find("os=") then - test_env.TEST_TARGET_OS = helper_arg:gsub("(.*)os=([^%,]+)(.*)","%2") + for _, argument in ipairs(arg) do + if argument:find("^env=") then + test_env.TYPE_TEST_ENV = argument:match("^env=(.*)$") + elseif argument == "clean" then + test_env.TEST_ENV_CLEAN = true + elseif argument == "travis" then + test_env.TRAVIS = true + elseif argument:find("^os=") then + test_env.TEST_TARGET_OS = argument:match("^os=(.*)$") + else + help() + end end if not test_env.TEST_TARGET_OS then -- cgit v1.2.3-55-g6feb