diff options
author | Peter Melnichenko <mpeterval@gmail.com> | 2016-07-08 12:35:01 +0300 |
---|---|---|
committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-07-08 12:35:01 +0300 |
commit | 88f6aaeb40958c10a3c7a6fb4d0d699481f2a7be (patch) | |
tree | f7a0312de8faf54b12f572af10f12bec04dde0ed /test | |
parent | 88ac29f0cfbe4064155c7a1f5ea706627bd08ef2 (diff) | |
download | luarocks-88f6aaeb40958c10a3c7a6fb4d0d699481f2a7be.tar.gz luarocks-88f6aaeb40958c10a3c7a6fb4d0d699481f2a7be.tar.bz2 luarocks-88f6aaeb40958c10a3c7a6fb4d0d699481f2a7be.zip |
Tests: infer Lua/LuaJIT version
Diffstat (limited to 'test')
-rw-r--r-- | test/test_environment.lua | 52 |
1 files changed, 24 insertions, 28 deletions
diff --git a/test/test_environment.lua b/test/test_environment.lua index 6de501fb..fad862ce 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua | |||
@@ -11,10 +11,6 @@ local function help() | |||
11 | Tests require to have Lua installed and added to PATH. Be sure sshd is runnig on your system, or | 11 | Tests require to have Lua installed and added to PATH. Be sure sshd is runnig on your system, or |
12 | use '--exclude-tags=ssh', to not execute tests which require sshd. | 12 | use '--exclude-tags=ssh', to not execute tests which require sshd. |
13 | USAGE -Xhelper <arguments> | 13 | USAGE -Xhelper <arguments> |
14 | lua=<version> (mandatory) type your full version of Lua (e.g. --lua 5.2.4) | ||
15 | OR | ||
16 | luajit=<version> (mandatory) type your full version of LuaJIT (e.g. --luajit 2.0.3) | ||
17 | |||
18 | env=<type> (default:"minimal") type what kind of environment to use ["minimal", "full"] | 14 | env=<type> (default:"minimal") type what kind of environment to use ["minimal", "full"] |
19 | clean remove existing testing environment | 15 | clean remove existing testing environment |
20 | travis add just if running on TravisCI | 16 | travis add just if running on TravisCI |
@@ -70,50 +66,49 @@ local function execute_output(command, print_command, env_variables) | |||
70 | return output:gsub("\n","") -- output adding new line, need to be removed | 66 | return output:gsub("\n","") -- output adding new line, need to be removed |
71 | end | 67 | end |
72 | 68 | ||
69 | --- Set test_env.LUA_V or test_env.LUAJIT_V based | ||
70 | -- on version of Lua used to run this script. | ||
71 | function test_env.set_lua_version() | ||
72 | if _G.jit then | ||
73 | test_env.LUAJIT_V = _G.jit.version:match("(2%.%d)%.%d") | ||
74 | else | ||
75 | test_env.LUA_V = _VERSION:match("5%.%d") | ||
76 | end | ||
77 | end | ||
78 | |||
73 | --- Set all arguments from input into global variables | 79 | --- Set all arguments from input into global variables |
74 | function test_env.set_args() | 80 | function test_env.set_args() |
75 | if arg[1] == nil then | 81 | if arg[1] == nil then |
76 | help() | 82 | help() |
77 | end | 83 | end |
78 | 84 | ||
79 | local args_position | 85 | local helper_arg |
80 | 86 | ||
81 | for i=1, #arg do | 87 | for i=1, #arg do |
82 | if arg[i]:find("-Xhelper") and arg[i+1]:find("lua=") and not arg[i+1]:find("luajit=") then | 88 | if arg[i] == "-Xhelper" then |
83 | args_position = i+1 | 89 | helper_arg = arg[i+1] |
84 | test_env.LUA_V = arg[args_position]:gsub("(.*)lua=([^%,]+)(.*)","%2") | 90 | break |
85 | break | ||
86 | elseif arg[i]:find("-Xhelper") and not arg[i+1]:find("lua=") and arg[i+1]:find("luajit=") then | ||
87 | args_position = i+1 | ||
88 | test_env.LUAJIT_V = arg[args_position]:gsub("(.*)luajit=([^%,]+)(.*)","%2") | ||
89 | break | ||
90 | elseif arg[i]:find("-Xhelper") and arg[i+1]:find("lua=") and arg[i+1]:find("luajit=") then | ||
91 | print("Please specify just Lua or LuaJIT version for testing in format 'lua=X.X.X' or 'luajit=X.X.X', for -Xhelper flag") | ||
92 | os.exit(1) | ||
93 | elseif arg[i]:find("-Xhelper") and not arg[i+1]:find("lua=") and not arg[i+1]:find("luajit=") then | ||
94 | print("Please add mandatory argument - version of Lua or LuaJIT in format 'lua=X.X.X' or 'luajit=X.X.X', for -Xhelper flag") | ||
95 | os.exit(1) | ||
96 | end | 91 | end |
97 | end | 92 | end |
98 | 93 | ||
99 | if not args_position then | 94 | if not helper_arg then |
100 | help() | 95 | help() |
101 | end | 96 | end |
102 | 97 | ||
103 | -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables | 98 | -- if at least Lua/LuaJIT version argument was found on input start to parse other arguments to env. variables |
104 | test_env.TYPE_TEST_ENV = "minimal" | 99 | test_env.TYPE_TEST_ENV = "minimal" |
105 | 100 | ||
106 | if arg[args_position]:find("env=") then | 101 | if helper_arg:find("env=") then |
107 | test_env.TYPE_TEST_ENV = arg[args_position]:gsub("(.*)env=([^%,]+)(.*)","%2") | 102 | test_env.TYPE_TEST_ENV = helper_arg:gsub("(.*)env=([^%,]+)(.*)","%2") |
108 | end | 103 | end |
109 | if arg[args_position]:find("clean") then | 104 | if helper_arg:find("clean") then |
110 | test_env.TEST_ENV_CLEAN = true | 105 | test_env.TEST_ENV_CLEAN = true |
111 | end | 106 | end |
112 | if arg[args_position]:find("travis") then | 107 | if helper_arg:find("travis") then |
113 | test_env.TRAVIS = true | 108 | test_env.TRAVIS = true |
114 | end | 109 | end |
115 | if arg[args_position]:find("os=") then | 110 | if helper_arg:find("os=") then |
116 | test_env.TEST_TARGET_OS = arg[args_position]:gsub("(.*)os=([^%,]+)(.*)","%2") | 111 | test_env.TEST_TARGET_OS = helper_arg:gsub("(.*)os=([^%,]+)(.*)","%2") |
117 | end | 112 | end |
118 | 113 | ||
119 | if not test_env.TEST_TARGET_OS then | 114 | if not test_env.TEST_TARGET_OS then |
@@ -418,6 +413,7 @@ end | |||
418 | function test_env.setup_specs(extra_rocks, luaversion_full) | 413 | function test_env.setup_specs(extra_rocks, luaversion_full) |
419 | -- if global variable about successful creation of testing environment doesn't exists, build environment | 414 | -- if global variable about successful creation of testing environment doesn't exists, build environment |
420 | if not test_env.setup_done then | 415 | if not test_env.setup_done then |
416 | test_env.set_lua_version() | ||
421 | test_env.set_args() | 417 | test_env.set_args() |
422 | 418 | ||
423 | if test_env.TRAVIS then | 419 | if test_env.TRAVIS then |