diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2016-07-19 19:55:42 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-19 19:55:42 -0300 |
| commit | b4536ebabffae8b5b8c3f1cd2eb1063225254100 (patch) | |
| tree | c7658afc65573b60db6f94e0f4c9cbcb6fada343 /test/test_environment.lua | |
| parent | 42de075dd63cb35107c514b55c061bf43f3ed184 (diff) | |
| parent | 3945f90b0bd80024294b048a793bae526cad30e2 (diff) | |
| download | luarocks-b4536ebabffae8b5b8c3f1cd2eb1063225254100.tar.gz luarocks-b4536ebabffae8b5b8c3f1cd2eb1063225254100.tar.bz2 luarocks-b4536ebabffae8b5b8c3f1cd2eb1063225254100.zip | |
Merge pull request #592 from robooo/new-tests
New tests & verbose mode
Diffstat (limited to 'test/test_environment.lua')
| -rw-r--r-- | test/test_environment.lua | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/test/test_environment.lua b/test/test_environment.lua index eb545a47..5d1e8198 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua | |||
| @@ -36,12 +36,24 @@ local function exists(path) | |||
| 36 | return lfs.attributes(path, "mode") ~= nil | 36 | return lfs.attributes(path, "mode") ~= nil |
| 37 | end | 37 | end |
| 38 | 38 | ||
| 39 | function test_env.quiet(commad) | ||
| 40 | if not test_env.VERBOSE then | ||
| 41 | if test_env.TEST_TARGET_OS == "linux" or test_env.TEST_TARGET_OS == "osx" then | ||
| 42 | return commad .. " 1> /dev/null 2> /dev/null" | ||
| 43 | elseif test_env.TEST_TARGET_OS == "windows" then | ||
| 44 | return commad .. " 2> NUL 1> NUL" | ||
| 45 | end | ||
| 46 | else | ||
| 47 | return command | ||
| 48 | end | ||
| 49 | end | ||
| 50 | |||
| 39 | --- Helper function for execute_bool and execute_output | 51 | --- Helper function for execute_bool and execute_output |
| 40 | -- @param command string: command to execute | 52 | -- @param command string: command to execute |
| 41 | -- @param print_command boolean: print command if 'true' | 53 | -- @param print_command boolean: print command if 'true' |
| 42 | -- @param env_variables table: table of environment variables to export {FOO="bar", BAR="foo"} | 54 | -- @param env_variables table: table of environment variables to export {FOO="bar", BAR="foo"} |
| 43 | -- @return final_command string: concatenated command to execution | 55 | -- @return final_command string: concatenated command to execution |
| 44 | local function execute_helper(command, print_command, env_variables) | 56 | function test_env.execute_helper(command, print_command, env_variables) |
| 45 | local final_command = "" | 57 | local final_command = "" |
| 46 | 58 | ||
| 47 | if print_command then | 59 | if print_command then |
| @@ -66,7 +78,7 @@ end | |||
| 66 | -- In Lua5.1 os.execute returns numeric value, but in Lua5.2+ returns boolean | 78 | -- In Lua5.1 os.execute returns numeric value, but in Lua5.2+ returns boolean |
| 67 | -- @return true/false boolean: status of the command execution | 79 | -- @return true/false boolean: status of the command execution |
| 68 | local function execute_bool(command, print_command, env_variables) | 80 | local function execute_bool(command, print_command, env_variables) |
| 69 | command = execute_helper(command, print_command, env_variables) | 81 | command = test_env.execute_helper(command, print_command, env_variables) |
| 70 | 82 | ||
| 71 | local ok = os.execute(command) | 83 | local ok = os.execute(command) |
| 72 | return ok == true or ok == 0 | 84 | return ok == true or ok == 0 |
| @@ -75,7 +87,7 @@ end | |||
| 75 | --- Execute command and returns output of command | 87 | --- Execute command and returns output of command |
| 76 | -- @return output string: output the command execution | 88 | -- @return output string: output the command execution |
| 77 | local function execute_output(command, print_command, env_variables) | 89 | local function execute_output(command, print_command, env_variables) |
| 78 | command = execute_helper(command, print_command, env_variables) | 90 | command = test_env.execute_helper(command, print_command, env_variables) |
| 79 | 91 | ||
| 80 | local file = assert(io.popen(command)) | 92 | local file = assert(io.popen(command)) |
| 81 | local output = file:read('*all') | 93 | local output = file:read('*all') |
| @@ -106,6 +118,8 @@ function test_env.set_args() | |||
| 106 | test_env.RESET_ENV = false | 118 | test_env.RESET_ENV = false |
| 107 | elseif argument == "clean" then | 119 | elseif argument == "clean" then |
| 108 | test_env.TEST_ENV_CLEAN = true | 120 | test_env.TEST_ENV_CLEAN = true |
| 121 | elseif argument == "verbose" then | ||
| 122 | test_env.VERBOSE = true | ||
| 109 | elseif argument == "travis" then | 123 | elseif argument == "travis" then |
| 110 | test_env.TRAVIS = true | 124 | test_env.TRAVIS = true |
| 111 | elseif argument:find("^os=") then | 125 | elseif argument:find("^os=") then |
| @@ -415,10 +429,11 @@ end | |||
| 415 | 429 | ||
| 416 | --- Test if required rock is installed if not, install it | 430 | --- Test if required rock is installed if not, install it |
| 417 | function test_env.need_rock(rock) | 431 | function test_env.need_rock(rock) |
| 418 | if test_env.run.luarocks_nocov("show " .. rock) then | 432 | print("Check if " .. rock .. " is installed") |
| 433 | if test_env.run.luarocks_noprint_nocov(test_env.quiet("show " .. rock)) then | ||
| 419 | return true | 434 | return true |
| 420 | else | 435 | else |
| 421 | return test_env.run.luarocks_nocov("install " .. rock) | 436 | return test_env.run.luarocks_noprint_nocov(test_env.quiet("install " .. rock)) |
| 422 | end | 437 | end |
| 423 | end | 438 | end |
| 424 | 439 | ||
| @@ -525,18 +540,20 @@ local function clean() | |||
| 525 | test_env.remove_subdirs(test_env.testing_paths.testing_dir, "testing[_%-]") | 540 | test_env.remove_subdirs(test_env.testing_paths.testing_dir, "testing[_%-]") |
| 526 | test_env.remove_files(test_env.testing_paths.testing_dir, "testing_") | 541 | test_env.remove_files(test_env.testing_paths.testing_dir, "testing_") |
| 527 | test_env.remove_files(test_env.testing_paths.testing_dir, "luacov") | 542 | test_env.remove_files(test_env.testing_paths.testing_dir, "luacov") |
| 543 | test_env.remove_files(test_env.testing_paths.testing_dir, "upload_config") | ||
| 528 | print("Cleaning done!") | 544 | print("Cleaning done!") |
| 529 | end | 545 | end |
| 530 | 546 | ||
| 531 | --- Install luarocks into testing prefix. | 547 | --- Install luarocks into testing prefix. |
| 532 | local function install_luarocks(install_env_vars) | 548 | local function install_luarocks(install_env_vars) |
| 533 | -- Configure LuaRocks testing environment | 549 | -- Configure LuaRocks testing environment |
| 534 | local configure_cmd = "./configure --with-lua=" .. test_env.testing_paths.luadir .. | 550 | title("Installing LuaRocks") |
| 535 | " --prefix=" .. test_env.testing_paths.testing_lrprefix .. | 551 | local configure_cmd = "./configure --with-lua=" .. test_env.testing_paths.luadir .. " --prefix=" .. test_env.testing_paths.testing_lrprefix |
| 536 | " && make clean" | 552 | assert(execute_bool(test_env.quiet(configure_cmd)), false, install_env_vars) |
| 537 | 553 | assert(execute_bool(test_env.quiet("make clean")), false, install_env_vars) | |
| 538 | assert(execute_bool(configure_cmd, false, install_env_vars)) | 554 | assert(execute_bool(test_env.quiet("make src/luarocks/site_config.lua")), false, install_env_vars) |
| 539 | assert(execute_bool("make src/luarocks/site_config.lua && make dev", false, install_env_vars)) | 555 | assert(execute_bool(test_env.quiet("make dev")), false, install_env_vars) |
| 556 | print("LuaRocks installed correctly!") | ||
| 540 | end | 557 | end |
| 541 | 558 | ||
| 542 | --- | 559 | --- |
