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/write_rockspec_spec.lua | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 spec/write_rockspec_spec.lua (limited to 'spec/write_rockspec_spec.lua') 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 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(-) (limited to 'spec/write_rockspec_spec.lua') 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(-) (limited to 'spec/write_rockspec_spec.lua') 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(-) (limited to 'spec/write_rockspec_spec.lua') 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 3945f90b0bd80024294b048a793bae526cad30e2 Mon Sep 17 00:00:00 2001 From: roboo Date: Tue, 19 Jul 2016 22:56:28 +0200 Subject: Test improvements --- spec/build_spec.lua | 36 +++++++++++++++++++----------------- spec/help_spec.lua | 6 +++--- spec/install_spec.lua | 12 ++++++------ spec/make_spec.lua | 10 +++++----- spec/pack_spec.lua | 6 ++---- spec/remove_spec.lua | 2 +- spec/search_spec.lua | 6 +----- spec/upload_spec.lua | 6 +++--- spec/util_spec.lua | 13 ++++++++----- spec/write_rockspec_spec.lua | 3 +-- 10 files changed, 49 insertions(+), 51 deletions(-) (limited to 'spec/write_rockspec_spec.lua') diff --git a/spec/build_spec.lua b/spec/build_spec.lua index 682c6dcf..2ede5211 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -57,7 +57,7 @@ describe("LuaRocks build tests #blackbox #b_build", function() end) it("LuaRocks build lpeg verbose", function() - assert.is_true(run.luarocks_bool("build --verbose lpeg")) + assert.is.truthy(run.luarocks("build --verbose lpeg")) end) it("LuaRocks build lpeg branch=master", function() @@ -82,9 +82,8 @@ describe("LuaRocks build tests #blackbox #b_build", function() end) describe("LuaRocks build - basic builds", function() - it("LuaRocks build luadoc", function() - assert.is_true(run.luarocks_bool("build luadoc")) + assert.is_true(run.luarocks_bool(test_env.quiet("build luadoc"))) end) it("LuaRocks build luacov diff version", function() @@ -103,12 +102,12 @@ describe("LuaRocks build tests #blackbox #b_build", function() end) it("LuaRocks build supported platforms lpty", function() - assert.is_true(run.luarocks_bool("build lpty")) + assert.is_true(run.luarocks_bool(test_env.quiet("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_true(run.luarocks_bool(test_env.quiet("build luasec --nodeps"))) assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasec")) end) @@ -119,31 +118,34 @@ describe("LuaRocks build tests #blackbox #b_build", function() 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) - + if test_env.TYPE_TEST_ENV == "full" then + it("LuaRocks build luacheck show downloads test_config", function() + local output = run.luarocks("build luacheck", { LUAROCKS_CONFIG = testing_paths.testing_dir .. "/testing_config_show_downloads.lua"} ) + assert.is.truthy(output:match("%.%.%.")) + end) + end + it("LuaRocks build luasec only deps", function() - assert.is_true(run.luarocks_bool("build luasec --only-deps")) + assert.is_true(run.luarocks_bool(test_env.quiet("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.truthy(run.luarocks("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.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) 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.truthy(run.luarocks("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.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lpeg")) assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) end) @@ -151,7 +153,7 @@ describe("LuaRocks build tests #blackbox #b_build", 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(run.luarocks("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")) @@ -159,10 +161,10 @@ describe("LuaRocks build tests #blackbox #b_build", function() 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(test_env.quiet("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(run.luarocks("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")) diff --git a/spec/help_spec.lua b/spec/help_spec.lua index 0d41e2e9..88aa5030 100644 --- a/spec/help_spec.lua +++ b/spec/help_spec.lua @@ -10,7 +10,7 @@ describe("LuaRocks help tests #blackbox #b_help", function() end) it("LuaRocks help with no flags/arguments", function() - assert.is_true(run.luarocks_bool("help")) + assert.is_true(run.luarocks_bool(test_env.quiet("help"))) end) it("LuaRocks help invalid argument", function() @@ -18,10 +18,10 @@ describe("LuaRocks help tests #blackbox #b_help", function() end) it("LuaRocks help config", function() - assert.is_true(run.luarocks_bool("help config")) + assert.is_true(run.luarocks_bool(test_env.quiet("help config"))) end) it("LuaRocks-admin help with no flags/arguments", function() - assert.is_true(run.luarocks_admin_bool("help")) + assert.is_true(run.luarocks_admin_bool(test_env.quiet("help"))) end) end) diff --git a/spec/install_spec.lua b/spec/install_spec.lua index 28e349c3..bd480c21 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -73,31 +73,31 @@ describe("LuaRocks install tests #blackbox #b_install", function() 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")) + run.luarocks_bool(test_env.quiet(" install luasec --nodeps")) + assert.is_true(run.luarocks_bool(test_env.quiet("show luasec"))) if env_variables.TYPE_TEST_ENV == "minimal" then - assert.is_false(run.luarocks_bool("show luasocket")) + assert.is_false(run.luarocks_bool(test_env.quiet("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(run.luarocks_bool("build --pack-binary-rock luasocket 3.0rc1-1")) + assert.is_true(run.luarocks_bool(test_env.quiet("build --pack-binary-rock luasocket 3.0rc1-1"))) local output = run.luarocks("install --only-deps " .. "luasocket-3.0rc1-1." .. test_env.platform .. ".rock") assert.are.same(output, "Successfully installed dependencies for luasocket 3.0rc1-1") assert.is_true(os.remove("luasocket-3.0rc1-1." .. test_env.platform .. ".rock")) end) it("LuaRocks install reinstall", function() - assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket 3.0rc1-1")) + assert.is_true(run.luarocks_bool(test_env.quiet("build --pack-binary-rock luasocket 3.0rc1-1"))) assert.is_true(run.luarocks_bool("install " .. "luasocket-3.0rc1-1." .. test_env.platform .. ".rock")) assert.is_true(run.luarocks_bool("install --deps-mode=none " .. "luasocket-3.0rc1-1." .. test_env.platform .. ".rock")) assert.is_true(os.remove("luasocket-3.0rc1-1." .. test_env.platform .. ".rock")) end) it("LuaRocks install binary rock of cprint", function() - assert.is_true(run.luarocks_bool("build --pack-binary-rock cprint")) + assert.is_true(run.luarocks_bool(test_env.quiet("build --pack-binary-rock cprint"))) 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) diff --git a/spec/make_spec.lua b/spec/make_spec.lua index 3e843f7b..e684033a 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua @@ -30,10 +30,10 @@ describe("LuaRocks make tests #blackbox #b_make", function() assert.is_true(run.luarocks_bool("download --source luasocket 3.0rc1-1")) 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")) + assert.is_true(run.luarocks_bool(test_env.quiet("make luasocket-3.0rc1-1.rockspec"))) -- test it - assert.is_true(run.luarocks_bool("show luasocket")) + assert.is_true(run.luarocks_bool(test_env.quiet("show luasocket"))) assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/luasocket")) -- delete downloaded and unpacked files @@ -61,7 +61,7 @@ describe("LuaRocks make tests #blackbox #b_make", 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_true(run.luarocks_bool(test_env.quiet("show lxsh"))) assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) end) @@ -69,7 +69,7 @@ describe("LuaRocks make tests #blackbox #b_make", 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_true(run.luarocks_bool(test_env.quiet("show lxsh"))) assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/luarocks/rocks/lxsh")) end) @@ -91,7 +91,7 @@ describe("LuaRocks make tests #blackbox #b_make", function() end) it("LuaRocks make pack binary rock", function() - assert.is_true(run.luarocks_bool("make --deps-mode=none --pack-binary-rock")) + assert.is_true(run.luarocks_bool(test_env.quiet("make --deps-mode=none --pack-binary-rock"))) assert.is.truthy(lfs.attributes("lxsh-0.8.6-2.all.rock")) end) end) diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index 78aab9aa..0e5b31c6 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua @@ -24,8 +24,7 @@ describe("LuaRocks pack tests #blackbox #b_pack", function() end) it("LuaRocks pack basic", function() - assert.is_true(run.luarocks_bool("list")) - assert.is_true(run.luarocks_bool("pack luacov")) + assert.is_true(run.luarocks_bool(test_env.quiet("pack luacov"))) assert.is_true(test_env.remove_files(lfs.currentdir(), "luacov-")) end) @@ -49,9 +48,8 @@ describe("LuaRocks pack tests #blackbox #b_pack", function() assert.is_false(run.luarocks_bool("pack say")) end) - it("LuaRocks pack src", function() - assert.is_true(run.luarocks_bool("install luasec")) + assert.is_true(run.luarocks_bool(test_env.quiet("install luasec"))) assert.is_true(run.luarocks_bool("download --rockspec luasocket 3.0rc1-1")) assert.is_true(run.luarocks_bool("pack luasocket-3.0rc1-1.rockspec")) assert.is_true(test_env.remove_files(lfs.currentdir(), "luasocket-")) diff --git a/spec/remove_spec.lua b/spec/remove_spec.lua index c7f83b95..7bf1bb10 100644 --- a/spec/remove_spec.lua +++ b/spec/remove_spec.lua @@ -45,7 +45,7 @@ describe("LuaRocks remove tests #blackbox #b_remove", function() describe("LuaRocks remove more complex tests", function() before_each(function() - assert.is_true(test_env.need_rock("luasocket")) + assert.is.truthy(test_env.need_rock("luasocket")) end) it("LuaRocks remove fail, break dependencies", function() diff --git a/spec/search_spec.lua b/spec/search_spec.lua index 33c49856..b31624b8 100644 --- a/spec/search_spec.lua +++ b/spec/search_spec.lua @@ -30,11 +30,7 @@ describe("LuaRocks search tests #blackbox #b_search", function() end) it("LuaRocks search with flag all", function() - assert.is_true(run.luarocks_bool("search --all")) + assert.is_true(run.luarocks_bool(test_env.quiet("search --all"))) end) - it("LuaRocks search zlib", function() - local num = 123 - assert.is_true(run.luarocks_bool("search " .. num)) - end) end) diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua index 02b68611..c68a1cdf 100644 --- a/spec/upload_spec.lua +++ b/spec/upload_spec.lua @@ -53,7 +53,7 @@ describe("LuaRocks upload tests #blackbox #b_upload", function() describe("LuaRocks upload tests with Xavante server #mock", function() before_each(function() - assert.is_true(test_env.need_rock("restserver-xavante")) + assert.is.truthy(test_env.need_rock("restserver-xavante")) local final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.testing_dir .. "/mock-server.lua &", true, test_env.env_variables) os.execute(final_command) end) @@ -63,10 +63,10 @@ describe("LuaRocks upload tests #blackbox #b_upload", function() end) it("LuaRocks upload rockspec with api-key", function() - assert.is_true(run.luarocks_bool("upload " .. testing_paths.testing_server .. "/luasocket-3.0rc1-1.rockspec --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) + assert.is_true(run.luarocks_bool("upload " .. testing_paths.testing_server .. "/luasocket-3.0rc1-2.rockspec --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) end) it("LuaRocks upload rockspec with api-key and skip-pack", function() - assert.is_true(run.luarocks_bool("upload --skip-pack " .. testing_paths.testing_server .. "/luasocket-3.0rc1-1.rockspec --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) + assert.is_true(run.luarocks_bool("upload --skip-pack " .. testing_paths.testing_server .. "/luasocket-3.0rc1-2.rockspec --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) end) end) end) diff --git a/spec/util_spec.lua b/spec/util_spec.lua index 9118ffc9..23e3ebd8 100644 --- a/spec/util_spec.lua +++ b/spec/util_spec.lua @@ -34,13 +34,16 @@ describe("Basic tests #blackbox #b_util", function() local delete_path = lfs.currentdir() assert.is_true(os.remove(delete_path)) - assert.is_false(run.luarocks_bool(" ")) + local output = run.luarocks("") + assert.is.falsy(output:find("LuaRocks scm, a module deployment system for Lua")) assert.is_true(lfs.chdir(main_path)) - assert.is_true(run.luarocks_bool(" ")) + + output = run.luarocks("") + assert.is.truthy(output:find("LuaRocks scm, a module deployment system for Lua")) end) it("LuaRocks timeout", function() - assert.is_true(run.luarocks_bool("--timeout=10")) + assert.is.truthy(run.luarocks("--timeout=10")) end) it("LuaRocks timeout invalid", function() @@ -48,7 +51,7 @@ describe("Basic tests #blackbox #b_util", function() end) it("LuaRocks only server=testing", function() - assert.is_true(run.luarocks_bool("--only-server=testing")) + assert.is.truthy(run.luarocks("--only-server=testing")) end) it("LuaRocks test site config", function() @@ -56,7 +59,7 @@ describe("Basic tests #blackbox #b_util", function() 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(run.luarocks("")) 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")) diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua index 85e345d5..531d11eb 100644 --- a/spec/write_rockspec_spec.lua +++ b/spec/write_rockspec_spec.lua @@ -64,8 +64,7 @@ describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() 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_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) -- cgit v1.2.3-55-g6feb