From 238ba6b21cfcb1af56f1e70dd50de201fc3482a7 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 11 Apr 2022 19:16:10 -0300 Subject: tests: avoid repeated hardcoded package version numbers all over --- spec/add_spec.lua | 12 ++--- spec/build_spec.lua | 10 ++-- spec/deps_spec.lua | 102 +++++++++++++++++++----------------- spec/install_spec.lua | 61 +++++++++++---------- spec/list_spec.lua | 5 +- spec/make_spec.lua | 66 +++++++++++------------ spec/new_version_spec.lua | 14 ++--- spec/pack_spec.lua | 4 +- spec/remove_spec.lua | 37 +++++++------ spec/test_spec.lua | 9 ++-- spec/upload_spec.lua | 4 +- spec/util/test_env.lua | 131 +++++++++++++++++++++++++++++++++++++--------- spec/util/versions.lua | 14 +++++ 13 files changed, 291 insertions(+), 178 deletions(-) create mode 100644 spec/util/versions.lua diff --git a/spec/add_spec.lua b/spec/add_spec.lua index ea6274ba..b17cadac 100644 --- a/spec/add_spec.lua +++ b/spec/add_spec.lua @@ -5,8 +5,8 @@ local testing_paths = test_env.testing_paths test_env.unload_luarocks() local extra_rocks = { - "/luasocket-3.0rc1-2.src.rock", - "/luasocket-3.0rc1-2.rockspec" + "/luasocket-${LUASOCKET}.src.rock", + "/luasocket-${LUASOCKET}.rockspec" } describe("LuaRocks add tests #integration", function() @@ -25,20 +25,20 @@ describe("LuaRocks add tests #integration", function() end) it("invalid server", function() - assert.is_false(run.luarocks_admin_bool("--server=invalid add " .. testing_paths.testing_server .. "/luasocket-3.0rc1-2.src.rock")) + assert.is_false(run.luarocks_admin_bool("--server=invalid add " .. testing_paths.testing_server .. "/luasocket-${LUASOCKET}.src.rock")) end) it("invalid server #ssh", function() - assert.is_true(run.luarocks_admin_bool("--server=testing add " .. testing_paths.testing_server .. "/luasocket-3.0rc1-2.src.rock")) + assert.is_true(run.luarocks_admin_bool("--server=testing add " .. testing_paths.testing_server .. "/luasocket-${LUASOCKET}.src.rock")) end) --TODO This test fails, sftp support not yet implemented it("invalid server", function() - assert.is_false(run.luarocks_admin_bool("--server=testing add luasocket-3.0rc1-2.src.rock", { LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/testing_config_sftp.lua" } )) + assert.is_false(run.luarocks_admin_bool("--server=testing add luasocket-${LUASOCKET}.src.rock", { LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/testing_config_sftp.lua" } )) end) it("split server url", function() - assert.is_false(run.luarocks_admin_bool("--server=\"localhost@/tmp/luarocks_testing\" add " .. testing_paths.testing_server .. "/luasocket-3.0rc1-2.src.rock")) + assert.is_false(run.luarocks_admin_bool("--server=\"localhost@/tmp/luarocks_testing\" add " .. testing_paths.testing_server .. "/luasocket-${LUASOCKET}.src.rock")) end) end) end) diff --git a/spec/build_spec.lua b/spec/build_spec.lua index a970a5da..ba6c1a94 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -19,9 +19,9 @@ local extra_rocks = { "/lmathx-20150505-1.rockspec", "/lpeg-1.0.0-1.rockspec", "/lpeg-1.0.0-1.src.rock", - "/luafilesystem-1.6.3-1.src.rock", - "/luasocket-3.0rc1-2.src.rock", - "/luasocket-3.0rc1-2.rockspec", + "/luafilesystem-${LUAFILESYSTEM}.src.rock", + "/luasocket-${LUASOCKET}.src.rock", + "/luasocket-${LUASOCKET}.rockspec", "/stdlib-41.0.0-1.src.rock", "spec/fixtures/a_rock-1.0-1.src.rock", "/busted-2.0.0-1.rockspec", @@ -137,8 +137,8 @@ describe("LuaRocks build #integration", function() describe("basic builds", function() it("luacov diff version", function() - assert.is_true(run.luarocks_bool("build luacov 0.15.0-1")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/luacov/0.15.0-1/luacov-0.15.0-1.rockspec")) + assert.is_true(run.luarocks_bool("build luacov ${LUACOV}")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/luacov/${LUACOV}/luacov-${LUACOV}.rockspec")) end) it("command stdlib", function() diff --git a/spec/deps_spec.lua b/spec/deps_spec.lua index 35fd8be5..b0064298 100644 --- a/spec/deps_spec.lua +++ b/spec/deps_spec.lua @@ -6,11 +6,11 @@ local testing_paths = test_env.testing_paths test_env.unload_luarocks() local extra_rocks = { - "/lxsh-0.8.6-2.src.rock", - "/lxsh-0.8.6-2.rockspec", - "/luasocket-3.0rc1-2.src.rock", - "/luasocket-3.0rc1-2.rockspec", - "/lpeg-1.0.0-1.src.rock", + "/lxsh-${LXSH}.src.rock", + "/lxsh-${LXSH}.rockspec", + "/luasocket-${LUASOCKET}.src.rock", + "/luasocket-${LUASOCKET}.rockspec", + "/lpeg-${LPEG}.src.rock", } describe("LuaRocks deps-mode #integration", function() @@ -23,92 +23,96 @@ describe("LuaRocks deps-mode #integration", 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_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) end) it("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_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) end) it("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_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.falsy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) end) it("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_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.falsy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) end) it("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_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.falsy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) 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_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) end) it("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("download --source lxsh ${LXSH_V}")) + assert.is_true(run.luarocks_bool("unpack lxsh-${LXSH}.src.rock")) + lfs.chdir("lxsh-${LXSH}/lxsh-${LXSH_V}-1/") assert.is_true(run.luarocks_bool("make --tree=" .. testing_paths.testing_tree .. " --deps-mode=order")) - 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")) + finally(function() + lfs.chdir(testing_paths.testrun_dir) + test_env.remove_dir("lxsh-${LXSH}") + assert.is_true(os.remove("lxsh-${LXSH}.src.rock")) + end) - assert.is.falsy(lfs.attributes(testing_paths.testing_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) end) it("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("download --source lxsh ${LXSH_V}")) + assert.is_true(run.luarocks_bool("unpack lxsh-${LXSH}.src.rock")) + lfs.chdir("lxsh-${LXSH}/lxsh-${LXSH_V}-1/") assert.is_true(run.luarocks_bool("make --tree=" .. testing_paths.testing_sys_tree .. " --deps-mode=order")) - 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")) + finally(function() + lfs.chdir(testing_paths.testrun_dir) + test_env.remove_dir("lxsh-${LXSH}") + assert.is_true(os.remove("lxsh-${LXSH}.src.rock")) + end) - assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/1.0.0-1/lpeg-1.0.0-1.rockspec")) - assert.is.falsy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lpeg/${LPEG}/lpeg-${LPEG}.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) end) end) diff --git a/spec/install_spec.lua b/spec/install_spec.lua index ea6e1d3f..24dbdb30 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -5,23 +5,24 @@ local testing_paths = test_env.testing_paths local env_variables = test_env.env_variables local write_file = test_env.write_file local git_repo = require("spec.util.git_repo") +local V = test_env.V test_env.unload_luarocks() local extra_rocks = { "/cprint-0.1-2.src.rock", "/cprint-0.1-2.rockspec", - "/lpeg-0.12-1.src.rock", + "/lpeg-${LPEG}.src.rock", "/luassert-1.7.0-1.src.rock", - "/luasocket-3.0rc1-2.src.rock", - "/luasocket-3.0rc1-2.rockspec", - "/lxsh-0.8.6-2.src.rock", - "/lxsh-0.8.6-2.rockspec", + "/luasocket-${LUASOCKET}.src.rock", + "/luasocket-${LUASOCKET}.rockspec", + "/lxsh-${LXSH}.src.rock", + "/lxsh-${LXSH}.rockspec", "/say-1.2-1.src.rock", "/say-1.0-1.src.rock", "/wsapi-1.6-1.src.rock", - "/luafilesystem-1.6.3-2.src.rock", - "/luafilesystem-1.6.3-1.src.rock", + "/luafilesystem-${LUAFILESYSTEM}.src.rock", + "/luafilesystem-${LUAFILESYSTEM_OLD}.src.rock", "spec/fixtures/a_repo/has_build_dep-1.0-1.all.rock", "spec/fixtures/a_repo/a_build_dep-1.0-1.all.rock", "spec/fixtures/a_repo/a_rock-1.0-1.src.rock", @@ -78,7 +79,7 @@ describe("luarocks install #integration", function() end) it("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_true(run.luarocks_bool("install lxsh ${LXSH} --only-deps")) assert.is_false(run.luarocks_bool("show lxsh")) end) @@ -170,16 +171,20 @@ describe("luarocks install #integration", function() end) it('handle versioned modules when installing another version with --keep #268', function() + local libdir = testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION + assert.is_true(run.luarocks_bool("install luafilesystem")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) + assert.is.truthy(lfs.attributes(libdir .."/lfs."..test_env.lib_extension)) + + local suffix = (V"${LUAFILESYSTEM_OLD}"):gsub("[%.%-]", "_") - assert.is_true(run.luarocks_bool("install luafilesystem 1.6.3-1 --keep")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/luafilesystem_1_6_3_1-lfs."..test_env.lib_extension)) + assert.is_true(run.luarocks_bool("install luafilesystem ${LUAFILESYSTEM_OLD} --keep")) + assert.is.truthy(lfs.attributes(libdir .. "/lfs."..test_env.lib_extension)) + assert.is.truthy(lfs.attributes(libdir .. "/luafilesystem_"..suffix.."-lfs."..test_env.lib_extension)) assert.is_true(run.luarocks_bool("install luafilesystem")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/luafilesystem_1_6_3_1-lfs."..test_env.lib_extension)) + assert.is.truthy(lfs.attributes(libdir .. "/lfs."..test_env.lib_extension)) + assert.is.falsy(lfs.attributes(libdir .. "/luafilesystem_"..suffix.."-lfs."..test_env.lib_extension)) end) it('handle non-Lua files in build.install.lua when upgrading sailorproject/sailor#138', function() @@ -193,21 +198,21 @@ describe("luarocks install #integration", function() end) it("only-deps of luasocket packed rock", function() - assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket 3.0rc1-2")) - local output = run.luarocks("install --only-deps " .. "luasocket-3.0rc1-2." .. test_env.platform .. ".rock") - assert.match("Successfully installed dependencies for luasocket 3.0rc1-2", output, 1, true) - assert.is_true(os.remove("luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) + assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket ${LUASOCKET}")) + local output = run.luarocks("install --only-deps " .. "luasocket-${LUASOCKET}." .. test_env.platform .. ".rock") + assert.match(V"Successfully installed dependencies for luasocket ${LUASOCKET}", output, 1, true) + assert.is_true(os.remove("luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) end) it("reinstall", function() - assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket 3.0rc1-2")) - assert.is_true(run.luarocks_bool("install " .. "luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) - assert.is_true(run.luarocks_bool("install --deps-mode=none " .. "luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) - assert.is_true(os.remove("luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) + assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket ${LUASOCKET}")) + assert.is_true(run.luarocks_bool("install " .. "luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) + assert.is_true(run.luarocks_bool("install --deps-mode=none " .. "luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) + assert.is_true(os.remove("luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) end) it("installation rolls back on failure", function() - assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket 3.0rc1-2")) + assert.is_true(run.luarocks_bool("build --pack-binary-rock luasocket ${LUASOCKET}")) local luadir = testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION lfs.mkdir(luadir) @@ -219,7 +224,7 @@ describe("luarocks install #integration", function() fd:close() -- try to install and fail - assert.is_false(run.luarocks_bool("install " .. "luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) + assert.is_false(run.luarocks_bool("install " .. "luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) -- file is still there assert.is.truthy(lfs.attributes(luadir .. "/socket")) @@ -230,13 +235,13 @@ describe("luarocks install #integration", function() assert.is_true(os.remove(luadir .. "/socket")) -- try again and succeed - assert.is_true(run.luarocks_bool("install " .. "luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) + assert.is_true(run.luarocks_bool("install " .. "luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) -- files installed successfully assert.is.truthy(lfs.attributes(luadir .. "/socket/ftp.lua")) assert.is.truthy(lfs.attributes(luadir .. "/mime.lua")) - assert.is_true(os.remove("luasocket-3.0rc1-2." .. test_env.platform .. ".rock")) + assert.is_true(os.remove("luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) end) it("binary rock of cprint", function() @@ -246,11 +251,11 @@ describe("luarocks install #integration", function() end) it("accepts --no-manifest flag", function() - assert.is_true(run.luarocks_bool("install lxsh 0.8.6-2")) + assert.is_true(run.luarocks_bool("install lxsh ${LXSH}")) assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/manifest")) assert.is.truthy(os.remove(testing_paths.testing_sys_rocks .. "/manifest")) - assert.is_true(run.luarocks_bool("install --no-manifest lxsh 0.8.6-2")) + assert.is_true(run.luarocks_bool("install --no-manifest lxsh ${LXSH}")) assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/manifest")) end) end) diff --git a/spec/list_spec.lua b/spec/list_spec.lua index 875d72a4..54c63bea 100644 --- a/spec/list_spec.lua +++ b/spec/list_spec.lua @@ -1,4 +1,5 @@ local test_env = require("spec.util.test_env") +local V = test_env.V local run = test_env.run local testing_paths = test_env.testing_paths @@ -22,13 +23,13 @@ describe("luarocks list #integration", function() it("--porcelain", function() local output = run.luarocks("list --porcelain") - assert.is.truthy(output:find("luacov\t0.15.0-1\tinstalled\t" .. testing_paths.testing_sys_rocks, 1, true)) + assert.is.truthy(output:find(V"luacov\t${LUACOV}\tinstalled\t" .. testing_paths.testing_sys_rocks, 1, true)) end) it("shows version number", function() local output = run.luarocks("list") assert.is.truthy(output:find("luacov")) - assert.matches("0.15.0-1", output, 1, true) + assert.matches(V"${LUACOV}", output, 1, true) end) it("LuaRocks install outdated and list it", function() diff --git a/spec/make_spec.lua b/spec/make_spec.lua index e14eb66b..626d84df 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua @@ -8,11 +8,11 @@ local write_file = test_env.write_file test_env.unload_luarocks() local extra_rocks = { - "/luasocket-3.0rc1-2.src.rock", - "/luasocket-3.0rc1-2.rockspec", - "/lpeg-0.12-1.src.rock", - "/lxsh-0.8.6-2.src.rock", - "/lxsh-0.8.6-2.rockspec" + "/luasocket-${LUASOCKET}.src.rock", + "/luasocket-${LUASOCKET}.rockspec", + "/lpeg-${LPEG}.src.rock", + "/lxsh-${LXSH}.src.rock", + "/lxsh-${LXSH}.rockspec" } describe("luarocks make #integration", function() @@ -35,35 +35,35 @@ describe("luarocks make #integration", 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") + test_env.remove_dir("luasocket-${LUASOCKET}") + os.remove("luasocket-${LUASOCKET}.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")) - lfs.chdir("luasocket-3.0rc1-2/luasocket-3.0-rc1/") - assert.is_true(run.luarocks_bool("make luasocket-3.0rc1-2.rockspec")) + assert.is_true(run.luarocks_bool("download --source luasocket ${LUASOCKET}")) + assert.is_true(run.luarocks_bool("unpack luasocket-${LUASOCKET}.src.rock")) + lfs.chdir("luasocket-${LUASOCKET}/luasocket/") + assert.is_true(run.luarocks_bool("make luasocket-${LUASOCKET}.rockspec")) -- 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")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/luasocket/${LUASOCKET}/luasocket-${LUASOCKET}.rockspec")) end) it("--no-doc", function() finally(function() lfs.chdir(testing_paths.testrun_dir) - test_env.remove_dir("luasocket-3.0rc1-2") - os.remove("luasocket-3.0rc1-2.src.rock") + test_env.remove_dir("luasocket-${LUASOCKET}") + os.remove("luasocket-${LUASOCKET}.src.rock") end) - 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")) - lfs.chdir("luasocket-3.0rc1-2/luasocket-3.0-rc1/") - assert.is_true(run.luarocks_bool("make --no-doc luasocket-3.0rc1-2.rockspec")) + assert.is_true(run.luarocks_bool("download --source luasocket ${LUASOCKET}")) + assert.is_true(run.luarocks_bool("unpack luasocket-${LUASOCKET}.src.rock")) + lfs.chdir("luasocket-${LUASOCKET}/luasocket") + assert.is_true(run.luarocks_bool("make --no-doc luasocket-${LUASOCKET}.rockspec")) assert.is_true(run.luarocks_bool("show luasocket")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/luasocket/3.0rc1-2/doc")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/luasocket/${LUASOCKET}/doc")) end) it("--only-deps", function() @@ -82,24 +82,24 @@ describe("luarocks make #integration", function() 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/")) + assert.is_true(run.luarocks_bool("download --source lxsh ${LXSH}")) + assert.is_true(run.luarocks_bool("unpack lxsh-${LXSH}.src.rock")) + assert.is_true(lfs.chdir("lxsh-${LXSH}/lxsh-${LXSH_V}-1/")) end) -- delete downloaded and unpacked files after_each(function() 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")) + test_env.remove_dir("lxsh-${LXSH}") + assert.is_true(os.remove("lxsh-${LXSH}.src.rock")) end) it("default rockspec", function() - assert.is_true(run.luarocks_bool("new_version lxsh-0.8.6-2.rockspec")) + assert.is_true(run.luarocks_bool("new_version lxsh-${LXSH}.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-3/lxsh-0.8.6-3.rockspec")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH_V}-3/lxsh-${LXSH_V}-3.rockspec")) end) it("unnamed rockspec", function() @@ -107,35 +107,35 @@ describe("luarocks make #integration", function() os.remove("rockspec") end) - test_env.copy("lxsh-0.8.6-2.rockspec", "rockspec") + test_env.copy("lxsh-${LXSH}.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")) + assert.is.truthy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) end) it("ambiguous rockspec", function() - assert.is.truthy(os.rename("lxsh-0.8.6-2.rockspec", "lxsh2-0.8.6-2.rockspec")) + assert.is.truthy(os.rename("lxsh-${LXSH}.rockspec", "lxsh2-${LXSH}.rockspec")) local output = run.luarocks("make") assert.is.truthy(output:match("Error: Inconsistency between rockspec filename")) assert.is_false(run.luarocks_bool("show lxsh")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) end) it("ambiguous unnamed rockspec", function() - assert.is.truthy(os.rename("lxsh-0.8.6-2.rockspec", "1_rockspec")) + assert.is.truthy(os.rename("lxsh-${LXSH}.rockspec", "1_rockspec")) test_env.copy("1_rockspec", "2_rockspec") local output = run.luarocks("make") assert.is.truthy(output:match("Error: Please specify which rockspec file to use")) assert.is_false(run.luarocks_bool("show lxsh")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/0.8.6-2/lxsh-0.8.6-2.rockspec")) + assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/lxsh/${LXSH}/lxsh-${LXSH}.rockspec")) end) it("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")) + assert.is.truthy(lfs.attributes("lxsh-${LXSH}.all.rock")) end) end) diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua index f8795db0..d47cfd05 100644 --- a/spec/new_version_spec.lua +++ b/spec/new_version_spec.lua @@ -7,7 +7,7 @@ test_env.unload_luarocks() local extra_rocks = { "/abelhas-1.1-1.rockspec", - "/lpeg-0.12-1.rockspec" + "/lpeg-${LPEG}.rockspec" } describe("luarocks new_version #integration", function() @@ -41,8 +41,8 @@ describe("luarocks new_version #integration", function() describe("more complex tests", function() it("of luacov", function() - assert.is_true(run.luarocks_bool("download --rockspec luacov 0.15.0")) - assert.is_true(run.luarocks_bool("new_version luacov-0.15.0-1.rockspec 0.2")) + assert.is_true(run.luarocks_bool("download --rockspec luacov ${LUACOV_V}")) + assert.is_true(run.luarocks_bool("new_version luacov-${LUACOV}.rockspec 0.2")) assert.is.truthy(lfs.attributes("luacov-0.2-1.rockspec")) test_env.remove_files(lfs.currentdir(), "luacov%-") end) @@ -55,15 +55,15 @@ describe("luarocks new_version #integration", function() end) it("of luacov with tag", function() - assert.is_true(run.luarocks_bool("download --rockspec luacov 0.15.0")) - assert.is_true(run.luarocks_bool("new_version luacov-0.15.0-1.rockspec --tag v0.3")) + assert.is_true(run.luarocks_bool("download --rockspec luacov ${LUACOV_V}")) + assert.is_true(run.luarocks_bool("new_version luacov-${LUACOV}.rockspec --tag v0.3")) assert.is.truthy(lfs.attributes("luacov-0.3-1.rockspec")) test_env.remove_files(lfs.currentdir(), "luacov%-") end) it("updating md5", function() - assert.is_true(run.luarocks_bool("download --rockspec lpeg 0.12")) - assert.is_true(run.luarocks_bool("new_version lpeg-0.12-1.rockspec 0.2 https://luarocks.org/manifests/gvvaughan/lpeg-1.0.0-1.rockspec")) + assert.is_true(run.luarocks_bool("download --rockspec lpeg ${LPEG_V}")) + assert.is_true(run.luarocks_bool("new_version lpeg-${LPEG}.rockspec 0.2 https://luarocks.org/manifests/gvvaughan/lpeg-1.0.0-1.rockspec")) test_env.remove_files(lfs.currentdir(), "lpeg%-") end) end) diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index d81258c6..0a4e0d8a 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua @@ -8,8 +8,8 @@ test_env.unload_luarocks() local extra_rocks = { "/luassert-1.7.0-1.src.rock", - "/luasocket-3.0rc1-2.src.rock", - "/luasocket-3.0rc1-2.rockspec", + "/luasocket-${LUASOCKET}.src.rock", + "/luasocket-${LUASOCKET}.rockspec", "/say-1.2-1.src.rock", "/say-1.0-1.src.rock" } diff --git a/spec/remove_spec.lua b/spec/remove_spec.lua index 21a39696..a67db591 100644 --- a/spec/remove_spec.lua +++ b/spec/remove_spec.lua @@ -3,16 +3,17 @@ local lfs = require("lfs") local run = test_env.run local testing_paths = test_env.testing_paths local env_variables = test_env.env_variables +local V = test_env.V test_env.unload_luarocks() local extra_rocks = { "/abelhas-1.1-1.src.rock", - "/copas-2.0.1-1.src.rock", + "/copas-${COPAS}.src.rock", "/coxpcall-1.16.0-1.src.rock", "/coxpcall-1.16.0-1.rockspec", - "/luafilesystem-1.7.0-1.src.rock", - "/luafilesystem-1.6.3-2.src.rock", + "/luafilesystem-${LUAFILESYSTEM}.src.rock", + "/luafilesystem-${LUAFILESYSTEM_OLD}.src.rock", } describe("luarocks remove #integration", function() @@ -85,31 +86,35 @@ describe("luarocks remove #integration", function() end) it("restores old versions", function() - assert.is_true(run.luarocks_bool("install luafilesystem 1.6.3")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) + local libdir = testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION + + assert.is_true(run.luarocks_bool("install luafilesystem ${LUAFILESYSTEM_OLD_V}")) + assert.is.truthy(lfs.attributes(libdir.."/lfs."..test_env.lib_extension)) if test_env.TEST_TARGET_OS ~= "windows" then - local fd = io.open(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension, "r") - assert(fd:read("*a"):match("LuaFileSystem 1.6.3", 1, true)) + local fd = io.open(libdir.."/lfs."..test_env.lib_extension, "r") + assert(fd:read("*a"):match(V"LuaFileSystem ${LUAFILESYSTEM_OLD_V}", 1, true)) fd:close() end - assert.is_true(run.luarocks_bool("install luafilesystem 1.7.0 --keep")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/luafilesystem_1_6_3_2-lfs."..test_env.lib_extension)) + local suffix = (V"${LUAFILESYSTEM_OLD}"):gsub("[%.%-]", "_") + + assert.is_true(run.luarocks_bool("install luafilesystem ${LUAFILESYSTEM_V} --keep")) + assert.is.truthy(lfs.attributes(libdir.."/lfs."..test_env.lib_extension)) + assert.is.truthy(lfs.attributes(libdir.."/luafilesystem_"..suffix.."-lfs."..test_env.lib_extension)) if test_env.TEST_TARGET_OS ~= "windows" then - local fd = io.open(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension, "r") - assert(fd:read("*a"):match("LuaFileSystem 1.7.0", 1, true)) + local fd = io.open(libdir.."/lfs."..test_env.lib_extension, "r") + assert(fd:read("*a"):match(V"LuaFileSystem ${LUAFILESYSTEM_V}", 1, true)) fd:close() end - assert.is_true(run.luarocks_bool("remove luafilesystem 1.7.0")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension)) + assert.is_true(run.luarocks_bool("remove luafilesystem ${LUAFILESYSTEM_V}")) + assert.is.truthy(lfs.attributes(libdir.."/lfs."..test_env.lib_extension)) if test_env.TEST_TARGET_OS ~= "windows" then - local fd = io.open(testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION.."/lfs."..test_env.lib_extension, "r") - assert(fd:read("*a"):match("LuaFileSystem 1.6.3", 1, true)) + local fd = io.open(libdir.."/lfs."..test_env.lib_extension, "r") + assert(fd:read("*a"):match(V"LuaFileSystem ${LUAFILESYSTEM_OLD_V}", 1, true)) fd:close() end end) diff --git a/spec/test_spec.lua b/spec/test_spec.lua index 943d0e48..21844d63 100644 --- a/spec/test_spec.lua +++ b/spec/test_spec.lua @@ -10,7 +10,7 @@ test_env.unload_luarocks() local extra_rocks = { "/busted-2.0.0-1.rockspec", "/lua_cliargs-3.0-1.src.rock", - "/luafilesystem-1.7.0-2.src.rock", + "/luafilesystem-${LUAFILESYSTEM}.src.rock", "/luasystem-0.2.1-0.src.rock", "/dkjson-2.5-2.src.rock", "/say-1.3-1.rockspec", @@ -41,6 +41,7 @@ describe("luarocks test #integration", function() lazy_setup(function() -- Try to cache rocks from the host system to speed up test for _, r in ipairs(extra_rocks) do + r = test_env.V(r) local n, v = r:match("^/(.*)%-([^%-]+)%-%d+%.[^%-]+$") os.execute("luarocks pack " .. n .. " " .. v) end @@ -84,17 +85,17 @@ describe("luarocks test #integration", function() assert.is_true(run.luarocks_bool("unpack busted_project-0.1-1.src.rock")) lfs.chdir("busted_project-0.1-1/busted_project") assert.is_true(run.luarocks_bool("make")) - + run.luarocks_bool("remove busted") local prepareOutput = run.luarocks_bool("test --prepare") assert.is_true(run.luarocks_bool("show busted")) - + -- Assert that "test --prepare" run successfully assert.is_true(prepareOutput) local output = run.luarocks("test") assert.not_match(tostring(prepareOutput), output) - + end) end) end) diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua index 73775992..73f26cd7 100644 --- a/spec/upload_spec.lua +++ b/spec/upload_spec.lua @@ -23,12 +23,12 @@ describe("luarocks upload #integration", function() end) it("api key invalid and skip-pack", function() - assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --skip-pack " .. testing_paths.testing_server .. "/luasocket-3.0rc1-2.rockspec")) + assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --skip-pack " .. testing_paths.testing_server .. "/luasocket-${LUASOCKET}.rockspec")) end) it("force #unix", function() assert.is_true(test_env.need_rock("dkjson")) - assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --force " .. testing_paths.testing_server .. "/luasocket-3.0rc1-2.rockspec")) + assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --force " .. testing_paths.testing_server .. "/luasocket-${LUASOCKET}.rockspec")) end) describe("tests with Xavante server #mock", function() diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index 737d90a5..6a466bae 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua @@ -1,6 +1,7 @@ local test_env = {} local lfs = require("lfs") +local versions = require("spec.util.versions") local help_message = [[ LuaRocks test-suite @@ -36,14 +37,6 @@ local function title(str) print(("-"):rep(#str)) end -function test_env.exists(path) - return lfs.attributes(path, "mode") ~= nil -end - -function test_env.file_if_exists(path) - return lfs.attributes(path, "mode") and path -end - --- Quote argument for shell processing. Fixes paths on Windows. -- Adds double quotes and escapes. Based on function in fs/win32.lua. -- @param arg string: Unquoted argument. @@ -66,6 +59,62 @@ local function Q(arg) end end +local function V(str) + return (str:gsub("${([^}]-)}", function(name) + name = name:lower() + local prefix, suffix = name:match("^(.*)_(.)$") + if suffix then + name = prefix + local d = assert(versions[name]) + local v, r = d:match("^([^-]*)%-(%d*)$") + if suffix == "d" then + return d + elseif suffix == "v" then + return v + elseif suffix == "r" then + return v + else + print("Test error: invalid suffix " .. suffix .. " in variable " .. name) + os.exit(1) + end + else + if not versions[name] then + print("Test error: no version definition for " .. name) + os.exit(1) + end + return versions[name] + end + end)) +end + +local os_remove = os.remove +os.remove = function(f) -- luacheck: ignore + return os_remove(V(f)) +end + +local os_rename = os.rename +os.rename = function(a, b) -- luacheck: ignore + return os_rename(V(a), V(b)) +end + +local lfs_chdir = lfs.chdir +lfs.chdir = function(d) -- luacheck: ignore + return lfs_chdir(V(d)) +end + +local lfs_attributes = lfs.attributes +lfs.attributes = function(f, ...) -- luacheck: ignore + return lfs_attributes(V(f), ...) +end + +function test_env.exists(path) + return lfs.attributes(path, "mode") ~= nil +end + +function test_env.file_if_exists(path) + return lfs.attributes(path, "mode") and path +end + function test_env.quiet(command) if not test_env.VERBOSE then if test_env.TEST_TARGET_OS == "windows" then @@ -79,6 +128,9 @@ function test_env.quiet(command) end function test_env.copy(source, destination) + source = V(source) + destination = V(destination) + local r_source, err = io.open(source, "r") local r_destination, err = io.open(destination, "w") @@ -303,6 +355,9 @@ function test_env.set_args() end function test_env.copy_dir(source_path, target_path) + source_path = V(source_path) + target_path = V(target_path) + local testing_paths = test_env.testing_paths if test_env.TEST_TARGET_OS == "windows" then execute_bool(testing_paths.win_tools .. "/cp -R ".. source_path .. "/. " .. target_path) @@ -314,6 +369,8 @@ end --- Remove directory recursively -- @param path string: directory path to delete function test_env.remove_dir(path) + path = V(path) + if test_env.exists(path) then for file in lfs.dir(path) do if file ~= "." and file ~= ".." then @@ -334,6 +391,8 @@ end -- @param path string: path to directory -- @param pattern string: pattern matching basenames of subdirectories to be removed function test_env.remove_subdirs(path, pattern) + path = V(path) + if test_env.exists(path) then for file in lfs.dir(path) do if file ~= "." and file ~= ".." then @@ -352,6 +411,8 @@ end -- @param pattern string: pattern matching basenames of files to be deleted -- @return result_check boolean: true if one or more files deleted function test_env.remove_files(path, pattern) + path = V(path) + local result_check = false if test_env.exists(path) then for file in lfs.dir(path) do @@ -378,6 +439,8 @@ local function download_rocks(urls, save_path) local to_download = {} local fixtures = {} for _, url in ipairs(urls) do + url = V(url) + if url:match("^spec/fixtures") then table.insert(fixtures, (url:gsub("^spec/fixtures", test_env.testing_paths.fixtures_dir))) else @@ -399,7 +462,10 @@ local function download_rocks(urls, save_path) else cmd = "wget -cP " .. save_path end - assert(execute_bool(cmd.." "..table.concat(to_download, " "))) + local ok = execute_bool(cmd.." "..table.concat(to_download, " ")) + if not ok then + os.exit(1) + end end return (#fixtures > 0) or (#to_download > 0) @@ -409,6 +475,8 @@ end -- @param pathname string: path to file. -- @param str string: content of the file. function test_env.write_file(pathname, str, finally) + pathname = V(pathname) + local file = assert(io.open(pathname, "w")) file:write(str) file:close() @@ -487,6 +555,7 @@ local function make_run_function(cmd_name, exec_function, with_coverage, do_prin end return function(cmd, new_vars) + cmd = V(cmd) local temp_vars = {} for k, v in pairs(test_env.env_variables) do temp_vars[k] = v @@ -519,7 +588,11 @@ local function move_file(src, dst) if test_env.TEST_TARGET_OS == "windows" then execute_bool(test_env.testing_paths.win_tools .. "/mv " .. src .. " " .. dst) else - execute_bool("mv " .. src .. " " .. dst) + local ok = execute_bool("mv " .. src .. " " .. dst) + if not ok then + print(debug.traceback()) + os.exit(1) + end end end @@ -541,9 +614,9 @@ local function build_environment(rocks, env_variables) test_env.run.luarocks_admin_nocov("make_manifest " .. Q(testing_paths.testing_cache)) for _, rock in ipairs(rocks) do - if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. Q(rock), env_variables) then - test_env.run.luarocks_nocov("build --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock), env_variables) - test_env.run.luarocks_nocov("pack --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock), env_variables) + if not test_env.run.luarocks_nocov(test_env.quiet("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. Q(rock), env_variables)) then + assert(test_env.run.luarocks_nocov("build --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock), env_variables)) + assert(test_env.run.luarocks_nocov("pack --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock), env_variables)) move_file(rock .. "-*.rock", testing_paths.testing_cache) end end @@ -685,6 +758,8 @@ end -- Return `true` if the rock is already installed or has been installed successfully, -- `false` if installation failed. function test_env.need_rock(rock) + rock = V(rock) + print("Check if " .. rock .. " is installed") if test_env.run.luarocks_noprint_nocov(test_env.quiet("show " .. rock)) then return true @@ -887,10 +962,12 @@ local function prepare_mock_server_binary_rocks() local rocks = { -- rocks needed for mock-server - "luasocket-3.0rc1-2.src.rock", + "luasocket-${LUASOCKET}.src.rock", "coxpcall-1.16.0-1.src.rock", - "copas-2.0.1-1.src.rock", - "luafilesystem-1.7.0-2.src.rock", + "binaryheap-${BINARYHEAP}.src.rock", + "timerwheel-${TIMERWHEEL}.src.rock", + "copas-${COPAS}.src.rock", + "luafilesystem-${LUAFILESYSTEM}.src.rock", "xavante-2.4.0-1.src.rock", "wsapi-1.6.1-1.src.rock", "rings-1.3.0-1.src.rock", @@ -901,6 +978,7 @@ local function prepare_mock_server_binary_rocks() } local make_manifest = download_rocks(rocks, testing_paths.testing_server) for _, rock in ipairs(rocks) do + rock = V(rock) local rockname = rock:gsub("%-[^-]+%-%d+%.[%a.]+$", "") if not find_binary_rock(rock, testing_paths.testing_server) then test_env.run.luarocks_nocov("build " .. Q(testing_paths.testing_server .. "/" .. rock) .. " --tree=" .. testing_paths.testing_cache) @@ -937,25 +1015,29 @@ function test_env.main() local urls = {} -- names of rock and rockspec files to be downloaded if test_env.TYPE_TEST_ENV == "full" then - table.insert(urls, "/luafilesystem-1.6.3-1.src.rock") - table.insert(urls, "/luasocket-3.0rc1-1.src.rock") - table.insert(urls, "/luasocket-3.0rc1-1.rockspec") + table.insert(urls, "/luafilesystem-${LUAFILESYSTEM}.src.rock") + table.insert(urls, "/luasocket-${LUASOCKET}.src.rock") + table.insert(urls, "/luasocket-${LUASOCKET}.rockspec") table.insert(urls, "/md5-1.2-1.src.rock") --table.insert(urls, "/lzlib-0.4.1.53-1.src.rock") table.insert(urls, "/lua-zlib-1.2-0.src.rock") table.insert(urls, "/lua-bz2-0.1.0-1.src.rock") rocks = {"luafilesystem", "luasocket", "md5", "lua-zlib", "lua-bz2"} if test_env.TEST_TARGET_OS ~= "windows" then - table.insert(urls, "/luaposix-33.2.1-1.src.rock") + if test_env.lua_version == "5.1" then + table.insert(urls, "/bit32-${BIT32}.src.rock") + table.insert(rocks, "bit32") + end + table.insert(urls, "/luaposix-${LUAPOSIX}.src.rock") table.insert(rocks, "luaposix") end end -- luacov is needed for both minimal or full environment - table.insert(urls, "/luacov-0.15.0-1.rockspec") - table.insert(urls, "/luacov-0.15.0-1.src.rock") - table.insert(urls, "/cluacov-0.1.1-1.rockspec") - table.insert(urls, "/cluacov-0.1.1-1.src.rock") + table.insert(urls, "/luacov-${LUACOV}.rockspec") + table.insert(urls, "/luacov-${LUACOV}.src.rock") + table.insert(urls, "/cluacov-${CLUACOV}.rockspec") + table.insert(urls, "/cluacov-${CLUACOV}.src.rock") table.insert(rocks, "luacov") table.insert(rocks, "cluacov") @@ -977,5 +1059,6 @@ 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() +test_env.V = V return test_env diff --git a/spec/util/versions.lua b/spec/util/versions.lua new file mode 100644 index 00000000..b0d5c453 --- /dev/null +++ b/spec/util/versions.lua @@ -0,0 +1,14 @@ +return { + binaryheap = "0.4-1", -- dependency for copas + bit32 = "5.3.5.1-1", -- dependency for luaposix on Lua 5.1 + cluacov = "0.1.2-1", + copas = "3.0.0-1", + lpeg = "1.0.0-1", + luacov = "0.15.0-1", + luafilesystem = "1.8.0-1", + luafilesystem_old = "1.6.3-2", + luaposix = "35.1-1", + luasocket = "3.0.0-1", + lxsh = "0.8.6-2", + timerwheel = "0.2.0-2", -- dependency for copas +} -- cgit v1.2.3-55-g6feb