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 --- 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 ++++++++++++++++++ 25 files changed, 1532 insertions(+) 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 (limited to 'spec') 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 -- cgit v1.2.3-55-g6feb