diff options
| author | Peter Melnichenko <mpeterval@gmail.com> | 2016-07-08 16:47:28 +0300 |
|---|---|---|
| committer | Peter Melnichenko <mpeterval@gmail.com> | 2016-07-08 17:44:03 +0300 |
| commit | 09315362c8c1eb78311586247ddd46f1add1aae6 (patch) | |
| tree | 0059dbfe295b4c94aa1d1f8b354497d502debaa8 /test/test_environment.lua | |
| parent | 325c7578cdd5421035930a3a7ee2bb385c10d8fc (diff) | |
| download | luarocks-09315362c8c1eb78311586247ddd46f1add1aae6.tar.gz luarocks-09315362c8c1eb78311586247ddd46f1add1aae6.tar.bz2 luarocks-09315362c8c1eb78311586247ddd46f1add1aae6.zip | |
Tests: add file/dir existence check utility function
Use it instead of os.rename(path, path).
Diffstat (limited to 'test/test_environment.lua')
| -rw-r--r-- | test/test_environment.lua | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/test/test_environment.lua b/test/test_environment.lua index 065a12c2..a48a59a3 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua | |||
| @@ -32,6 +32,10 @@ local function title(str) | |||
| 32 | print(("-"):rep(#str)) | 32 | print(("-"):rep(#str)) |
| 33 | end | 33 | end |
| 34 | 34 | ||
| 35 | local function exists(path) | ||
| 36 | return lfs.attributes(path, "mode") ~= nil | ||
| 37 | end | ||
| 38 | |||
| 35 | --- Helper function for execute_bool and execute_output | 39 | --- Helper function for execute_bool and execute_output |
| 36 | -- @param command string: command to execute | 40 | -- @param command string: command to execute |
| 37 | -- @param print_command boolean: print command if 'true' | 41 | -- @param print_command boolean: print command if 'true' |
| @@ -125,7 +129,7 @@ end | |||
| 125 | --- Remove directory recursively | 129 | --- Remove directory recursively |
| 126 | -- @param path string: directory path to delete | 130 | -- @param path string: directory path to delete |
| 127 | function test_env.remove_dir(path) | 131 | function test_env.remove_dir(path) |
| 128 | if lfs.attributes(path) then | 132 | if exists(path) then |
| 129 | for file in lfs.dir(path) do | 133 | for file in lfs.dir(path) do |
| 130 | if file ~= "." and file ~= ".." then | 134 | if file ~= "." and file ~= ".." then |
| 131 | local full_path = path..'/'..file | 135 | local full_path = path..'/'..file |
| @@ -145,7 +149,7 @@ end | |||
| 145 | -- @param path string: path to directory | 149 | -- @param path string: path to directory |
| 146 | -- @param pattern string: pattern matching basenames of subdirectories to be removed | 150 | -- @param pattern string: pattern matching basenames of subdirectories to be removed |
| 147 | function test_env.remove_subdirs(path, pattern) | 151 | function test_env.remove_subdirs(path, pattern) |
| 148 | if lfs.attributes(path) then | 152 | if exists(path) then |
| 149 | for file in lfs.dir(path) do | 153 | for file in lfs.dir(path) do |
| 150 | if file ~= "." and file ~= ".." then | 154 | if file ~= "." and file ~= ".." then |
| 151 | local full_path = path..'/'..file | 155 | local full_path = path..'/'..file |
| @@ -164,7 +168,7 @@ end | |||
| 164 | -- @return result_check boolean: true if one or more files deleted | 168 | -- @return result_check boolean: true if one or more files deleted |
| 165 | function test_env.remove_files(path, pattern) | 169 | function test_env.remove_files(path, pattern) |
| 166 | local result_check = false | 170 | local result_check = false |
| 167 | if lfs.attributes(path) then | 171 | if exists(path) then |
| 168 | for file in lfs.dir(path) do | 172 | for file in lfs.dir(path) do |
| 169 | if file ~= "." and file ~= ".." then | 173 | if file ~= "." and file ~= ".." then |
| 170 | if file:find(pattern) then | 174 | if file:find(pattern) then |
| @@ -189,7 +193,7 @@ local function download_rocks(urls, save_path) | |||
| 189 | 193 | ||
| 190 | for _, url in ipairs(urls) do | 194 | for _, url in ipairs(urls) do |
| 191 | -- check if already downloaded | 195 | -- check if already downloaded |
| 192 | if not os.rename(save_path .. url, save_path .. url) then | 196 | if not exists(save_path .. url) then |
| 193 | execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url) | 197 | execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url) |
| 194 | make_manifest = true | 198 | make_manifest = true |
| 195 | end | 199 | end |
| @@ -346,21 +350,19 @@ local function create_paths(luaversion_full) | |||
| 346 | if test_env.TRAVIS then | 350 | if test_env.TRAVIS then |
| 347 | testing_paths.luadir = lfs.currentdir() .. "/lua_install" | 351 | testing_paths.luadir = lfs.currentdir() .. "/lua_install" |
| 348 | testing_paths.lua = testing_paths.luadir .. "/bin/lua" | 352 | testing_paths.lua = testing_paths.luadir .. "/bin/lua" |
| 349 | end | 353 | elseif test_env.LUA_V then |
| 350 | 354 | if exists("/usr/bin/lua") then | |
| 351 | if test_env.LUA_V and not test_env.TRAVIS then | ||
| 352 | if lfs.attributes("/usr/bin/lua") then | ||
| 353 | testing_paths.luadir = "/usr" | 355 | testing_paths.luadir = "/usr" |
| 354 | testing_paths.lua = testing_paths.luadir .. "/bin/lua" | 356 | testing_paths.lua = testing_paths.luadir .. "/bin/lua" |
| 355 | elseif lfs.attributes("/usr/local/bin/lua") then | 357 | elseif exists("/usr/local/bin/lua") then |
| 356 | testing_paths.luadir = "/usr/local" | 358 | testing_paths.luadir = "/usr/local" |
| 357 | testing_paths.lua = testing_paths.luadir .. "/bin/lua" | 359 | testing_paths.lua = testing_paths.luadir .. "/bin/lua" |
| 358 | end | 360 | end |
| 359 | elseif test_env.LUAJIT_V and not test_env.TRAVIS then | 361 | elseif test_env.LUAJIT_V then |
| 360 | if lfs.attributes("/usr/bin/luajit") then | 362 | if exists("/usr/bin/luajit") then |
| 361 | testing_paths.luadir = "/usr" | 363 | testing_paths.luadir = "/usr" |
| 362 | testing_paths.lua = testing_paths.luadir .. "/bin/luajit" | 364 | testing_paths.lua = testing_paths.luadir .. "/bin/luajit" |
| 363 | elseif lfs.attributes("/usr/local/bin/luajit") then | 365 | elseif exists("/usr/local/bin/luajit") then |
| 364 | testing_paths.luadir = "/usr/local" | 366 | testing_paths.luadir = "/usr/local" |
| 365 | testing_paths.lua = testing_paths.luadir .. "/bin/luajit" | 367 | testing_paths.lua = testing_paths.luadir .. "/bin/luajit" |
| 366 | end | 368 | end |
| @@ -397,7 +399,7 @@ function test_env.setup_specs(extra_rocks) | |||
| 397 | -- if global variable about successful creation of testing environment doesn't exists, build environment | 399 | -- if global variable about successful creation of testing environment doesn't exists, build environment |
| 398 | if not test_env.setup_done then | 400 | if not test_env.setup_done then |
| 399 | if test_env.TRAVIS then | 401 | if test_env.TRAVIS then |
| 400 | if not os.rename(os.getenv("HOME") .. "/.ssh/id_rsa.pub", os.getenv("HOME") .. "/.ssh/id_rsa.pub") then | 402 | if not exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then |
| 401 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") | 403 | execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") |
| 402 | execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") | 404 | execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") |
| 403 | execute_bool("chmod og-wx ~/.ssh/authorized_keys") | 405 | execute_bool("chmod og-wx ~/.ssh/authorized_keys") |
| @@ -431,7 +433,7 @@ function test_env.need_luasocket() | |||
| 431 | else | 433 | else |
| 432 | local testing_cache = test_env.testing_paths.testing_cache .. "/" | 434 | local testing_cache = test_env.testing_paths.testing_cache .. "/" |
| 433 | local luasocket_rock = "luasocket-3.0rc1-1." .. test_env.platform .. ".rock" | 435 | local luasocket_rock = "luasocket-3.0rc1-1." .. test_env.platform .. ".rock" |
| 434 | if not os.rename( testing_cache .. luasocket_rock, testing_cache .. luasocket_rock) then | 436 | if not exists(testing_cache .. luasocket_rock) then |
| 435 | test_env.run.luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1") | 437 | test_env.run.luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1") |
| 436 | os.rename(luasocket_rock, testing_cache .. luasocket_rock) | 438 | os.rename(luasocket_rock, testing_cache .. luasocket_rock) |
| 437 | end | 439 | end |
