Skip to content

Commit

Permalink
Test suite: use test/test_environment as busted helper
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mpeterv committed Jul 8, 2016
1 parent fc7d6f7 commit 54cf8ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return {
default = {
helper = "test/test_environment"
}
}
42 changes: 13 additions & 29 deletions test/test_environment.lua
Original file line number Diff line number Diff line change
@@ -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"..
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 54cf8ad

Please sign in to comment.