From 5f069526966ae37319ba745644a43e0cf64ad62c Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Tue, 5 Jul 2016 15:24:01 +0300 Subject: Fix field name building in type_check.lua Use 'parent[field]' notation for non-string fields. --- src/luarocks/type_check.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/luarocks/type_check.lua b/src/luarocks/type_check.lua index 82763401..63c59ca2 100644 --- a/src/luarocks/type_check.lua +++ b/src/luarocks/type_check.lua @@ -234,9 +234,12 @@ end local function mkfield(context, field) if context == "" then - return field + return tostring(field) + elseif type(field) == "string" then + return context.."."..field + else + return context.."["..tostring(field).."]" end - return context.."."..field end --- Type check the contents of a table. -- cgit v1.2.3-55-g6feb From b5b285a678fe78b80d452cc9eb7565b8bf087b81 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Tue, 5 Jul 2016 15:46:43 +0300 Subject: Fix implicit number-to-string coversion in luarocks.help --- src/luarocks/help.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/luarocks/help.lua b/src/luarocks/help.lua index 28f97702..871e97e9 100644 --- a/src/luarocks/help.lua +++ b/src/luarocks/help.lua @@ -65,7 +65,7 @@ function help.command(flags, command) --verbose Display verbose output of commands executed. --timeout= Timeout on network operations, in seconds. 0 means no timeout (wait forever). - Default is ]]..cfg.connection_timeout..[[.]]) + Default is ]]..tostring(cfg.connection_timeout)..[[.]]) print_section("VARIABLES") util.printout([[ Variables from the "variables" table of the configuration file -- cgit v1.2.3-55-g6feb From 5af7e0d7c2dcf65e41ae8523f3771e9528be32a7 Mon Sep 17 00:00:00 2001 From: robooo Date: Thu, 7 Jul 2016 21:58:19 +0200 Subject: New test-suite for LuaRocks (#581) First version of new test-suite, using Busted framework based on Google Summer of Code project: https://summerofcode.withgoogle.com/projects/#5695811874717696 * Rewritten from Bash to Lua * Tests now check if they did what they were supposed to, beyond only checking success or failure of the `luarocks` command * Support for black-box (launching `luarocks` as an external command) and white-box (testing functions in modules directly) testing --- .travis.yml | 74 ++++- spec/add_spec.lua | 46 +++ spec/build_spec.lua | 182 ++++++++++++ spec/config_spec.lua | 90 ++++++ spec/deps_spec.lua | 115 ++++++++ spec/doc_spec.lua | 57 ++++ spec/download_spec.lua | 37 +++ spec/fetch_spec.lua | 16 ++ spec/help_spec.lua | 29 ++ spec/install_spec.lua | 130 +++++++++ spec/lint_spec.lua | 51 ++++ spec/list_spec.lua | 41 +++ spec/make_manifest_spec.lua | 19 ++ spec/make_spec.lua | 99 +++++++ spec/new_version_spec.lua | 53 ++++ spec/pack_spec.lua | 35 +++ spec/path_spec.lua | 28 ++ spec/purge_spec.lua | 30 ++ spec/refresh_cache_spec.lua | 19 ++ spec/remove_spec.lua | 85 ++++++ spec/search_spec.lua | 42 +++ spec/show_spec.lua | 56 ++++ spec/unpack_spec.lua | 61 ++++ spec/upload_spec.lua | 41 +++ spec/util_spec.lua | 96 +++++++ spec/write_rockspec_spec.lua | 74 +++++ test/README.md | 59 ++++ test/test_environment.lua | 625 +++++++++++++++++++++++++++++++++++++++++ test/testing.lua | 483 -------------------------------- test/testing.sh | 651 ------------------------------------------- 30 files changed, 2281 insertions(+), 1143 deletions(-) create mode 100644 spec/add_spec.lua create mode 100644 spec/build_spec.lua create mode 100644 spec/config_spec.lua create mode 100644 spec/deps_spec.lua create mode 100644 spec/doc_spec.lua create mode 100644 spec/download_spec.lua create mode 100644 spec/fetch_spec.lua create mode 100644 spec/help_spec.lua create mode 100644 spec/install_spec.lua create mode 100644 spec/lint_spec.lua create mode 100644 spec/list_spec.lua create mode 100644 spec/make_manifest_spec.lua create mode 100644 spec/make_spec.lua create mode 100644 spec/new_version_spec.lua create mode 100644 spec/pack_spec.lua create mode 100644 spec/path_spec.lua create mode 100644 spec/purge_spec.lua create mode 100644 spec/refresh_cache_spec.lua create mode 100644 spec/remove_spec.lua create mode 100644 spec/search_spec.lua create mode 100644 spec/show_spec.lua create mode 100644 spec/unpack_spec.lua create mode 100644 spec/upload_spec.lua create mode 100644 spec/util_spec.lua create mode 100644 spec/write_rockspec_spec.lua create mode 100644 test/README.md create mode 100644 test/test_environment.lua delete mode 100644 test/testing.lua delete mode 100755 test/testing.sh diff --git a/.travis.yml b/.travis.yml index 69ec28f3..c8755e7f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,69 @@ -language: c +language: python -compiler: gcc +matrix: + include: + - os: linux + env: + - LUA="lua=5.1" + - os: linux + env: + - LUA="lua=5.2" + - os: linux + env: + - LUA="lua=5.3" + - os: linux + env: + - LUA="luajit=2.0" + - os: linux + env: + - LUA="luajit=2.1" + - os: osx + language: generic + env: + - LUA="lua=5.1" + - os: osx + language: generic + env: + - LUA="lua=5.2" + - os: osx + language: generic + env: + - LUA="lua=5.3" + - os: osx + language: generic + env: + - LUA="luajit=2.0" + - os: osx + language: generic + env: + - LUA="luajit=2.1" -sudo: false -env: - matrix: - - LUA_VER=5.1.5 - - LUA_VER=5.2.4 - - LUA_VER=5.3.1 +before_install: + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install python3; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then virtualenv venv -p python3; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then source venv/bin/activate; fi -script: cd test && ./testing.sh --travis --lua $LUA_VER + - pip install hererocks + - hererocks lua_install -r^ --$LUA + - export PATH=$PATH:$PWD/lua_install/bin # Add directory with all installed binaries to PATH + +install: + - luarocks install busted + - luarocks install luacov + - luarocks install luacov-coveralls + +script: + - busted -Xhelper travis,$LUA --verbose + - busted -Xhelper travis,$LUA,env=full --verbose + +after_success: + - luacov-coveralls -c $TRAVIS_BUILD_DIR/test/luacov.config --exclude $TRAVIS_BUILD_DIR/test/ + - $PWD/lua_install/bin/luacov -c $TRAVIS_BUILD_DIR/test/luacov.config + - grep "Summary" -B1 -A1000 $TRAVIS_BUILD_DIR/test/luacov.report.out + +notifications: + email: + on_success: change + on_failure: change \ No newline at end of file diff --git a/spec/add_spec.lua b/spec/add_spec.lua new file mode 100644 index 00000000..e417f974 --- /dev/null +++ b/spec/add_spec.lua @@ -0,0 +1,46 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local add = require("luarocks.add") + +local extra_rocks = { + "/luasocket-3.0rc1-1.src.rock", + "/luasocket-3.0rc1-1.rockspec" +} + +expose("LuaRocks add tests #blackbox #b_add", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + testing_paths = test_env.testing_paths + run = test_env.run + end) + + describe("LuaRocks-admin add tests", function() + it("LuaRocks-admin add invalid rock #ssh", function() + assert.is_false(run.luarocks_admin_bool("--server=testing add invalid")) + end) + + it("LuaRocks-admin add missing argument", function() + assert.is_false(run.luarocks_admin_bool("--server=testing add")) + end) + + it("LuaRocks-admin add invalid server", function() + assert.is_false(run.luarocks_admin_bool("--server=invalid add " .. testing_paths.testing_server .. "/luasocket-3.0rc1-1.src.rock")) + end) + + it("LuaRocks-admin add invalid server #ssh", function() + assert.is_true(run.luarocks_admin_bool("--server=testing add " .. testing_paths.testing_server .. "/luasocket-3.0rc1-1.src.rock")) + end) + + --TODO This test fails, sftp not implemented + it("LuaRocks-admin add invalid server", function() --? + assert.is_false(run.luarocks_admin_bool("--server=testing add luasocket-3.0rc1-1.src.rock", { LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config_sftp.lua" } )) + end) + + it("LuaRocks-admin add, split server url", function() + assert.is_false(run.luarocks_admin_bool("--server=\"localhost@/tmp/luarocks_testing\" add " .. testing_paths.testing_server .. "luasocket-3.0rc1-1.src.rock")) + end) + end) +end) \ No newline at end of file diff --git a/spec/build_spec.lua b/spec/build_spec.lua new file mode 100644 index 00000000..6665de0b --- /dev/null +++ b/spec/build_spec.lua @@ -0,0 +1,182 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local build = require("luarocks.build") + +local extra_rocks = { + "/lmathx-20120430.51-1.src.rock", + "/lmathx-20120430.51-1.rockspec", + "/lmathx-20120430.52-1.src.rock", + "/lmathx-20120430.52-1.rockspec", + "/lmathx-20150505-1.src.rock", + "/lmathx-20150505-1.rockspec", + "/lpeg-0.12-1.src.rock", + "/lpty-1.0.1-1.src.rock", + "/luadoc-3.0.1-1.src.rock", + "/luafilesystem-1.6.3-1.src.rock", + "/lualogging-1.3.0-1.src.rock", + "/luarepl-0.4-1.src.rock", + "/luasec-0.6-1.rockspec", + "/luasocket-3.0rc1-1.src.rock", + "/luasocket-3.0rc1-1.rockspec", + "/lxsh-0.8.6-2.src.rock", + "/lxsh-0.8.6-2.rockspec", + "/stdlib-41.0.0-1.src.rock", + "/validate-args-1.5.4-1.rockspec" +} + +expose("LuaRocks build tests #blackbox #b_build", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + testing_paths = test_env.testing_paths + run = test_env.run + end) + + describe("LuaRocks build - basic testing set", function() + it("LuaRocks build with no flags/arguments", function() + assert.is_false(run.luarocks_bool("build")) + end) + + it("LuaRocks build invalid", function() + assert.is_false(run.luarocks_bool("build invalid")) + end) + end) + + describe("LuaRocks build - building lpeg with flags", function() + it("LuaRocks build fail build permissions", function() + if test_env.TEST_TARGET_OS == "osx" or test_env.TEST_TARGET_OS == "linux" then + assert.is_false(run.luarocks_bool("build --tree=/usr lpeg")) + end + end) + + it("LuaRocks build fail build permissions parent", function() + if test_env.TEST_TARGET_OS == "osx" or test_env.TEST_TARGET_OS == "linux" then + assert.is_false(run.luarocks_bool("build --tree=/usr/invalid lpeg")) + end + end) + + it("LuaRocks build lpeg verbose", function() + assert.is_true(run.luarocks_bool("build --verbose lpeg")) + end) + + it("LuaRocks build lpeg branch=master", function() + assert.is_true(run.luarocks_bool("build --branch=master lpeg")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) + end) + + it("LuaRocks build lpeg deps-mode=123", function() + assert.is_false(run.luarocks_bool("build --deps-mode=123 lpeg")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) + end) + + it("LuaRocks build lpeg only-sources example", function() + assert.is_true(run.luarocks_bool("build --only-sources=\"http://example.com\" lpeg")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) + end) + + it("LuaRocks build lpeg with empty tree", function() + assert.is_false(run.luarocks_bool("build --tree=\"\" lpeg")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) + end) + end) + + describe("LuaRocks build - basic builds", function() + + it("LuaRocks build luadoc", function() + assert.is_true(run.luarocks_bool("build luadoc")) + end) + + it("LuaRocks build luacov diff version", function() + assert.is_true(run.luarocks_bool("build luacov 0.11.0-1")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luacov")) + end) + + it("LuaRocks build command stdlib", function() + assert.is_true(run.luarocks_bool("build stdlib")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/stdlib")) + end) + + it("LuaRocks build install bin luarepl", function() + assert.is_true(run.luarocks_bool("build luarepl")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luarepl")) + end) + + it("LuaRocks build supported platforms lpty", function() + assert.is_true(run.luarocks_bool("build lpty")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpty")) + end) + + it("LuaRocks build luasec with skipping dependency checks", function() + assert.is_true(run.luarocks_bool("build luasec --nodeps")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasec")) + end) + + it("LuaRocks build lmathx deps partial match", function() + assert.is_true(run.luarocks_bool("build lmathx")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lmathx")) + end) + end) + + describe("LuaRocks build - more complex tests", function() + + it("LuaRocks build luacheck show downloads test_config", function() + local out = run.luarocks("build luacheck", { LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config_show_downloads.lua"} ) + print(out) + end) + + it("LuaRocks build luasec only deps", function() + assert.is_true(run.luarocks_bool("build luasec --only-deps")) + assert.is_false(run.luarocks_bool("show luasec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasec")) + end) + + it("LuaRocks build only deps of downloaded rockspec of lxsh", function() + assert.is_true(run.luarocks_bool("download --rockspec lxsh 0.8.6-2")) + assert.is_true(run.luarocks_bool("build lxsh-0.8.6-2.rockspec --only-deps")) + assert.is_false(run.luarocks_bool("show lxsh")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + assert.is_true(os.remove("lxsh-0.8.6-2.rockspec")) + end) + + it("LuaRocks build only deps of downloaded rock of lxsh", function() + assert.is_true(run.luarocks_bool("download --source lxsh 0.8.6-2")) + assert.is_true(run.luarocks_bool("build lxsh-0.8.6-2.src.rock --only-deps")) + assert.is_false(run.luarocks_bool("show lxsh")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) + end) + + it("LuaRocks build no https", function() + assert.is_true(run.luarocks_bool("download --rockspec validate-args 1.5.4-1")) + assert.is_true(run.luarocks_bool("build validate-args-1.5.4-1.rockspec")) + + assert.is_true(run.luarocks_bool("show validate-args")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/validate-args")) + + assert.is_true(os.remove("validate-args-1.5.4-1.rockspec")) + end) + + it("LuaRocks build with https", function() + assert.is_true(run.luarocks_bool("download --rockspec validate-args 1.5.4-1")) + assert.is_true(run.luarocks_bool("install luasec")) + assert.is_true(run.luarocks_bool("build validate-args-1.5.4-1.rockspec")) + + assert.is_true(run.luarocks_bool("show validate-args")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/validate-args")) + + assert.is_true(os.remove("validate-args-1.5.4-1.rockspec")) + end) + + it("LuaRocks build missing external", function() + assert.is_true(test_env.need_luasocket()) + assert.is_false(run.luarocks_bool("build " .. testing_paths.testing_dir .. "/testfiles/missing_external-0.1-1.rockspec INEXISTENT_INCDIR=\"/invalid/dir\"")) + end) + + it("LuaRocks build invalid patch", function() + assert.is_true(test_env.need_luasocket()) + assert.is_false(run.luarocks_bool("build " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) + end) + end) +end) diff --git a/spec/config_spec.lua b/spec/config_spec.lua new file mode 100644 index 00000000..f6cabd8c --- /dev/null +++ b/spec/config_spec.lua @@ -0,0 +1,90 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local cfg = require("luarocks.cfg") + +expose("LuaRocks config tests #blackbox #b_config", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + test_env.unload_luarocks() -- need to be required here, because site_config is created after first loading of specs + site_config = require("luarocks.site_config") + testing_paths = test_env.testing_paths + run = test_env.run + end) + + describe("LuaRocks config - basic tests", function() + it("LuaRocks config with no flags/arguments", function() + assert.is_false(run.luarocks_bool("config")) + end) + + it("LuaRocks config include dir", function() + local output = run.luarocks("config --lua-incdir") + assert.are.same(output, site_config.LUA_INCDIR) + end) + + it("LuaRocks config library dir", function() + local output = run.luarocks("config --lua-libdir") + assert.are.same(output, site_config.LUA_LIBDIR) + end) + + it("LuaRocks config lua version", function() + local output = run.luarocks("config --lua-ver") + local lua_version = _VERSION:gsub("Lua ", "") + if test_env.LUAJIT_V then + lua_version = "5.1" + end + assert.are.same(output, lua_version) + end) + + it("LuaRocks config rock trees", function() + assert.is_true(run.luarocks_bool("config --rock-trees")) + end) + + it("LuaRocks config user config", function() + local user_config_path = run.luarocks("config --user-config") + assert.is.truthy(lfs.attributes(user_config_path)) + end) + + it("LuaRocks config missing user config", function() + assert.is_false(run.luarocks_bool("config --user-config", {LUAROCKS_CONFIG = "missing_file.lua"})) + end) + end) + + describe("LuaRocks config - more complex tests", function() + it("LuaRocks fail system config", function() + os.remove(testing_paths.testing_lrprefix .. "/etc/luarocks/config.lua") + assert.is_false(run.luarocks_bool("config --system-config;")) + end) + + it("LuaRocks system config", function() + local scdir = testing_paths.testing_lrprefix .. "/etc/luarocks" + lfs.mkdir(testing_paths.testing_lrprefix) + lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") + lfs.mkdir(scdir) + + local sysconfig = io.open(scdir .. "/config.lua", "w+") + sysconfig:write(" ") + sysconfig:close() + + local output = run.luarocks("config --system-config;") + assert.are.same(output, scdir .. "/config.lua") + test_env.remove_dir(testing_paths.testing_lrprefix) + end) + + it("LuaRocks fail system config invalid", function() + local scdir = testing_paths.testing_lrprefix .. "/etc/luarocks" + lfs.mkdir(testing_paths.testing_lrprefix) + lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") + lfs.mkdir(scdir) + + local sysconfig = io.open(scdir .. "/config.lua", "w+") + sysconfig:write("if if if") + sysconfig:close() + + assert.is_false(run.luarocks_bool("config --system-config;")) + test_env.remove_dir(testing_paths.testing_lrprefix) + end) + end) +end) \ No newline at end of file diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua new file mode 100644 index 00000000..ce784080 --- /dev/null +++ b/spec/deps_spec.lua @@ -0,0 +1,115 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local deps = require("luarocks.deps") + +local extra_rocks = { + "/lxsh-0.8.6-2.src.rock", + "/lxsh-0.8.6-2.rockspec", + "/luasocket-3.0rc1-1.src.rock", + "/luasocket-3.0rc1-1.rockspec", + "/lpeg-0.12-1.src.rock" +} + +expose("LuaRocks deps tests #blackbox #b_deps", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + testing_paths = test_env.testing_paths + run = test_env.run + end) + + it("LuaRocks deps mode one", function() + assert.is_true(run.luarocks_bool("build --tree=system lpeg")) + assert.is_true(run.luarocks_bool("build --deps-mode=one --tree=" .. testing_paths.testing_tree .. " lxsh")) + + assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + end) + + it("LuaRocks deps mode order", function() + assert.is_true(run.luarocks_bool("build --tree=system lpeg")) + assert.is_true(run.luarocks_bool("build --deps-mode=order --tree=" .. testing_paths.testing_tree .. " lxsh")) + + assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + end) + + it("LuaRocks deps mode order sys", function() + assert.is_true(run.luarocks_bool("build --tree=" .. testing_paths.testing_tree .. " lpeg")) + assert.is_true(run.luarocks_bool("build --deps-mode=order --tree=" .. testing_paths.testing_sys_tree .. " lxsh")) + + assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + end) + + it("LuaRocks deps mode all sys", function() + assert.is_true(run.luarocks_bool("build --tree=" .. testing_paths.testing_tree .. " lpeg")) + assert.is_true(run.luarocks_bool("build --deps-mode=all --tree=" .. testing_paths.testing_sys_tree .. " lxsh")) + + assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + end) + + it("LuaRocks deps mode none", function() + assert.is_true(run.luarocks_bool("build --tree=" .. testing_paths.testing_tree .. " lpeg")) + assert.is_true(run.luarocks_bool("build --deps-mode=none lxsh")) + + assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + end) + + it("LuaRocks nodeps alias", function() + assert.is_true(run.luarocks_bool("build --tree=" .. testing_paths.testing_tree .. " --nodeps lxsh")) + + assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + end) + + it("LuaRocks deps mode make order", function() + assert.is_true(run.luarocks_bool("build --tree=" .. testing_paths.testing_sys_tree .. " lpeg")) + assert.is_true(run.luarocks_bool("download --source lxsh 0.8.6")) + assert.is_true(run.luarocks_bool("unpack lxsh-0.8.6-2.src.rock")) + lfs.chdir("lxsh-0.8.6-2/lxsh-0.8.6-1/") + assert.is_true(run.luarocks_bool("make --tree=" .. testing_paths.testing_tree .. " --deps-mode=order")) + + lfs.chdir(testing_paths.luarocks_dir) + test_env.remove_dir("lxsh-0.8.6-2") + assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) + + assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + end) + + it("LuaRocks deps mode make order sys", function() + assert.is_true(run.luarocks_bool("build --tree=" .. testing_paths.testing_tree .. " lpeg")) + assert.is_true(run.luarocks_bool("download --source lxsh 0.8.6")) + assert.is_true(run.luarocks_bool("unpack lxsh-0.8.6-2.src.rock")) + lfs.chdir("lxsh-0.8.6-2/lxsh-0.8.6-1/") + assert.is_true(run.luarocks_bool("make --tree=" .. testing_paths.testing_sys_tree .. " --deps-mode=order")) + + lfs.chdir(testing_paths.luarocks_dir) + test_env.remove_dir("lxsh-0.8.6-2") + assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) + + assert.is.truthy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) + assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + end) +end) \ No newline at end of file diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua new file mode 100644 index 00000000..476b8ea8 --- /dev/null +++ b/spec/doc_spec.lua @@ -0,0 +1,57 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local doc = require("luarocks.doc") + +local extra_rocks = { + "/luarepl-0.4-1.src.rock" +} + +expose("LuaRocks doc tests #blackbox #b_doc", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + testing_paths = test_env.testing_paths + run = test_env.run + end) + + describe("LuaRocks doc basic tests", function() + it("LuaRocks doc with no flags/arguments", function() + assert.is_false(run.luarocks_bool("doc")) + end) + it("LuaRocks doc with invalid argument", function() + assert.is_false(run.luarocks_bool("doc invalid")) + end) + end) + + describe("LuaRocks doc tests with flags", function() + it("LuaRocks doc of installed luarepl", function() + assert.is_true(run.luarocks_bool("install luarepl")) + assert.is_true(run.luarocks_bool("doc luarepl")) + end) + + it("LuaRocks doc of luacov and access its home page", function() + assert.is_true(run.luarocks_bool("install luacov")) + assert.is_true(run.luarocks_bool("doc luacov --home")) + end) + + it("LuaRocks doc of luacov and list doc folder", function() + assert.is_true(run.luarocks_bool("install luacov")) + local output = assert.is.truthy(run.luarocks("doc luacov --list")) + assert.is.truthy(output:find("/lib/luarocks/rocks/luacov/0.11.0--1/doc/")) + end) + + it("LuaRocks doc of luacov local", function() + assert.is_true(run.luarocks_bool("install luacov")) + assert.is_true(run.luarocks_bool("doc luacov --local")) + end) + + it("LuaRocks doc of luacov porcelain", function() + assert.is_true(run.luarocks_bool("install luacov")) + assert.is_true(run.luarocks_bool("doc luacov --porcelain")) + end) + end) +end) + + diff --git a/spec/download_spec.lua b/spec/download_spec.lua new file mode 100644 index 00000000..9b5d9e2e --- /dev/null +++ b/spec/download_spec.lua @@ -0,0 +1,37 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local download = require("luarocks.download") + +local extra_rocks = { + "/validate-args-1.5.4-1.rockspec" +} + +expose("LuaRocks download tests #blackbox #b_download", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + run = test_env.run + end) + + it("LuaRocks download with no flags/arguments", function() + assert.is_false(run.luarocks_bool("download")) + end) + + it("LuaRocks download invalid", function() + assert.is_false(run.luarocks_bool("download invalid")) + end) + + it("LuaRocks download all with delete downloaded files", function() --TODO maybe download --all more rocks + assert.is_true(run.luarocks_bool("download --all validate-args")) + assert.is.truthy(lfs.attributes("validate-args-1.5.4-1.rockspec")) + test_env.remove_files(lfs.currentdir(), "validate--args--") + end) + + it("LuaRocks download rockspec version", function() + assert.is_true(run.luarocks_bool("download --rockspec validate-args 1.5.4-1")) + assert.is.truthy(lfs.attributes("validate-args-1.5.4-1.rockspec")) + test_env.remove_files(lfs.currentdir(), "validate--args--") + end) +end) diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua new file mode 100644 index 00000000..1f298733 --- /dev/null +++ b/spec/fetch_spec.lua @@ -0,0 +1,16 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local fetch = require("luarocks.fetch") + +describe("Luarocks fetch test #whitebox #w_fetch", function() + it("Fetch url to base dir", function() + assert.are.same("v0.3", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip")) + assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip")) + assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz")) + assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2")) + assert.are.same("parser.moon", fetch.url_to_base_dir("git://github.com/Cirru/parser.moon")) + assert.are.same("v0.3", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3")) + end) +end) \ No newline at end of file diff --git a/spec/help_spec.lua b/spec/help_spec.lua new file mode 100644 index 00000000..0f40dd38 --- /dev/null +++ b/spec/help_spec.lua @@ -0,0 +1,29 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local help = require("luarocks.help") + +expose("LuaRocks help tests #blackbox #b_help", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + run = test_env.run + end) + + it("LuaRocks help with no flags/arguments", function() + assert.is_true(run.luarocks_bool("help")) + end) + + it("LuaRocks help invalid argument", function() + assert.is_false(run.luarocks_bool("help invalid")) + end) + + it("LuaRocks help config", function() + assert.is_true(run.luarocks_bool("help config")) + end) + + it("LuaRocks-admin help with no flags/arguments", function() + assert.is_true(run.luarocks_admin_bool("help")) + end) +end) \ No newline at end of file diff --git a/spec/install_spec.lua b/spec/install_spec.lua new file mode 100644 index 00000000..306bbbc1 --- /dev/null +++ b/spec/install_spec.lua @@ -0,0 +1,130 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local install = require("luarocks.install") + +local extra_rocks = { + "/cprint-0.1-2.src.rock", + "/cprint-0.1-2.rockspec", + "/lpeg-0.12-1.src.rock", + "/luasec-0.6-1.rockspec", + "/luassert-1.7.0-1.src.rock", + "/luasocket-3.0rc1-1.src.rock", + "/luasocket-3.0rc1-1.rockspec", + "/lxsh-0.8.6-2.src.rock", + "/lxsh-0.8.6-2.rockspec", + "/say-1.2-1.src.rock", + "/say-1.0-1.src.rock", + "/wsapi-1.6-1.src.rock" +} + +expose("LuaRocks install tests #blackbox #b_install", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + testing_paths = test_env.testing_paths + env_variables = test_env.env_variables + run = test_env.run + platform = test_env.platform + end) + + describe("LuaRocks install - basic tests", function() + it("LuaRocks install with no flags/arguments", function() + assert.is_false(run.luarocks_bool("install")) + end) + + it("LuaRocks install with invalid argument", function() + assert.is_false(run.luarocks_bool("install invalid")) + end) + + it("LuaRocks install invalid patch", function() + assert.is_false(run.luarocks_bool("install " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) + end) + + it("LuaRocks install invalid rock", function() + assert.is_false(run.luarocks_bool("install \"invalid.rock\" ")) + end) + + it("LuaRocks install with local flag as root", function() + assert.is_false(run.luarocks_bool("install --local luasocket", { USER = "root" } )) + end) + + it("LuaRocks install not a zip file", function() + assert.is_false(run.luarocks_bool("install " .. testing_paths.testing_dir .. "/testfiles/not_a_zipfile-1.0-1.src.rock")) + end) + + it("LuaRocks install only-deps of lxsh show there is no lxsh", function() + assert.is_true(run.luarocks_bool("install lxsh 0.8.6-2 --only-deps")) + assert.is_false(run.luarocks_bool("show lxsh")) + end) + + it("LuaRocks install incompatible architecture", function() + assert.is_false(run.luarocks_bool("install \"foo-1.0-1.impossible-x86.rock\" ")) + end) + + it("LuaRocks install wsapi with bin", function() + run.luarocks_bool("install wsapi") + end) + + it("LuaRocks install luasec and show luasocket (dependency)", function() + assert.is_true(run.luarocks_bool("install luasec")) + assert.is_true(run.luarocks_bool("show luasocket")) + end) + end) + + describe("LuaRocks install - more complex tests", function() + it('LuaRocks install luasec with skipping dependency checks', function() + run.luarocks(" install luasec --nodeps") + assert.is_true(run.luarocks_bool("show luasec")) + if env_variables.TYPE_TEST_ENV == "minimal" then + assert.is_false(run.luarocks_bool("show luasocket")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) + end + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasec")) + end) + + it("LuaRocks install only-deps of luasocket packed rock", function() + assert.is_true(test_env.need_luasocket()) + local output = run.luarocks("install --only-deps " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. platform .. ".rock") + assert.are.same(output, "Successfully installed dependencies for luasocket 3.0rc1-1") + end) + + it("LuaRocks install binary rock of cprint", function() + assert.is_true(test_env.need_luasocket()) + assert.is_true(run.luarocks_bool("build --pack-binary-rock cprint")) + assert.is_true(run.luarocks_bool("install cprint-0.1-2." .. platform .. ".rock")) + assert.is_true(os.remove("cprint-0.1-2." .. platform .. ".rock")) + end) + + it("LuaRocks install reinstall", function() + assert.is_true(test_env.need_luasocket()) + assert.is_true(run.luarocks_bool("install " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. platform .. ".rock")) + assert.is_true(run.luarocks_bool("install --deps-mode=none " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. platform .. ".rock")) + end) + end) + + describe("New install functionality based on pull request 552", function() + it("LuaRocks install break dependencies warning", function() + assert.is_true(run.luarocks_bool("install say 1.2")) + assert.is_true(run.luarocks_bool("install luassert")) + assert.is_true(run.luarocks_bool("install say 1.0")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.2-1")) + end) + it("LuaRocks install break dependencies force", function() + assert.is_true(run.luarocks_bool("install say 1.2")) + assert.is_true(run.luarocks_bool("install luassert")) + local output = run.luarocks("install --force say 1.0") + assert.is.truthy(output:find("Checking stability of dependencies")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.2-1")) + end) + it("LuaRocks install break dependencies force fast", function() + assert.is_true(run.luarocks_bool("install say 1.2")) + assert.is_true(run.luarocks_bool("install luassert")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.2-1")) + local output = run.luarocks("install --force-fast say 1.0") + assert.is.falsy(output:find("Checking stability of dependencies")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.0-1")) + end) + end) +end) \ No newline at end of file diff --git a/spec/lint_spec.lua b/spec/lint_spec.lua new file mode 100644 index 00000000..cba80a3e --- /dev/null +++ b/spec/lint_spec.lua @@ -0,0 +1,51 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local lint = require("luarocks.lint") + +local extra_rocks = { + "/validate-args-1.5.4-1.rockspec" +} + +expose("LuaRocks lint tests #blackbox #b_lint", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + testing_paths = test_env.testing_paths + run = test_env.run + end) + + it("LuaRocks lint with no flags/arguments", function() + assert.is_false(run.luarocks_bool("lint")) + end) + + it("LuaRocks lint invalid argument", function() + assert.is_false(run.luarocks_bool("lint invalid")) + end) + + it("LuaRocks lint OK", function() + assert.is_true(run.luarocks_bool("download --rockspec validate-args 1.5.4-1")) + local output = run.luarocks("lint validate-args-1.5.4-1.rockspec") + assert.are.same(output, "") + assert.is_true(os.remove("validate-args-1.5.4-1.rockspec")) + end) + + describe("LuaRocks lint mismatch set", function() + it("LuaRocks lint mismatch string", function() + assert.is_false(run.luarocks_bool("lint " .. testing_paths.testing_dir .. "/testfiles/type_mismatch_string-1.0-1.rockspec")) + end) + + it("LuaRocks lint mismatch version", function() + assert.is_false(run.luarocks_bool("lint " .. testing_paths.testing_dir .. "/testfiles/type_mismatch_version-1.0-1.rockspec")) + end) + + it("LuaRocks lint mismatch table", function() + assert.is_false(run.luarocks_bool("lint " .. testing_paths.testing_dir .. "/testfiles/type_mismatch_table-1.0-1.rockspec")) + end) + + it("LuaRocks lint mismatch no build table", function() + assert.is_false(run.luarocks_bool("lint " .. testing_paths.testing_dir .. "/testfiles/no_build_table-1.0-1.rockspec")) + end) + end) +end) \ No newline at end of file diff --git a/spec/list_spec.lua b/spec/list_spec.lua new file mode 100644 index 00000000..545483df --- /dev/null +++ b/spec/list_spec.lua @@ -0,0 +1,41 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local list = require("luarocks.list") + +local extra_rocks = { + "/say-1.0-1.src.rock", + "/say-1.2-1.src.rock" +} + +expose("LuaRocks list tests #blackbox #b_list", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + run = test_env.run + testing_paths = test_env.testing_paths + end) + + it("LuaRocks list with no flags/arguments", function() + local output = run.luarocks("list") + assert.is.truthy(output:find("luacov")) + end) + + it("LuaRocks list porcelain", function() + local output = run.luarocks("list --porcelain") + local path = testing_paths.testing_sys_tree:gsub("-", "--") -- !not sure! why this is good + assert.is.truthy(output:find("luacov\t0.11.0--1\tinstalled\t" .. path .. "/lib/luarocks/rocks" )) + end) + + it("LuaRocks install outdated and list it", function() + assert.is_true(run.luarocks_bool("install say 1.0-1")) + local output = run.luarocks("list --outdated") + assert.is.truthy(output:find("say")) + end) + + it("LuaRocks list invalid tree", function() + local output = run.luarocks("--tree=/some/invalid/tree list") + assert.are.same(output, "Installed rocks:----------------") + end) +end) diff --git a/spec/make_manifest_spec.lua b/spec/make_manifest_spec.lua new file mode 100644 index 00000000..c6cb1328 --- /dev/null +++ b/spec/make_manifest_spec.lua @@ -0,0 +1,19 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local make_manifest = require("luarocks.make_manifest") + +expose("LuaRocks make_manifest tests #blackbox #b_make_manifest", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + run = test_env.run + end) + + describe("LuaRocks-admin make manifest tests", function() + it("LuaRocks-admin make manifest", function() + assert.is_true(run.luarocks_admin_bool("make_manifest")) + end) + end) +end) \ No newline at end of file diff --git a/spec/make_spec.lua b/spec/make_spec.lua new file mode 100644 index 00000000..f70bb7e9 --- /dev/null +++ b/spec/make_spec.lua @@ -0,0 +1,99 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local make = require("luarocks.make") + +local extra_rocks = { + "/lpeg-0.12-1.src.rock", + "/luasocket-3.0rc1-1.src.rock", + "/luasocket-3.0rc1-1.rockspec", + "/lxsh-0.8.6-2.src.rock", + "/lxsh-0.8.6-2.rockspec" +} + +expose("LuaRocks make tests #blackbox #b_make", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + run = test_env.run + testing_paths = test_env.testing_paths + end) + + it("LuaRocks make with no flags/arguments", function() + lfs.chdir("test") + assert.is_false(run.luarocks_bool("make")) + lfs.chdir(testing_paths.luarocks_dir) + end) + + it("LuaRocks make with rockspec", function() + -- make luasocket + assert.is_true(run.luarocks_bool("download --source luasocket")) + assert.is_true(run.luarocks_bool("unpack luasocket-3.0rc1-1.src.rock")) + lfs.chdir("luasocket-3.0rc1-1/luasocket-3.0-rc1/") + assert.is_true(run.luarocks_bool("make luasocket-3.0rc1-1.rockspec")) + + -- test it + assert.is_true(run.luarocks_bool("show luasocket")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) + + -- delete downloaded and unpacked files + lfs.chdir(testing_paths.luarocks_dir) + test_env.remove_dir("luasocket-3.0rc1-1") + assert.is_true(os.remove("luasocket-3.0rc1-1.src.rock")) + end) + + describe("LuaRocks making rockspecs (using lxsh)", function() + --download lxsh and unpack it + before_each(function() + assert.is_true(run.luarocks_bool("download --source lxsh 0.8.6-2")) + assert.is_true(run.luarocks_bool("unpack lxsh-0.8.6-2.src.rock")) + assert.is_true(lfs.chdir("lxsh-0.8.6-2/lxsh-0.8.6-1/")) + end) + + -- delete downloaded and unpacked files + after_each(function() + assert.is_true(lfs.chdir(testing_paths.luarocks_dir)) + test_env.remove_dir("lxsh-0.8.6-2") + assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) + end) + + it("LuaRocks make default rockspec", function() + assert.is_true(run.luarocks_bool("new_version lxsh-0.8.6-2.rockspec")) + assert.is_true(run.luarocks_bool("make")) + + assert.is_true(run.luarocks_bool("show lxsh")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + end) + + it("LuaRocks make unnamed rockspec", function() + os.execute("cp lxsh-0.8.6-2.rockspec rockspec") --rewrite with lfs + assert.is_true(run.luarocks_bool("make")) + + assert.is_true(run.luarocks_bool("show lxsh")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + end) + + it("LuaRocks make ambiguous rockspec", function() + assert.is.truthy(os.rename("lxsh-0.8.6-2.rockspec", "lxsh2-0.8.6-2.rockspec")) + assert.is_false(run.luarocks_bool("make")) + + assert.is_false(run.luarocks_bool("show lxsh")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + end) + + it("LuaRocks make ambiguous unnamed rockspec", function() + assert.is.truthy(os.rename("lxsh-0.8.6-2.rockspec", "1_rockspec")) + os.execute("cp 1_rockspec 2_rockspec") --rewrite with lfs + assert.is_false(run.luarocks_bool("make")) + + assert.is_false(run.luarocks_bool("show lxsh")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) + end) + + it("LuaRocks make pack binary rock", function() + assert.is_true(run.luarocks_bool("make --deps-mode=none --pack-binary-rock")) + assert.is.truthy(lfs.attributes("lxsh-0.8.6-2.all.rock")) + end) + end) +end) \ No newline at end of file diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua new file mode 100644 index 00000000..57014226 --- /dev/null +++ b/spec/new_version_spec.lua @@ -0,0 +1,53 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local new_version = require("luarocks.new_version") + +local extra_rocks = { + "/abelhas-1.0-1.rockspec" +} + +expose("LuaRocks new_version tests #blackbox #b_new_version", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + testing_paths = test_env.testing_paths + run = test_env.run + end) + + describe("LuaRocks new_version basic tests", function() + it("LuaRocks new version with no flags/arguments", function() + lfs.chdir("test") + assert.is_false(run.luarocks_bool("new_version")) + lfs.chdir(testing_paths.luarocks_dir) + end) + + it("LuaRocks new version invalid", function() + assert.is_false(run.luarocks_bool("new_version invalid")) + end) + end) + + describe("LuaRocks new_version more complex tests", function() + it("LuaRocks new_version of luacov", function() + assert.is_true(run.luarocks_bool("download --rockspec luacov 0.11.0")) + assert.is_true(run.luarocks_bool("new_version luacov-0.11.0-1.rockspec 0.2")) + assert.is.truthy(lfs.attributes("luacov-0.2-1.rockspec")) + test_env.remove_files(lfs.currentdir(), "luacov--") + end) + + it("LuaRocks new_version url of abelhas", function() + assert.is_true(run.luarocks_bool("download --rockspec abelhas 1.0")) + assert.is_true(run.luarocks_bool("new_version abelhas-1.0-1.rockspec 1.1 http://luaforge.net/frs/download.php/2658/abelhas-1.0.tar.gz")) + assert.is.truthy(lfs.attributes("abelhas-1.1-1.rockspec")) + test_env.remove_files(lfs.currentdir(), "abelhas--") + end) + + it("LuaRocks new_version of luacov with tag", function() + assert.is_true(run.luarocks_bool("download --rockspec luacov 0.11.0")) + assert.is_true(run.luarocks_bool("new_version luacov-0.11.0-1.rockspec --tag v0.3")) + assert.is.truthy(lfs.attributes("luacov-0.3-1.rockspec")) + test_env.remove_files(lfs.currentdir(), "luacov--") + end) + end) +end) \ No newline at end of file diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua new file mode 100644 index 00000000..a07e7ed2 --- /dev/null +++ b/spec/pack_spec.lua @@ -0,0 +1,35 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local pack = require("luarocks.pack") + +local extra_rocks = { + "/luasec-0.6-1.rockspec", + "/luasocket-3.0rc1-1.src.rock", + "/luasocket-3.0rc1-1.rockspec" +} + +expose("LuaRocks pack tests #blackbox #b_pack", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + testing_paths = test_env.testing_paths + run = test_env.run + end) + + it("LuaRocks pack basic", function() + assert.is_true(run.luarocks_bool("list")) + assert.is_true(run.luarocks_bool("pack luacov")) + assert.is_true(test_env.remove_files(lfs.currentdir(), "luacov-")) + end) + + it("LuaRocks pack src", function() + assert.is_true(run.luarocks_bool("install luasec")) + assert.is_true(run.luarocks_bool("download --rockspec luasocket")) + assert.is_true(run.luarocks_bool("pack luasocket-3.0rc1-1.rockspec")) + assert.is_true(test_env.remove_files(lfs.currentdir(), "luasocket-")) + end) +end) + + diff --git a/spec/path_spec.lua b/spec/path_spec.lua new file mode 100644 index 00000000..266ada89 --- /dev/null +++ b/spec/path_spec.lua @@ -0,0 +1,28 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local path = require("luarocks.path") + +expose("LuaRocks path tests #blackbox #b_path", function() + before_each(function() + test_env.setup_specs(extra_rocks) + run = test_env.run + end) + + it("LuaRocks path bin", function() + assert.is_true(run.luarocks_bool("path --bin")) + end) + + it("LuaRocks path lr-path", function() + assert.is_true(run.luarocks_bool("path --lr-path")) + end) + + it("LuaRocks path lr-cpath", function() + assert.is_true(run.luarocks_bool("path --lr-cpath")) + end) + + it("LuaRocks path with tree", function() + assert.is_true(run.luarocks_bool("path --tree=lua_modules")) + end) +end) diff --git a/spec/purge_spec.lua b/spec/purge_spec.lua new file mode 100644 index 00000000..639f96f3 --- /dev/null +++ b/spec/purge_spec.lua @@ -0,0 +1,30 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local purge = require("luarocks.purge") + +expose("LuaRocks purge tests #blackbox #b_purge", function() + before_each(function() + test_env.setup_specs(extra_rocks) + testing_paths = test_env.testing_paths + run = test_env.run + end) + + describe("LuaRocks purge basic tests", function() + it("LuaRocks purge missing tree", function() + assert.is_false(run.luarocks_bool("purge --tree=" .. testing_paths.testing_tree)) + end) + it("LuaRocks purge tree with no string", function() + assert.is_false(run.luarocks_bool("purge --tree=1")) + end) + it("LuaRocks purge tree with no string", function() + assert.is_true(run.luarocks_bool("purge --tree=" .. testing_paths.testing_sys_tree)) + end) + it("LuaRocks purge old versions tree", function() + assert.is_true(run.luarocks_bool("purge --old-versions --tree=" .. testing_paths.testing_sys_tree)) + end) + end) +end) + + diff --git a/spec/refresh_cache_spec.lua b/spec/refresh_cache_spec.lua new file mode 100644 index 00000000..27a95e5c --- /dev/null +++ b/spec/refresh_cache_spec.lua @@ -0,0 +1,19 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local refresh_cache = require("luarocks.refresh_cache") + +expose("LuaRocks refresh_cache tests #blackbox #b_refresh_cache", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + run = test_env.run + end) + + describe("LuaRocks-admin refresh cache tests #ssh", function() + it("LuaRocks-admin refresh cache", function() + assert.is_true(run.luarocks_admin_bool("--server=testing refresh_cache")) + end) + end) +end) \ No newline at end of file diff --git a/spec/remove_spec.lua b/spec/remove_spec.lua new file mode 100644 index 00000000..a94673a8 --- /dev/null +++ b/spec/remove_spec.lua @@ -0,0 +1,85 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local remove = require("luarocks.remove") + +local extra_rocks = { + "/abelhas-1.0-1.rockspec", + "/lualogging-1.3.0-1.src.rock", + "/luasocket-3.0rc1-1.src.rock", + "/luasocket-3.0rc1-1.rockspec" +} + +expose("LuaRocks remove tests #blackbox #b_remove", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + testing_paths = test_env.testing_paths + run = test_env.run + end) + + describe("LuaRocks remove basic tests", function() + it("LuaRocks remove with no flags/arguments", function() + assert.is_false(run.luarocks_bool("remove")) + end) + + it("LuaRocks remove invalid rock", function() + assert.is_false(run.luarocks_bool("remove invalid.rock")) + end) + + it("LuaRocks remove missing rock", function() + assert.is_false(run.luarocks_bool("remove missing_rock")) + end) + + it("LuaRocks remove invalid argument", function() + assert.is_false(run.luarocks_bool("remove luacov --deps-mode")) + end) + + it("LuaRocks remove builded abelhas", function() + assert.is_true(run.luarocks_bool("build abelhas 1.0")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/abelhas")) + assert.is_true(run.luarocks_bool("remove abelhas 1.0")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/abelhas")) + end) + end) + + describe("LuaRocks remove more complex tests", function() + it("LuaRocks remove fail, break dependencies", function() + assert.is_true(test_env.need_luasocket()) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) + assert.is_true(run.luarocks_bool("build lualogging")) + + assert.is_false(run.luarocks_bool("remove luasocket")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) + end) + + it("LuaRocks remove force", function() + assert.is_true(test_env.need_luasocket()) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) + assert.is_true(run.luarocks_bool("build lualogging")) + + local output = run.luarocks("remove --force luasocket") + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) + assert.is.truthy(output:find("Checking stability of dependencies")) + end) + + it("LuaRocks remove force fast", function() + assert.is_true(test_env.need_luasocket()) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) + assert.is_true(run.luarocks_bool("build lualogging")) + + local output = run.luarocks("remove --force-fast luasocket") + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) + assert.is.falsy(output:find("Checking stability of dependencies")) + end) + end) + + it("LuaRocks-admin remove #ssh", function() + assert.is_true(run.luarocks_admin_bool("--server=testing remove luasocket-3.0rc1-1.src.rock")) + end) + + it("LuaRocks-admin remove missing", function() + assert.is_false(run.luarocks_admin_bool("--server=testing remove")) + end) +end) \ No newline at end of file diff --git a/spec/search_spec.lua b/spec/search_spec.lua new file mode 100644 index 00000000..a0258942 --- /dev/null +++ b/spec/search_spec.lua @@ -0,0 +1,42 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local search = require("luarocks.search") + +local extra_rocks = { +"/lzlib-0.4.1.53-1.src.rock" +} + +expose("LuaRocks search tests #blackbox #b_search", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + run = test_env.run + end) + + it("LuaRocks search with no flags/arguments", function() + assert.is_false(run.luarocks_bool("search")) + end) + + it("LuaRocks search zlib", function() + assert.is_true(run.luarocks_bool("search zlib")) + end) + + it("LuaRocks search zlib 1.1", function() + assert.is_true(run.luarocks_bool("search zlib 1.1")) + end) + + it("LuaRocks search missing rock", function() + assert.is_true(run.luarocks_bool("search missing_rock")) + end) + + it("LuaRocks search with flag all", function() + assert.is_true(run.luarocks_bool("search --all")) + end) + + it("LuaRocks search zlib", function() + local num = 123 + assert.is_true(run.luarocks_bool("search " .. num)) + end) +end) \ No newline at end of file diff --git a/spec/show_spec.lua b/spec/show_spec.lua new file mode 100644 index 00000000..85797eb6 --- /dev/null +++ b/spec/show_spec.lua @@ -0,0 +1,56 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local show = require("luarocks.show") + +expose("LuaRocks show tests #blackbox #b_show", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + run = test_env.run + end) + + it("LuaRocks show with no flags/arguments", function() + assert.is_false(run.luarocks_bool("show")) + end) + + describe("LuaRocks show basic tests with flags", function() + it("LuaRocks show invalid", function() + assert.is_false(run.luarocks_bool("show invalid")) + end) + + it("LuaRocks show luacov", function() + local output = run.luarocks("show luacov") + end) + + it("LuaRocks show modules of luacov", function() + local output = run.luarocks("show --modules luacov") + end) + + it("LuaRocks show dependencies of luacov", function() + local output = run.luarocks("show --deps luacov") + end) + + it("LuaRocks show rockspec of luacov", function() + local output = run.luarocks("show --rockspec luacov") + end) + + it("LuaRocks show mversion of luacov", function() + local output = run.luarocks("show --mversion luacov") + end) + + it("LuaRocks show rock tree of luacov", function() + local output = run.luarocks("show --rock-tree luacov") + end) + + it("LuaRocks show rock directory of luacov", function() + local output = run.luarocks("show --rock-dir luacov") + end) + end) + + it("LuaRocks show old version of luacov", function() + run.luarocks("install luacov 0.11.0") + run.luarocks("show luacov 0.11.0") + end) +end) diff --git a/spec/unpack_spec.lua b/spec/unpack_spec.lua new file mode 100644 index 00000000..efe902f5 --- /dev/null +++ b/spec/unpack_spec.lua @@ -0,0 +1,61 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local unpack = require("luarocks.unpack") + +local extra_rocks = { + "/cprint-0.1-2.src.rock", + "/cprint-0.1-2.rockspec" +} + +expose("LuaRocks unpack tests #blackbox #b_unpack", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + testing_paths = test_env.testing_paths + run = test_env.run + platform = test_env.platform + end) + + describe("LuaRocks unpack basic fail tests", function() + it("LuaRocks unpack with no flags/arguments", function() + assert.is_false(run.luarocks_bool("unpack")) + end) + it("LuaRocks unpack with invalid rockspec", function() + assert.is_false(run.luarocks_bool("unpack invalid.rockspec")) + end) + it("LuaRocks unpack with invalid patch", function() + assert.is_false(run.luarocks_bool("unpack " .. testing_paths.testing_dir .. "/testfiles/invalid_patch-0.1-1.rockspec")) + end) + end) + + describe("LuaRocks unpack more complex tests", function() + it("LuaRocks unpack download", function() + assert.is_true(run.luarocks_bool("unpack cprint")) + test_env.remove_dir("cprint-0.1-2") + end) + it("LuaRocks unpack src", function() + assert.is_true(run.luarocks_bool("download --source cprint")) + assert.is_true(run.luarocks_bool("unpack cprint-0.1-2.src.rock")) + os.remove("cprint-0.1-2.src.rock") + test_env.remove_dir("cprint-0.1-2") + end) + it("LuaRocks unpack src", function() + assert.is_true(run.luarocks_bool("download --rockspec cprint")) + assert.is_true(run.luarocks_bool("unpack cprint-0.1-2.rockspec")) + os.remove("cprint-0.1-2.rockspec") + os.remove("lua-cprint") + test_env.remove_dir("cprint-0.1-2") + end) + it("LuaRocks unpack binary", function() + assert.is_true(run.luarocks_bool("build cprint")) + assert.is_true(run.luarocks_bool("pack cprint")) + assert.is_true(run.luarocks_bool("unpack cprint-0.1-2." .. platform .. ".rock")) + test_env.remove_dir("cprint-0.1-2") + os.remove("cprint-0.1-2." .. platform .. ".rock") + end) + end) +end) + + diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua new file mode 100644 index 00000000..daf40d61 --- /dev/null +++ b/spec/upload_spec.lua @@ -0,0 +1,41 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local upload = require("luarocks.upload") + +local extra_rocks = { + "/lua-cjson-2.1.0-1.src.rock" +} + +expose("LuaRocks upload tests #blackbox #b_upload", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + run = test_env.run + end) + + it("LuaRocks upload with no flags/arguments", function() + assert.is_false(run.luarocks_bool("upload")) + end) + + it("LuaRocks upload invalid rockspec", function() + assert.is_false(run.luarocks_bool("upload invalid.rockspec")) + end) + + it("LuaRocks upload api key invalid", function() + assert.is_false(run.luarocks_bool("upload --api-key=invalid invalid.rockspec")) + end) + + it("LuaRocks upload api key invalid and skip-pack", function() + assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --skip-pack luacov-0.11.0-1.rockspec")) + end) + + it("LuaRocks upload force", function() + assert.is_true(run.luarocks_bool("install lua-cjson")) + assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --force luacov-0.11.0-1.rockspec")) + assert.is_true(run.luarocks_bool("install lua-cjson")) + end) +end) + + diff --git a/spec/util_spec.lua b/spec/util_spec.lua new file mode 100644 index 00000000..7c22d1cb --- /dev/null +++ b/spec/util_spec.lua @@ -0,0 +1,96 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +expose("Basic tests #blackbox #b_util", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + testing_paths = test_env.testing_paths + env_variables = test_env.env_variables + run = test_env.run + end) + + it("LuaRocks version", function() + assert.is_true(run.luarocks_bool("--version")) + end) + + it("LuaRocks unknown command", function() + assert.is_false(run.luarocks_bool("unknown_command")) + end) + + it("LuaRocks arguments fail", function() + assert.is_false(run.luarocks_bool("--porcelain=invalid")) + assert.is_false(run.luarocks_bool("--invalid-flag")) + assert.is_false(run.luarocks_bool("--server")) + assert.is_false(run.luarocks_bool("--server --porcelain")) + assert.is_false(run.luarocks_bool("--invalid-flag=abc")) + assert.is_false(run.luarocks_bool("invalid=5")) + end) + + it("LuaRocks execute from not existing directory", function() + local main_path = lfs.currentdir() + assert.is_true(lfs.mkdir("idontexist")) + assert.is_true(lfs.chdir("idontexist")) + local delete_path = lfs.currentdir() + assert.is_true(os.remove(delete_path)) + + assert.is_false(run.luarocks_bool(" ")) + assert.is_true(lfs.chdir(main_path)) + assert.is_true(run.luarocks_bool(" ")) + end) + + it("LuaRocks timeout", function() + assert.is_true(run.luarocks_bool("--timeout=10")) + end) + + it("LuaRocks timeout invalid", function() + assert.is_false(run.luarocks_bool("--timeout=abc")) + end) + + it("LuaRocks only server=testing", function() + assert.is_true(run.luarocks_bool("--only-server=testing")) + end) + + it("LuaRocks test site config", function() + assert.is.truthy(os.rename("src/luarocks/site_config.lua", "src/luarocks/site_config.lua.tmp")) + assert.is.falsy(lfs.attributes("src/luarocks/site_config.lua")) + assert.is.truthy(lfs.attributes("src/luarocks/site_config.lua.tmp")) + + assert.is_true(run.luarocks_bool("")) + + assert.is.truthy(os.rename("src/luarocks/site_config.lua.tmp", "src/luarocks/site_config.lua")) + assert.is.falsy(lfs.attributes("src/luarocks/site_config.lua.tmp")) + assert.is.truthy(lfs.attributes("src/luarocks/site_config.lua")) + end) + + describe("LuaRocks sysconfig fails", function() + local scdir = "" + + before_each(function() + scdir = testing_paths.testing_lrprefix .. "/etc/luarocks/" + lfs.mkdir(testing_paths.testing_lrprefix) + lfs.mkdir(testing_paths.testing_lrprefix .. "/etc/") + lfs.mkdir(scdir) + end) + + after_each(function() + test_env.remove_dir(testing_paths.testing_lrprefix) + end) + + it("LuaRocks sysconfig fail", function() + local sysconfig = io.open(scdir .. "/config.lua", "w+") + sysconfig:write("aoeui") + sysconfig:close() + + assert.is_false(run.luarocks_bool("list")) + end) + + it("LuaRocks sysconfig fail", function() + local sysconfig = io.open(scdir .. "/config-" .. env_variables.LUA_VERSION .. ".lua", "w+") + sysconfig:write("aoeui") + sysconfig:close() + + assert.is_false(run.luarocks_bool("list")) + end) + end) +end) diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua new file mode 100644 index 00000000..d6e32f15 --- /dev/null +++ b/spec/write_rockspec_spec.lua @@ -0,0 +1,74 @@ +local test_env = require("test/test_environment") +local lfs = require("lfs") + +test_env.unload_luarocks() +local write_rockspec = require("luarocks.write_rockspec") + +expose("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() + + before_each(function() + test_env.setup_specs(extra_rocks) + run = test_env.run + end) + + describe("LuaRocks write_rockspec basic tests", function() + it("LuaRocks write_rockspec with no flags/arguments", function() + assert.is_true(run.luarocks_bool("write_rockspec")) + os.remove("luarocks-scm-1.rockspec") + end) + + it("LuaRocks write_rockspec with invalid argument", function() + assert.is_false(run.luarocks_bool("write_rockspec invalid")) + end) + + it("LuaRocks write_rockspec invalid zip", function() + assert.is_false(run.luarocks_bool("write_rockspec http://example.com/invalid.zip")) + end) + end) + + describe("LuaRocks write_rockspec more complex tests", function() + it("LuaRocks write_rockspec git luarocks", function() + assert.is_true(run.luarocks_bool("write_rockspec git://github.com/keplerproject/luarocks")) + assert.is.truthy(lfs.attributes("luarocks-scm-1.rockspec")) + assert.is_true(os.remove("luarocks-scm-1.rockspec")) + end) + + it("LuaRocks write_rockspec git luarocks --tag=v2.3.0", function() + assert.is_true(run.luarocks_bool("write_rockspec git://github.com/keplerproject/luarocks --tag=v2.3.0")) + assert.is.truthy(lfs.attributes("luarocks-2.3.0-1.rockspec")) + assert.is_true(os.remove("luarocks-2.3.0-1.rockspec")) + end) + + it("LuaRocks write_rockspec git luarocks with format flag", function() + assert.is_true(run.luarocks_bool("write_rockspec git://github.com/mbalmer/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2")) + assert.is.truthy(lfs.attributes("luarocks-scm-1.rockspec")) + assert.is_true(os.remove("luarocks-scm-1.rockspec")) + end) + + it("LuaRocks write_rockspec git luarocks with full flags", function() + assert.is_true(run.luarocks_bool("write_rockspec git://github.com/mbalmer/luarocks --lua-version=5.1,5.2 --license=\"MIT/X11\" " + .. " --homepage=\"http://www.luarocks.org\" --summary=\"A package manager for Lua modules\" ")) + assert.is.truthy(lfs.attributes("luarocks-scm-1.rockspec")) + assert.is_true(os.remove("luarocks-scm-1.rockspec")) + end) + + it("LuaRocks write_rockspec rockspec via http", function() + assert.is_true(run.luarocks_bool("write_rockspec http://luarocks.org/releases/luarocks-2.1.0.tar.gz --lua-version=5.1")) + assert.is.truthy(lfs.attributes("luarocks-2.1.0-1.rockspec")) + assert.is_true(os.remove("luarocks-2.1.0-1.rockspec")) + end) + + it("LuaRocks write_rockspec base dir, luassert.tar.gz via https", function() + assert.is_true(run.luarocks_bool("write_rockspec https://github.com/downloads/Olivine-Labs/luassert/luassert-1.2.tar.gz --lua-version=5.1")) + assert.is.truthy(lfs.attributes("luassert-1.2-1.rockspec")) + assert.is_true(os.remove("luassert-1.2-1.rockspec")) + end) + + it("LuaRocks write_rockspec git luafcgi with many flags", function() + assert.is_true(run.luarocks_bool("write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license=\"3-clause BSD\" " + .. "--lua-version=5.1,5.2")) + assert.is.truthy(lfs.attributes("luafcgi-scm-1.rockspec")) -- TODO maybe read it content and find arguments from flags? + assert.is_true(os.remove("luafcgi-scm-1.rockspec")) + end) + end) +end) \ No newline at end of file diff --git a/test/README.md b/test/README.md new file mode 100644 index 00000000..c374438f --- /dev/null +++ b/test/README.md @@ -0,0 +1,59 @@ +#LuaRocks testsuite +##Overview +Test suite for LuaRocks project with Busted unit testing framework(http://olivinelabs.com/busted/). + +* Contains white-box & black-box tests +* Easy setup for your purpose on command line or from configuration file + + +## Dependencies +* Lua >= 5.1 +* Busted with dependencies + + +##Usage +Running of tests is based on basic Busted usage. *-Xhelper* flag is mandatory for inserting arguments into testing (primary black-box). Flag *--tags=* or *-t* is mandatory for specifying which tests will run. Mandatory *-Xhelper* flag always needs version of Lua or LuaJIT (e.g. *lua=5.2.4* or *luajit=2.0.3*). Start tests inside LuaRocks folder or specify with *-C* flag. + +**Arguments for Busted helper script** + +``` +lua=, !mandatory! type your full version of Lua (e.g. lua=5.2.4) +OR +luajit=, !mandatory! type your full version of LuaJIT (e.g. luajit=5.2.4) + +env=, (default:"minimal") type what kind of environment to use ["minimal", "full"] +clean, remove existing testing environment +travis, add just if running on TravisCI +os=, type your OS ["linux", "os x", "windows"] +``` +--------------------------------------------------------------------------------------------- +####_**Tags** of tests are required and are in this format:_ + +**whitebox** - run all whitebox tests + +**blackbox** - run all blackbox tests + +**ssh** - run all tests which require ssh + +**w**\_*name-of-command* - whitebox testing of command + +**b**\_*name-of-command* - blackbox testing of command + +for example: `b_install` or `w_help` + +###Examples +To run white-box tests in LuaRocks directory type : + +`busted -t "whitebox"` + +To run black-box tests just of *install* command (we defined our OS, so OS check is skipped.): + +`busted -Xhelper lua=5.2.4,os=linux -t "b_install"` + +To run black-box tests of *install* command, whitebox of *help* command (using *full* type of environment): + +`busted -Xhelper lua=5.2.4,env=full -t "b_install", "w_help"` + +To run black-box tests without tests, which use ssh: + +`busted -Xhelper lua=5.2.4 -t "blackbox" --exclude-tags=ssh` \ No newline at end of file diff --git a/test/test_environment.lua b/test/test_environment.lua new file mode 100644 index 00000000..6de501fb --- /dev/null +++ b/test/test_environment.lua @@ -0,0 +1,625 @@ +local lfs = require("lfs") +local test_env = {} +local arg = arg or { ... } + +local function help() + print("LuaRocks test-suite\n\n".. + [[ + INFORMATION + New test-suite for LuaRocks project, using unit testing framework Busted. + REQUIREMENTS + Tests require to have Lua installed and added to PATH. Be sure sshd is runnig on your system, or + use '--exclude-tags=ssh', to not execute tests which require sshd. + USAGE -Xhelper + lua= (mandatory) type your full version of Lua (e.g. --lua 5.2.4) + OR + luajit= (mandatory) type your full version of LuaJIT (e.g. --luajit 2.0.3) + + env= (default:"minimal") type what kind of environment to use ["minimal", "full"] + clean remove existing testing environment + travis add just if running on TravisCI + os= type your OS ["linux", "osx", "windows"] + ]]); + os.exit(1) +end + +--- Helper function for execute_bool and execute_output +-- @param command string: command to execute +-- @param print_command boolean: print command if 'true' +-- @param env_variables table: table of environment variables to export {FOO="bar", BAR="foo"} +-- @return final_command string: concatenated command to execution +local function execute_helper(command, print_command, env_variables) + local final_command = "" + + if print_command then + print("\n[EXECUTING]: " .. command) + end + + if env_variables then + final_command = "export " + for k,v in pairs(env_variables) do + final_command = final_command .. k .. "='" .. v .. "' " + end + -- remove last space and add ';' to separate exporting variables from command + final_command = final_command:sub(1, -2) .. "; " + end + + final_command = final_command .. command + + return final_command +end + +--- Execute command and returns true/false +-- In Lua5.1 os.execute returns numeric value, but in Lua5.2+ returns boolean +-- @return true/false boolean: status of the command execution +local function execute_bool(command, print_command, env_variables) + command = execute_helper(command, print_command, env_variables) + + local ok = os.execute(command) + return ok == true or ok == 0 +end + +--- Execute command and returns output of command +-- @return output string: output the command execution +local function execute_output(command, print_command, env_variables) + command = execute_helper(command, print_command, env_variables) + + local file = assert(io.popen(command)) + local output = file:read('*all') + file:close() + return output:gsub("\n","") -- output adding new line, need to be removed +end + +--- Set all arguments from input into global variables +function test_env.set_args() + if arg[1] == nil then + help() + end + + local args_position + + for i=1, #arg do + if arg[i]:find("-Xhelper") and arg[i+1]:find("lua=") and not arg[i+1]:find("luajit=") then + args_position = i+1 + test_env.LUA_V = arg[args_position]:gsub("(.*)lua=([^%,]+)(.*)","%2") + break + elseif arg[i]:find("-Xhelper") and not arg[i+1]:find("lua=") and arg[i+1]:find("luajit=") then + args_position = i+1 + test_env.LUAJIT_V = arg[args_position]:gsub("(.*)luajit=([^%,]+)(.*)","%2") + break + elseif arg[i]:find("-Xhelper") and arg[i+1]:find("lua=") and arg[i+1]:find("luajit=") then + print("Please specify just Lua or LuaJIT version for testing in format 'lua=X.X.X' or 'luajit=X.X.X', for -Xhelper flag") + os.exit(1) + elseif arg[i]:find("-Xhelper") and not arg[i+1]:find("lua=") and not arg[i+1]:find("luajit=") then + print("Please add mandatory argument - version of Lua or LuaJIT in format 'lua=X.X.X' or 'luajit=X.X.X', for -Xhelper flag") + os.exit(1) + end + end + + if not args_position 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 arg[args_position]:find("env=") then + test_env.TYPE_TEST_ENV = arg[args_position]:gsub("(.*)env=([^%,]+)(.*)","%2") + end + if arg[args_position]:find("clean") then + test_env.TEST_ENV_CLEAN = true + end + if arg[args_position]:find("travis") then + test_env.TRAVIS = true + end + if arg[args_position]:find("os=") then + test_env.TEST_TARGET_OS = arg[args_position]:gsub("(.*)os=([^%,]+)(.*)","%2") + end + + if not test_env.TEST_TARGET_OS then + print("[OS CHECK]") + if execute_bool("sw_vers") then + test_env.TEST_TARGET_OS = "osx" + elseif execute_bool("uname -s") then + test_env.TEST_TARGET_OS = "linux" + else + test_env.TEST_TARGET_OS = "windows" + end + print("--------------") + end + return true +end + +--- Remove directory recursively +-- @param path string: directory path to delete +function test_env.remove_dir(path) + if lfs.attributes(path) then + for file in lfs.dir(path) do + if file ~= "." and file ~= ".." then + local full_path = path..'/'..file + local attr = lfs.attributes(full_path) + + if attr.mode == "directory" then + test_env.remove_dir(full_path) + os.remove(full_path) + else + os.remove(full_path) + end + end + end + end + os.remove(path) +end + +--- Remove directory recursively +-- @param path string: directory path to delete +-- @param pattern string: pattern in directories +function test_env.remove_dir_pattern(path, pattern) + if lfs.attributes(path) then + for file in lfs.dir(path) do + if file ~= "." and file ~= ".." then + local full_path = path..'/'..file + local attr = lfs.attributes(full_path) + + if attr.mode == "directory" and file:find(pattern) then + test_env.remove_dir(full_path) + os.remove(full_path) + end + end + end + end +end + +--- Remove files based on filename +-- @param path string: directory where to delete files +-- @param pattern string: pattern in filenames +-- @return result_check boolean: true if one or more files deleted +function test_env.remove_files(path, pattern) + local result_check = false + if lfs.attributes(path) then + for file in lfs.dir(path) do + if file ~= "." and file ~= ".." then + if file:find(pattern) then + if os.remove(path .. "/" .. file) then + result_check = true + end + end + end + end + end + return result_check +end + + +--- Function for downloading rocks and rockspecs +-- @param rocks table: table with full name of rocks/rockspecs to download +-- @param save_path string: path to directory, where to download rocks/rockspecs +-- @return make_manifest boolean: true if new rocks downloaded +local function download_rocks(rocks, save_path) + local luarocks_repo = "https://luarocks.org" + local make_manifest = false + + for _,rock in ipairs(rocks) do + -- check if already downloaded + if not os.rename( save_path .. rock, save_path .. rock) then + execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. rock) + make_manifest = true + end + end + return make_manifest +end + +--- Create config files for testing +-- @param config_path string: path where to save config file +-- @param config_content string: content of this config file +local function create_config(config_path, config_content) + local file, err = io.open(config_path, "w+") + if not file then return nil, err end + file:write(config_content) + file:close() +end + +--- Create md5sum of directory structure recursively, based on filename and size +-- @param path string: path to directory for generate md5sum +-- @param testing_os string(optional): version of PC OS +-- @return md5sum string: md5sum of directory +local function hash_environment(path, testing_os) + local md5sum = "" + testing_os = testing_os or test_env.TEST_TARGET_OS + + if testing_os == "linux" then + md5sum = execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum") + end + if testing_os == "osx" then + md5sum = execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5") + end + --TODO if testing_os == "windows" then + -- md5sum = execute_output("find . -printf \"%s %p\n\" | md5sum") + -- end + return md5sum +end + +--- Create environment variables needed for tests +-- @param testing_paths table: table with paths to testing directory +-- @return env_variables table: table with created environment variables +local function create_env(testing_paths) + local luaversion_short = _VERSION:gsub("Lua ", "") + + if test_env.LUAJIT_V then + luaversion_short="5.1" + end + + local env_variables = {} + env_variables.LUA_VERSION = luaversion_short + env_variables.LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua" + env_variables.LUA_PATH = testing_paths.testing_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" + env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" + env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/" .. luaversion_short .. "/?.lua;" + env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.testing_sys_tree .. "/share/lua/".. luaversion_short .. "/?/init.lua;" + env_variables.LUA_PATH = env_variables.LUA_PATH .. testing_paths.src_dir .. "/?.lua;" + env_variables.LUA_CPATH = testing_paths.testing_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" + .. testing_paths.testing_sys_tree .. "/lib/lua/" .. luaversion_short .. "/?.so;" + env_variables.PATH = os.getenv("PATH") .. ":" .. testing_paths.testing_tree .. "/bin:" .. testing_paths.testing_sys_tree .. "/bin" + + return env_variables +end + +--- Create md5sums of origin system and system-copy testing directory +-- @param testing_paths table: table with paths to testing directory +-- @return md5sums table: table of md5sums of system and system-copy testing directory +local function create_md5sums(testing_paths) + local md5sums = {} + md5sums.testing_tree_copy_md5 = hash_environment(testing_paths.testing_tree_copy) + md5sums.testing_sys_tree_copy_md5 = hash_environment(testing_paths.testing_sys_tree_copy) + + return md5sums +end + +local function run_luarocks(testing_paths, env_variables) + + local function make_command_function(exec_function, lua_cmd, do_print) + return function(cmd, new_vars) + local temp_vars = {} + for k, v in pairs(env_variables) do + temp_vars[k] = v + end + if new_vars then + for k, v in pairs(new_vars) do + temp_vars[k] = v + end + end + return exec_function(lua_cmd .. cmd, do_print, temp_vars) + end + end + + local run = {} + + local cov_str = testing_paths.lua .. " -e\"require('luacov.runner')('" .. testing_paths.testing_dir .. "/luacov.config')\" " + + local luarocks_cmd = cov_str .. testing_paths.src_dir .. "/bin/luarocks " + run.luarocks = make_command_function(execute_output, luarocks_cmd, true) + run.luarocks_bool = make_command_function(execute_bool, luarocks_cmd, true) + run.luarocks_noprint = make_command_function(execute_bool, luarocks_cmd, false) + + local luarocks_nocov_cmd = testing_paths.lua .. " " .. testing_paths.src_dir .. "/bin/luarocks " + run.luarocks_nocov = make_command_function(execute_bool, luarocks_nocov_cmd, true) + run.luarocks_noprint_nocov = make_command_function(execute_bool, luarocks_nocov_cmd, false) + + local luarocks_admin_cmd = cov_str .. testing_paths.src_dir .. "/bin/luarocks-admin " + run.luarocks_admin = make_command_function(execute_output, luarocks_admin_cmd, true) + run.luarocks_admin_bool = make_command_function(execute_bool, luarocks_admin_cmd, true) + + local luarocks_admin_nocov_cmd = testing_paths.lua .. " " .. testing_paths.src_dir .. "/bin/luarocks-admin " + run.luarocks_admin_nocov = make_command_function(execute_bool, luarocks_admin_nocov_cmd, false) + + return run +end + +--- Build environment for testing +local function build_environment(env_rocks, testing_paths, env_variables) + print("\n--------------------") + print("BUILDING ENVIRONMENT") + print("--------------------") + test_env.remove_dir(testing_paths.testing_tree) + test_env.remove_dir(testing_paths.testing_sys_tree) + test_env.remove_dir(testing_paths.testing_tree_copy) + test_env.remove_dir(testing_paths.testing_sys_tree_copy) + + lfs.mkdir(testing_paths.testing_tree) + lfs.mkdir(testing_paths.testing_sys_tree) + + local run = run_luarocks(testing_paths, env_variables) + run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) + run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) + + for _,package in ipairs(env_rocks) do + if not run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) then + run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) + run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. package .. "; mv " .. package .. "-*.rock " .. testing_paths.testing_cache, env_variables) + end + end + + execute_bool("cp -a " .. testing_paths.testing_tree .. "/. " .. testing_paths.testing_tree_copy) + execute_bool("cp -a " .. testing_paths.testing_sys_tree .. "/. " .. testing_paths.testing_sys_tree_copy) +end + +--- Reset testing environment +local function reset_environment(testing_paths, md5sums) + local testing_tree_md5 = hash_environment(testing_paths.testing_tree) + local testing_sys_tree_md5 = hash_environment(testing_paths.testing_sys_tree) + + if testing_tree_md5 ~= md5sums.testing_tree_copy_md5 then + test_env.remove_dir(testing_paths.testing_tree) + execute_bool("cp -a " .. testing_paths.testing_tree_copy .. "/. " .. testing_paths.testing_tree) + end + if testing_sys_tree_md5 ~= md5sums.testing_sys_tree_copy_md5 then + test_env.remove_dir(testing_paths.testing_sys_tree) + execute_bool("cp -a " .. testing_paths.testing_sys_tree_copy .. "/. " .. testing_paths.testing_sys_tree) + end + + print("\n[ENVIRONMENT RESET]") +end + +local function create_paths(luaversion_full) + local testing_paths = {} + + testing_paths.luadir = "" + + if test_env.TRAVIS then + testing_paths.luadir = lfs.currentdir() .. "/lua_install" + testing_paths.lua = testing_paths.luadir .. "/bin/lua" + end + + if test_env.LUA_V and not test_env.TRAVIS then + if lfs.attributes("/usr/bin/lua") then + testing_paths.luadir = "/usr" + testing_paths.lua = testing_paths.luadir .. "/bin/lua" + elseif lfs.attributes("/usr/local/bin/lua") then + testing_paths.luadir = "/usr/local" + testing_paths.lua = testing_paths.luadir .. "/bin/lua" + end + elseif test_env.LUAJIT_V and not test_env.TRAVIS then + if lfs.attributes("/usr/bin/luajit") then + testing_paths.luadir = "/usr" + testing_paths.lua = testing_paths.luadir .. "/bin/luajit" + elseif lfs.attributes("/usr/local/bin/luajit") then + testing_paths.luadir = "/usr/local" + testing_paths.lua = testing_paths.luadir .. "/bin/luajit" + end + end + + testing_paths.luarocks_tmp = "/tmp/luarocks_testing" --windows? + + testing_paths.luarocks_dir = lfs.currentdir() + testing_paths.testing_dir = testing_paths.luarocks_dir .. "/test" + testing_paths.src_dir = testing_paths.luarocks_dir .. "/src" + testing_paths.testing_lrprefix = testing_paths.testing_dir .. "/testing_lrprefix-" .. luaversion_full + testing_paths.testing_tree = testing_paths.testing_dir .. "/testing-" .. luaversion_full + testing_paths.testing_tree_copy = testing_paths.testing_dir .. "/testing_copy-" .. luaversion_full + testing_paths.testing_sys_tree = testing_paths.testing_dir .. "/testing_sys-" .. luaversion_full + testing_paths.testing_sys_tree_copy = testing_paths.testing_dir .. "/testing_sys_copy-" .. luaversion_full + testing_paths.testing_cache = testing_paths.testing_dir .. "/testing_cache-" .. luaversion_full + testing_paths.testing_server = testing_paths.testing_dir .. "/testing_server-" .. luaversion_full + + return testing_paths +end + +--- Helper function to unload luarocks modules from global table package.loaded +-- Needed to load our local (testing) version of LuaRocks +function test_env.unload_luarocks() + for modname, _ in pairs(package.loaded) do + if modname:match("^luarocks%.") then + package.loaded[modname] = nil + end + end +end + +--- Function for initially setup of environment, variables, md5sums for spec files +function test_env.setup_specs(extra_rocks, luaversion_full) + -- if global variable about successful creation of testing environment doesn't exists, build environment + if not test_env.setup_done then + test_env.set_args() + + if test_env.TRAVIS then + if not os.rename(os.getenv("HOME") .. "/.ssh/id_rsa.pub", os.getenv("HOME") .. "/.ssh/id_rsa.pub") then + execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") + execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") + execute_bool("chmod og-wx ~/.ssh/authorized_keys") + execute_bool("ssh-keyscan localhost >> ~/.ssh/known_hosts") + end + end + + luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V + + test_env.main() + + -- Set paths, env_vars and functions for specs + test_env.testing_paths = create_paths(luaversion_full) + test_env.env_variables = create_env(test_env.testing_paths) + package.path = test_env.env_variables.LUA_PATH + + test_env.run = run_luarocks(test_env.testing_paths, test_env.env_variables) + test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables) + test_env.md5sums = create_md5sums(test_env.testing_paths) + test_env.setup_done = true + end + + if extra_rocks then + local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) + if make_manifest then + local run = run_luarocks(test_env.testing_paths, test_env.env_variables) + run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) + end + end + + reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables) + + return true +end + +--- Helper function for tests which needs luasocket installed +function test_env.need_luasocket(luarocks_nocov, testing_cache, platform) + luarocks_nocov = luarocks_nocov or test_env.run.luarocks_nocov + testing_cache = testing_cache or test_env.testing_paths.testing_cache + platform = platform or test_env.platform + + if luarocks_nocov("show luasocket") then + return true + else + testing_cache = testing_cache .. "/" + local luasocket_rock = "luasocket-3.0rc1-1." .. platform .. ".rock" + if not os.rename( testing_cache .. luasocket_rock, testing_cache .. luasocket_rock) then + luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1") + os.rename(luasocket_rock, testing_cache .. luasocket_rock) + end + luarocks_nocov("install " .. testing_cache .. luasocket_rock) + end + return true +end + +--- +-- Main function to create config files and testing environment +function test_env.main(luaversion_full, env_type, env_clean) + luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V + local testing_paths = create_paths(luaversion_full) + + env_clean = env_clean or test_env.TEST_ENV_CLEAN + if env_clean then + print("Cleaning testing directory...") + test_env.remove_dir(testing_paths.luarocks_tmp) + test_env.remove_dir_pattern(testing_paths.testing_dir, "testing_") + test_env.remove_dir_pattern(testing_paths.testing_dir, "testing-") + test_env.remove_files(testing_paths.testing_dir, "testing_") + test_env.remove_files(testing_paths.testing_dir, "luacov") + print("Cleaning done!") + end + + lfs.mkdir(testing_paths.testing_cache) + lfs.mkdir(testing_paths.luarocks_tmp) + +--- CONFIG FILES +-- testing_config.lua and testing_config_show_downloads.lua + local config_content = ([[rocks_trees = { + "%{testing_tree}", + { name = "system", root = "%{testing_sys_tree}" }, +} +rocks_servers = { + "%{testing_server}" +} +local_cache = "%{testing_cache}" +upload_server = "testing" +upload_user = "%{user}" +upload_servers = { + testing = { + rsync = "localhost/tmp/luarocks_testing", + }, +} +external_deps_dirs = { + "/usr/local", + "/usr", + -- These are used for a test that fails, so it + -- can point to invalid paths: + { + prefix = "/opt", + bin = "bin", + include = "include", + lib = { "lib", "lib64" }, + } +}]]):gsub("%%%b{}", { + ["%{user}"] = os.getenv("USER"), + ["%{testing_sys_tree}"] = testing_paths.testing_sys_tree, + ["%{testing_tree}"] = testing_paths.testing_tree, + ["%{testing_server}"] = testing_paths.testing_server, + ["%{testing_cache}"] = testing_paths.testing_cache}) + + create_config(testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") + create_config(testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content + .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") + +-- testing_config_sftp.lua + config_content=([[rocks_trees = { + "%{testing_tree}", + "%{testing_sys_tree}", +} +local_cache = "%{testing_cache}" +upload_server = "testing" +upload_user = "%{user}" +upload_servers = { + testing = { + sftp = "localhost/tmp/luarocks_testing", + }, +}]]):gsub("%%%b{}", { + ["%{user}"] = os.getenv("USER"), + ["%{testing_sys_tree}"] = testing_paths.testing_sys_tree, + ["%{testing_tree}"] = testing_paths.testing_tree, + ["%{testing_cache}"] = testing_paths.testing_cache}) + + create_config(testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) + +-- luacov.config + config_content=([[return { + statsfile = "%{testing_dir}/luacov.stats.out", + reportfile = "%{testing_dir}/luacov.report.out", + modules = { + ["luarocks"] = "src/bin/luarocks", + ["luarocks-admin"] = "src/bin/luarocks-admin", + ["luarocks.*"] = "src", + ["luarocks.*.*"] = "src", + ["luarocks.*.*.*"] = "src" + } +}]]):gsub("%%%b{}", { + ["%{testing_dir}"] = testing_paths.testing_dir}) + + create_config(testing_paths.testing_dir .. "/luacov.config", config_content) + + -- Create environment variables for configuration + local temp_env_variables = {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua",LUA_PATH="",LUA_CPATH=""} + + -- Configure LuaRocks testing environment + local configure_cmd = "./configure --with-lua=" .. testing_paths.luadir .. " --prefix=" .. testing_paths.testing_lrprefix + configure_cmd = configure_cmd .. " && make clean" + + if not execute_bool(configure_cmd, false, temp_env_variables) then + os.exit(1) + end + if not execute_bool("make src/luarocks/site_config.lua && make dev", false, temp_env_variables) then + os.exit(1) + end + + -- Preparation of rocks for building environment + env_type = env_type or test_env.TYPE_TEST_ENV + + local env_rocks = {} -- short names of rocks, required for building environment + local rocks = {} -- full names of rocks required for download + rocks[#rocks+1] = "/luacov-0.11.0-1.rockspec" + rocks[#rocks+1] = "/luacov-0.11.0-1.src.rock" + + if env_type == "full" then + rocks[#rocks+1] = "/luafilesystem-1.6.3-1.src.rock" + rocks[#rocks+1] = "/luasocket-3.0rc1-1.src.rock" + rocks[#rocks+1] = "/luasocket-3.0rc1-1.rockspec" + rocks[#rocks+1] = "/luaposix-33.2.1-1.src.rock" + rocks[#rocks+1] = "/md5-1.2-1.src.rock" + rocks[#rocks+1] = "/lzlib-0.4.1.53-1.src.rock" + env_rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} + end + if env_type == "full" and luaversion_full ~= "5.1.5" then + rocks[#rocks+1] = "/luabitop-1.0.2-1.rockspec" + rocks[#rocks+1] = "/luabitop-1.0.2-1.src.rock" + table.insert(env_rocks, "luabitop") + end + + table.insert(env_rocks, "luacov") -- luacov is needed for minimal or full environment + + -- Download rocks needed for LuaRocks testing environment + lfs.mkdir(testing_paths.testing_server) + download_rocks(rocks, testing_paths.testing_server) + + build_environment(env_rocks, testing_paths, temp_env_variables) + + print("----------------") + print(" RUNNING TESTS") + print("----------------") +end + +return test_env diff --git a/test/testing.lua b/test/testing.lua deleted file mode 100644 index 1a837484..00000000 --- a/test/testing.lua +++ /dev/null @@ -1,483 +0,0 @@ - -local variables = {} - --- Expand variables in the format $foo or ${foo} according --- to the variables table. -local function expand_variables(str) - return str:gsub("%$({?)([A-Za-z0-9_]+)(}?)", function(o, v, c) - return #o <= #c and (variables[v] or "") .. (#o < #c and c or "") - end) -end - --- @param cmd command to run --- @param envtable optional table of temporary environment variables -local function run(cmd, envtable) - cmd = expand_variables(cmd) - local env = {} - for var, val in pairs(envtable) do - table.insert(env, var.."='"..expand_variables(val).."' ") - end - local code = os.execute(table.concat(env)..cmd) - return (code == 0 or code == true) -end - -local function cd_run(dir, cmd, envtable) - return run("cd "..dir.." && "..cmd, envtable) -end - -local function run_get_contents(cmd) -end - -local function mkdir(dirname) - cmd = expand_variables(dirname) - -- TODO -end - -local function rm_rf(...) - -- TODO -end - -local function mv(src, dst) - -- TODO -end - -local function exists(filename) - filename = expand_variables(filename) - -- TODO -end - -local function glob(patt) - -- TODO -end - -local function touch(filename) - -- TODO -end - -local function rm(...) - for _, filename in ipairs {...} do - filename = expand_variables(filename) - -- TODO - end - return true -end - -local function file_set_contents(filename, contents) - filename = expand_variables(filename) - - local fd, err = io.open(filename, "w") - if not fd then return nil, err end - fd:write(contents) - fd:close() - return true -end - -local function need_luasocket() - -- TODO -end - -local tests = { - - test_version = function() return run "$luarocks --version" end, - fail_unknown_command = function() return run "$luarocks unknown_command" end, - fail_arg_boolean_parameter = function() return run "$luarocks --porcelain=invalid" end, - fail_arg_boolean_unknown = function() return run "$luarocks --invalid-flag" end, - fail_arg_string_no_parameter = function() return run "$luarocks --server" end, - fail_arg_string_followed_by_flag = function() return run "$luarocks --server --porcelain" end, - fail_arg_string_unknown = function() return run "$luarocks --invalid-flag=abc" end, - test_empty_list = function() return run "$luarocks list" end, - test_list_outdated = function () return run "$luarocks list --outdated" end, - fail_sysconfig_err = function() - mkdir "$testing_lrprefix/etc/luarocks" - file_set_contents("$testing_lrprefix/etc/luarocks/config.lua", "aoeui") - return run "$luarocks list" - and rm "$testing_lrprefix/etc/luarocks/config.lua" - end, - fail_sysconfig_default_err = function() - mkdir "$testing_lrprefix/etc/luarocks" - file_set_contents("$testing_lrprefix/etc/luarocks/config-$luashortversion.lua", "aoeui") - return run "$luarocks list" - and rm "$testing_lrprefix/etc/luarocks/config-$luashortversion.lua" - end, - fail_build_noarg = function() return run "$luarocks build" end, - fail_download_noarg = function() return run "$luarocks download" end, - fail_install_noarg = function() return run "$luarocks install" end, - fail_lint_noarg = function() return run "$luarocks lint" end, - fail_search_noarg = function() return run "$luarocks search" end, - fail_show_noarg = function() return run "$luarocks show" end, - fail_unpack_noarg = function() return run "$luarocks unpack" end, - fail_upload_noarg = function() return run "$luarocks upload" end, - fail_remove_noarg = function() return run "$luarocks remove" end, - fail_doc_noarg = function() return run "$luarocks doc" end, - fail_new_version_noarg = function() return run "$luarocks new_version" end, - fail_write_rockspec_noarg = function() return run "$luarocks write_rockspec" end, - fail_build_invalid = function() return run "$luarocks build invalid" end, - fail_download_invalid = function() return run "$luarocks download invalid" end, - fail_install_invalid = function() return run "$luarocks install invalid" end, - fail_lint_invalid = function() return run "$luarocks lint invalid" end, - fail_show_invalid = function() return run "$luarocks show invalid" end, - fail_new_version_invalid = function() return run "$luarocks new_version invalid" end, - test_list_invalidtree = function() return run "$luarocks --tree=/some/invalid/tree list" end, - fail_inexistent_dir = function() - -- Unix only? - return run "mkdir idontexist; cd idontexist; rmdir ../idontexist; $luarocks; err=$?; cd ..; return $err" - end, - fail_make_norockspec = function() return run "$luarocks make" end, - fail_build_permissions = function() return run "$luarocks build --tree=/usr lpeg" end, - fail_build_permissions_parent = function() return run "$luarocks build --tree=/usr/invalid lpeg" end, - test_build_verbose = function() return run "$luarocks build --verbose lpeg" end, - fail_build_blank_arg = function() return run "$luarocks build --tree="" lpeg" end, - test_build_withpatch = function() need_luasocket(); return run "$luarocks build luadoc" end, - test_build_diffversion = function() return run "$luarocks build luacov ${version_luacov}" end, - test_build_command = function() return run "$luarocks build stdlib" end, - test_build_install_bin = function() return run "$luarocks build luarepl" end, - test_build_nohttps = function() - need_luasocket() - return run "$luarocks download --rockspec validate-args ${verrev_validate_args}" - and run "$luarocks build ./validate-args-${version_validate_args}-1.rockspec" - and rm "./validate-args-${version_validate_args}-1.rockspec" - end, - test_build_https = function() - need_luasocket() - return run "$luarocks download --rockspec validate-args ${verrev_validate_args}" - and run "$luarocks install luasec" - and run "$luarocks build ./validate-args-${verrev_validate_args}.rockspec" - and rm "./validate-args-${verrev_validate_args}.rockspec" - end, - test_build_supported_platforms = function() return run "$luarocks build lpty" end, - test_build_only_deps_rockspec = function() - return run "$luarocks download --rockspec lxsh ${verrev_lxsh}" - and run "$luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps" - and (not run "$luarocks show lxsh") - end, - test_build_only_deps_src_rock = function() - return run "$luarocks download --source lxsh ${verrev_lxsh}" - and run "$luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps" - and (not run "$luarocks show lxsh") - end, - test_build_only_deps = function() return run "$luarocks build luasec --only-deps" and (not run "$luarocks show luasec") end, - test_install_only_deps = function() return run "$luarocks install lxsh ${verrev_lxsh} --only-deps" and (not run "$luarocks show lxsh") end, - fail_build_missing_external = function() return run '$luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"' end, - fail_build_invalidpatch = function() - need_luasocket() - return run '$luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"' - end, - test_build_deps_partial_match = function() return run "$luarocks build lmathx" end, - test_build_show_downloads = function() - return run("$luarocks build alien", { LUAROCKS_CONFIG="$testing_dir/testing_config_show_downloads.lua" }) - end, - test_download_all = function() - return run "$luarocks download --all validate-args" - and rm(glob("validate-args-*")) - end, - test_download_rockspecversion = function() - return run "$luarocks download --rockspec validate-args ${verrev_validate_args}" - and rm(glob("validate-args-*")) - end, - test_help = function() return run "$luarocks help" end, - fail_help_invalid = function() return run "$luarocks help invalid" end, - test_install_binaryrock = function() - return run "$luarocks build --pack-binary-rock cprint" - and run "$luarocks install ./cprint-${verrev_cprint}.${platform}.rock" - and rm "./cprint-${verrev_cprint}.${platform}.rock" - end, - test_install_with_bin = function() return run "$luarocks install wsapi" end, - fail_install_notazipfile = function() return run '$luarocks install "$testing_dir/testfiles/not_a_zipfile-1.0-1.src.rock"' end, - fail_install_invalidpatch = function() - need_luasocket() - return run '$luarocks install "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"' - end, - fail_install_invalid_filename = function() return run '$luarocks install "invalid.rock"' end, - fail_install_invalid_arch = function() return run '$luarocks install "foo-1.0-1.impossible-x86.rock"' end, - test_install_reinstall = function() - return run '$luarocks install "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"' - and run '$luarocks install --deps-mode=none "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"' - end, - fail_local_root = function() return run("$luarocks install --local luasocket", { USER="root" }) end, - test_site_config = function() - mv("../src/luarocks/site_config.lua", "../src/luarocks/site_config.lua.tmp") - local ok = run "$luarocks" - mv("../src/luarocks/site_config.lua.tmp", "../src/luarocks/site_config.lua") - return ok - end, - test_lint_ok = function() - return run "$luarocks download --rockspec validate-args ${verrev_validate_args}" - and run "$luarocks lint ./validate-args-${verrev_validate_args}.rockspec" - and rm "./validate-args-${verrev_validate_args}.rockspec" - end, - fail_lint_type_mismatch_string = function() return run '$luarocks lint "$testing_dir/testfiles/type_mismatch_string-1.0-1.rockspec"' end, - fail_lint_type_mismatch_version = function() return run '$luarocks lint "$testing_dir/testfiles/type_mismatch_version-1.0-1.rockspec"' end, - fail_lint_type_mismatch_table = function() return run '$luarocks lint "$testing_dir/testfiles/type_mismatch_table-1.0-1.rockspec"' end, - fail_lint_no_build_table = function() return run '$luarocks lint "$testing_dir/testfiles/no_build_table-0.1-1.rockspec"' end, - test_list = function() return run "$luarocks list" end, - test_list_porcelain = function() return run "$luarocks list --porcelain" end, - test_make_with_rockspec = function() - return rm_rf "./luasocket-${verrev_luasocket}" - and run "$luarocks download --source luasocket" - and run "$luarocks unpack ./luasocket-${verrev_luasocket}.src.rock" - and cd_run("luasocket-${verrev_luasocket}/${srcdir_luasocket}", "$luarocks make luasocket-${verrev_luasocket}.rockspec") - and rm_rf "./luasocket-${verrev_luasocket}" - end, - test_make_default_rockspec = function() - return rm_rf "./lxsh-${verrev_lxsh}" - and run "$luarocks download --source lxsh ${verrev_lxsh}" - and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock" - and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", "$luarocks make") - and rm_rf "./lxsh-${verrev_lxsh}" - end, - test_make_pack_binary_rock = function() - return rm_rf "./lxsh-${verrev_lxsh}" - and run "$luarocks download --source lxsh ${verrev_lxsh}" - and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock" - and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", "$luarocks make --deps-mode=none --pack-binary-rock") - and exists "lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1/lxsh-${verrev_lxsh}.all.rock" - and rm_rf "./lxsh-${verrev_lxsh}" - end, - fail_make_which_rockspec = function() - rm_rf "./luasocket-${verrev_luasocket}" - run "$luarocks download --source luasocket" - run "$luarocks unpack ./luasocket-${verrev_luasocket}.src.rock" - local ok = cd_run("luasocket-${verrev_luasocket}/${srcdir_luasocket}", "$luarocks make") - rm_rf "./luasocket-${verrev_luasocket}" - return ok - end, - test_new_version = function() - return run "$luarocks download --rockspec luacov ${version_luacov}" - and run "$luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2" - and rm(glob("./luacov-0.*")) - end, - test_new_version_url = function() - return run "$luarocks download --rockspec abelhas 1.0" - and run "$luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz" - and rm(glob("./abelhas-*")) - end, - test_pack = function() - return run "$luarocks list" - and run "$luarocks pack luacov" - and rm(glob("./luacov-*.rock")) - end, - test_pack_src = function() - return run "$luarocks install luasec" - and run "$luarocks download --rockspec luasocket" - and run "$luarocks pack ./luasocket-${verrev_luasocket}.rockspec" - and rm(glob("./luasocket-${version_luasocket}-*.rock")) - end, - test_path = function() return run "$luarocks path --bin" end, - test_path_lr_path = function() return run "$luarocks path --lr-path" end, - test_path_lr_cpath = function() return run "$luarocks path --lr-cpath" end, - test_path_lr_bin = function() return run "$luarocks path --lr-bin" end, - test_path_with_tree = function() return run "$luarocks path --tree=lua_modules" end, - fail_purge_missing_tree = function() return run '$luarocks purge --tree="$testing_tree"' end, - test_purge = function() return run '$luarocks purge --tree="$testing_sys_tree"' end, - test_remove = function() - return run "$luarocks build abelhas ${version_abelhas}" - and run "$luarocks remove abelhas ${version_abelhas}" - end, - test_remove_force = function() - need_luasocket() - return run "$luarocks build lualogging" - and run "$luarocks remove --force luasocket" - end, - fail_remove_deps = function() - need_luasocket() - return run "$luarocks build lualogging" - and run "$luarocks remove luasocket" - end, - fail_remove_missing = function() return run "$luarocks remove missing_rock" end, - fail_remove_invalid_name = function() return run "$luarocks remove invalid.rock" end, - test_search_found = function() return run "$luarocks search zlib" end, - test_search_missing = function() return run "$luarocks search missing_rock" end, - test_show = function() return run "$luarocks show luacov" end, - test_show_modules = function() return run "$luarocks show --modules luacov" end, - test_show_home = function() return run "$luarocks show --home luacov" end, - test_show_depends = function() - need_luasocket() - return run "$luarocks install luasec" - and run "$luarocks show luasec" - end, - test_show_oldversion = function() - return run "$luarocks install luacov ${version_luacov}" - and run "$luarocks show luacov ${version_luacov}" - end, - test_unpack_download = function() - return rm_rf "./cprint-${verrev_cprint}" - and run "$luarocks unpack cprint" - and rm_rf "./cprint-${verrev_cprint}" - end, - test_unpack_src = function() - return rm_rf "./cprint-${verrev_cprint}" - and run "$luarocks download --source cprint" - and run "$luarocks unpack ./cprint-${verrev_cprint}.src.rock" - and rm_rf "./cprint-${verrev_cprint}" - end, - test_unpack_rockspec = function() - return rm_rf "./cprint-${verrev_cprint}" - and run "$luarocks download --rockspec cprint" - and run "$luarocks unpack ./cprint-${verrev_cprint}.rockspec" - and rm_rf "./cprint-${verrev_cprint}" - end, - test_unpack_binary = function() - return rm_rf "./cprint-${verrev_cprint}" - and run "$luarocks build cprint" - and run "$luarocks pack cprint" - and run "$luarocks unpack ./cprint-${verrev_cprint}.${platform}.rock" - and rm_rf "./cprint-${verrev_cprint}" - end, - fail_unpack_invalidpatch = function() - need_luasocket() - return run '$luarocks unpack "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"' - end, - fail_unpack_invalidrockspec = function() - need_luasocket() - return run '$luarocks unpack "invalid.rockspec"' - end, - fail_upload_invalidrockspec = function() return run '$luarocks upload "invalid.rockspec"' end, - fail_upload_invalidkey = function() return run '$luarocks upload --api-key="invalid" "invalid.rockspec"' end, - test_admin_help = function() return run "$luarocks_admin help" end, - test_admin_make_manifest = function() return run "$luarocks_admin make_manifest" end, - test_admin_add_rsync = function() return run '$luarocks_admin --server=testing add "$testing_server/luasocket-${verrev_luasocket}.src.rock"' end, - test_admin_add_sftp = function() - return run("$luarocks_admin --server=testing add ./luasocket-${verrev_luasocket}.src.rock", { LUAROCKS_CONFIG="$testing_dir/testing_config_sftp.lua" }) - end, - fail_admin_add_missing = function() return run "$luarocks_admin --server=testing add" end, - fail_admin_invalidserver = function() return run '$luarocks_admin --server=invalid add "$testing_server/luasocket-${verrev_luasocket}.src.rock"' end, - fail_admin_invalidrock = function() return run "$luarocks_admin --server=testing add invalid" end, - test_admin_refresh_cache = function() return run "$luarocks_admin --server=testing refresh_cache" end, - test_admin_remove = function() return run "$luarocks_admin --server=testing remove luasocket-${verrev_luasocket}.src.rock" end, - fail_admin_remove_missing = function() return run "$luarocks_admin --server=testing remove" end, - fail_deps_mode_invalid_arg = function() return run "$luarocks remove luacov --deps-mode" end, - - test_deps_mode_one = function() - return run '$luarocks build --tree="system" lpeg' - and run '$luarocks list' - and run '$luarocks build --deps-mode=one --tree="$testing_tree" lxsh' - and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' ~= "" - end, - test_deps_mode_order = function() - return run '$luarocks build --tree="system" lpeg' - and run '$luarocks build --deps-mode=order --tree="$testing_tree" lxsh' - and run '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' - and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' == "" - end, - test_deps_mode_order_sys = function() - return run '$luarocks build --tree="$testing_tree" lpeg' - and run '$luarocks build --deps-mode=order --tree="$testing_sys_tree" lxsh' - and run_get_contents '$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg' ~= "" - end, - test_deps_mode_all_sys = function() - return run '$luarocks build --tree="$testing_tree" lpeg' - and run '$luarocks build --deps-mode=all --tree="$testing_sys_tree" lxsh' - and run_get_contents '$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg' == "" - end, - - test_deps_mode_none = function() - return run '$luarocks build --tree="$testing_tree" --deps-mode=none lxsh' - and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' == "" - end, - test_deps_mode_nodeps_alias = function() - return run '$luarocks build --tree="$testing_tree" --nodeps lxsh' - and run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' == "" - end, - test_deps_mode_make_order = function() - local ok = run '$luarocks build --tree="$testing_sys_tree" lpeg' - and rm_rf "./lxsh-${verrev_lxsh}" - and run "$luarocks download --source lxsh ${verrev_lxsh}" - and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock" - and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", '$luarocks make --tree="$testing_tree" --deps-mode=order') - if not ok then - return false - end - local found = run_get_contents '$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg' - rm_rf "./lxsh-${verrev_lxsh}" - return found == "" - end, - test_deps_mode_make_order_sys = function() - local ok = run '$luarocks build --tree="$testing_tree" lpeg' - and rm_rf "./lxsh-${verrev_lxsh}" - and run "$luarocks download --source lxsh ${verrev_lxsh}" - and run "$luarocks unpack ./lxsh-${verrev_lxsh}.src.rock" - and cd_run("lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1", '$luarocks make --tree="$testing_sys_tree" --deps-mode=order') - if not ok then - return false - end - local found = run_get_contents '$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg' - rm_rf "./lxsh-${verrev_lxsh}" - return found ~= "" - end, - test_write_rockspec = function() return run "$luarocks write_rockspec git://github.com/keplerproject/luarocks" end, - test_write_rockspec_lib = function() return run '$luarocks write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license="3-clause BSD" --lua-version=5.1,5.2' end, - test_write_rockspec_format = function() return run '$luarocks write_rockspec git://github.com/keplerproject/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2' end, - test_write_rockspec_fullargs = function() return run '$luarocks write_rockspec git://github.com/keplerproject/luarocks --lua-version=5.1,5.2 --license="MIT/X11" --homepage="http://www.luarocks.org" --summary="A package manager for Lua modules"' end, - fail_write_rockspec_args = function() return run "$luarocks write_rockspec invalid" end, - fail_write_rockspec_args_url = function() return run "$luarocks write_rockspec http://example.com/invalid.zip" end, - test_write_rockspec_http = function() return run "$luarocks write_rockspec http://luarocks.org/releases/luarocks-2.1.0.tar.gz --lua-version=5.1" end, - test_write_rockspec_basedir = function() return run "$luarocks write_rockspec https://github.com/downloads/Olivine-Labs/luassert/luassert-1.2.tar.gz --lua-version=5.1" end, - - fail_config_noflags = function() return run "$luarocks config; " end, - test_config_lua_incdir = function() return run "$luarocks config --lua-incdir; " end, - test_config_lua_libdir = function() return run "$luarocks config --lua-libdir; " end, - test_config_lua_ver = function() return run "$luarocks config --lua-ver; " end, - fail_config_system_config = function() - return rm "$testing_lrprefix/etc/luarocks/config.lua" - and run "$luarocks config --system-config; " - end, - test_config_system_config = function() - local ok = mkdir "$testing_lrprefix/etc/luarocks" - and touch "$testing_lrprefix/etc/luarocks/config.lua" - and run "$luarocks config --system-config; " - rm "$testing_lrprefix/etc/luarocks/config.lua" - return ok - end, - fail_config_system_config_invalid = function() - local ok = mkdir "$testing_lrprefix/etc/luarocks" - and run "echo 'if if if' > '$testing_lrprefix/etc/luarocks/config.lua' ;" - and run "$luarocks config --system-config" - rm "$testing_lrprefix/etc/luarocks/config.lua" - return ok - end, - test_config_user_config = function() return run "$luarocks config --user-config; " end, - fail_config_user_config = function() return run "LUAROCKS_CONFIG='/missing_file.lua' $luarocks config --user-config; " end, - test_config_rock_trees = function() return run "$luarocks config --rock-trees;" end, - test_config_help = function() return run "$luarocks help config;" end, - test_doc = function() - return run "$luarocks install luarepl" - and run "$luarocks doc luarepl" - end, - test_doc_home = function() - return run "$luarocks install luacov" - and run "$luarocks doc luacov --home" - end, - fail_doc_invalid = function () return run "$luarocks doc invalid" end, - - -- Tests for https://github.com/keplerproject/luarocks/issues/375 - test_fetch_base_dir = function() - local fetch = require "luarocks.fetch" - - return assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3.zip")) - and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.zip")) - and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.gz")) - and assert("lua-compat-5.2" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2.tar.bz2")) - and assert("parser.moon" == fetch.url_to_base_dir("git://github.com/Cirru/parser.moon")) - and assert("v0.3" == fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3")) - end, - - -- Tests for https://github.com/keplerproject/luarocks/issues/552 - test_install_break_dependencies_warning = function() - need_luasocket() - return run "$luarocks install say ${new_version_say}" - and run "$luarocks install luassert" - and run "$luarocks install say ${old_version_say}" - end, - test_install_break_dependencies_force = function() - need_luasocket() - return run "$luarocks install say ${new_version_say}" - and run "$luarocks install luassert" - and run "$luarocks install --force say ${old_version_say}" - end, - test_install_break_dependencies_force = function() - need_luasocket() - return run "$luarocks install say ${new_version_say}" - and run "$luarocks install luassert" - and run "$luarocks install --force-fast say ${old_version_say}" - end -} diff --git a/test/testing.sh b/test/testing.sh deleted file mode 100755 index cb10441c..00000000 --- a/test/testing.sh +++ /dev/null @@ -1,651 +0,0 @@ -#!/bin/bash -e - -# Setup ######################################### - -[ -e ../configure ] || { - echo "Please run this from the test/ directory." - exit 1 -} - -if [ -z "$*" ] -then - ps aux | grep -q '[s]shd' || { - echo "Run sudo /bin/sshd in order to perform all tests." - exit 1 - } -fi - -if [ "$1" == "--travis" ] -then - travis=true - shift -fi - -luaversion=5.1.5 - -if [ "$1" == "--lua" ] -then - shift - luaversion=$1 - shift -fi - -luashortversion=`echo $luaversion | cut -d. -f 1-2` - -testing_dir="$PWD" - -testing_lrprefix="$testing_dir/testing_lrprefix-$luaversion" -testing_tree="$testing_dir/testing-$luaversion" -testing_sys_tree="$testing_dir/testing_sys-$luaversion" -testing_tree_copy="$testing_dir/testing_copy-$luaversion" -testing_sys_tree_copy="$testing_dir/testing_sys_copy-$luaversion" -testing_cache="$testing_dir/testing_cache-$luaversion" -testing_server="$testing_dir/testing_server-$luaversion" - -if [ "$1" == "--clean" ] -then - shift - rm -rf "$testing_cache" - rm -rf "$testing_server" -fi - -[ "$1" ] || rm -f luacov.stats.out -rm -f luacov.report.out -rm -rf /tmp/luarocks_testing -mkdir /tmp/luarocks_testing -rm -rf "$testing_lrprefix" -rm -rf "$testing_tree" -rm -rf "$testing_sys_tree" -rm -rf "$testing_tree_copy" -rm -rf "$testing_sys_tree_copy" -rm -rf "$testing_dir/testing_config.lua" -rm -rf "$testing_dir/testing_config_show_downloads.lua" -rm -rf "$testing_dir/testing_config_sftp.lua" -rm -rf "$testing_dir/luacov.config" - -mkdir -p "$testing_cache" - -[ "$1" = "clean" ] && { - rm -f luacov.stats.out - exit 0 -} - -cat < $testing_dir/testing_config.lua -rocks_trees = { - "$testing_tree", - { name = "system", root = "$testing_sys_tree" }, -} -rocks_servers = { - "$testing_server" -} -local_cache = "$testing_cache" -upload_server = "testing" -upload_user = "$USER" -upload_servers = { - testing = { - rsync = "localhost/tmp/luarocks_testing", - }, -} -external_deps_dirs = { - "/usr/local", - "/usr", - -- These are used for a test that fails, so it - -- can point to invalid paths: - { - prefix = "/opt", - bin = "bin", - include = "include", - lib = { "lib", "lib64" }, - } -} -EOF -( - cat $testing_dir/testing_config.lua - echo "show_downloads = true" -) > $testing_dir/testing_config_show_downloads.lua -cat < $testing_dir/testing_config_sftp.lua -rocks_trees = { - "$testing_tree", - "$testing_sys_tree", -} -local_cache = "$testing_cache" -upload_server = "testing" -upload_user = "$USER" -upload_servers = { - testing = { - sftp = "localhost/tmp/luarocks_testing", - }, -} -EOF -cat < $testing_dir/luacov.config -return { - statsfile = "$testing_dir/luacov.stats.out", - reportfile = "$testing_dir/luacov.report.out", - modules = { - ["luarocks"] = "src/bin/luarocks", - ["luarocks-admin"] = "src/bin/luarocks-admin", - ["luarocks.*"] = "src", - ["luarocks.*.*"] = "src", - ["luarocks.*.*.*"] = "src" - } -} -EOF - -export LUAROCKS_CONFIG="$testing_dir/testing_config.lua" -export LUA_PATH= -export LUA_CPATH= - -if [ "$travis" ] -then - luadir=/tmp/lua-$luaversion - pushd /tmp - if [ ! -e "$luadir/bin/lua" ] - then - mkdir -p lua - echo "Downloading lua $luaversion..." - wget "http://www.lua.org/ftp/lua-$luaversion.tar.gz" &> /dev/null - tar zxpf "lua-$luaversion.tar.gz" - cd "lua-$luaversion" - echo "Building lua $luaversion..." - make linux INSTALL_TOP="$luadir" &> /dev/null - make install INSTALL_TOP="$luadir" &> /dev/null - fi - popd - [ -e ~/.ssh/id_rsa.pub ] || ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa - cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys - chmod og-wx ~/.ssh/authorized_keys - ssh-keyscan localhost >> ~/.ssh/known_hosts -else - luadir="/Programs/Lua/Current" - if [ ! -e "$luadir" ] - then - luadir="/usr/local" - fi -fi - -if [ `uname -m` = i686 ] -then - platform="linux-x86" -else - platform="linux-x86_64" -fi - -lua="$luadir/bin/lua" - -version_luasocket=3.0rc1 -verrev_luasocket=${version_luasocket}-1 -srcdir_luasocket=luasocket-3.0-rc1 - -version_cprint=0.1 -verrev_cprint=0.1-2 - -new_version_say=1.2-1 -old_version_say=1.0-1 - -version_luacov=0.11.0 -verrev_luacov=${version_luacov}-1 -version_lxsh=0.8.6 -version_validate_args=1.5.4 -verrev_validate_args=1.5.4-1 -verrev_lxsh=${version_lxsh}-2 -version_abelhas=1.0 -verrev_abelhas=${version_abelhas}-1 - -luasec=luasec - -cd .. -./configure --with-lua="$luadir" --prefix="$testing_lrprefix" -make clean -make src/luarocks/site_config.lua -make dev -cd src -basedir=$PWD -run_lua() { - if [ "$1" = "--noecho" ]; then shift; noecho=1; else noecho=0; fi - if [ "$1" = "--nocov" ]; then shift; nocov=1; else nocov=0; fi - if [ "$noecho" = 0 ] - then - echo $* - fi - cmd=$1 - shift - if [ "$nocov" = 0 ] - then - "$lua" -e"require('luacov.runner')('$testing_dir/luacov.config')" "$basedir/bin/$cmd" "$@" - else - "$lua" "$basedir/bin/$cmd" "$@" - fi -} -luarocks="run_lua luarocks" -luarocks_nocov="run_lua --nocov luarocks" -luarocks_noecho="run_lua --noecho luarocks" -luarocks_noecho_nocov="run_lua --noecho --nocov luarocks" -luarocks_admin="run_lua luarocks-admin" -luarocks_admin_nocov="run_lua --nocov luarocks-admin" - -################################################### - -mkdir -p "$testing_server" -( - cd "$testing_server" - luarocks_repo="https://luarocks.org" - get() { [ -e `basename "$1"` ] || wget -c "$1"; } - get "$luarocks_repo/luacov-${verrev_luacov}.src.rock" - get "$luarocks_repo/luacov-${verrev_luacov}.rockspec" - get "$luarocks_repo/luadoc-3.0.1-1.src.rock" - get "$luarocks_repo/lualogging-1.3.0-1.src.rock" - get "$luarocks_repo/luasocket-${verrev_luasocket}.src.rock" - get "$luarocks_repo/luasocket-${verrev_luasocket}.rockspec" - get "$luarocks_repo/luafilesystem-1.6.3-1.src.rock" - get "$luarocks_repo/stdlib-41.0.0-1.src.rock" - get "$luarocks_repo/luarepl-0.4-1.src.rock" - get "$luarocks_repo/validate-args-1.5.4-1.rockspec" - get "$luarocks_repo/luasec-0.6-1.rockspec" - get "$luarocks_repo/luabitop-1.0.2-1.rockspec" - get "$luarocks_repo/luabitop-1.0.2-1.src.rock" - get "$luarocks_repo/lpty-1.0.1-1.src.rock" - get "$luarocks_repo/cprint-${verrev_cprint}.src.rock" - get "$luarocks_repo/cprint-${verrev_cprint}.rockspec" - get "$luarocks_repo/wsapi-1.6-1.src.rock" - get "$luarocks_repo/lxsh-${verrev_lxsh}.src.rock" - get "$luarocks_repo/lxsh-${verrev_lxsh}.rockspec" - get "$luarocks_repo/abelhas-${verrev_abelhas}.rockspec" - get "$luarocks_repo/lzlib-0.4.1.53-1.src.rock" - get "$luarocks_repo/lpeg-0.12-1.src.rock" - get "$luarocks_repo/luaposix-33.2.1-1.src.rock" - get "$luarocks_repo/md5-1.2-1.src.rock" - get "$luarocks_repo/lmathx-20120430.51-1.src.rock" - get "$luarocks_repo/lmathx-20120430.51-1.rockspec" - get "$luarocks_repo/lmathx-20120430.52-1.src.rock" - get "$luarocks_repo/lmathx-20120430.52-1.rockspec" - get "$luarocks_repo/lmathx-20150505-1.src.rock" - get "$luarocks_repo/lmathx-20150505-1.rockspec" - get "$luarocks_repo/lua-path-0.2.3-1.src.rock" - get "$luarocks_repo/lua-cjson-2.1.0-1.src.rock" - get "$luarocks_repo/luacov-coveralls-0.1.1-1.src.rock" - get "$luarocks_repo/say-1.2-1.src.rock" - get "$luarocks_repo/say-1.0-1.src.rock" - get "$luarocks_repo/luassert-1.7.0-1.src.rock" -) -$luarocks_admin_nocov make_manifest "$testing_server" - -################################################### - -checksum_path() { - ( cd "$1"; find . -printf "%s %p\n" | md5sum ) -} - -build_environment() { - rm -rf "$testing_tree" - rm -rf "$testing_sys_tree" - rm -rf "$testing_tree_copy" - rm -rf "$testing_sys_tree_copy" - mkdir -p "$testing_tree" - mkdir -p "$testing_sys_tree" - $luarocks_admin_nocov make_manifest "$testing_cache" - for package in "$@" - do - $luarocks_nocov install --only-server="$testing_cache" --tree="$testing_sys_tree" $package || { - $luarocks_nocov build --tree="$testing_sys_tree" $package - $luarocks_nocov pack --tree="$testing_sys_tree" $package; mv $package-*.rock "$testing_cache" - } - done - export LUA_PATH= - export LUA_CPATH= - eval `$luarocks_noecho_nocov path --bin` - cp -a "$testing_tree" "$testing_tree_copy" - cp -a "$testing_sys_tree" "$testing_sys_tree_copy" - testing_tree_copy_md5=`checksum_path "$testing_tree_copy"` - testing_sys_tree_copy_md5=`checksum_path "$testing_sys_tree_copy"` -} - -reset_environment() { - testing_tree_md5=`checksum_path "$testing_tree"` - testing_sys_tree_md5=`checksum_path "$testing_sys_tree"` - if [ "$testing_tree_md5" != "$testing_tree_copy_md5" ] - then - rm -rf "$testing_tree" - cp -a "$testing_tree_copy" "$testing_tree" - fi - if [ "$testing_sys_tree_md5" != "$testing_sys_tree_copy_md5" ] - then - rm -rf "$testing_sys_tree" - cp -a "$testing_sys_tree_copy" "$testing_sys_tree" - fi -} - -need() { - echo "Obtaining $1 $2..." - if $luarocks show $1 &> /dev/null - then - echo "Already available" - return - fi - platrock="$1-$2.$platform.rock" - if [ ! -e "$testing_cache/$platrock" ] - then - echo "Building $1 $2..." - $luarocks_nocov build --pack-binary-rock $1 $2 - mv "$platrock" "$testing_cache" - fi - echo "Installing $1 $2..." - $luarocks_nocov install "$testing_cache/$platrock" - return -} -need_luasocket() { need luasocket $verrev_luasocket; } - -# Tests ######################################### -test_version() { $luarocks --version; } - -fail_unknown_command() { $luarocks unknown_command; } - -fail_arg_boolean_parameter() { $luarocks --porcelain=invalid; } -fail_arg_boolean_unknown() { $luarocks --invalid-flag; } -fail_arg_string_no_parameter() { $luarocks --server; } -fail_arg_string_followed_by_flag() { $luarocks --server --porcelain; } -fail_arg_string_unknown() { $luarocks --invalid-flag=abc; } - -fail_invalid_assignment() { $luarocks invalid=5; } - -test_empty_list() { $luarocks list; } -test_list_outdated() { $luarocks list --outdated; } - -fail_sysconfig_err() { local err=0; local scdir="$testing_lrprefix/etc/luarocks/"; mkdir -p "$scdir"; local sysconfig="$scdir/config.lua"; echo "aoeui" > "$sysconfig"; echo $sysconfig; $luarocks list; err=$?; rm "$sysconfig"; return "$err"; } -fail_sysconfig_default_err() { local err=0; local scdir="$testing_lrprefix/etc/luarocks/"; mkdir -p "$scdir"; local sysconfig="$scdir/config-$luashortversion.lua"; echo "aoeui" > "$sysconfig"; echo $sysconfig; $luarocks list; err=$?; rm "$sysconfig"; return "$err"; } - -fail_build_noarg() { $luarocks build; } -fail_download_noarg() { $luarocks download; } -fail_install_noarg() { $luarocks install; } -fail_lint_noarg() { $luarocks lint; } -fail_search_noarg() { $luarocks search; } -fail_show_noarg() { $luarocks show; } -fail_unpack_noarg() { $luarocks unpack; } -fail_upload_noarg() { $luarocks upload; } -fail_remove_noarg() { $luarocks remove; } -fail_doc_noarg() { $luarocks doc; } - -fail_build_invalid() { $luarocks build invalid; } -fail_download_invalid() { $luarocks download invalid; } -fail_install_invalid() { $luarocks install invalid; } -fail_lint_invalid() { $luarocks lint invalid; } -fail_show_invalid() { $luarocks show invalid; } -fail_new_version_invalid() { $luarocks new_version invalid; } - -test_list_invalidtree() { $luarocks --tree=/some/invalid/tree list; } - -fail_inexistent_dir() { mkdir idontexist; cd idontexist; rmdir ../idontexist; $luarocks; err=$?; cd ..; return $err; } - -fail_make_norockspec() { $luarocks make; } - -fail_build_permissions() { $luarocks build --tree=/usr lpeg; } -fail_build_permissions_parent() { $luarocks build --tree=/usr/invalid lpeg; } - -test_build_verbose() { $luarocks build --verbose lpeg; } -test_build_timeout() { $luarocks --timeout=10; } -fail_build_timeout_invalid() { $luarocks --timeout=abc; } -test_build_branch() { $luarocks build --branch=master lpeg; } -fail_build_invalid_entry_deps_mode() { $luarocks build --deps-mode=123 lpeg; } -test_build_only_server() { $luarocks --only-server=testing; } -test_build_only_sources() { $luarocks build --only-sources="http://example.com" lpeg; } -fail_build_blank_arg() { $luarocks build --tree="" lpeg; } -test_build_withpatch() { need_luasocket; $luarocks build luadoc; } -test_build_diffversion() { $luarocks build luacov ${version_luacov}; } -test_build_command() { $luarocks build stdlib; } -test_build_install_bin() { $luarocks build luarepl; } -test_build_nohttps() { need_luasocket; $luarocks download --rockspec validate-args ${verrev_validate_args} && $luarocks build ./validate-args-${version_validate_args}-1.rockspec && rm ./validate-args-${version_validate_args}-1.rockspec; } -test_build_https() { need_luasocket; $luarocks download --rockspec validate-args ${verrev_validate_args} && $luarocks install $luasec && $luarocks build ./validate-args-${verrev_validate_args}.rockspec && rm ./validate-args-${verrev_validate_args}.rockspec; } -test_build_supported_platforms() { $luarocks build lpty; } -test_build_only_deps_rockspec() { $luarocks download --rockspec lxsh ${verrev_lxsh} && $luarocks build ./lxsh-${verrev_lxsh}.rockspec --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } -test_build_only_deps_src_rock() { $luarocks download --source lxsh ${verrev_lxsh} && $luarocks build ./lxsh-${verrev_lxsh}.src.rock --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } -test_build_only_deps() { $luarocks build luasec --only-deps && { $luarocks show luasec; [ $? -ne 0 ]; }; } -test_install_only_deps() { $luarocks install lxsh ${verrev_lxsh} --only-deps && { $luarocks show lxsh; [ $? -ne 0 ]; }; } -test_build_no_deps() { $luarocks build luasec --nodeps; } -test_install_no_deps() { $luarocks install luasec --nodeps; } -fail_build_missing_external() { $luarocks build "$testing_dir/testfiles/missing_external-0.1-1.rockspec" INEXISTENT_INCDIR="/invalid/dir"; } -fail_build_invalidpatch() { need_luasocket; $luarocks build "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } - -test_build_deps_partial_match() { $luarocks build lmathx; } -test_build_show_downloads() { export LUAROCKS_CONFIG="$testing_dir/testing_config_show_downloads.lua" && $luarocks build alien; export LUAROCKS_CONFIG="$testing_dir/testing_config.lua"; } - -test_download_all() { $luarocks download --all validate-args && rm validate-args-*; } -test_download_rockspecversion() { $luarocks download --rockspec validate-args ${verrev_validate_args} && rm validate-args-*; } - -test_help() { $luarocks help; } -fail_help_invalid() { $luarocks help invalid; } - -test_install_only_deps() { $luarocks install --only-deps "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"; } -test_install_binaryrock() { $luarocks build --pack-binary-rock cprint && $luarocks install ./cprint-${verrev_cprint}.${platform}.rock && rm ./cprint-${verrev_cprint}.${platform}.rock; } -test_install_with_bin() { $luarocks install wsapi; } -fail_install_notazipfile() { $luarocks install "$testing_dir/testfiles/not_a_zipfile-1.0-1.src.rock"; } -fail_install_invalidpatch() { need_luasocket; $luarocks install "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } -fail_install_invalid_filename() { $luarocks install "invalid.rock"; } -fail_install_invalid_arch() { $luarocks install "foo-1.0-1.impossible-x86.rock"; } -test_install_reinstall() { $luarocks install "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"; $luarocks install --deps-mode=none "$testing_cache/luasocket-$verrev_luasocket.$platform.rock"; } - -fail_local_root() { USER=root $luarocks install --local luasocket; } - -test_site_config() { mv ../src/luarocks/site_config.lua ../src/luarocks/site_config.lua.tmp; $luarocks; mv ../src/luarocks/site_config.lua.tmp ../src/luarocks/site_config.lua; } - -test_lint_ok() { $luarocks download --rockspec validate-args ${verrev_validate_args} && $luarocks lint ./validate-args-${verrev_validate_args}.rockspec && rm ./validate-args-${verrev_validate_args}.rockspec; } -fail_lint_type_mismatch_string() { $luarocks lint "$testing_dir/testfiles/type_mismatch_string-1.0-1.rockspec"; } -fail_lint_type_mismatch_version() { $luarocks lint "$testing_dir/testfiles/type_mismatch_version-1.0-1.rockspec"; } -fail_lint_type_mismatch_table() { $luarocks lint "$testing_dir/testfiles/type_mismatch_table-1.0-1.rockspec"; } -fail_lint_no_build_table() { $luarocks lint "$testing_dir/testfiles/no_build_table-0.1-1.rockspec"; } - -test_list() { $luarocks list; } -test_list_porcelain() { $luarocks list --porcelain; } - -test_make_with_rockspec() { rm -rf ./luasocket-${verrev_luasocket} && $luarocks download --source luasocket && $luarocks unpack ./luasocket-${verrev_luasocket}.src.rock && cd luasocket-${verrev_luasocket}/${srcdir_luasocket} && $luarocks make luasocket-${verrev_luasocket}.rockspec && cd ../.. && rm -rf ./luasocket-${verrev_luasocket}; } -test_make_default_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks new_version lxsh-${verrev_lxsh}.rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } -test_make_unnamed_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && cp lxsh-${verrev_lxsh}.rockspec rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } -fail_make_ambiguous_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && cp lxsh-${verrev_lxsh}.rockspec lxsh2-${verrev_lxsh}.rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } -fail_make_ambiguous_unnamed_rockspec() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && mv lxsh-${verrev_lxsh}.rockspec 1_rockspec && cp 1_rockspec 2_rockspec && $luarocks make && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } -test_make_pack_binary_rock() { rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --deps-mode=none --pack-binary-rock && [ -e ./lxsh-${verrev_lxsh}.all.rock ] && cd ../.. && rm -rf ./lxsh-${verrev_lxsh}; } - -test_new_version() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec 0.2 && rm ./luacov-0.*; } -test_new_version_url() { $luarocks download --rockspec abelhas 1.0 && $luarocks new_version ./abelhas-1.0-1.rockspec 1.1 https://github.com/downloads/ittner/abelhas/abelhas-1.1.tar.gz && rm ./abelhas-*; } -test_new_version_tag() { $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version ./luacov-${version_luacov}-1.rockspec --tag v0.3 && rm ./luacov-0.3-1.rockspec; } -test_new_version_tag_without_arg() { rm -rf ./*rockspec && $luarocks download --rockspec luacov ${version_luacov} && $luarocks new_version --tag v0.3 && rm ./luacov-0.3-1.rockspec; } - -test_pack() { $luarocks list && $luarocks pack luacov && rm ./luacov-*.rock; } -test_pack_src() { $luarocks install $luasec && $luarocks download --rockspec luasocket && $luarocks pack ./luasocket-${verrev_luasocket}.rockspec && rm ./luasocket-${version_luasocket}-*.rock; } - -test_path() { $luarocks path --bin; } -test_path_lr_path() { $luarocks path --lr-path; } -test_path_lr_cpath() { $luarocks path --lr-cpath; } -test_path_lr_bin() { $luarocks path --lr-bin; } -test_path_with_tree() { $luarocks path --tree=lua_modules; } - -fail_purge_missing_tree() { $luarocks purge --tree="$testing_tree"; } -fail_purge_tree_notstring() { $luarocks purge --tree=1; } -test_purge() { $luarocks purge --tree="$testing_sys_tree"; } -test_purge_oldversions() { $luarocks purge --old-versions --tree="$testing_sys_tree"; } - -test_remove() { $luarocks build abelhas ${version_abelhas} && $luarocks remove abelhas ${version_abelhas}; } -test_remove_force() { need_luasocket; $luarocks build lualogging && $luarocks remove --force luasocket; } -test_remove_force_fast() { need_luasocket; $luarocks build lualogging && $luarocks remove --force-fast luasocket; } -fail_remove_deps() { need_luasocket; $luarocks build lualogging && $luarocks remove luasocket; } -fail_remove_missing() { $luarocks remove missing_rock; } -fail_remove_invalid_name() { $luarocks remove invalid.rock; } - -test_search_found() { $luarocks search zlib; } -test_search_missing() { $luarocks search missing_rock; } -test_search_version() { $luarocks search zlib 1.1; } -test_search_all() { $luarocks search --all; } -fail_search_nostring() { $var=123; $luarocks search $var; } - -test_show() { $luarocks show luacov; } -test_show_modules() { $luarocks show --modules luacov; } -test_show_home() { $luarocks show --home luacov; } -test_show_deps() { $luarocks show --deps luacov; } -test_show_rockspec() { $luarocks show --rockspec luacov; } -test_show_mversion() { $luarocks show --mversion luacov; } -test_show_rocktree() { $luarocks show --rock-tree luacov; } -test_show_rockdir() { $luarocks show --rock-dir luacov; } -test_show_depends() { need_luasocket; $luarocks install $luasec && $luarocks show luasec; } -test_show_oldversion() { $luarocks install luacov ${version_luacov} && $luarocks show luacov ${version_luacov}; } - -test_unpack_download() { rm -rf ./cprint-${verrev_cprint} && $luarocks unpack cprint && rm -rf ./cprint-${verrev_cprint}; } -test_unpack_src() { rm -rf ./cprint-${verrev_cprint} && $luarocks download --source cprint && $luarocks unpack ./cprint-${verrev_cprint}.src.rock && rm -rf ./cprint-${verrev_cprint}; } -test_unpack_rockspec() { rm -rf ./cprint-${verrev_cprint} && $luarocks download --rockspec cprint && $luarocks unpack ./cprint-${verrev_cprint}.rockspec && rm -rf ./cprint-${verrev_cprint}; } -test_unpack_binary() { rm -rf ./cprint-${verrev_cprint} && $luarocks build cprint && $luarocks pack cprint && $luarocks unpack ./cprint-${verrev_cprint}.${platform}.rock && rm -rf ./cprint-${verrev_cprint}; } -fail_unpack_invalidpatch() { need_luasocket; $luarocks unpack "$testing_dir/testfiles/invalid_patch-0.1-1.rockspec"; } -fail_unpack_invalidrockspec() { need_luasocket; $luarocks unpack "invalid.rockspec"; } - -fail_upload_invalidrockspec() { $luarocks upload "invalid.rockspec"; } -fail_upload_invalidkey() { $luarocks upload --api-key="invalid" "invalid.rockspec"; } -fail_upload_skippack() { $luarocks upload --api-key="invalid" --skip-pack "luacov-${verrev_luacov}.rockspec"; } -fail_upload_force() { $luarocks install lua-cjson && $luarocks upload --api-key="invalid" --force "luacov-${verrev_luacov}.rockspec" && $luarocks remove lua-cjson; } - - -test_admin_help() { $luarocks_admin help; } - -test_admin_make_manifest() { $luarocks_admin make_manifest; } -test_admin_add_rsync() { $luarocks_admin --server=testing add "$testing_server/luasocket-${verrev_luasocket}.src.rock"; } -test_admin_add_sftp() { export LUAROCKS_CONFIG="$testing_dir/testing_config_sftp.lua" && $luarocks_admin --server=testing add ./luasocket-${verrev_luasocket}.src.rock; export LUAROCKS_CONFIG="$testing_dir/testing_config.lua"; } -fail_admin_add_missing() { $luarocks_admin --server=testing add; } -fail_admin_invalidserver() { $luarocks_admin --server=invalid add "$testing_server/luasocket-${verrev_luasocket}.src.rock"; } -fail_admin_invalidrock() { $luarocks_admin --server=testing add invalid; } -test_admin_refresh_cache() { $luarocks_admin --server=testing refresh_cache; } -test_admin_remove() { $luarocks_admin --server=testing remove luasocket-${verrev_luasocket}.src.rock; } -fail_admin_remove_missing() { $luarocks_admin --server=testing remove; } -fail_admin_split_server_url() { $luarocks_admin --server="localhost@/tmp/luarocks_testing" add "$testing_server/luasocket-${verrev_luasocket}.src.rock"; } - -fail_deps_mode_invalid_arg() { $luarocks remove luacov --deps-mode; } -test_deps_mode_one() { $luarocks build --tree="system" lpeg && $luarocks list && $luarocks build --deps-mode=one --tree="$testing_tree" lxsh && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 1 ]; } -test_deps_mode_order() { $luarocks build --tree="system" lpeg && $luarocks build --deps-mode=order --tree="$testing_tree" lxsh && $luarocks_noecho list --tree="$testing_tree" --porcelain lpeg && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ]; } -test_deps_mode_order_sys() { $luarocks build --tree="$testing_tree" lpeg && $luarocks build --deps-mode=order --tree="$testing_sys_tree" lxsh && [ `$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg | wc -l` = 1 ]; } -test_deps_mode_all_sys() { $luarocks build --tree="$testing_tree" lpeg && $luarocks build --deps-mode=all --tree="$testing_sys_tree" lxsh && [ `$luarocks_noecho list --tree="$testing_sys_tree" --porcelain lpeg | wc -l` = 0 ]; } -test_deps_mode_none() { $luarocks build --tree="$testing_tree" --deps-mode=none lxsh; [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ]; } -test_deps_mode_nodeps_alias() { $luarocks build --tree="$testing_tree" --nodeps lxsh; [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ]; } -test_deps_mode_make_order() { $luarocks build --tree="$testing_sys_tree" lpeg && rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --tree="$testing_tree" --deps-mode=order && cd ../.. && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 0 ] && rm -rf ./lxsh-${verrev_lxsh}; } -test_deps_mode_make_order_sys() { $luarocks build --tree="$testing_tree" lpeg && rm -rf ./lxsh-${verrev_lxsh} && $luarocks download --source lxsh ${verrev_lxsh} && $luarocks unpack ./lxsh-${verrev_lxsh}.src.rock && cd lxsh-${verrev_lxsh}/lxsh-${version_lxsh}-1 && $luarocks make --tree="$testing_sys_tree" --deps-mode=order && cd ../.. && [ `$luarocks_noecho list --tree="$testing_tree" --porcelain lpeg | wc -l` = 1 ] && rm -rf ./lxsh-${verrev_lxsh}; } - -test_write_rockspec() { $luarocks write_rockspec git://github.com/keplerproject/luarocks; } -test_write_rockspec_name() { $luarocks write_rockspec luarocks git://github.com/keplerproject/luarocks; } -test_write_rockspec_name_version() { $luarocks write_rockspec luarocks 7.8.9 git://github.com/keplerproject/luarocks; } -test_write_rockspec_current_dir() { $luarocks write_rockspec; } -test_write_rockspec_tag() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --tag=v2.3.0; } -test_write_rockspec_lib() { $luarocks write_rockspec git://github.com/mbalmer/luafcgi --lib=fcgi --license="3-clause BSD" --lua-version=5.1,5.2; } -test_write_rockspec_format() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --rockspec-format=1.1 --lua-version=5.1,5.2; } -test_write_rockspec_fullargs() { $luarocks write_rockspec git://github.com/keplerproject/luarocks --lua-version=5.1,5.2 --license="MIT/X11" --homepage="http://www.luarocks.org" --summary="A package manager for Lua modules"; } -fail_write_rockspec_args() { $luarocks write_rockspec invalid; } -fail_write_rockspec_args_url() { $luarocks write_rockspec http://example.com/invalid.zip; } -test_write_rockspec_http() { $luarocks write_rockspec http://luarocks.org/releases/luarocks-2.1.0.tar.gz --lua-version=5.1; } -test_write_rockspec_basedir() { $luarocks write_rockspec https://github.com/downloads/Olivine-Labs/luassert/luassert-1.2.tar.gz --lua-version=5.1; } - -fail_config_noflags() { $luarocks config; } -test_config_lua_incdir() { $luarocks config --lua-incdir; } -test_config_lua_libdir() { $luarocks config --lua-libdir; } -test_config_lua_ver() { $luarocks config --lua-ver; } -fail_config_system_config() { rm -f "$testing_lrprefix/etc/luarocks/config.lua"; $luarocks config --system-config; } -test_config_system_config() { mkdir -p "$testing_lrprefix/etc/luarocks"; touch "$testing_lrprefix/etc/luarocks/config.lua"; $luarocks config --system-config; err=$?; rm -f "$testing_lrprefix/etc/luarocks/config.lua"; return $err; } -fail_config_system_config_invalid() { mkdir -p "$testing_lrprefix/etc/luarocks"; echo "if if if" > "$testing_lrprefix/etc/luarocks/config.lua"; $luarocks config --system-config; err=$?; rm -f "$testing_lrprefix/etc/luarocks/config.lua"; return $err; } -test_config_user_config() { $luarocks config --user-config; } -fail_config_user_config() { LUAROCKS_CONFIG="/missing_file.lua" $luarocks config --user-config; } -test_config_rock_trees() { $luarocks config --rock-trees; } -test_config_help() { $luarocks help config; } - -# Tests for https://github.com/keplerproject/luarocks/issues/375 -test_fetch_base_dir() { $lua < Date: Fri, 8 Jul 2016 12:04:08 +0300 Subject: .travis.yml: don't use virtualenv Install python 2 and avoid using virtualenv, pip on osx works fine without it. Also remove unnecessary path prefix and add newline at the end. --- .travis.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index c8755e7f..0ec4b0cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,11 +40,7 @@ matrix: before_install: - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install python3; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then virtualenv venv -p python3; fi - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then source venv/bin/activate; fi - + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install python; fi - pip install hererocks - hererocks lua_install -r^ --$LUA - export PATH=$PATH:$PWD/lua_install/bin # Add directory with all installed binaries to PATH @@ -60,10 +56,10 @@ script: after_success: - luacov-coveralls -c $TRAVIS_BUILD_DIR/test/luacov.config --exclude $TRAVIS_BUILD_DIR/test/ - - $PWD/lua_install/bin/luacov -c $TRAVIS_BUILD_DIR/test/luacov.config + - luacov -c $TRAVIS_BUILD_DIR/test/luacov.config - grep "Summary" -B1 -A1000 $TRAVIS_BUILD_DIR/test/luacov.report.out notifications: email: on_success: change - on_failure: change \ No newline at end of file + on_failure: change -- cgit v1.2.3-55-g6feb From 88f6aaeb40958c10a3c7a6fb4d0d699481f2a7be Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 12:35:01 +0300 Subject: Tests: infer Lua/LuaJIT version --- .travis.yml | 6 +++--- test/test_environment.lua | 52 ++++++++++++++++++++++------------------------- 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0ec4b0cf..02bdb6c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,10 +49,10 @@ install: - luarocks install busted - luarocks install luacov - luarocks install luacov-coveralls - + script: - - busted -Xhelper travis,$LUA --verbose - - busted -Xhelper travis,$LUA,env=full --verbose + - busted -Xhelper travis --verbose + - busted -Xhelper travis,env=full --verbose after_success: - luacov-coveralls -c $TRAVIS_BUILD_DIR/test/luacov.config --exclude $TRAVIS_BUILD_DIR/test/ 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() Tests require to have Lua installed and added to PATH. Be sure sshd is runnig on your system, or use '--exclude-tags=ssh', to not execute tests which require sshd. USAGE -Xhelper - lua= (mandatory) type your full version of Lua (e.g. --lua 5.2.4) - OR - luajit= (mandatory) type your full version of LuaJIT (e.g. --luajit 2.0.3) - env= (default:"minimal") type what kind of environment to use ["minimal", "full"] clean remove existing testing environment travis add just if running on TravisCI @@ -70,50 +66,49 @@ local function execute_output(command, print_command, env_variables) return output:gsub("\n","") -- output adding new line, need to be removed end +--- Set test_env.LUA_V or test_env.LUAJIT_V based +-- on version of Lua used to run this script. +function test_env.set_lua_version() + if _G.jit then + test_env.LUAJIT_V = _G.jit.version:match("(2%.%d)%.%d") + else + test_env.LUA_V = _VERSION:match("5%.%d") + end +end + --- Set all arguments from input into global variables function test_env.set_args() if arg[1] == nil then help() end - - local args_position - + + local helper_arg + for i=1, #arg do - if arg[i]:find("-Xhelper") and arg[i+1]:find("lua=") and not arg[i+1]:find("luajit=") then - args_position = i+1 - test_env.LUA_V = arg[args_position]:gsub("(.*)lua=([^%,]+)(.*)","%2") - break - elseif arg[i]:find("-Xhelper") and not arg[i+1]:find("lua=") and arg[i+1]:find("luajit=") then - args_position = i+1 - test_env.LUAJIT_V = arg[args_position]:gsub("(.*)luajit=([^%,]+)(.*)","%2") - break - elseif arg[i]:find("-Xhelper") and arg[i+1]:find("lua=") and arg[i+1]:find("luajit=") then - print("Please specify just Lua or LuaJIT version for testing in format 'lua=X.X.X' or 'luajit=X.X.X', for -Xhelper flag") - os.exit(1) - elseif arg[i]:find("-Xhelper") and not arg[i+1]:find("lua=") and not arg[i+1]:find("luajit=") then - print("Please add mandatory argument - version of Lua or LuaJIT in format 'lua=X.X.X' or 'luajit=X.X.X', for -Xhelper flag") - os.exit(1) + if arg[i] == "-Xhelper" then + helper_arg = arg[i+1] + break end end - if not args_position then + 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 arg[args_position]:find("env=") then - test_env.TYPE_TEST_ENV = arg[args_position]:gsub("(.*)env=([^%,]+)(.*)","%2") + if helper_arg:find("env=") then + test_env.TYPE_TEST_ENV = helper_arg:gsub("(.*)env=([^%,]+)(.*)","%2") end - if arg[args_position]:find("clean") then + if helper_arg:find("clean") then test_env.TEST_ENV_CLEAN = true end - if arg[args_position]:find("travis") then + if helper_arg:find("travis") then test_env.TRAVIS = true end - if arg[args_position]:find("os=") then - test_env.TEST_TARGET_OS = arg[args_position]:gsub("(.*)os=([^%,]+)(.*)","%2") + if helper_arg:find("os=") then + test_env.TEST_TARGET_OS = helper_arg:gsub("(.*)os=([^%,]+)(.*)","%2") end if not test_env.TEST_TARGET_OS then @@ -418,6 +413,7 @@ end function test_env.setup_specs(extra_rocks, luaversion_full) -- if global variable about successful creation of testing environment doesn't exists, build environment if not test_env.setup_done then + test_env.set_lua_version() test_env.set_args() if test_env.TRAVIS then -- cgit v1.2.3-55-g6feb From fc7d6f7f6542c5eeef8d92ed717132caa45901c8 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 12:44:16 +0300 Subject: Remove all the unused imports in test suite --- spec/add_spec.lua | 4 +--- spec/build_spec.lua | 1 - spec/config_spec.lua | 3 +-- spec/deps_spec.lua | 3 +-- spec/doc_spec.lua | 2 -- spec/download_spec.lua | 1 - spec/fetch_spec.lua | 3 +-- spec/help_spec.lua | 4 +--- spec/install_spec.lua | 3 +-- spec/lint_spec.lua | 4 +--- spec/list_spec.lua | 2 -- spec/make_manifest_spec.lua | 4 +--- spec/make_spec.lua | 3 +-- spec/new_version_spec.lua | 3 +-- spec/pack_spec.lua | 1 - spec/path_spec.lua | 2 -- spec/purge_spec.lua | 2 -- spec/refresh_cache_spec.lua | 4 +--- spec/remove_spec.lua | 3 +-- spec/search_spec.lua | 4 +--- spec/show_spec.lua | 2 -- spec/unpack_spec.lua | 2 -- spec/upload_spec.lua | 2 -- 23 files changed, 13 insertions(+), 49 deletions(-) diff --git a/spec/add_spec.lua b/spec/add_spec.lua index e417f974..5d020859 100644 --- a/spec/add_spec.lua +++ b/spec/add_spec.lua @@ -1,8 +1,6 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() -local add = require("luarocks.add") local extra_rocks = { "/luasocket-3.0rc1-1.src.rock", @@ -43,4 +41,4 @@ expose("LuaRocks add tests #blackbox #b_add", function() assert.is_false(run.luarocks_admin_bool("--server=\"localhost@/tmp/luarocks_testing\" add " .. testing_paths.testing_server .. "luasocket-3.0rc1-1.src.rock")) end) end) -end) \ No newline at end of file +end) diff --git a/spec/build_spec.lua b/spec/build_spec.lua index 6665de0b..ee88cce4 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -2,7 +2,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") test_env.unload_luarocks() -local build = require("luarocks.build") local extra_rocks = { "/lmathx-20120430.51-1.src.rock", diff --git a/spec/config_spec.lua b/spec/config_spec.lua index f6cabd8c..a7842811 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua @@ -2,7 +2,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") test_env.unload_luarocks() -local cfg = require("luarocks.cfg") expose("LuaRocks config tests #blackbox #b_config", function() @@ -87,4 +86,4 @@ expose("LuaRocks config tests #blackbox #b_config", function() test_env.remove_dir(testing_paths.testing_lrprefix) end) end) -end) \ No newline at end of file +end) diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua index ce784080..3a0cda74 100644 --- a/spec/deps_spec.lua +++ b/spec/deps_spec.lua @@ -2,7 +2,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") test_env.unload_luarocks() -local deps = require("luarocks.deps") local extra_rocks = { "/lxsh-0.8.6-2.src.rock", @@ -112,4 +111,4 @@ expose("LuaRocks deps tests #blackbox #b_deps", function() assert.is.falsy(lfs.attributes(testing_paths.testing_tree .. "/lib/luarocks/rocks/lxsh")) assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) end) -end) \ No newline at end of file +end) diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua index 476b8ea8..d0d6ff1e 100644 --- a/spec/doc_spec.lua +++ b/spec/doc_spec.lua @@ -1,8 +1,6 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() -local doc = require("luarocks.doc") local extra_rocks = { "/luarepl-0.4-1.src.rock" diff --git a/spec/download_spec.lua b/spec/download_spec.lua index 9b5d9e2e..d1216d33 100644 --- a/spec/download_spec.lua +++ b/spec/download_spec.lua @@ -2,7 +2,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") test_env.unload_luarocks() -local download = require("luarocks.download") local extra_rocks = { "/validate-args-1.5.4-1.rockspec" diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua index 1f298733..05a709e4 100644 --- a/spec/fetch_spec.lua +++ b/spec/fetch_spec.lua @@ -1,5 +1,4 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() local fetch = require("luarocks.fetch") @@ -13,4 +12,4 @@ describe("Luarocks fetch test #whitebox #w_fetch", function() assert.are.same("parser.moon", fetch.url_to_base_dir("git://github.com/Cirru/parser.moon")) assert.are.same("v0.3", fetch.url_to_base_dir("https://github.com/hishamhm/lua-compat-5.2/archive/v0.3")) end) -end) \ No newline at end of file +end) diff --git a/spec/help_spec.lua b/spec/help_spec.lua index 0f40dd38..08f6f1f1 100644 --- a/spec/help_spec.lua +++ b/spec/help_spec.lua @@ -1,8 +1,6 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() -local help = require("luarocks.help") expose("LuaRocks help tests #blackbox #b_help", function() @@ -26,4 +24,4 @@ expose("LuaRocks help tests #blackbox #b_help", function() it("LuaRocks-admin help with no flags/arguments", function() assert.is_true(run.luarocks_admin_bool("help")) end) -end) \ No newline at end of file +end) diff --git a/spec/install_spec.lua b/spec/install_spec.lua index 306bbbc1..a598f324 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -2,7 +2,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") test_env.unload_luarocks() -local install = require("luarocks.install") local extra_rocks = { "/cprint-0.1-2.src.rock", @@ -127,4 +126,4 @@ expose("LuaRocks install tests #blackbox #b_install", function() assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/say/1.0-1")) end) end) -end) \ No newline at end of file +end) diff --git a/spec/lint_spec.lua b/spec/lint_spec.lua index cba80a3e..58c87c4e 100644 --- a/spec/lint_spec.lua +++ b/spec/lint_spec.lua @@ -1,8 +1,6 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() -local lint = require("luarocks.lint") local extra_rocks = { "/validate-args-1.5.4-1.rockspec" @@ -48,4 +46,4 @@ expose("LuaRocks lint tests #blackbox #b_lint", function() assert.is_false(run.luarocks_bool("lint " .. testing_paths.testing_dir .. "/testfiles/no_build_table-1.0-1.rockspec")) end) end) -end) \ No newline at end of file +end) diff --git a/spec/list_spec.lua b/spec/list_spec.lua index 545483df..edc310ca 100644 --- a/spec/list_spec.lua +++ b/spec/list_spec.lua @@ -1,8 +1,6 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() -local list = require("luarocks.list") local extra_rocks = { "/say-1.0-1.src.rock", diff --git a/spec/make_manifest_spec.lua b/spec/make_manifest_spec.lua index c6cb1328..a5b19eff 100644 --- a/spec/make_manifest_spec.lua +++ b/spec/make_manifest_spec.lua @@ -1,8 +1,6 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() -local make_manifest = require("luarocks.make_manifest") expose("LuaRocks make_manifest tests #blackbox #b_make_manifest", function() @@ -16,4 +14,4 @@ expose("LuaRocks make_manifest tests #blackbox #b_make_manifest", function() assert.is_true(run.luarocks_admin_bool("make_manifest")) end) end) -end) \ No newline at end of file +end) diff --git a/spec/make_spec.lua b/spec/make_spec.lua index f70bb7e9..b0177fc5 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua @@ -2,7 +2,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") test_env.unload_luarocks() -local make = require("luarocks.make") local extra_rocks = { "/lpeg-0.12-1.src.rock", @@ -96,4 +95,4 @@ expose("LuaRocks make tests #blackbox #b_make", function() assert.is.truthy(lfs.attributes("lxsh-0.8.6-2.all.rock")) end) end) -end) \ No newline at end of file +end) diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua index 57014226..685d31b4 100644 --- a/spec/new_version_spec.lua +++ b/spec/new_version_spec.lua @@ -2,7 +2,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") test_env.unload_luarocks() -local new_version = require("luarocks.new_version") local extra_rocks = { "/abelhas-1.0-1.rockspec" @@ -50,4 +49,4 @@ expose("LuaRocks new_version tests #blackbox #b_new_version", function() test_env.remove_files(lfs.currentdir(), "luacov--") end) end) -end) \ No newline at end of file +end) diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index a07e7ed2..39d8bc5c 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua @@ -2,7 +2,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") test_env.unload_luarocks() -local pack = require("luarocks.pack") local extra_rocks = { "/luasec-0.6-1.rockspec", diff --git a/spec/path_spec.lua b/spec/path_spec.lua index 266ada89..cffc186b 100644 --- a/spec/path_spec.lua +++ b/spec/path_spec.lua @@ -1,8 +1,6 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() -local path = require("luarocks.path") expose("LuaRocks path tests #blackbox #b_path", function() before_each(function() diff --git a/spec/purge_spec.lua b/spec/purge_spec.lua index 639f96f3..f5515cb5 100644 --- a/spec/purge_spec.lua +++ b/spec/purge_spec.lua @@ -1,8 +1,6 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() -local purge = require("luarocks.purge") expose("LuaRocks purge tests #blackbox #b_purge", function() before_each(function() diff --git a/spec/refresh_cache_spec.lua b/spec/refresh_cache_spec.lua index 27a95e5c..ef8c3a12 100644 --- a/spec/refresh_cache_spec.lua +++ b/spec/refresh_cache_spec.lua @@ -1,8 +1,6 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() -local refresh_cache = require("luarocks.refresh_cache") expose("LuaRocks refresh_cache tests #blackbox #b_refresh_cache", function() @@ -16,4 +14,4 @@ expose("LuaRocks refresh_cache tests #blackbox #b_refresh_cache", function() assert.is_true(run.luarocks_admin_bool("--server=testing refresh_cache")) end) end) -end) \ No newline at end of file +end) diff --git a/spec/remove_spec.lua b/spec/remove_spec.lua index a94673a8..1b3cda7e 100644 --- a/spec/remove_spec.lua +++ b/spec/remove_spec.lua @@ -2,7 +2,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") test_env.unload_luarocks() -local remove = require("luarocks.remove") local extra_rocks = { "/abelhas-1.0-1.rockspec", @@ -82,4 +81,4 @@ expose("LuaRocks remove tests #blackbox #b_remove", function() it("LuaRocks-admin remove missing", function() assert.is_false(run.luarocks_admin_bool("--server=testing remove")) end) -end) \ No newline at end of file +end) diff --git a/spec/search_spec.lua b/spec/search_spec.lua index a0258942..8e84931b 100644 --- a/spec/search_spec.lua +++ b/spec/search_spec.lua @@ -1,8 +1,6 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() -local search = require("luarocks.search") local extra_rocks = { "/lzlib-0.4.1.53-1.src.rock" @@ -39,4 +37,4 @@ expose("LuaRocks search tests #blackbox #b_search", function() local num = 123 assert.is_true(run.luarocks_bool("search " .. num)) end) -end) \ No newline at end of file +end) diff --git a/spec/show_spec.lua b/spec/show_spec.lua index 85797eb6..c2f70c92 100644 --- a/spec/show_spec.lua +++ b/spec/show_spec.lua @@ -1,8 +1,6 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() -local show = require("luarocks.show") expose("LuaRocks show tests #blackbox #b_show", function() diff --git a/spec/unpack_spec.lua b/spec/unpack_spec.lua index efe902f5..3930a583 100644 --- a/spec/unpack_spec.lua +++ b/spec/unpack_spec.lua @@ -1,8 +1,6 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() -local unpack = require("luarocks.unpack") local extra_rocks = { "/cprint-0.1-2.src.rock", diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua index daf40d61..f0125966 100644 --- a/spec/upload_spec.lua +++ b/spec/upload_spec.lua @@ -1,8 +1,6 @@ local test_env = require("test/test_environment") -local lfs = require("lfs") test_env.unload_luarocks() -local upload = require("luarocks.upload") local extra_rocks = { "/lua-cjson-2.1.0-1.src.rock" -- cgit v1.2.3-55-g6feb 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 From 20a1baba59e7555b3140e0c2226948447fe8e62a Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 13:50:11 +0300 Subject: Tests: disable insulation and use describe() instead of expose() --- .busted | 3 ++- spec/add_spec.lua | 2 +- spec/build_spec.lua | 2 +- spec/config_spec.lua | 2 +- spec/deps_spec.lua | 2 +- spec/doc_spec.lua | 2 +- spec/download_spec.lua | 2 +- spec/help_spec.lua | 2 +- spec/install_spec.lua | 2 +- spec/lint_spec.lua | 2 +- spec/list_spec.lua | 2 +- spec/make_manifest_spec.lua | 2 +- spec/make_spec.lua | 2 +- spec/new_version_spec.lua | 2 +- spec/pack_spec.lua | 2 +- spec/path_spec.lua | 2 +- spec/purge_spec.lua | 2 +- spec/refresh_cache_spec.lua | 2 +- spec/remove_spec.lua | 2 +- spec/search_spec.lua | 2 +- spec/show_spec.lua | 2 +- spec/unpack_spec.lua | 2 +- spec/upload_spec.lua | 2 +- spec/util_spec.lua | 2 +- spec/write_rockspec_spec.lua | 2 +- 25 files changed, 26 insertions(+), 25 deletions(-) diff --git a/.busted b/.busted index 7c67e719..29a8137b 100644 --- a/.busted +++ b/.busted @@ -1,5 +1,6 @@ return { default = { - helper = "test/test_environment" + helper = "test/test_environment", + ["auto-insulate"] = false } } diff --git a/spec/add_spec.lua b/spec/add_spec.lua index 5d020859..930c221d 100644 --- a/spec/add_spec.lua +++ b/spec/add_spec.lua @@ -7,7 +7,7 @@ local extra_rocks = { "/luasocket-3.0rc1-1.rockspec" } -expose("LuaRocks add tests #blackbox #b_add", function() +describe("LuaRocks add tests #blackbox #b_add", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/build_spec.lua b/spec/build_spec.lua index ee88cce4..7248e8f0 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -25,7 +25,7 @@ local extra_rocks = { "/validate-args-1.5.4-1.rockspec" } -expose("LuaRocks build tests #blackbox #b_build", function() +describe("LuaRocks build tests #blackbox #b_build", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/config_spec.lua b/spec/config_spec.lua index a7842811..df2480ac 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua @@ -3,7 +3,7 @@ local lfs = require("lfs") test_env.unload_luarocks() -expose("LuaRocks config tests #blackbox #b_config", function() +describe("LuaRocks config tests #blackbox #b_config", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua index 3a0cda74..9bb4709d 100644 --- a/spec/deps_spec.lua +++ b/spec/deps_spec.lua @@ -11,7 +11,7 @@ local extra_rocks = { "/lpeg-0.12-1.src.rock" } -expose("LuaRocks deps tests #blackbox #b_deps", function() +describe("LuaRocks deps tests #blackbox #b_deps", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua index d0d6ff1e..e4e7f5f2 100644 --- a/spec/doc_spec.lua +++ b/spec/doc_spec.lua @@ -6,7 +6,7 @@ local extra_rocks = { "/luarepl-0.4-1.src.rock" } -expose("LuaRocks doc tests #blackbox #b_doc", function() +describe("LuaRocks doc tests #blackbox #b_doc", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/download_spec.lua b/spec/download_spec.lua index d1216d33..2485960d 100644 --- a/spec/download_spec.lua +++ b/spec/download_spec.lua @@ -7,7 +7,7 @@ local extra_rocks = { "/validate-args-1.5.4-1.rockspec" } -expose("LuaRocks download tests #blackbox #b_download", function() +describe("LuaRocks download tests #blackbox #b_download", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/help_spec.lua b/spec/help_spec.lua index 08f6f1f1..376b6ceb 100644 --- a/spec/help_spec.lua +++ b/spec/help_spec.lua @@ -2,7 +2,7 @@ local test_env = require("test/test_environment") test_env.unload_luarocks() -expose("LuaRocks help tests #blackbox #b_help", function() +describe("LuaRocks help tests #blackbox #b_help", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/install_spec.lua b/spec/install_spec.lua index a598f324..f8869791 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -18,7 +18,7 @@ local extra_rocks = { "/wsapi-1.6-1.src.rock" } -expose("LuaRocks install tests #blackbox #b_install", function() +describe("LuaRocks install tests #blackbox #b_install", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/lint_spec.lua b/spec/lint_spec.lua index 58c87c4e..ce753618 100644 --- a/spec/lint_spec.lua +++ b/spec/lint_spec.lua @@ -6,7 +6,7 @@ local extra_rocks = { "/validate-args-1.5.4-1.rockspec" } -expose("LuaRocks lint tests #blackbox #b_lint", function() +describe("LuaRocks lint tests #blackbox #b_lint", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/list_spec.lua b/spec/list_spec.lua index edc310ca..344607e3 100644 --- a/spec/list_spec.lua +++ b/spec/list_spec.lua @@ -7,7 +7,7 @@ local extra_rocks = { "/say-1.2-1.src.rock" } -expose("LuaRocks list tests #blackbox #b_list", function() +describe("LuaRocks list tests #blackbox #b_list", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/make_manifest_spec.lua b/spec/make_manifest_spec.lua index a5b19eff..c6b0753c 100644 --- a/spec/make_manifest_spec.lua +++ b/spec/make_manifest_spec.lua @@ -2,7 +2,7 @@ local test_env = require("test/test_environment") test_env.unload_luarocks() -expose("LuaRocks make_manifest tests #blackbox #b_make_manifest", function() +describe("LuaRocks make_manifest tests #blackbox #b_make_manifest", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/make_spec.lua b/spec/make_spec.lua index b0177fc5..5ae23fd5 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua @@ -11,7 +11,7 @@ local extra_rocks = { "/lxsh-0.8.6-2.rockspec" } -expose("LuaRocks make tests #blackbox #b_make", function() +describe("LuaRocks make tests #blackbox #b_make", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua index 685d31b4..140c9906 100644 --- a/spec/new_version_spec.lua +++ b/spec/new_version_spec.lua @@ -7,7 +7,7 @@ local extra_rocks = { "/abelhas-1.0-1.rockspec" } -expose("LuaRocks new_version tests #blackbox #b_new_version", function() +describe("LuaRocks new_version tests #blackbox #b_new_version", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index 39d8bc5c..1671152c 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua @@ -9,7 +9,7 @@ local extra_rocks = { "/luasocket-3.0rc1-1.rockspec" } -expose("LuaRocks pack tests #blackbox #b_pack", function() +describe("LuaRocks pack tests #blackbox #b_pack", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/path_spec.lua b/spec/path_spec.lua index cffc186b..d201f337 100644 --- a/spec/path_spec.lua +++ b/spec/path_spec.lua @@ -2,7 +2,7 @@ local test_env = require("test/test_environment") test_env.unload_luarocks() -expose("LuaRocks path tests #blackbox #b_path", function() +describe("LuaRocks path tests #blackbox #b_path", function() before_each(function() test_env.setup_specs(extra_rocks) run = test_env.run diff --git a/spec/purge_spec.lua b/spec/purge_spec.lua index f5515cb5..30ce15e2 100644 --- a/spec/purge_spec.lua +++ b/spec/purge_spec.lua @@ -2,7 +2,7 @@ local test_env = require("test/test_environment") test_env.unload_luarocks() -expose("LuaRocks purge tests #blackbox #b_purge", function() +describe("LuaRocks purge tests #blackbox #b_purge", function() before_each(function() test_env.setup_specs(extra_rocks) testing_paths = test_env.testing_paths diff --git a/spec/refresh_cache_spec.lua b/spec/refresh_cache_spec.lua index ef8c3a12..764cbcb5 100644 --- a/spec/refresh_cache_spec.lua +++ b/spec/refresh_cache_spec.lua @@ -2,7 +2,7 @@ local test_env = require("test/test_environment") test_env.unload_luarocks() -expose("LuaRocks refresh_cache tests #blackbox #b_refresh_cache", function() +describe("LuaRocks refresh_cache tests #blackbox #b_refresh_cache", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/remove_spec.lua b/spec/remove_spec.lua index 1b3cda7e..4129e755 100644 --- a/spec/remove_spec.lua +++ b/spec/remove_spec.lua @@ -10,7 +10,7 @@ local extra_rocks = { "/luasocket-3.0rc1-1.rockspec" } -expose("LuaRocks remove tests #blackbox #b_remove", function() +describe("LuaRocks remove tests #blackbox #b_remove", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/search_spec.lua b/spec/search_spec.lua index 8e84931b..93e85928 100644 --- a/spec/search_spec.lua +++ b/spec/search_spec.lua @@ -6,7 +6,7 @@ local extra_rocks = { "/lzlib-0.4.1.53-1.src.rock" } -expose("LuaRocks search tests #blackbox #b_search", function() +describe("LuaRocks search tests #blackbox #b_search", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/show_spec.lua b/spec/show_spec.lua index c2f70c92..a58eea52 100644 --- a/spec/show_spec.lua +++ b/spec/show_spec.lua @@ -2,7 +2,7 @@ local test_env = require("test/test_environment") test_env.unload_luarocks() -expose("LuaRocks show tests #blackbox #b_show", function() +describe("LuaRocks show tests #blackbox #b_show", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/unpack_spec.lua b/spec/unpack_spec.lua index 3930a583..1e9df811 100644 --- a/spec/unpack_spec.lua +++ b/spec/unpack_spec.lua @@ -7,7 +7,7 @@ local extra_rocks = { "/cprint-0.1-2.rockspec" } -expose("LuaRocks unpack tests #blackbox #b_unpack", function() +describe("LuaRocks unpack tests #blackbox #b_unpack", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua index f0125966..ce998987 100644 --- a/spec/upload_spec.lua +++ b/spec/upload_spec.lua @@ -6,7 +6,7 @@ local extra_rocks = { "/lua-cjson-2.1.0-1.src.rock" } -expose("LuaRocks upload tests #blackbox #b_upload", function() +describe("LuaRocks upload tests #blackbox #b_upload", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/util_spec.lua b/spec/util_spec.lua index 7c22d1cb..7e0289d6 100644 --- a/spec/util_spec.lua +++ b/spec/util_spec.lua @@ -1,7 +1,7 @@ local test_env = require("test/test_environment") local lfs = require("lfs") -expose("Basic tests #blackbox #b_util", function() +describe("Basic tests #blackbox #b_util", function() before_each(function() test_env.setup_specs(extra_rocks) diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua index d6e32f15..4c29f204 100644 --- a/spec/write_rockspec_spec.lua +++ b/spec/write_rockspec_spec.lua @@ -4,7 +4,7 @@ local lfs = require("lfs") test_env.unload_luarocks() local write_rockspec = require("luarocks.write_rockspec") -expose("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() +describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() before_each(function() test_env.setup_specs(extra_rocks) -- cgit v1.2.3-55-g6feb From 8867f3324d97584ed24f3a1082144e9b1375d663 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 14:30:00 +0300 Subject: Make env vars, paths and run commands available on test env load --- spec/add_spec.lua | 4 +- spec/build_spec.lua | 4 +- spec/config_spec.lua | 4 +- spec/deps_spec.lua | 2 + spec/doc_spec.lua | 3 +- spec/download_spec.lua | 2 +- spec/help_spec.lua | 2 +- spec/install_spec.lua | 6 +-- spec/lint_spec.lua | 4 +- spec/list_spec.lua | 4 +- spec/make_manifest_spec.lua | 2 +- spec/make_spec.lua | 4 +- spec/new_version_spec.lua | 4 +- spec/pack_spec.lua | 3 +- spec/path_spec.lua | 2 +- spec/purge_spec.lua | 4 +- spec/refresh_cache_spec.lua | 2 +- spec/remove_spec.lua | 4 +- spec/search_spec.lua | 2 +- spec/show_spec.lua | 2 +- spec/unpack_spec.lua | 4 +- spec/upload_spec.lua | 2 +- spec/util_spec.lua | 6 +-- spec/write_rockspec_spec.lua | 4 +- test/test_environment.lua | 94 ++++++++++++++++++++------------------------ 25 files changed, 82 insertions(+), 92 deletions(-) diff --git a/spec/add_spec.lua b/spec/add_spec.lua index 930c221d..dca6f850 100644 --- a/spec/add_spec.lua +++ b/spec/add_spec.lua @@ -1,4 +1,6 @@ local test_env = require("test/test_environment") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -11,8 +13,6 @@ describe("LuaRocks add tests #blackbox #b_add", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks-admin add tests", function() diff --git a/spec/build_spec.lua b/spec/build_spec.lua index 7248e8f0..1ce99089 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -1,5 +1,7 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -29,8 +31,6 @@ describe("LuaRocks build tests #blackbox #b_build", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks build - basic testing set", function() diff --git a/spec/config_spec.lua b/spec/config_spec.lua index df2480ac..4a09fdcf 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua @@ -1,5 +1,7 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -9,8 +11,6 @@ describe("LuaRocks config tests #blackbox #b_config", function() test_env.setup_specs(extra_rocks) test_env.unload_luarocks() -- need to be required here, because site_config is created after first loading of specs site_config = require("luarocks.site_config") - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks config - basic tests", function() diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua index 9bb4709d..5df96452 100644 --- a/spec/deps_spec.lua +++ b/spec/deps_spec.lua @@ -1,5 +1,7 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua index e4e7f5f2..9dbeaab8 100644 --- a/spec/doc_spec.lua +++ b/spec/doc_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -10,8 +11,6 @@ describe("LuaRocks doc tests #blackbox #b_doc", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks doc basic tests", function() diff --git a/spec/download_spec.lua b/spec/download_spec.lua index 2485960d..320d9304 100644 --- a/spec/download_spec.lua +++ b/spec/download_spec.lua @@ -1,5 +1,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run test_env.unload_luarocks() @@ -11,7 +12,6 @@ describe("LuaRocks download tests #blackbox #b_download", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) it("LuaRocks download with no flags/arguments", function() diff --git a/spec/help_spec.lua b/spec/help_spec.lua index 376b6ceb..35bb6817 100644 --- a/spec/help_spec.lua +++ b/spec/help_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -6,7 +7,6 @@ describe("LuaRocks help tests #blackbox #b_help", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) it("LuaRocks help with no flags/arguments", function() diff --git a/spec/install_spec.lua b/spec/install_spec.lua index f8869791..876e25fc 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -1,5 +1,8 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths +local env_variables = test_env.env_variables test_env.unload_luarocks() @@ -22,9 +25,6 @@ describe("LuaRocks install tests #blackbox #b_install", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - env_variables = test_env.env_variables - run = test_env.run platform = test_env.platform end) diff --git a/spec/lint_spec.lua b/spec/lint_spec.lua index ce753618..f7496037 100644 --- a/spec/lint_spec.lua +++ b/spec/lint_spec.lua @@ -1,4 +1,6 @@ local test_env = require("test/test_environment") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -10,8 +12,6 @@ describe("LuaRocks lint tests #blackbox #b_lint", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) it("LuaRocks lint with no flags/arguments", function() diff --git a/spec/list_spec.lua b/spec/list_spec.lua index 344607e3..1b082ab6 100644 --- a/spec/list_spec.lua +++ b/spec/list_spec.lua @@ -1,4 +1,6 @@ local test_env = require("test/test_environment") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -11,8 +13,6 @@ describe("LuaRocks list tests #blackbox #b_list", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run - testing_paths = test_env.testing_paths end) it("LuaRocks list with no flags/arguments", function() diff --git a/spec/make_manifest_spec.lua b/spec/make_manifest_spec.lua index c6b0753c..5bd9e2f3 100644 --- a/spec/make_manifest_spec.lua +++ b/spec/make_manifest_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -6,7 +7,6 @@ describe("LuaRocks make_manifest tests #blackbox #b_make_manifest", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) describe("LuaRocks-admin make manifest tests", function() diff --git a/spec/make_spec.lua b/spec/make_spec.lua index 5ae23fd5..2821c143 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua @@ -1,5 +1,7 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -15,8 +17,6 @@ describe("LuaRocks make tests #blackbox #b_make", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run - testing_paths = test_env.testing_paths end) it("LuaRocks make with no flags/arguments", function() diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua index 140c9906..2274bce3 100644 --- a/spec/new_version_spec.lua +++ b/spec/new_version_spec.lua @@ -1,5 +1,7 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -11,8 +13,6 @@ describe("LuaRocks new_version tests #blackbox #b_new_version", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks new_version basic tests", function() diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index 1671152c..416184a8 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua @@ -1,5 +1,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run test_env.unload_luarocks() @@ -13,8 +14,6 @@ describe("LuaRocks pack tests #blackbox #b_pack", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) it("LuaRocks pack basic", function() diff --git a/spec/path_spec.lua b/spec/path_spec.lua index d201f337..fcdb36cf 100644 --- a/spec/path_spec.lua +++ b/spec/path_spec.lua @@ -1,11 +1,11 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() describe("LuaRocks path tests #blackbox #b_path", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) it("LuaRocks path bin", function() diff --git a/spec/purge_spec.lua b/spec/purge_spec.lua index 30ce15e2..e6f12ddb 100644 --- a/spec/purge_spec.lua +++ b/spec/purge_spec.lua @@ -1,12 +1,12 @@ local test_env = require("test/test_environment") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() describe("LuaRocks purge tests #blackbox #b_purge", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks purge basic tests", function() diff --git a/spec/refresh_cache_spec.lua b/spec/refresh_cache_spec.lua index 764cbcb5..34d211ab 100644 --- a/spec/refresh_cache_spec.lua +++ b/spec/refresh_cache_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -6,7 +7,6 @@ describe("LuaRocks refresh_cache tests #blackbox #b_refresh_cache", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) describe("LuaRocks-admin refresh cache tests #ssh", function() diff --git a/spec/remove_spec.lua b/spec/remove_spec.lua index 4129e755..41c6348a 100644 --- a/spec/remove_spec.lua +++ b/spec/remove_spec.lua @@ -1,5 +1,7 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -14,8 +16,6 @@ describe("LuaRocks remove tests #blackbox #b_remove", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) describe("LuaRocks remove basic tests", function() diff --git a/spec/search_spec.lua b/spec/search_spec.lua index 93e85928..33c49856 100644 --- a/spec/search_spec.lua +++ b/spec/search_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -10,7 +11,6 @@ describe("LuaRocks search tests #blackbox #b_search", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) it("LuaRocks search with no flags/arguments", function() diff --git a/spec/show_spec.lua b/spec/show_spec.lua index a58eea52..6f055612 100644 --- a/spec/show_spec.lua +++ b/spec/show_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -6,7 +7,6 @@ describe("LuaRocks show tests #blackbox #b_show", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) it("LuaRocks show with no flags/arguments", function() diff --git a/spec/unpack_spec.lua b/spec/unpack_spec.lua index 1e9df811..db71aa06 100644 --- a/spec/unpack_spec.lua +++ b/spec/unpack_spec.lua @@ -1,4 +1,6 @@ local test_env = require("test/test_environment") +local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() @@ -11,8 +13,6 @@ describe("LuaRocks unpack tests #blackbox #b_unpack", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run platform = test_env.platform end) diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua index ce998987..c10ef0e9 100644 --- a/spec/upload_spec.lua +++ b/spec/upload_spec.lua @@ -1,4 +1,5 @@ local test_env = require("test/test_environment") +local run = test_env.run test_env.unload_luarocks() @@ -10,7 +11,6 @@ describe("LuaRocks upload tests #blackbox #b_upload", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) it("LuaRocks upload with no flags/arguments", function() diff --git a/spec/util_spec.lua b/spec/util_spec.lua index 7e0289d6..39ce3c83 100644 --- a/spec/util_spec.lua +++ b/spec/util_spec.lua @@ -1,13 +1,13 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run +local testing_paths = test_env.testing_paths +local env_variables = test_env.env_variables describe("Basic tests #blackbox #b_util", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - env_variables = test_env.env_variables - run = test_env.run end) it("LuaRocks version", function() diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua index 4c29f204..cf0a642e 100644 --- a/spec/write_rockspec_spec.lua +++ b/spec/write_rockspec_spec.lua @@ -1,5 +1,6 @@ local test_env = require("test/test_environment") local lfs = require("lfs") +local run = test_env.run test_env.unload_luarocks() local write_rockspec = require("luarocks.write_rockspec") @@ -8,7 +9,6 @@ describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() before_each(function() test_env.setup_specs(extra_rocks) - run = test_env.run end) describe("LuaRocks write_rockspec basic tests", function() @@ -71,4 +71,4 @@ describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() assert.is_true(os.remove("luafcgi-scm-1.rockspec")) end) end) -end) \ No newline at end of file +end) diff --git a/test/test_environment.lua b/test/test_environment.lua index bde43163..b3ac3b18 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -254,44 +254,40 @@ local function create_md5sums(testing_paths) return md5sums end -local function run_luarocks(testing_paths, env_variables) - - local function make_command_function(exec_function, lua_cmd, do_print) - return function(cmd, new_vars) - local temp_vars = {} - for k, v in pairs(env_variables) do +local function make_run_function(cmd_name, exec_function, with_coverage, do_print) + local cmd_prefix = test_env.testing_paths.lua .. " " + + if with_coverage then + cmd_prefix = cmd_prefix .. "-e \"require('luacov.runner')('" .. test_env.testing_paths.testing_dir .. "/luacov.config')\" " + end + + cmd_prefix = cmd_prefix .. test_env.testing_paths.src_dir .. "/bin/" .. cmd_name .. " " + + return function(cmd, new_vars) + local temp_vars = {} + for k, v in pairs(test_env.env_variables) do + temp_vars[k] = v + end + if new_vars then + for k, v in pairs(new_vars) do temp_vars[k] = v end - if new_vars then - for k, v in pairs(new_vars) do - temp_vars[k] = v - end - end - return exec_function(lua_cmd .. cmd, do_print, temp_vars) end + return exec_function(cmd_prefix .. cmd, do_print, temp_vars) end +end - local run = {} - - local cov_str = testing_paths.lua .. " -e\"require('luacov.runner')('" .. testing_paths.testing_dir .. "/luacov.config')\" " - - local luarocks_cmd = cov_str .. testing_paths.src_dir .. "/bin/luarocks " - run.luarocks = make_command_function(execute_output, luarocks_cmd, true) - run.luarocks_bool = make_command_function(execute_bool, luarocks_cmd, true) - run.luarocks_noprint = make_command_function(execute_bool, luarocks_cmd, false) - - local luarocks_nocov_cmd = testing_paths.lua .. " " .. testing_paths.src_dir .. "/bin/luarocks " - run.luarocks_nocov = make_command_function(execute_bool, luarocks_nocov_cmd, true) - run.luarocks_noprint_nocov = make_command_function(execute_bool, luarocks_nocov_cmd, false) - - local luarocks_admin_cmd = cov_str .. testing_paths.src_dir .. "/bin/luarocks-admin " - run.luarocks_admin = make_command_function(execute_output, luarocks_admin_cmd, true) - run.luarocks_admin_bool = make_command_function(execute_bool, luarocks_admin_cmd, true) - - local luarocks_admin_nocov_cmd = testing_paths.lua .. " " .. testing_paths.src_dir .. "/bin/luarocks-admin " - run.luarocks_admin_nocov = make_command_function(execute_bool, luarocks_admin_nocov_cmd, false) - - return run +local function make_run_functions() + return { + luarocks = make_run_function("luarocks", execute_output, true, true), + luarocks_bool = make_run_function("luarocks", execute_bool, true, true), + luarocks_noprint = make_run_function("luarocks", execute_bool, true, false), + luarocks_nocov = make_run_function("luarocks", execute_bool, false, true), + luarocks_noprint_nocov = make_run_function("luarocks", execute_bool, false, false), + luarocks_admin = make_run_function("luarocks-admin", execute_output, true, true), + luarocks_admin_bool = make_run_function("luarocks-admin", execute_bool, true, true), + luarocks_admin_nocov = make_run_function("luarocks-admin", execute_bool, false, false) + } end --- Build environment for testing @@ -307,14 +303,13 @@ local function build_environment(env_rocks, testing_paths, env_variables) lfs.mkdir(testing_paths.testing_tree) lfs.mkdir(testing_paths.testing_sys_tree) - local run = run_luarocks(testing_paths, env_variables) - run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) - run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) + test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) + test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) for _,package in ipairs(env_rocks) do - if not run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) then - run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) - run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. package .. "; mv " .. package .. "-*.rock " .. testing_paths.testing_cache, env_variables) + if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) then + test_env.run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) + test_env.run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. package .. "; mv " .. package .. "-*.rock " .. testing_paths.testing_cache, env_variables) end end @@ -394,12 +389,9 @@ function test_env.unload_luarocks() end --- Function for initially setup of environment, variables, md5sums for spec files -function test_env.setup_specs(extra_rocks, luaversion_full) +function test_env.setup_specs(extra_rocks) -- if global variable about successful creation of testing environment doesn't exists, build environment if not test_env.setup_done then - test_env.set_lua_version() - test_env.set_args() - if test_env.TRAVIS then if not os.rename(os.getenv("HOME") .. "/.ssh/id_rsa.pub", os.getenv("HOME") .. "/.ssh/id_rsa.pub") then execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") @@ -409,16 +401,9 @@ function test_env.setup_specs(extra_rocks, luaversion_full) end end - luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V - test_env.main() - - -- Set paths, env_vars and functions for specs - test_env.testing_paths = create_paths(luaversion_full) - test_env.env_variables = create_env(test_env.testing_paths) package.path = test_env.env_variables.LUA_PATH - test_env.run = run_luarocks(test_env.testing_paths, test_env.env_variables) test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables) test_env.md5sums = create_md5sums(test_env.testing_paths) test_env.setup_done = true @@ -427,8 +412,7 @@ function test_env.setup_specs(extra_rocks, luaversion_full) if extra_rocks then local make_manifest = download_rocks(extra_rocks, test_env.testing_paths.testing_server) if make_manifest then - local run = run_luarocks(test_env.testing_paths, test_env.env_variables) - run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) + test_env.run.luarocks_admin_nocov("make_manifest " .. test_env.testing_paths.testing_server) end end @@ -602,4 +586,10 @@ upload_servers = { print("----------------") end +test_env.set_lua_version() +test_env.set_args() +test_env.testing_paths = create_paths(test_env.LUA_V or test_env.LUAJIT_V) +test_env.env_variables = create_env(test_env.testing_paths) +test_env.run = make_run_functions() + return test_env -- cgit v1.2.3-55-g6feb From ab86e13d0a408691b48786c394404736b7ac8dc0 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 14:41:15 +0300 Subject: Remove some more unused stuff and globals from tests --- spec/config_spec.lua | 3 ++- spec/deps_spec.lua | 2 -- spec/help_spec.lua | 2 +- spec/install_spec.lua | 11 +++++------ spec/make_manifest_spec.lua | 2 +- spec/path_spec.lua | 2 +- spec/purge_spec.lua | 2 +- spec/refresh_cache_spec.lua | 2 +- spec/show_spec.lua | 2 +- spec/unpack_spec.lua | 5 ++--- spec/util_spec.lua | 2 +- spec/write_rockspec_spec.lua | 3 +-- 12 files changed, 17 insertions(+), 21 deletions(-) diff --git a/spec/config_spec.lua b/spec/config_spec.lua index 4a09fdcf..0dee8620 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua @@ -2,13 +2,14 @@ local test_env = require("test/test_environment") local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths +local site_config test_env.unload_luarocks() describe("LuaRocks config tests #blackbox #b_config", function() before_each(function() - test_env.setup_specs(extra_rocks) + test_env.setup_specs() test_env.unload_luarocks() -- need to be required here, because site_config is created after first loading of specs site_config = require("luarocks.site_config") end) diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua index 5df96452..c1bd404d 100644 --- a/spec/deps_spec.lua +++ b/spec/deps_spec.lua @@ -17,8 +17,6 @@ describe("LuaRocks deps tests #blackbox #b_deps", function() before_each(function() test_env.setup_specs(extra_rocks) - testing_paths = test_env.testing_paths - run = test_env.run end) it("LuaRocks deps mode one", function() diff --git a/spec/help_spec.lua b/spec/help_spec.lua index 35bb6817..0d41e2e9 100644 --- a/spec/help_spec.lua +++ b/spec/help_spec.lua @@ -6,7 +6,7 @@ test_env.unload_luarocks() describe("LuaRocks help tests #blackbox #b_help", function() before_each(function() - test_env.setup_specs(extra_rocks) + test_env.setup_specs() end) it("LuaRocks help with no flags/arguments", function() diff --git a/spec/install_spec.lua b/spec/install_spec.lua index 876e25fc..0e406e22 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -25,7 +25,6 @@ describe("LuaRocks install tests #blackbox #b_install", function() before_each(function() test_env.setup_specs(extra_rocks) - platform = test_env.platform end) describe("LuaRocks install - basic tests", function() @@ -85,21 +84,21 @@ describe("LuaRocks install tests #blackbox #b_install", function() it("LuaRocks install only-deps of luasocket packed rock", function() assert.is_true(test_env.need_luasocket()) - local output = run.luarocks("install --only-deps " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. platform .. ".rock") + local output = run.luarocks("install --only-deps " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. test_env.platform .. ".rock") assert.are.same(output, "Successfully installed dependencies for luasocket 3.0rc1-1") end) it("LuaRocks install binary rock of cprint", function() assert.is_true(test_env.need_luasocket()) assert.is_true(run.luarocks_bool("build --pack-binary-rock cprint")) - assert.is_true(run.luarocks_bool("install cprint-0.1-2." .. platform .. ".rock")) - assert.is_true(os.remove("cprint-0.1-2." .. platform .. ".rock")) + assert.is_true(run.luarocks_bool("install cprint-0.1-2." .. test_env.platform .. ".rock")) + assert.is_true(os.remove("cprint-0.1-2." .. test_env.platform .. ".rock")) end) it("LuaRocks install reinstall", function() assert.is_true(test_env.need_luasocket()) - assert.is_true(run.luarocks_bool("install " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. platform .. ".rock")) - assert.is_true(run.luarocks_bool("install --deps-mode=none " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. platform .. ".rock")) + assert.is_true(run.luarocks_bool("install " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. test_env.platform .. ".rock")) + assert.is_true(run.luarocks_bool("install --deps-mode=none " .. testing_paths.testing_cache .. "/luasocket-3.0rc1-1." .. test_env.platform .. ".rock")) end) end) diff --git a/spec/make_manifest_spec.lua b/spec/make_manifest_spec.lua index 5bd9e2f3..1c7f5bf8 100644 --- a/spec/make_manifest_spec.lua +++ b/spec/make_manifest_spec.lua @@ -6,7 +6,7 @@ test_env.unload_luarocks() describe("LuaRocks make_manifest tests #blackbox #b_make_manifest", function() before_each(function() - test_env.setup_specs(extra_rocks) + test_env.setup_specs() end) describe("LuaRocks-admin make manifest tests", function() diff --git a/spec/path_spec.lua b/spec/path_spec.lua index fcdb36cf..22f07591 100644 --- a/spec/path_spec.lua +++ b/spec/path_spec.lua @@ -5,7 +5,7 @@ test_env.unload_luarocks() describe("LuaRocks path tests #blackbox #b_path", function() before_each(function() - test_env.setup_specs(extra_rocks) + test_env.setup_specs() end) it("LuaRocks path bin", function() diff --git a/spec/purge_spec.lua b/spec/purge_spec.lua index e6f12ddb..09a9d433 100644 --- a/spec/purge_spec.lua +++ b/spec/purge_spec.lua @@ -6,7 +6,7 @@ test_env.unload_luarocks() describe("LuaRocks purge tests #blackbox #b_purge", function() before_each(function() - test_env.setup_specs(extra_rocks) + test_env.setup_specs() end) describe("LuaRocks purge basic tests", function() diff --git a/spec/refresh_cache_spec.lua b/spec/refresh_cache_spec.lua index 34d211ab..c20771ab 100644 --- a/spec/refresh_cache_spec.lua +++ b/spec/refresh_cache_spec.lua @@ -6,7 +6,7 @@ test_env.unload_luarocks() describe("LuaRocks refresh_cache tests #blackbox #b_refresh_cache", function() before_each(function() - test_env.setup_specs(extra_rocks) + test_env.setup_specs() end) describe("LuaRocks-admin refresh cache tests #ssh", function() diff --git a/spec/show_spec.lua b/spec/show_spec.lua index 6f055612..f528a6de 100644 --- a/spec/show_spec.lua +++ b/spec/show_spec.lua @@ -6,7 +6,7 @@ test_env.unload_luarocks() describe("LuaRocks show tests #blackbox #b_show", function() before_each(function() - test_env.setup_specs(extra_rocks) + test_env.setup_specs() end) it("LuaRocks show with no flags/arguments", function() diff --git a/spec/unpack_spec.lua b/spec/unpack_spec.lua index db71aa06..76e9e5a8 100644 --- a/spec/unpack_spec.lua +++ b/spec/unpack_spec.lua @@ -13,7 +13,6 @@ describe("LuaRocks unpack tests #blackbox #b_unpack", function() before_each(function() test_env.setup_specs(extra_rocks) - platform = test_env.platform end) describe("LuaRocks unpack basic fail tests", function() @@ -49,9 +48,9 @@ describe("LuaRocks unpack tests #blackbox #b_unpack", function() it("LuaRocks unpack binary", function() assert.is_true(run.luarocks_bool("build cprint")) assert.is_true(run.luarocks_bool("pack cprint")) - assert.is_true(run.luarocks_bool("unpack cprint-0.1-2." .. platform .. ".rock")) + assert.is_true(run.luarocks_bool("unpack cprint-0.1-2." .. test_env.platform .. ".rock")) test_env.remove_dir("cprint-0.1-2") - os.remove("cprint-0.1-2." .. platform .. ".rock") + os.remove("cprint-0.1-2." .. test_env.platform .. ".rock") end) end) end) diff --git a/spec/util_spec.lua b/spec/util_spec.lua index 39ce3c83..9118ffc9 100644 --- a/spec/util_spec.lua +++ b/spec/util_spec.lua @@ -7,7 +7,7 @@ local env_variables = test_env.env_variables describe("Basic tests #blackbox #b_util", function() before_each(function() - test_env.setup_specs(extra_rocks) + test_env.setup_specs() end) it("LuaRocks version", function() diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua index cf0a642e..85e345d5 100644 --- a/spec/write_rockspec_spec.lua +++ b/spec/write_rockspec_spec.lua @@ -3,12 +3,11 @@ local lfs = require("lfs") local run = test_env.run test_env.unload_luarocks() -local write_rockspec = require("luarocks.write_rockspec") describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() before_each(function() - test_env.setup_specs(extra_rocks) + test_env.setup_specs() end) describe("LuaRocks write_rockspec basic tests", function() -- cgit v1.2.3-55-g6feb From f5d35cf9cad5ad8cd9f6e201dda783657e4510a3 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 14:45:51 +0300 Subject: Tests: fix luabitop installation condition --- test/test_environment.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index b3ac3b18..d6561f68 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -567,7 +567,7 @@ upload_servers = { rocks[#rocks+1] = "/lzlib-0.4.1.53-1.src.rock" env_rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} end - if env_type == "full" and luaversion_full ~= "5.1.5" then + if env_type == "full" and luaversion_full ~= "5.1" then rocks[#rocks+1] = "/luabitop-1.0.2-1.rockspec" rocks[#rocks+1] = "/luabitop-1.0.2-1.src.rock" table.insert(env_rocks, "luabitop") -- cgit v1.2.3-55-g6feb From c4f2a8404130696c503414876cf335a82aab359f Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:08:31 +0300 Subject: Tests: refactor config creation --- test/test_environment.lua | 145 ++++++++++++++++++++++++++-------------------- 1 file changed, 81 insertions(+), 64 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index d6561f68..4c1b13c8 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -441,6 +441,14 @@ function test_env.need_luasocket(luarocks_nocov, testing_cache, platform) return true end +--- For each key-value pair in replacements table +-- replace %{key} in given string with value. +local function substitute(str, replacements) + return (str:gsub("%%%b{}", function(marker) + return replacements[marker:sub(3, -2)] + end)) +end + --- -- Main function to create config files and testing environment function test_env.main(luaversion_full, env_type, env_clean) @@ -461,78 +469,87 @@ function test_env.main(luaversion_full, env_type, env_clean) lfs.mkdir(testing_paths.testing_cache) lfs.mkdir(testing_paths.luarocks_tmp) ---- CONFIG FILES --- testing_config.lua and testing_config_show_downloads.lua - local config_content = ([[rocks_trees = { - "%{testing_tree}", - { name = "system", root = "%{testing_sys_tree}" }, -} -rocks_servers = { - "%{testing_server}" -} -local_cache = "%{testing_cache}" -upload_server = "testing" -upload_user = "%{user}" -upload_servers = { - testing = { - rsync = "localhost/tmp/luarocks_testing", - }, -} -external_deps_dirs = { - "/usr/local", - "/usr", - -- These are used for a test that fails, so it - -- can point to invalid paths: - { - prefix = "/opt", - bin = "bin", - include = "include", - lib = { "lib", "lib64" }, - } -}]]):gsub("%%%b{}", { - ["%{user}"] = os.getenv("USER"), - ["%{testing_sys_tree}"] = testing_paths.testing_sys_tree, - ["%{testing_tree}"] = testing_paths.testing_tree, - ["%{testing_server}"] = testing_paths.testing_server, - ["%{testing_cache}"] = testing_paths.testing_cache}) + --- CONFIG FILES + -- testing_config.lua and testing_config_show_downloads.lua + local config_content = substitute([[ + rocks_trees = { + "%{testing_tree}", + { name = "system", root = "%{testing_sys_tree}" }, + } + rocks_servers = { + "%{testing_server}" + } + local_cache = "%{testing_cache}" + upload_server = "testing" + upload_user = "%{user}" + upload_servers = { + testing = { + rsync = "localhost/tmp/luarocks_testing", + }, + } + external_deps_dirs = { + "/usr/local", + "/usr", + -- These are used for a test that fails, so it + -- can point to invalid paths: + { + prefix = "/opt", + bin = "bin", + include = "include", + lib = { "lib", "lib64" }, + } + } + ]], { + user = os.getenv("USER"), + testing_sys_tree = testing_paths.testing_sys_tree, + testing_tree = testing_paths.testing_tree, + testing_server = testing_paths.testing_server, + testing_cache = testing_paths.testing_cache + }) create_config(testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") create_config(testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") --- testing_config_sftp.lua - config_content=([[rocks_trees = { - "%{testing_tree}", - "%{testing_sys_tree}", -} -local_cache = "%{testing_cache}" -upload_server = "testing" -upload_user = "%{user}" -upload_servers = { - testing = { - sftp = "localhost/tmp/luarocks_testing", - }, -}]]):gsub("%%%b{}", { - ["%{user}"] = os.getenv("USER"), - ["%{testing_sys_tree}"] = testing_paths.testing_sys_tree, - ["%{testing_tree}"] = testing_paths.testing_tree, - ["%{testing_cache}"] = testing_paths.testing_cache}) + -- testing_config_sftp.lua + config_content = substitute([[ + rocks_trees = { + "%{testing_tree}", + "%{testing_sys_tree}", + } + local_cache = "%{testing_cache}" + upload_server = "testing" + upload_user = "%{user}" + upload_servers = { + testing = { + sftp = "localhost/tmp/luarocks_testing", + }, + } + ]], { + user = os.getenv("USER"), + testing_sys_tree = testing_paths.testing_sys_tree, + testing_tree = testing_paths.testing_tree, + testing_cache = testing_paths.testing_cache + }) create_config(testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) --- luacov.config - config_content=([[return { - statsfile = "%{testing_dir}/luacov.stats.out", - reportfile = "%{testing_dir}/luacov.report.out", - modules = { - ["luarocks"] = "src/bin/luarocks", - ["luarocks-admin"] = "src/bin/luarocks-admin", - ["luarocks.*"] = "src", - ["luarocks.*.*"] = "src", - ["luarocks.*.*.*"] = "src" - } -}]]):gsub("%%%b{}", { - ["%{testing_dir}"] = testing_paths.testing_dir}) + -- luacov.config + config_content = substitute([[ + return { + statsfile = "%{testing_dir}/luacov.stats.out", + reportfile = "%{testing_dir}/luacov.report.out", + modules = { + ["luarocks"] = "src/bin/luarocks", + ["luarocks-admin"] = "src/bin/luarocks-admin", + ["luarocks.*"] = "src", + ["luarocks.*.*"] = "src", + ["luarocks.*.*.*"] = "src" + } + } + ]], { + testing_dir = testing_paths.testing_dir + }) create_config(testing_paths.testing_dir .. "/luacov.config", config_content) -- cgit v1.2.3-55-g6feb From c700cd6eee23a46cde73017f5e1e4c06867feb2b Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:16:33 +0300 Subject: Tests: reformat help message --- test/test_environment.lua | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index 4c1b13c8..1edf3987 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -1,22 +1,28 @@ local lfs = require("lfs") local test_env = {} -local arg = arg + +local help_message = [[ +LuaRocks test-suite + +INFORMATION + New test-suite for LuaRocks project, using unit testing framework Busted. +REQUIREMENTS + Tests require to have Lua installed and added to PATH. Be sure sshd is + running on your system, or use '--exclude-tags=ssh', to not execute tests + which require sshd. +USAGE + busted [-Xhelper ] +ARGUMENTS + env= Set type of environment to use ("minimal" or "full", + default: "minimal"). + clean Remove existing testing environment. + travis Add if running on TravisCI. + os= Set OS ("linux", "osx", or "windows"). +]] local function help() - print("LuaRocks test-suite\n\n".. - [[ - INFORMATION - New test-suite for LuaRocks project, using unit testing framework Busted. - REQUIREMENTS - Tests require to have Lua installed and added to PATH. Be sure sshd is runnig on your system, or - use '--exclude-tags=ssh', to not execute tests which require sshd. - USAGE -Xhelper - env= (default:"minimal") type what kind of environment to use ["minimal", "full"] - clean remove existing testing environment - travis add just if running on TravisCI - os= type your OS ["linux", "osx", "windows"] - ]]); - os.exit(1) + print(help_message) + os.exit(1) end --- Helper function for execute_bool and execute_output -- cgit v1.2.3-55-g6feb From 34baafd3d7a7d32bc7a3a4c519071de6355d0351 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:25:54 +0300 Subject: Tests: fix config creation error handling --- test/test_environment.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index 1edf3987..9f22e701 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -198,8 +198,7 @@ end -- @param config_path string: path where to save config file -- @param config_content string: content of this config file local function create_config(config_path, config_content) - local file, err = io.open(config_path, "w+") - if not file then return nil, err end + local file = assert(io.open(config_path, "w")) file:write(config_content) file:close() end -- cgit v1.2.3-55-g6feb From e0f97460ba8d212c8336a7ff2ccec61cf0ec983c Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:30:31 +0300 Subject: Tests: remove optional OS argument in hash_environment --- test/test_environment.lua | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index 9f22e701..372351de 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -205,22 +205,16 @@ end --- Create md5sum of directory structure recursively, based on filename and size -- @param path string: path to directory for generate md5sum --- @param testing_os string(optional): version of PC OS -- @return md5sum string: md5sum of directory -local function hash_environment(path, testing_os) - local md5sum = "" - testing_os = testing_os or test_env.TEST_TARGET_OS - - if testing_os == "linux" then - md5sum = execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum") - end - if testing_os == "osx" then - md5sum = execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5") +local function hash_environment(path) + if test_env.TEST_TARGET_OS == "linux" then + return execute_output("find " .. path .. " -printf \"%s %p\n\" | md5sum") + elseif test_env.TEST_TARGET_OS == "osx" then + return execute_output("find " .. path .. " -type f -exec stat -f \"%z %N\" {} \\; | md5") + else + -- TODO: Windows + return "" end - --TODO if testing_os == "windows" then - -- md5sum = execute_output("find . -printf \"%s %p\n\" | md5sum") - -- end - return md5sum end --- Create environment variables needed for tests -- cgit v1.2.3-55-g6feb From d13af5115615a851125b4b20df370ec4d79ba939 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:33:45 +0300 Subject: Tests: fix need_luasocket() Return false if installation failed. Also, remove optional arguments. --- test/test_environment.lua | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index 372351de..a3802cc0 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -421,23 +421,18 @@ function test_env.setup_specs(extra_rocks) end --- Helper function for tests which needs luasocket installed -function test_env.need_luasocket(luarocks_nocov, testing_cache, platform) - luarocks_nocov = luarocks_nocov or test_env.run.luarocks_nocov - testing_cache = testing_cache or test_env.testing_paths.testing_cache - platform = platform or test_env.platform - - if luarocks_nocov("show luasocket") then +function test_env.need_luasocket() + if test_env.run.luarocks_nocov("show luasocket") then return true else - testing_cache = testing_cache .. "/" - local luasocket_rock = "luasocket-3.0rc1-1." .. platform .. ".rock" + local testing_cache = test_env.testing_paths.testing_cache .. "/" + local luasocket_rock = "luasocket-3.0rc1-1." .. test_env.platform .. ".rock" if not os.rename( testing_cache .. luasocket_rock, testing_cache .. luasocket_rock) then - luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1") + test_env.run.luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1") os.rename(luasocket_rock, testing_cache .. luasocket_rock) end - luarocks_nocov("install " .. testing_cache .. luasocket_rock) + return test_env.run.luarocks_nocov("install " .. testing_cache .. luasocket_rock) end - return true end --- For each key-value pair in replacements table -- cgit v1.2.3-55-g6feb From c3975b3758e83486039c04cdd251445ed3e3b938 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:49:59 +0300 Subject: Tests: move config creation into its function --- test/test_environment.lua | 82 +++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index a3802cc0..f5cc701e 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -194,12 +194,12 @@ local function download_rocks(rocks, save_path) return make_manifest end ---- Create config files for testing --- @param config_path string: path where to save config file --- @param config_content string: content of this config file -local function create_config(config_path, config_content) - local file = assert(io.open(config_path, "w")) - file:write(config_content) +--- Create a file containing a string. +-- @param path string: path to file. +-- @param str string: content of the file. +local function write_file(path, str) + local file = assert(io.open(path, "w")) + file:write(str) file:close() end @@ -443,27 +443,10 @@ local function substitute(str, replacements) end)) end ---- --- Main function to create config files and testing environment -function test_env.main(luaversion_full, env_type, env_clean) - luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V - local testing_paths = create_paths(luaversion_full) - env_clean = env_clean or test_env.TEST_ENV_CLEAN - if env_clean then - print("Cleaning testing directory...") - test_env.remove_dir(testing_paths.luarocks_tmp) - test_env.remove_dir_pattern(testing_paths.testing_dir, "testing_") - test_env.remove_dir_pattern(testing_paths.testing_dir, "testing-") - test_env.remove_files(testing_paths.testing_dir, "testing_") - test_env.remove_files(testing_paths.testing_dir, "luacov") - print("Cleaning done!") - end - - lfs.mkdir(testing_paths.testing_cache) - lfs.mkdir(testing_paths.luarocks_tmp) - - --- CONFIG FILES +--- Create configs for luacov and several versions of Luarocks +-- configs needed for some tests. +local function create_configs() -- testing_config.lua and testing_config_show_downloads.lua local config_content = substitute([[ rocks_trees = { @@ -495,14 +478,14 @@ function test_env.main(luaversion_full, env_type, env_clean) } ]], { user = os.getenv("USER"), - testing_sys_tree = testing_paths.testing_sys_tree, - testing_tree = testing_paths.testing_tree, - testing_server = testing_paths.testing_server, - testing_cache = testing_paths.testing_cache + testing_sys_tree = test_env.testing_paths.testing_sys_tree, + testing_tree = test_env.testing_paths.testing_tree, + testing_server = test_env.testing_paths.testing_server, + testing_cache = test_env.testing_paths.testing_cache }) - create_config(testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") - create_config(testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content + write_file(test_env.testing_paths.testing_dir .. "/testing_config.lua", config_content .. " \nweb_browser = \"true\"") + write_file(test_env.testing_paths.testing_dir .. "/testing_config_show_downloads.lua", config_content .. "show_downloads = true \n rocks_servers={\"http://luarocks.org/repositories/rocks\"}") -- testing_config_sftp.lua @@ -521,12 +504,12 @@ function test_env.main(luaversion_full, env_type, env_clean) } ]], { user = os.getenv("USER"), - testing_sys_tree = testing_paths.testing_sys_tree, - testing_tree = testing_paths.testing_tree, - testing_cache = testing_paths.testing_cache + testing_sys_tree = test_env.testing_paths.testing_sys_tree, + testing_tree = test_env.testing_paths.testing_tree, + testing_cache = test_env.testing_paths.testing_cache }) - create_config(testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) + write_file(test_env.testing_paths.testing_dir .. "/testing_config_sftp.lua", config_content) -- luacov.config config_content = substitute([[ @@ -542,10 +525,33 @@ function test_env.main(luaversion_full, env_type, env_clean) } } ]], { - testing_dir = testing_paths.testing_dir + testing_dir = test_env.testing_paths.testing_dir }) - create_config(testing_paths.testing_dir .. "/luacov.config", config_content) + write_file(test_env.testing_paths.testing_dir .. "/luacov.config", config_content) +end + +--- +-- Main function to create config files and testing environment +function test_env.main(luaversion_full, env_type, env_clean) + luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V + local testing_paths = create_paths(luaversion_full) + + env_clean = env_clean or test_env.TEST_ENV_CLEAN + if env_clean then + print("Cleaning testing directory...") + test_env.remove_dir(testing_paths.luarocks_tmp) + test_env.remove_dir_pattern(testing_paths.testing_dir, "testing_") + test_env.remove_dir_pattern(testing_paths.testing_dir, "testing-") + test_env.remove_files(testing_paths.testing_dir, "testing_") + test_env.remove_files(testing_paths.testing_dir, "luacov") + print("Cleaning done!") + end + + lfs.mkdir(testing_paths.testing_cache) + lfs.mkdir(testing_paths.luarocks_tmp) + + create_configs() -- Create environment variables for configuration local temp_env_variables = {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua",LUA_PATH="",LUA_CPATH=""} -- cgit v1.2.3-55-g6feb From 858c649db5107946184e30e67bf861826aa5c64d Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 15:56:37 +0300 Subject: Tests: remove optional .main() arguments --- test/test_environment.lua | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index f5cc701e..8cc8e295 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -533,12 +533,10 @@ end --- -- Main function to create config files and testing environment -function test_env.main(luaversion_full, env_type, env_clean) - luaversion_full = luaversion_full or test_env.LUA_V or test_env.LUAJIT_V - local testing_paths = create_paths(luaversion_full) +function test_env.main() + local testing_paths = test_env.testing_paths - env_clean = env_clean or test_env.TEST_ENV_CLEAN - if env_clean then + if test_env.TEST_ENV_CLEAN then print("Cleaning testing directory...") test_env.remove_dir(testing_paths.luarocks_tmp) test_env.remove_dir_pattern(testing_paths.testing_dir, "testing_") @@ -568,14 +566,12 @@ function test_env.main(luaversion_full, env_type, env_clean) end -- Preparation of rocks for building environment - env_type = env_type or test_env.TYPE_TEST_ENV - local env_rocks = {} -- short names of rocks, required for building environment local rocks = {} -- full names of rocks required for download rocks[#rocks+1] = "/luacov-0.11.0-1.rockspec" rocks[#rocks+1] = "/luacov-0.11.0-1.src.rock" - if env_type == "full" then + if test_env.TYPE_TEST_ENV == "full" then rocks[#rocks+1] = "/luafilesystem-1.6.3-1.src.rock" rocks[#rocks+1] = "/luasocket-3.0rc1-1.src.rock" rocks[#rocks+1] = "/luasocket-3.0rc1-1.rockspec" @@ -583,11 +579,12 @@ function test_env.main(luaversion_full, env_type, env_clean) rocks[#rocks+1] = "/md5-1.2-1.src.rock" rocks[#rocks+1] = "/lzlib-0.4.1.53-1.src.rock" env_rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} - end - if env_type == "full" and luaversion_full ~= "5.1" then - rocks[#rocks+1] = "/luabitop-1.0.2-1.rockspec" - rocks[#rocks+1] = "/luabitop-1.0.2-1.src.rock" - table.insert(env_rocks, "luabitop") + + if test_env.LUA_V ~= "5.1" then + rocks[#rocks+1] = "/luabitop-1.0.2-1.rockspec" + rocks[#rocks+1] = "/luabitop-1.0.2-1.src.rock" + table.insert(env_rocks, "luabitop") + end end table.insert(env_rocks, "luacov") -- luacov is needed for minimal or full environment -- cgit v1.2.3-55-g6feb From b57ce08dce1efa471bc1ae5fad2f154bae426f75 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:00:57 +0300 Subject: Tests: move clean() into separate function, fix a pattern --- test/test_environment.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index 8cc8e295..94acf1c8 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -531,19 +531,23 @@ local function create_configs() write_file(test_env.testing_paths.testing_dir .. "/luacov.config", config_content) end +--- Remove testing directories. +local function clean() + print("Cleaning testing directory...") + test_env.remove_dir(test_env.testing_paths.luarocks_tmp) + test_env.remove_dir_pattern(test_env.testing_paths.testing_dir, "testing[_%-]") + test_env.remove_files(test_env.testing_paths.testing_dir, "testing_") + test_env.remove_files(test_env.testing_paths.testing_dir, "luacov") + print("Cleaning done!") +end + --- -- Main function to create config files and testing environment function test_env.main() local testing_paths = test_env.testing_paths if test_env.TEST_ENV_CLEAN then - print("Cleaning testing directory...") - test_env.remove_dir(testing_paths.luarocks_tmp) - test_env.remove_dir_pattern(testing_paths.testing_dir, "testing_") - test_env.remove_dir_pattern(testing_paths.testing_dir, "testing-") - test_env.remove_files(testing_paths.testing_dir, "testing_") - test_env.remove_files(testing_paths.testing_dir, "luacov") - print("Cleaning done!") + clean() end lfs.mkdir(testing_paths.testing_cache) -- cgit v1.2.3-55-g6feb From 1097d6cbc877b22b343b4f4531ce0a1d3b286307 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:09:05 +0300 Subject: Tests: adjust file/dir removing functions --- test/test_environment.lua | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index 94acf1c8..4f684f0a 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -122,11 +122,9 @@ function test_env.remove_dir(path) for file in lfs.dir(path) do if file ~= "." and file ~= ".." then local full_path = path..'/'..file - local attr = lfs.attributes(full_path) - if attr.mode == "directory" then + if lfs.attributes(full_path, "mode") == "directory" then test_env.remove_dir(full_path) - os.remove(full_path) else os.remove(full_path) end @@ -136,28 +134,26 @@ function test_env.remove_dir(path) os.remove(path) end ---- Remove directory recursively --- @param path string: directory path to delete --- @param pattern string: pattern in directories -function test_env.remove_dir_pattern(path, pattern) +--- Remove subdirectories of a directory that match a pattern +-- @param path string: path to directory +-- @param pattern string: pattern matching basenames of subdirectories to be removed +function test_env.remove_subdirs(path, pattern) if lfs.attributes(path) then for file in lfs.dir(path) do if file ~= "." and file ~= ".." then local full_path = path..'/'..file - local attr = lfs.attributes(full_path) - if attr.mode == "directory" and file:find(pattern) then + if lfs.attributes(full_path, "mode") == "directory" and file:find(pattern) then test_env.remove_dir(full_path) - os.remove(full_path) end end end end end ---- Remove files based on filename +--- Remove files matching a pattern -- @param path string: directory where to delete files --- @param pattern string: pattern in filenames +-- @param pattern string: pattern matching basenames of files to be deleted -- @return result_check boolean: true if one or more files deleted function test_env.remove_files(path, pattern) local result_check = false @@ -535,7 +531,7 @@ end local function clean() print("Cleaning testing directory...") test_env.remove_dir(test_env.testing_paths.luarocks_tmp) - test_env.remove_dir_pattern(test_env.testing_paths.testing_dir, "testing[_%-]") + test_env.remove_subdirs(test_env.testing_paths.testing_dir, "testing[_%-]") test_env.remove_files(test_env.testing_paths.testing_dir, "testing_") test_env.remove_files(test_env.testing_paths.testing_dir, "luacov") print("Cleaning done!") -- cgit v1.2.3-55-g6feb From f1dc482cdae4af3a7370fef9fea016d037270d51 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:15:26 +0300 Subject: Tests: move luarocks installation into its own function --- test/test_environment.lua | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index 4f684f0a..3b03f921 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -537,6 +537,17 @@ local function clean() print("Cleaning done!") end +--- Install luarocks into testing prefix. +local function install_luarocks(install_env_vars) + -- Configure LuaRocks testing environment + local configure_cmd = "./configure --with-lua=" .. test_env.testing_paths.luadir .. + " --prefix=" .. test_env.testing_paths.testing_lrprefix .. + " && make clean" + + assert(execute_bool(configure_cmd, false, install_env_vars)) + assert(execute_bool("make src/luarocks/site_config.lua && make dev", false, install_env_vars)) +end + --- -- Main function to create config files and testing environment function test_env.main() @@ -551,19 +562,13 @@ function test_env.main() create_configs() - -- Create environment variables for configuration - local temp_env_variables = {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config.lua",LUA_PATH="",LUA_CPATH=""} + local install_env_vars = { + LUAROCKS_CONFIG = test_env.testing_paths.testing_dir .. "/testing_config.lua", + LUA_PATH = "", + LUA_CPATH = "" + } - -- Configure LuaRocks testing environment - local configure_cmd = "./configure --with-lua=" .. testing_paths.luadir .. " --prefix=" .. testing_paths.testing_lrprefix - configure_cmd = configure_cmd .. " && make clean" - - if not execute_bool(configure_cmd, false, temp_env_variables) then - os.exit(1) - end - if not execute_bool("make src/luarocks/site_config.lua && make dev", false, temp_env_variables) then - os.exit(1) - end + install_luarocks(install_env_vars) -- Preparation of rocks for building environment local env_rocks = {} -- short names of rocks, required for building environment @@ -593,7 +598,7 @@ function test_env.main() lfs.mkdir(testing_paths.testing_server) download_rocks(rocks, testing_paths.testing_server) - build_environment(env_rocks, testing_paths, temp_env_variables) + build_environment(env_rocks, testing_paths, install_env_vars) print("----------------") print(" RUNNING TESTS") -- cgit v1.2.3-55-g6feb From 3fd5bea3820777f7b1e6373529471b74d68fe523 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:27:47 +0300 Subject: Tests: utility function for marking sections --- test/test_environment.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index 3b03f921..a3ce7ceb 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -25,6 +25,13 @@ local function help() os.exit(1) end +local function title(str) + print() + print(("-"):rep(#str)) + print(str) + print(("-"):rep(#str)) +end + --- Helper function for execute_bool and execute_output -- @param command string: command to execute -- @param print_command boolean: print command if 'true' @@ -102,7 +109,8 @@ function test_env.set_args() end if not test_env.TEST_TARGET_OS then - print("[OS CHECK]") + title("OS CHECK") + if execute_bool("sw_vers") then test_env.TEST_TARGET_OS = "osx" elseif execute_bool("uname -s") then @@ -110,7 +118,6 @@ function test_env.set_args() else test_env.TEST_TARGET_OS = "windows" end - print("--------------") end return true end @@ -287,9 +294,7 @@ end --- Build environment for testing local function build_environment(env_rocks, testing_paths, env_variables) - print("\n--------------------") - print("BUILDING ENVIRONMENT") - print("--------------------") + title("BUILDING ENVIRONMENT") test_env.remove_dir(testing_paths.testing_tree) test_env.remove_dir(testing_paths.testing_sys_tree) test_env.remove_dir(testing_paths.testing_tree_copy) @@ -402,6 +407,7 @@ function test_env.setup_specs(extra_rocks) test_env.platform = execute_output(test_env.testing_paths.lua .. " -e 'print(require(\"luarocks.cfg\").arch)'", false, test_env.env_variables) test_env.md5sums = create_md5sums(test_env.testing_paths) test_env.setup_done = true + title("RUNNING TESTS") end if extra_rocks then @@ -412,8 +418,6 @@ function test_env.setup_specs(extra_rocks) end reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables) - - return true end --- Helper function for tests which needs luasocket installed @@ -599,10 +603,6 @@ function test_env.main() download_rocks(rocks, testing_paths.testing_server) build_environment(env_rocks, testing_paths, install_env_vars) - - print("----------------") - print(" RUNNING TESTS") - print("----------------") end test_env.set_lua_version() -- cgit v1.2.3-55-g6feb From 9d233d0e474efa25e2e5e02bea9f9e54a532fbe0 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:36:19 +0300 Subject: Tests: adjust build_environment --- test/test_environment.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index a3ce7ceb..cfbab89b 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -292,9 +292,12 @@ local function make_run_functions() } end ---- Build environment for testing -local function build_environment(env_rocks, testing_paths, env_variables) +--- Rebuild environment. +-- Remove old installed rocks and install new ones, +-- updating manifests and tree copies. +local function build_environment(rocks, env_variables) title("BUILDING ENVIRONMENT") + local testing_paths = test_env.testing_paths test_env.remove_dir(testing_paths.testing_tree) test_env.remove_dir(testing_paths.testing_sys_tree) test_env.remove_dir(testing_paths.testing_tree_copy) @@ -306,10 +309,11 @@ local function build_environment(env_rocks, testing_paths, env_variables) test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_server) test_env.run.luarocks_admin_nocov("make_manifest " .. testing_paths.testing_cache) - for _,package in ipairs(env_rocks) do - if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) then - test_env.run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. package, env_variables) - test_env.run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. package .. "; mv " .. package .. "-*.rock " .. testing_paths.testing_cache, env_variables) + for _, rock in ipairs(rocks) do + if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) then + test_env.run.luarocks_nocov("build --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) + test_env.run.luarocks_nocov("pack --tree=" .. testing_paths.testing_sys_tree .. " " .. rock, env_variables) + execute_bool("mv " .. rock .. "-*.rock " .. testing_paths.testing_cache) end end @@ -602,7 +606,7 @@ function test_env.main() lfs.mkdir(testing_paths.testing_server) download_rocks(rocks, testing_paths.testing_server) - build_environment(env_rocks, testing_paths, install_env_vars) + build_environment(env_rocks, install_env_vars) end test_env.set_lua_version() -- cgit v1.2.3-55-g6feb From 325c7578cdd5421035930a3a7ee2bb385c10d8fc Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:42:00 +0300 Subject: Tests: adjust rock/rockspec downloading --- test/test_environment.lua | 51 +++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index cfbab89b..065a12c2 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -180,17 +180,17 @@ end --- Function for downloading rocks and rockspecs --- @param rocks table: table with full name of rocks/rockspecs to download +-- @param urls table: array of full names of rocks/rockspecs to download -- @param save_path string: path to directory, where to download rocks/rockspecs -- @return make_manifest boolean: true if new rocks downloaded -local function download_rocks(rocks, save_path) +local function download_rocks(urls, save_path) local luarocks_repo = "https://luarocks.org" local make_manifest = false - for _,rock in ipairs(rocks) do + for _, url in ipairs(urls) do -- check if already downloaded - if not os.rename( save_path .. rock, save_path .. rock) then - execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. rock) + if not os.rename(save_path .. url, save_path .. url) then + execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url) make_manifest = true end end @@ -579,34 +579,33 @@ function test_env.main() install_luarocks(install_env_vars) -- Preparation of rocks for building environment - local env_rocks = {} -- short names of rocks, required for building environment - local rocks = {} -- full names of rocks required for download - rocks[#rocks+1] = "/luacov-0.11.0-1.rockspec" - rocks[#rocks+1] = "/luacov-0.11.0-1.src.rock" - - if test_env.TYPE_TEST_ENV == "full" then - rocks[#rocks+1] = "/luafilesystem-1.6.3-1.src.rock" - rocks[#rocks+1] = "/luasocket-3.0rc1-1.src.rock" - rocks[#rocks+1] = "/luasocket-3.0rc1-1.rockspec" - rocks[#rocks+1] = "/luaposix-33.2.1-1.src.rock" - rocks[#rocks+1] = "/md5-1.2-1.src.rock" - rocks[#rocks+1] = "/lzlib-0.4.1.53-1.src.rock" - env_rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} + local rocks = {} -- names of rocks, required for building environment + local urls = {} -- names of rock and rockspec files to be downloaded + table.insert(urls, "/luacov-0.11.0-1.rockspec") + table.insert(urls, "/luacov-0.11.0-1.src.rock") + + if test_env.TYPE_TEST_ENV == "full" then + table.insert(urls, "/luafilesystem-1.6.3-1.src.rock") + table.insert(urls, "/luasocket-3.0rc1-1.src.rock") + table.insert(urls, "/luasocket-3.0rc1-1.rockspec") + table.insert(urls, "/luaposix-33.2.1-1.src.rock") + table.insert(urls, "/md5-1.2-1.src.rock") + table.insert(urls, "/lzlib-0.4.1.53-1.src.rock") + rocks = {"luafilesystem", "luasocket", "luaposix", "md5", "lzlib"} if test_env.LUA_V ~= "5.1" then - rocks[#rocks+1] = "/luabitop-1.0.2-1.rockspec" - rocks[#rocks+1] = "/luabitop-1.0.2-1.src.rock" - table.insert(env_rocks, "luabitop") + table.insert(urls, "/luabitop-1.0.2-1.rockspec") + table.insert(urls, "/luabitop-1.0.2-1.src.rock") + table.insert(rocks, "luabitop") end end - table.insert(env_rocks, "luacov") -- luacov is needed for minimal or full environment - + table.insert(rocks, "luacov") -- luacov is needed for minimal or full environment + -- Download rocks needed for LuaRocks testing environment lfs.mkdir(testing_paths.testing_server) - download_rocks(rocks, testing_paths.testing_server) - - build_environment(env_rocks, install_env_vars) + download_rocks(urls, testing_paths.testing_server) + build_environment(rocks, install_env_vars) end test_env.set_lua_version() -- cgit v1.2.3-55-g6feb From 09315362c8c1eb78311586247ddd46f1add1aae6 Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 16:47:28 +0300 Subject: Tests: add file/dir existence check utility function Use it instead of os.rename(path, path). --- test/test_environment.lua | 30 ++++++++++++++++-------------- 1 file 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) print(("-"):rep(#str)) end +local function exists(path) + return lfs.attributes(path, "mode") ~= nil +end + --- Helper function for execute_bool and execute_output -- @param command string: command to execute -- @param print_command boolean: print command if 'true' @@ -125,7 +129,7 @@ end --- Remove directory recursively -- @param path string: directory path to delete function test_env.remove_dir(path) - if lfs.attributes(path) then + if exists(path) then for file in lfs.dir(path) do if file ~= "." and file ~= ".." then local full_path = path..'/'..file @@ -145,7 +149,7 @@ end -- @param path string: path to directory -- @param pattern string: pattern matching basenames of subdirectories to be removed function test_env.remove_subdirs(path, pattern) - if lfs.attributes(path) then + if exists(path) then for file in lfs.dir(path) do if file ~= "." and file ~= ".." then local full_path = path..'/'..file @@ -164,7 +168,7 @@ end -- @return result_check boolean: true if one or more files deleted function test_env.remove_files(path, pattern) local result_check = false - if lfs.attributes(path) then + if exists(path) then for file in lfs.dir(path) do if file ~= "." and file ~= ".." then if file:find(pattern) then @@ -189,7 +193,7 @@ local function download_rocks(urls, save_path) for _, url in ipairs(urls) do -- check if already downloaded - if not os.rename(save_path .. url, save_path .. url) then + if not exists(save_path .. url) then execute_bool("wget -cP " .. save_path .. " " .. luarocks_repo .. url) make_manifest = true end @@ -346,21 +350,19 @@ local function create_paths(luaversion_full) if test_env.TRAVIS then testing_paths.luadir = lfs.currentdir() .. "/lua_install" testing_paths.lua = testing_paths.luadir .. "/bin/lua" - end - - if test_env.LUA_V and not test_env.TRAVIS then - if lfs.attributes("/usr/bin/lua") then + elseif test_env.LUA_V then + if exists("/usr/bin/lua") then testing_paths.luadir = "/usr" testing_paths.lua = testing_paths.luadir .. "/bin/lua" - elseif lfs.attributes("/usr/local/bin/lua") then + elseif exists("/usr/local/bin/lua") then testing_paths.luadir = "/usr/local" testing_paths.lua = testing_paths.luadir .. "/bin/lua" end - elseif test_env.LUAJIT_V and not test_env.TRAVIS then - if lfs.attributes("/usr/bin/luajit") then + elseif test_env.LUAJIT_V then + if exists("/usr/bin/luajit") then testing_paths.luadir = "/usr" testing_paths.lua = testing_paths.luadir .. "/bin/luajit" - elseif lfs.attributes("/usr/local/bin/luajit") then + elseif exists("/usr/local/bin/luajit") then testing_paths.luadir = "/usr/local" testing_paths.lua = testing_paths.luadir .. "/bin/luajit" end @@ -397,7 +399,7 @@ function test_env.setup_specs(extra_rocks) -- if global variable about successful creation of testing environment doesn't exists, build environment if not test_env.setup_done then if test_env.TRAVIS then - if not os.rename(os.getenv("HOME") .. "/.ssh/id_rsa.pub", os.getenv("HOME") .. "/.ssh/id_rsa.pub") then + if not exists(os.getenv("HOME") .. "/.ssh/id_rsa.pub") then execute_bool("ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa") execute_bool("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys") execute_bool("chmod og-wx ~/.ssh/authorized_keys") @@ -431,7 +433,7 @@ function test_env.need_luasocket() else local testing_cache = test_env.testing_paths.testing_cache .. "/" local luasocket_rock = "luasocket-3.0rc1-1." .. test_env.platform .. ".rock" - if not os.rename( testing_cache .. luasocket_rock, testing_cache .. luasocket_rock) then + if not exists(testing_cache .. luasocket_rock) then test_env.run.luarocks_nocov("build --pack-binary-rock luasocket 3.0rc1-1") os.rename(luasocket_rock, testing_cache .. luasocket_rock) end -- cgit v1.2.3-55-g6feb From a05ba7ce42ae4e42f80b5cacdd8770ae5e6cc04b Mon Sep 17 00:00:00 2001 From: Peter Melnichenko Date: Fri, 8 Jul 2016 20:28:43 +0300 Subject: Infer Lua version using luarocks.cfg when not on travis --- test/test_environment.lua | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/test/test_environment.lua b/test/test_environment.lua index a48a59a3..6de7a4e2 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -7,9 +7,8 @@ LuaRocks test-suite INFORMATION New test-suite for LuaRocks project, using unit testing framework Busted. REQUIREMENTS - Tests require to have Lua installed and added to PATH. Be sure sshd is - running on your system, or use '--exclude-tags=ssh', to not execute tests - which require sshd. + Be sure sshd is running on your system, or use '--exclude-tags=ssh', + to not execute tests which require sshd. USAGE busted [-Xhelper ] ARGUMENTS @@ -343,30 +342,11 @@ local function reset_environment(testing_paths, md5sums) end local function create_paths(luaversion_full) - local testing_paths = {} + local cfg = require("luarocks.cfg") - testing_paths.luadir = "" - - if test_env.TRAVIS then - testing_paths.luadir = lfs.currentdir() .. "/lua_install" - testing_paths.lua = testing_paths.luadir .. "/bin/lua" - elseif test_env.LUA_V then - if exists("/usr/bin/lua") then - testing_paths.luadir = "/usr" - testing_paths.lua = testing_paths.luadir .. "/bin/lua" - elseif exists("/usr/local/bin/lua") then - testing_paths.luadir = "/usr/local" - testing_paths.lua = testing_paths.luadir .. "/bin/lua" - end - elseif test_env.LUAJIT_V then - if exists("/usr/bin/luajit") then - testing_paths.luadir = "/usr" - testing_paths.lua = testing_paths.luadir .. "/bin/luajit" - elseif exists("/usr/local/bin/luajit") then - testing_paths.luadir = "/usr/local" - testing_paths.lua = testing_paths.luadir .. "/bin/luajit" - end - end + local testing_paths = {} + testing_paths.luadir = cfg.variables.LUA_BINDIR:gsub("/bin/?$", "") + testing_paths.lua = cfg.variables.LUA_BINDIR .. "/" .. cfg.lua_interpreter testing_paths.luarocks_tmp = "/tmp/luarocks_testing" --windows? -- cgit v1.2.3-55-g6feb From 3641e01a460abc6459924cb9343d774758b8fc2f Mon Sep 17 00:00:00 2001 From: roboo Date: Sun, 10 Jul 2016 02:53:00 +0200 Subject: Tests added - new_version --- spec/new_version_spec.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua index 2274bce3..9207806a 100644 --- a/spec/new_version_spec.lua +++ b/spec/new_version_spec.lua @@ -6,7 +6,9 @@ local testing_paths = test_env.testing_paths test_env.unload_luarocks() local extra_rocks = { - "/abelhas-1.0-1.rockspec" + "/abelhas-1.0-1.rockspec", + "/md5-1.2-1.rockspec", + "/lpeg-0.12-1.rockspec", } describe("LuaRocks new_version tests #blackbox #b_new_version", function() @@ -25,6 +27,12 @@ describe("LuaRocks new_version tests #blackbox #b_new_version", function() it("LuaRocks new version invalid", function() assert.is_false(run.luarocks_bool("new_version invalid")) end) + + it("LuaRocks new version invalid url", function() + assert.is_true(run.luarocks_bool("download --rockspec abelhas 1.0")) + assert.is_true(run.luarocks_bool("new_version abelhas-1.0-1.rockspec 1.1 http://luainvalid")) + test_env.remove_files(lfs.currentdir(), "abelhas--") + end) end) describe("LuaRocks new_version more complex tests", function() @@ -48,5 +56,15 @@ describe("LuaRocks new_version tests #blackbox #b_new_version", function() assert.is.truthy(lfs.attributes("luacov-0.3-1.rockspec")) test_env.remove_files(lfs.currentdir(), "luacov--") end) + + it("LuaRocks new version updating md5", function() + assert.is_true(run.luarocks_bool("download --rockspec lpeg 0.12")) + assert.is_true(run.luarocks_bool("new_version lpeg-0.12-1.rockspec 0.2 https://luarocks.org/manifests/gvvaughan/lpeg-1.0.0-1.rockspec")) + test_env.remove_files(lfs.currentdir(), "lpeg--") + + -- assert.is_true(run.luarocks_bool("download --rockspec md5 1.2")) + -- assert.is_true(run.luarocks_bool("new_version md5-1.2-1.rockspec 1.3 https://luarocks.org/manifests/tomasguisasola/md5-1.2-1.rockspec")) + -- test_env.remove_files(lfs.currentdir(), "md5--") + end) end) end) -- cgit v1.2.3-55-g6feb From b275d158f6c5a83324d6d2de0edc23211eb9d664 Mon Sep 17 00:00:00 2001 From: roboo Date: Sun, 10 Jul 2016 17:34:50 +0200 Subject: Doc tests --- spec/doc_spec.lua | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua index 9dbeaab8..a04d3c14 100644 --- a/spec/doc_spec.lua +++ b/spec/doc_spec.lua @@ -1,10 +1,12 @@ local test_env = require("test/test_environment") local run = test_env.run +local testing_paths = test_env.testing_paths test_env.unload_luarocks() local extra_rocks = { - "/luarepl-0.4-1.src.rock" + "/luarepl-0.4-1.src.rock", + "/c3-1.0-1.src.rock" } describe("LuaRocks doc tests #blackbox #b_doc", function() @@ -20,6 +22,21 @@ describe("LuaRocks doc tests #blackbox #b_doc", function() it("LuaRocks doc with invalid argument", function() assert.is_false(run.luarocks_bool("doc invalid")) end) + it("LuaRocks doc with no homepage", function() + assert.is_true(run.luarocks_bool("install c3")) + assert.is_false(run.luarocks_bool("doc c3 --home")) + end) + it("LuaRocks doc with no home page and no doc folder", function() + assert.is_true(run.luarocks_bool("install c3")) + test_env.remove_dir(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/c3/1.0-1/doc") + assert.is_false(run.luarocks_bool("doc c3")) + end) + it("LuaRocks doc with no doc folder opening descript.homepage", function() + assert.is_true(run.luarocks_bool("install luarepl")) + test_env.remove_dir(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luarepl/0.4-1/doc") + local output = run.luarocks("doc luarepl") + assert.is.truthy(output:find("Local documentation directory not found")) + end) end) describe("LuaRocks doc tests with flags", function() -- cgit v1.2.3-55-g6feb From b8334ea38536b7db031dac925d426fb5e4783407 Mon Sep 17 00:00:00 2001 From: robooo Date: Sun, 10 Jul 2016 17:58:13 +0200 Subject: Update new_version_spec.lua --- spec/new_version_spec.lua | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua index 9207806a..4e4d5d27 100644 --- a/spec/new_version_spec.lua +++ b/spec/new_version_spec.lua @@ -7,8 +7,7 @@ test_env.unload_luarocks() local extra_rocks = { "/abelhas-1.0-1.rockspec", - "/md5-1.2-1.rockspec", - "/lpeg-0.12-1.rockspec", + "/lpeg-0.12-1.rockspec" } describe("LuaRocks new_version tests #blackbox #b_new_version", function() @@ -61,10 +60,6 @@ describe("LuaRocks new_version tests #blackbox #b_new_version", function() assert.is_true(run.luarocks_bool("download --rockspec lpeg 0.12")) assert.is_true(run.luarocks_bool("new_version lpeg-0.12-1.rockspec 0.2 https://luarocks.org/manifests/gvvaughan/lpeg-1.0.0-1.rockspec")) test_env.remove_files(lfs.currentdir(), "lpeg--") - - -- assert.is_true(run.luarocks_bool("download --rockspec md5 1.2")) - -- assert.is_true(run.luarocks_bool("new_version md5-1.2-1.rockspec 1.3 https://luarocks.org/manifests/tomasguisasola/md5-1.2-1.rockspec")) - -- test_env.remove_files(lfs.currentdir(), "md5--") end) end) end) -- cgit v1.2.3-55-g6feb