From 43adf5df7465c39a9f6fc735654aabac991cabb5 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 30 Mar 2018 15:21:05 -0300 Subject: Tests: make sure tests run from testrun/ --- spec/deps_spec.lua | 4 ++-- spec/make_spec.lua | 27 ++++++++++++++++++--------- spec/new_version_spec.lua | 12 ++++++++---- spec/pack_spec.lua | 6 +++--- spec/util/mock-server.lua | 2 +- spec/util/test_env.lua | 14 ++++++++------ spec/util_spec.lua | 6 +++--- 7 files changed, 43 insertions(+), 28 deletions(-) (limited to 'spec') diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua index 76ee68a7..67c1335f 100644 --- a/spec/deps_spec.lua +++ b/spec/deps_spec.lua @@ -85,7 +85,7 @@ describe("LuaRocks deps tests #blackbox #b_deps", function() 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) + lfs.chdir(testing_paths.testrun_dir) test_env.remove_dir("lxsh-0.8.6-2") assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) @@ -102,7 +102,7 @@ describe("LuaRocks deps tests #blackbox #b_deps", function() 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) + lfs.chdir(testing_paths.testrun_dir) test_env.remove_dir("lxsh-0.8.6-2") assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) diff --git a/spec/make_spec.lua b/spec/make_spec.lua index 88b35b22..bb219b68 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua @@ -21,12 +21,23 @@ describe("LuaRocks make tests #blackbox #b_make", function() end) it("LuaRocks make with no flags/arguments", function() - lfs.chdir("test") + finally(function() + lfs.chdir(testing_paths.testrun_dir) + test_env.remove_dir("empty") + end) + assert(lfs.mkdir("empty")) + assert(lfs.chdir("empty")) assert.is_false(run.luarocks_bool("make")) - lfs.chdir(testing_paths.luarocks_dir) end) it("LuaRocks make with rockspec", function() + finally(function() + -- delete downloaded and unpacked files + lfs.chdir(testing_paths.testrun_dir) + test_env.remove_dir("luasocket-3.0rc1-2") + os.remove("luasocket-3.0rc1-2.src.rock") + end) + -- make luasocket assert.is_true(run.luarocks_bool("download --source luasocket 3.0rc1-2")) assert.is_true(run.luarocks_bool("unpack luasocket-3.0rc1-2.src.rock")) @@ -36,11 +47,6 @@ describe("LuaRocks make tests #blackbox #b_make", function() -- test it assert.is_true(run.luarocks_bool("show luasocket")) assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/luasocket/3.0rc1-2/luasocket-3.0rc1-2.rockspec")) - - -- delete downloaded and unpacked files - lfs.chdir(testing_paths.luarocks_dir) - test_env.remove_dir("luasocket-3.0rc1-2") - assert.is_true(os.remove("luasocket-3.0rc1-2.src.rock")) end) describe("LuaRocks making rockspecs (using lxsh)", function() @@ -53,7 +59,7 @@ describe("LuaRocks make tests #blackbox #b_make", function() -- delete downloaded and unpacked files after_each(function() - assert.is_true(lfs.chdir(testing_paths.luarocks_dir)) + assert(lfs.chdir(testing_paths.testrun_dir)) test_env.remove_dir("lxsh-0.8.6-2") assert.is_true(os.remove("lxsh-0.8.6-2.src.rock")) end) @@ -67,12 +73,15 @@ describe("LuaRocks make tests #blackbox #b_make", function() end) it("LuaRocks make unnamed rockspec", function() + finally(function() + os.remove("rockspec") + end) + test_env.copy("lxsh-0.8.6-2.rockspec", "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_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) - os.remove("rockspec") end) it("LuaRocks make ambiguous rockspec", function() diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua index 65f60dd6..6d9d6860 100644 --- a/spec/new_version_spec.lua +++ b/spec/new_version_spec.lua @@ -6,21 +6,25 @@ local testing_paths = test_env.testing_paths test_env.unload_luarocks() local extra_rocks = test_env.mock_server_extra_rocks({ - "/abelhas-1.0-1.rockspec", + "/abelhas-1.1-1.rockspec", "/lpeg-0.12-1.rockspec" }) describe("LuaRocks new_version tests #blackbox #b_new_version", function() - before_each(function() + setup(function() test_env.setup_specs(extra_rocks) end) describe("basic tests", function() it("with no flags/arguments", function() - lfs.chdir("test") + finally(function() + lfs.chdir(testing_paths.testrun_dir) + test_env.remove_dir("empty") + end) + assert(lfs.mkdir("empty")) + assert(lfs.chdir("empty")) assert.is_false(run.luarocks_bool("new_version")) - lfs.chdir(testing_paths.luarocks_dir) end) it("with invalid", function() diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index 966195c5..86b4e2b2 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua @@ -26,7 +26,7 @@ describe("LuaRocks pack tests #blackbox #b_pack", function() it("LuaRocks pack basic", function() assert.is_true(run.luarocks_bool("pack luacov")) - assert.is_true(test_env.remove_files(lfs.currentdir(), "luacov-")) + assert.is_true(test_env.remove_files(lfs.currentdir(), "luacov%-")) end) it("LuaRocks pack invalid rockspec", function() @@ -47,14 +47,14 @@ describe("LuaRocks pack tests #blackbox #b_pack", function() assert.is_true(run.luarocks_bool("install say 1.0")) assert.is_true(run.luarocks_bool("pack say")) assert.is_truthy(lfs.attributes("say-1.2-1.all.rock")) - assert.is_true(test_env.remove_files(lfs.currentdir(), "say-")) + assert.is_true(test_env.remove_files(lfs.currentdir(), "say%-")) end) it("LuaRocks pack src", function() assert.is_true(run.luarocks_bool("install luasec " .. test_env.OPENSSL_DIRS)) assert.is_true(run.luarocks_bool("download --rockspec luasocket 3.0rc1-2")) assert.is_true(run.luarocks_bool("pack luasocket-3.0rc1-2.rockspec")) - assert.is_true(test_env.remove_files(lfs.currentdir(), "luasocket-")) + assert.is_true(test_env.remove_files(lfs.currentdir(), "luasocket%-")) end) end) diff --git a/spec/util/mock-server.lua b/spec/util/mock-server.lua index 244aceae..77d32927 100644 --- a/spec/util/mock-server.lua +++ b/spec/util/mock-server.lua @@ -70,7 +70,7 @@ server:add_resource("/file/{name:[^/]+}", { path = "/", produces = "text/plain", handler = function(query, name) - local fd = io.open("spec/fixtures/"..name, "r") + local fd = io.open("../spec/fixtures/"..name, "r") if not fd then return restserver.response():status(404) end diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index ce2b1728..2232de87 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua @@ -494,16 +494,16 @@ local function create_paths(luaversion_full) testing_paths.luarocks_tmp = "/tmp/luarocks_testing" end - testing_paths.luarocks_dir = lfs.currentdir() + local base_dir = lfs.currentdir() if test_env.TEST_TARGET_OS == "windows" then - testing_paths.luarocks_dir = testing_paths.luarocks_dir:gsub("\\","/") + base_dir = base_dir:gsub("\\","/") end - testing_paths.fixtures_dir = testing_paths.luarocks_dir .. "/spec/fixtures" - testing_paths.util_dir = testing_paths.luarocks_dir .. "/spec/util" - testing_paths.testrun_dir = testing_paths.luarocks_dir .. "/testrun" - testing_paths.src_dir = testing_paths.luarocks_dir .. "/src" + testing_paths.fixtures_dir = base_dir .. "/spec/fixtures" + testing_paths.util_dir = base_dir .. "/spec/util" + testing_paths.testrun_dir = base_dir .. "/testrun" + testing_paths.src_dir = base_dir .. "/src" testing_paths.testing_lrprefix = testing_paths.testrun_dir .. "/testing_lrprefix-" .. luaversion_full testing_paths.testing_tree = testing_paths.testrun_dir .. "/testing-" .. luaversion_full testing_paths.testing_tree_copy = testing_paths.testrun_dir .. "/testing_copy-" .. luaversion_full @@ -566,6 +566,8 @@ function test_env.setup_specs(extra_rocks) if test_env.RESET_ENV then reset_environment(test_env.testing_paths, test_env.md5sums, test_env.env_variables) end + + lfs.chdir(test_env.testing_paths.testrun_dir) end --- Test if required rock is installed and if not, install it. diff --git a/spec/util_spec.lua b/spec/util_spec.lua index 3aa8fbf5..209dae6f 100644 --- a/spec/util_spec.lua +++ b/spec/util_spec.lua @@ -53,9 +53,9 @@ describe("Basic tests #blackbox #b_util", function() it("LuaRocks only server=testing", function() assert.is.truthy(run.luarocks("--only-server=testing")) end) - - it("LuaRocks test site config", function() - local scname = "src/luarocks/core/site_config_"..test_env.lua_version:gsub("%.", "_")..".lua" + + it("#only LuaRocks test site config", function() + local scname = testing_paths.src_dir .. "/luarocks/core/site_config_"..test_env.lua_version:gsub("%.", "_")..".lua" assert.is.truthy(os.rename(scname, scname..".tmp")) assert.is.falsy(lfs.attributes(scname)) -- cgit v1.2.3-55-g6feb