From f76b7a2b13e411df2e696146bb0a6396781acd92 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Thu, 29 Feb 2024 00:46:06 -0300 Subject: tests: speed up and simplify --- spec/build_spec.lua | 71 --------------------------- spec/config_spec.lua | 2 +- spec/doc_spec.lua | 5 -- spec/install_spec.lua | 35 ------------- spec/list_spec.lua | 5 -- spec/make_manifest_spec.lua | 13 ----- spec/make_spec.lua | 42 ---------------- spec/purge_spec.lua | 32 ------------ spec/quick/admin_make_manifest.q | 46 +++++++++++++++++ spec/quick/build.q | 103 +++++++++++++++++++++++++++++++++++++-- spec/quick/doc.q | 13 +++++ spec/quick/install.q | 60 +++++++++++++++++++++++ spec/quick/list.q | 37 +++++++++++++- spec/quick/make.q | 51 +++++++++++++++++++ spec/quick/purge.q | 103 +++++++++++++++++++++++++++++++++++++++ spec/unit/dir_spec.lua | 2 +- spec/unit/fetch_spec.lua | 2 +- spec/unit/fun_spec.lua | 2 +- spec/unit/rockspecs_spec.lua | 2 +- spec/unit/sysdetect_spec.lua | 10 ++-- spec/unit/util_spec.lua | 2 +- spec/util/quick.lua | 46 +++++++++++++++++ spec/util/test_env.lua | 87 ++++++++++----------------------- src/luarocks/cmd.lua | 31 ++++++------ 24 files changed, 507 insertions(+), 295 deletions(-) delete mode 100644 spec/make_manifest_spec.lua delete mode 100644 spec/purge_spec.lua create mode 100644 spec/quick/admin_make_manifest.q create mode 100644 spec/quick/doc.q create mode 100644 spec/quick/make.q create mode 100644 spec/quick/purge.q diff --git a/spec/build_spec.lua b/spec/build_spec.lua index d07447c1..00eac2e1 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -154,77 +154,6 @@ describe("LuaRocks build #integration", function() end, finally) end) - it("supports --pin #pinning", function() - test_env.run_in_tmp(function(tmpdir) - write_file("test-1.0-1.rockspec", [[ - package = "test" - version = "1.0-1" - source = { - url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" - } - dependencies = { - "a_rock >= 0.8" - } - build = { - type = "builtin", - modules = { - test = "test.lua" - } - } - ]]) - write_file("test.lua", "return {}") - - assert.is_true(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --pin --tree=lua_modules")) - assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) - assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/2.0-1/a_rock-2.0-1.rockspec")) - local lockfilename = "./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/luarocks.lock" - assert.is.truthy(lfs.attributes(lockfilename)) - local lockdata = loadfile(lockfilename)() - assert.same({ - dependencies = { - ["a_rock"] = "2.0-1", - ["lua"] = test_env.lua_version .. "-1", - } - }, lockdata) - end, finally) - end) - - it("supports --pin --only-deps #pinning", function() - test_env.run_in_tmp(function(tmpdir) - write_file("test-1.0-1.rockspec", [[ - package = "test" - version = "1.0-1" - source = { - url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" - } - dependencies = { - "a_rock >= 0.8" - } - build = { - type = "builtin", - modules = { - test = "test.lua" - } - } - ]]) - write_file("test.lua", "return {}") - - assert.is_true(run.luarocks_bool("build --server=" .. testing_paths.fixtures_dir .. "/a_repo test-1.0-1.rockspec --pin --only-deps --tree=lua_modules")) - assert.is.falsy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/1.0-1/test-1.0-1.rockspec")) - assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/2.0-1/a_rock-2.0-1.rockspec")) - assert.is.truthy(lfs.attributes("./luarocks.lock")) - local lockfilename = "./luarocks.lock" - assert.is.truthy(lfs.attributes(lockfilename)) - local lockdata = loadfile(lockfilename)() - assert.same({ - dependencies = { - ["a_rock"] = "2.0-1", - ["lua"] = test_env.lua_version .. "-1", - } - }, lockdata) - end, finally) - end) - it("lmathx deps partial match", function() if test_env.LUA_V == "5.1" or test_env.LUAJIT_V then assert.is_true(run.luarocks_bool("build lmathx")) diff --git a/spec/config_spec.lua b/spec/config_spec.lua index 6bfac433..9dd8fbcb 100644 --- a/spec/config_spec.lua +++ b/spec/config_spec.lua @@ -142,7 +142,7 @@ describe("LuaRocks config tests #integration", function() it("can read as JSON", function() local output = run.luarocks("config rocks_trees --json") - assert.match('^%["', output) + assert.match('^%[{', output) end) it("reads an array -> hash config key", function() diff --git a/spec/doc_spec.lua b/spec/doc_spec.lua index 062b36e7..f48f951a 100644 --- a/spec/doc_spec.lua +++ b/spec/doc_spec.lua @@ -126,11 +126,6 @@ describe("luarocks doc #integration", function() end, finally) end) - it("with --local", function() - assert.is_true(run.luarocks_bool("install --local --server=" .. testing_paths.fixtures_dir .. "/a_repo a_rock")) - assert.is_true(run.luarocks_bool("doc --server=" .. testing_paths.fixtures_dir .. "/a_repo a_rock --local")) - end) - it("with --porcelain", function() test_env.run_in_tmp(function(tmpdir) test_env.write_file("test-1.0-1.rockspec", [[ diff --git a/spec/install_spec.lua b/spec/install_spec.lua index b4b064f0..66000c36 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -142,41 +142,6 @@ describe("luarocks install #integration", function() assert.is_true(os.remove("luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) end) - it("installation rolls back on failure", function() - if test_env.TYPE_TEST_ENV ~= "full" then - 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) - - run.luarocks_bool("remove " .. "luasocket") - - -- create a file where a folder should be - local fd = io.open(luadir .. "/socket", "w") - fd:write("\n") - fd:close() - - -- try to install and fail - assert.is_false(run.luarocks_bool("install " .. "luasocket-${LUASOCKET}." .. test_env.platform .. ".rock")) - - -- file is still there - assert.is.truthy(lfs.attributes(luadir .. "/socket")) - -- no left overs from failed installation - assert.is.falsy(lfs.attributes(luadir .. "/mime.lua")) - - -- remove file - assert.is_true(os.remove(luadir .. "/socket")) - - -- try again and succeed - 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-${LUASOCKET}." .. test_env.platform .. ".rock")) - end - end) - it("binary rock of cprint", function() assert.is_true(run.luarocks_bool("build --pack-binary-rock cprint")) assert.is_true(run.luarocks_bool("install cprint-${CPRINT}." .. test_env.platform .. ".rock")) diff --git a/spec/list_spec.lua b/spec/list_spec.lua index eeeb79d2..08d85879 100644 --- a/spec/list_spec.lua +++ b/spec/list_spec.lua @@ -19,11 +19,6 @@ describe("luarocks list #integration", function() assert.match("luacov", output) end) - it("--porcelain", function() - local output = run.luarocks("list --porcelain") - 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")) diff --git a/spec/make_manifest_spec.lua b/spec/make_manifest_spec.lua deleted file mode 100644 index 146b6178..00000000 --- a/spec/make_manifest_spec.lua +++ /dev/null @@ -1,13 +0,0 @@ -local test_env = require("spec.util.test_env") -local run = test_env.run - -describe("luarocks make_manifest #integration", function() - - before_each(function() - test_env.setup_specs() - end) - - it("runs", function() - assert.is_true(run.luarocks_admin_bool("make_manifest")) - end) -end) diff --git a/spec/make_spec.lua b/spec/make_spec.lua index 6cce0543..b0572630 100644 --- a/spec/make_spec.lua +++ b/spec/make_spec.lua @@ -213,48 +213,6 @@ describe("luarocks make #integration", function() end, finally) end) - it("overrides luarocks.lock with --pin #pinning", function() - test_env.run_in_tmp(function(tmpdir) - write_file("test-2.0-1.rockspec", [[ - package = "test" - version = "2.0-1" - source = { - url = "file://]] .. tmpdir:gsub("\\", "/") .. [[/test.lua" - } - dependencies = { - "a_rock >= 0.8" - } - build = { - type = "builtin", - modules = { - test = "test.lua" - } - } - ]]) - write_file("test.lua", "return {}") - write_file("luarocks.lock", [[ - return { - dependencies = { - ["a_rock"] = "1.0-1", - } - } - ]]) - - print(run.luarocks("make --server=" .. testing_paths.fixtures_dir .. "/a_repo --tree=lua_modules --pin")) - assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/2.0-1/test-2.0-1.rockspec")) - assert.is.truthy(lfs.attributes("./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/a_rock/2.0-1/a_rock-2.0-1.rockspec")) - local lockfilename = "./lua_modules/lib/luarocks/rocks-" .. test_env.lua_version .. "/test/2.0-1/luarocks.lock" - assert.is.truthy(lfs.attributes(lockfilename)) - local lockdata = loadfile(lockfilename)() - assert.same({ - dependencies = { - ["a_rock"] = "2.0-1", - ["lua"] = test_env.lua_version .. "-1", - } - }, lockdata) - end, finally) - end) - describe("#ddt upgrading rockspecs with double deploy types", function() local deploy_lib_dir = testing_paths.testing_sys_tree .. "/lib/lua/"..env_variables.LUA_VERSION local deploy_lua_dir = testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION diff --git a/spec/purge_spec.lua b/spec/purge_spec.lua deleted file mode 100644 index 7fdb74f4..00000000 --- a/spec/purge_spec.lua +++ /dev/null @@ -1,32 +0,0 @@ -local test_env = require("spec.util.test_env") -local run = test_env.run -local testing_paths = test_env.testing_paths - -local extra_rocks = { - "/say-1.0-1.src.rock", -} - -describe("luarocks purge #integration", function() - before_each(function() - test_env.setup_specs(extra_rocks) - end) - - it("missing tree", function() - assert.is_false(run.luarocks_bool("purge --tree=" .. testing_paths.testing_tree)) - end) - it("tree with no string", function() - assert.is_false(run.luarocks_bool("purge --tree=")) - end) - it("tree with no string", function() - assert.is_true(run.luarocks_bool("purge --tree=" .. testing_paths.testing_sys_tree)) - end) - it("tree missing files", function() - assert.is_true(run.luarocks_bool("install say 1.0")) - test_env.remove_dir(testing_paths.testing_sys_tree .. "/share/lua/"..test_env.lua_version.."/say") - assert.is_true(run.luarocks_bool("purge --tree=" .. testing_paths.testing_sys_tree)) - assert.is_false(test_env.exists(testing_paths.testing_sys_rocks .. "/say")) - end) - it("old versions tree", function() - assert.is_true(run.luarocks_bool("purge --old-versions --tree=" .. testing_paths.testing_sys_tree)) - end) -end) diff --git a/spec/quick/admin_make_manifest.q b/spec/quick/admin_make_manifest.q new file mode 100644 index 00000000..da203a05 --- /dev/null +++ b/spec/quick/admin_make_manifest.q @@ -0,0 +1,46 @@ +SUITE: luarocks-admin make_manifest + +================================================================================ +TEST: runs + +FILE: test-1.0-1.rockspec +-------------------------------------------------------------------------------- +package = "test" +version = "1.0-1" +source = { + url = "file://%{url(tmpdir)}/test.lua" +} +build = { + type = "builtin", + modules = { + test = "test.lua" + } +} +-------------------------------------------------------------------------------- + +FILE: test.lua +-------------------------------------------------------------------------------- +return {} +-------------------------------------------------------------------------------- + +RUN: luarocks make --pack-binary-rock ./test-1.0-1.rockspec + +RUN: luarocks-admin make_manifest . + +FILE_CONTENTS: ./manifest-%{lua_version} +-------------------------------------------------------------------------------- +commands = {} +modules = {} +repository = { + test = { + ["1.0-1"] = { + { + arch = "all" + }, + { + arch = "rockspec" + } + } + } +} +-------------------------------------------------------------------------------- diff --git a/spec/quick/build.q b/spec/quick/build.q index a1731da2..ee519adf 100644 --- a/spec/quick/build.q +++ b/spec/quick/build.q @@ -1,4 +1,7 @@ -TEST: luarocks build: fails when given invalid argument +SUITE: luarocks build + +================================================================================ +TEST: fails when given invalid argument RUN: luarocks build aoesuthaoeusahtoeustnaou --only-server=localhost EXIT: 1 STDERR: @@ -9,7 +12,7 @@ Could not find a result named aoesuthaoeusahtoeustnaou ================================================================================ -TEST: luarocks build: with no arguments behaves as luarocks make +TEST: with no arguments behaves as luarocks make FILE: c_module-1.0-1.rockspec -------------------------------------------------------------------------------- @@ -43,7 +46,7 @@ EXISTS: c_module.%{lib_extension} ================================================================================ -TEST: luarocks build: defaults to builtin type +TEST: defaults to builtin type FILE: a_rock-1.0-1.rockspec -------------------------------------------------------------------------------- @@ -74,7 +77,7 @@ a_rock 1.0 ================================================================================ -TEST: luarocks build: fails if no permissions to access the specified tree #unix +TEST: fails if no permissions to access the specified tree #unix RUN: luarocks build --tree=/usr ./a_rock-1.0.1-rockspec EXIT: 4 @@ -99,7 +102,7 @@ NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1/a_rock-1.0-1.rockspec ================================================================================ -TEST: luarocks build: fails if no permissions to access the parent #unix +TEST: fails if no permissions to access the parent #unix RUN: luarocks build --tree=/usr/invalid ./a_rock-1.0.1-rockspec EXIT: 4 @@ -160,3 +163,93 @@ STDOUT: a_rock 1.0-1 is already installed Use --force to reinstall -------------------------------------------------------------------------------- + + + +================================================================================ +TEST: supports --pin #pinning + +FILE: test-1.0-1.rockspec +-------------------------------------------------------------------------------- +package = "test" +version = "1.0-1" +source = { + url = "file://%{url(tmpdir)}/test.lua" +} +dependencies = { + "a_rock >= 0.8" +} +build = { + type = "builtin", + modules = { + test = "test.lua" + } +} +-------------------------------------------------------------------------------- + +FILE: test.lua +-------------------------------------------------------------------------------- +return {} +-------------------------------------------------------------------------------- + +RUN: luarocks build --only-server=%{fixtures_dir}/a_repo test-1.0-1.rockspec --pin --tree=lua_modules + +EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/test/1.0-1/test-1.0-1.rockspec +EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/a_rock/2.0-1/a_rock-2.0-1.rockspec + +EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/test/1.0-1/luarocks.lock + +FILE_CONTENTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/test/1.0-1/luarocks.lock +-------------------------------------------------------------------------------- +return { + dependencies = { + a_rock = "2.0-1", + lua = "%{lua_version}-1" + } +} +-------------------------------------------------------------------------------- + + + +================================================================================ +TEST: supports --pin --only-deps #pinning + +FILE: test-1.0-1.rockspec +-------------------------------------------------------------------------------- +package = "test" +version = "1.0-1" +source = { + url = "file://%{url(tmpdir)}/test.lua" +} +dependencies = { + "a_rock >= 0.8" +} +build = { + type = "builtin", + modules = { + test = "test.lua" + } +} +-------------------------------------------------------------------------------- + +FILE: test.lua +-------------------------------------------------------------------------------- +return {} +-------------------------------------------------------------------------------- + +RUN: luarocks build --only-server=%{fixtures_dir}/a_repo test-1.0-1.rockspec --pin --only-deps --tree=lua_modules + +NOT_EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/test/1.0-1/test-1.0-1.rockspec +EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/a_rock/2.0-1/a_rock-2.0-1.rockspec + +EXISTS: ./luarocks.lock + +FILE_CONTENTS: ./luarocks.lock +-------------------------------------------------------------------------------- +return { + dependencies = { + a_rock = "2.0-1", + lua = "%{lua_version}-1" + } +} +-------------------------------------------------------------------------------- diff --git a/spec/quick/doc.q b/spec/quick/doc.q new file mode 100644 index 00000000..4c71f838 --- /dev/null +++ b/spec/quick/doc.q @@ -0,0 +1,13 @@ +SUITE: luarocks doc + +================================================================================ +TEST: --local + +RUN: luarocks install --local --only-server=%{fixtures_dir}/a_repo a_rock + +RUN: luarocks doc a_rock --local + +STDOUT: +-------------------------------------------------------------------------------- +opening http://www.example.com +-------------------------------------------------------------------------------- diff --git a/spec/quick/install.q b/spec/quick/install.q index 503aaacc..72795504 100644 --- a/spec/quick/install.q +++ b/spec/quick/install.q @@ -415,3 +415,63 @@ STDOUT: myrock 1.0-1 is already installed Use --force to reinstall -------------------------------------------------------------------------------- + + + +================================================================================ +TEST: installation rolls back on failure + +FILE: myrock-1.0-1.rockspec +-------------------------------------------------------------------------------- +rockspec_format = "3.0" +package = "myrock" +version = "1.0-1" +source = { + url = "file://%{url(tmpdir)}/rock.lua" +} +build = { + modules = { + ["folder.rock"] = "rock.lua", + ["xyz"] = "xyz.lua", + }, +} +-------------------------------------------------------------------------------- + +FILE: rock.lua +-------------------------------------------------------------------------------- +return {} +-------------------------------------------------------------------------------- + +FILE: xyz.lua +-------------------------------------------------------------------------------- +return {} +-------------------------------------------------------------------------------- + +RUN: luarocks make --pack-binary-rock ./myrock-1.0-1.rockspec + +FILE: %{testing_sys_tree}/share/lua/%{lua_version}/folder +-------------------------------------------------------------------------------- +a file where a folder should be +-------------------------------------------------------------------------------- + +Try to install and fail because the file is in the folder's spot: + +RUN: luarocks install ./myrock-1.0-1.all.rock +EXIT: 1 + +EXISTS: %{testing_sys_tree}/share/lua/%{lua_version}/folder + +No leftovers from the failed installation: + +NOT_EXISTS: %{testing_sys_tree}/share/lua/%{lua_version}/xyz.lua + +Now we remove the file... + +RM: %{testing_sys_tree}/share/lua/%{lua_version}/folder + +Try again and succeed: + +RUN: luarocks install ./myrock-1.0-1.all.rock + +EXISTS: %{testing_sys_tree}/share/lua/%{lua_version}/folder/rock.lua +EXISTS: %{testing_sys_tree}/share/lua/%{lua_version}/xyz.lua diff --git a/spec/quick/list.q b/spec/quick/list.q index fbb3f557..a40f37ef 100644 --- a/spec/quick/list.q +++ b/spec/quick/list.q @@ -1,5 +1,7 @@ +SUITE: luarocks list + ================================================================================ -TEST: luarocks list: invalid tree +TEST: invalid tree RUN: luarocks --tree=%{path(/some/invalid/tree)} list @@ -8,3 +10,36 @@ STDOUT: Rocks installed for Lua %{lua_version} in %{path(/some/invalid/tree)} -------------------------------------------------------------------------------- + + +================================================================================ +TEST: --porcelain + +FILE: a_rock-1.0-1.rockspec +-------------------------------------------------------------------------------- +rockspec_format = "3.0" +package = "a_rock" +version = "1.0-1" +source = { + url = "file://%{url(%{fixtures_dir})}/a_rock.lua" +} +description = { + summary = "An example rockspec", +} +dependencies = { + "lua >= 5.1" +} +build = { + modules = { + build = "a_rock.lua" + }, +} +-------------------------------------------------------------------------------- +RUN: luarocks build a_rock-1.0-1.rockspec + +RUN: luarocks list --porcelain + +STDOUT: +-------------------------------------------------------------------------------- +a_rock 1.0-1 installed %{testing_sys_rocks} +-------------------------------------------------------------------------------- diff --git a/spec/quick/make.q b/spec/quick/make.q new file mode 100644 index 00000000..c77bb499 --- /dev/null +++ b/spec/quick/make.q @@ -0,0 +1,51 @@ +SUITE: luarocks make + +================================================================================ +TEST: overrides luarocks.lock with --pin #pinning + +FILE: test-2.0-1.rockspec +-------------------------------------------------------------------------------- +package = "test" +version = "2.0-1" +source = { + url = "file://%{path(tmpdir)}/test.lua" +} +dependencies = { + "a_rock >= 0.8" +} +build = { + type = "builtin", + modules = { + test = "test.lua" + } +} +-------------------------------------------------------------------------------- + +FILE: test.lua +-------------------------------------------------------------------------------- +return {} +-------------------------------------------------------------------------------- + +FILE: luarocks.lock +-------------------------------------------------------------------------------- +return { + dependencies = { + ["a_rock"] = "1.0-1", + } +} +-------------------------------------------------------------------------------- + +RUN: luarocks make --only-server=%{fixtures_dir}/a_repo --pin --tree=lua_modules + +EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/test/2.0-1/test-2.0-1.rockspec +EXISTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/a_rock/2.0-1/a_rock-2.0-1.rockspec + +FILE_CONTENTS: ./lua_modules/lib/luarocks/rocks-%{lua_version}/test/2.0-1/luarocks.lock +-------------------------------------------------------------------------------- +return { + dependencies = { + a_rock = "2.0-1", + lua = "%{lua_version}-1" + } +} +-------------------------------------------------------------------------------- diff --git a/spec/quick/purge.q b/spec/quick/purge.q new file mode 100644 index 00000000..a3f24b99 --- /dev/null +++ b/spec/quick/purge.q @@ -0,0 +1,103 @@ +SUITE: luarocks purge + +================================================================================ +TEST: needs a --tree argument +RUN: luarocks purge +EXIT: 1 + +================================================================================ +TEST: missing tree +RUN: luarocks purge --tree=missing-tree +EXIT: 1 + +================================================================================ +TEST: missing --tree argument +RUN: luarocks purge --tree= +EXIT: 1 + + +================================================================================ +TEST: runs + +FILE: testrock-1.0-1.rockspec +-------------------------------------------------------------------------------- +package = "testrock" +version = "1.0-1" +source = { + url = "file://%{url(tmpdir)}/testrock.lua" +} +dependencies = { + "a_rock >= 0.8" +} +build = { + type = "builtin", + modules = { + testrock = "testrock.lua" + } +} +-------------------------------------------------------------------------------- + +FILE: testrock.lua +-------------------------------------------------------------------------------- +return {} +-------------------------------------------------------------------------------- + +RUN: luarocks build --only-server=%{fixtures_dir}/a_repo testrock-1.0-1.rockspec + +EXISTS: %{testing_sys_rocks}/testrock +EXISTS: %{testing_sys_rocks}/a_rock + +RUN: luarocks purge --tree=%{testing_sys_tree} + +NOT_EXISTS: %{testing_sys_rocks}/testrock +NOT_EXISTS: %{testing_sys_rocks}/a_rock + + + +================================================================================ +TEST: works with missing files + +FILE: testrock-1.0-1.rockspec +-------------------------------------------------------------------------------- +package = "testrock" +version = "1.0-1" +source = { + url = "file://%{url(tmpdir)}/testrock.lua" +} +dependencies = { + "a_rock >= 0.8" +} +build = { + type = "builtin", + modules = { + testrock = "testrock.lua" + } +} +-------------------------------------------------------------------------------- + +FILE: testrock.lua +-------------------------------------------------------------------------------- +return {} +-------------------------------------------------------------------------------- + +RUN: luarocks build --only-server=%{fixtures_dir}/a_repo testrock-1.0-1.rockspec + +RMDIR: %{testing_sys_tree}/share/lua/%{lua_version}/testrock + +RUN: luarocks purge --tree=%{testing_sys_tree} + +NOT_EXISTS: %{testing_sys_rocks}/testrock +NOT_EXISTS: %{testing_sys_rocks}/a_rock + + + +================================================================================ +TEST: --old-versions + +RUN: luarocks install --only-server=%{fixtures_dir}/a_repo a_rock 2.0 +RUN: luarocks install --only-server=%{fixtures_dir}/a_repo a_rock 1.0 --keep + +RUN: luarocks purge --old-versions --tree=%{testing_sys_tree} + +EXISTS: %{testing_sys_rocks}/a_rock/2.0-1 +NOT_EXISTS: %{testing_sys_rocks}/a_rock/1.0-1 diff --git a/spec/unit/dir_spec.lua b/spec/unit/dir_spec.lua index da5d6389..55dd6e0e 100644 --- a/spec/unit/dir_spec.lua +++ b/spec/unit/dir_spec.lua @@ -8,7 +8,7 @@ local dir = require("luarocks.dir") describe("luarocks.dir #unit", function() local runner - setup(function() + lazy_setup(function() runner = require("luacov.runner") runner.init(testing_paths.testrun_dir .. "/luacov.config") end) diff --git a/spec/unit/fetch_spec.lua b/spec/unit/fetch_spec.lua index 4fc01d80..bea50d78 100644 --- a/spec/unit/fetch_spec.lua +++ b/spec/unit/fetch_spec.lua @@ -20,7 +20,7 @@ describe("luarocks fetch #unit", function() local runner - setup(function() + lazy_setup(function() cfg.init() fs.init() diff --git a/spec/unit/fun_spec.lua b/spec/unit/fun_spec.lua index d7db1362..bffb60d7 100644 --- a/spec/unit/fun_spec.lua +++ b/spec/unit/fun_spec.lua @@ -6,7 +6,7 @@ local fun = require("luarocks.fun") describe("luarocks.fun #unit", function() local runner - setup(function() + lazy_setup(function() runner = require("luacov.runner") runner.init(testing_paths.testrun_dir .. "/luacov.config") end) diff --git a/spec/unit/rockspecs_spec.lua b/spec/unit/rockspecs_spec.lua index 5b0573fe..7eb033c8 100644 --- a/spec/unit/rockspecs_spec.lua +++ b/spec/unit/rockspecs_spec.lua @@ -6,7 +6,7 @@ local lfs = require("lfs") describe("luarocks.rockspecs #unit", function() - setup(function() + lazy_setup(function() cfg.init() end) diff --git a/spec/unit/sysdetect_spec.lua b/spec/unit/sysdetect_spec.lua index 6ec6f6b6..d3b16955 100644 --- a/spec/unit/sysdetect_spec.lua +++ b/spec/unit/sysdetect_spec.lua @@ -4,9 +4,13 @@ local lfs = require("lfs") describe("luarocks.core.sysdetect #unix #unit", function() - setup(function() - os.execute("[ -e binary-samples ] || git clone --depth=1 https://github.com/hishamhm/binary-samples") - os.execute("cd binary-samples && git pull") + lazy_setup(function() + os.execute([=[ + [ -e binary-samples ] || { + git clone --depth=1 https://github.com/hishamhm/binary-samples + ( cd binary-samples && git pull ) + } + ]=]) end) local files = { diff --git a/spec/unit/util_spec.lua b/spec/unit/util_spec.lua index bb427b3e..8b234b2e 100644 --- a/spec/unit/util_spec.lua +++ b/spec/unit/util_spec.lua @@ -8,7 +8,7 @@ local core_util = require("luarocks.core.util") describe("luarocks.util #unit", function() local runner - setup(function() + lazy_setup(function() runner = require("luacov.runner") runner.init(testing_paths.testrun_dir .. "/luacov.config") end) diff --git a/spec/util/quick.lua b/spec/util/quick.lua index c313f575..5c49fff9 100644 --- a/spec/util/quick.lua +++ b/spec/util/quick.lua @@ -159,6 +159,16 @@ local function parse(filename) cur_block = cur_op cur_block_name = "FILE" table.insert(stack, "block start") + elseif cmd == "FILE_CONTENTS" then + cur_op = { + op = "FILE_CONTENTS", + name = arg, + data = {}, + } + table.insert(cur_test.ops, cur_op) + cur_block = cur_op + cur_block_name = "FILE_CONTENTS" + table.insert(stack, "block start") elseif cmd == "RUN" then local program, args = arg:match("([^ ]+)%s*(.*)$") if not program then @@ -195,6 +205,20 @@ local function parse(filename) line = cur_line, } table.insert(cur_test.ops, cur_op) + elseif cmd == "RMDIR" then + cur_op = { + op = "RMDIR", + file = dir.normalize(arg), + line = cur_line, + } + table.insert(cur_test.ops, cur_op) + elseif cmd == "RM" then + cur_op = { + op = "RM", + file = dir.normalize(arg), + line = cur_line, + } + table.insert(cur_test.ops, cur_op) elseif cmd == "EXIT" then if not cur_op or cur_op.op ~= "RUN" then fail("EXIT must be given in the context of a RUN") @@ -346,6 +370,28 @@ function quick.compile(filename, env) op.file = native_slash(op.file) write(([=[ ok, err = make_dir(%q) ]=]):format(op.file)) write(([=[ assert.truthy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) + elseif op.op == "RMDIR" then + op.file = native_slash(op.file) + write(([=[ ok, err = test_env.remove_dir(%q) ]=]):format(op.file)) + write(([=[ assert.falsy((lfs.attributes(%q) or {}).mode == "directory", error_message(%d, "MKDIR failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) + elseif op.op == "RM" then + op.file = native_slash(op.file) + write(([=[ ok, err = os.remove(%q) ]=]):format(op.file)) + write(([=[ assert.falsy((lfs.attributes(%q) or {}).mode == "file", error_message(%d, "RM failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.file, op.line, op.file)) + elseif op.op == "FILE_CONTENTS" then + write(([=[ do ]=])) + write(([=[ local fd_file = assert(io.open(%q, "rb")) ]=]):format(op.name)) + write(([=[ local file_data = fd_file:read("*a") ]=])) + write(([=[ fd_file:close() ]=])) + write([=[ local block_at = 1 ]=]) + write([=[ local s, e, line ]=]) + for i, line in ipairs(op.data) do + write(([=[ line = %q ]=]):format(line)) + write(([=[ s, e = string.find(file_data, line, 1, true) ]=])) + write(([=[ assert(s, error_message(%d, "FILE_CONTENTS %s did not match: " .. line, file_data)) ]=]):format(op.start + i, op.name)) + write(([=[ block_at = e + 1 ]=]):format(i)) + end + write([=[ end ]=]) elseif op.op == "RUN" then local cmd_helper = cmd_helpers[op.program] or ("%q"):format(op.program) local redirs = " 1>stdout.txt 2>stderr.txt " diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index 8ccb494b..be75b4ec 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua @@ -527,21 +527,6 @@ function test_env.write_file(pathname, str, finally) end end ---- Create md5sum of directory structure recursively, based on filename and size --- @param path string: path to directory for generate md5sum --- @return md5sum string: md5sum of directory -local function hash_environment(path) - if test_env.TEST_TARGET_OS == "linux" then - return execute_output(C("cd", path, "&& find . -printf \"%s %p\n\" | md5sum")) - elseif test_env.TEST_TARGET_OS == "osx" then - return execute_output(C("find", path, "-type f -exec stat -f \"%z %N\" {} \\; | md5")) - elseif test_env.TEST_TARGET_OS == "windows" then - return execute_output( - "\"" .. C(tool("find"), Q(path), "-printf", "\"%s %p\"") .. "\"" .. - " > temp_sum.txt && certUtil -hashfile temp_sum.txt && del temp_sum.txt") - end -end - --- Create environment variables needed for tests -- @param testing_paths table: table with paths to testing directory -- @return env_variables table: table with created environment variables @@ -551,6 +536,7 @@ local function create_env(testing_paths) local lrprefix = testing_paths.testing_lrprefix local tree = testing_paths.testing_tree local sys_tree = testing_paths.testing_sys_tree + local deps_tree = testing_paths.testing_deps_tree if test_env.LUAJIT_V then lua_v="5.1" @@ -567,38 +553,31 @@ local function create_env(testing_paths) else table.insert(lua_path, dir_path(lrprefix, "share", "lua", lua_v, "?.lua")) end - table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?.lua")) - table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?", "init.lua")) - table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?.lua")) - table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?", "init.lua")) + table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?.lua")) + table.insert(lua_path, dir_path(tree, "share", "lua", lua_v, "?", "init.lua")) + table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?.lua")) + table.insert(lua_path, dir_path(sys_tree, "share", "lua", lua_v, "?", "init.lua")) + table.insert(lua_path, dir_path(deps_tree, "share", "lua", lua_v, "?.lua")) + table.insert(lua_path, dir_path(deps_tree, "share", "lua", lua_v, "?", "init.lua")) table.insert(lua_path, dir_path(testing_paths.src_dir, "?.lua")) env_variables.LUA_PATH = table.concat(lua_path, ";") .. ";" local lua_cpath = {} local lib_pattern = "?." .. test_env.lib_extension - table.insert(lua_cpath, dir_path(tree, "lib", "lua", lua_v, lib_pattern)) - table.insert(lua_cpath, dir_path(sys_tree, "lib", "lua", lua_v, lib_pattern)) + table.insert(lua_cpath, dir_path(tree, "lib", "lua", lua_v, lib_pattern)) + table.insert(lua_cpath, dir_path(sys_tree, "lib", "lua", lua_v, lib_pattern)) + table.insert(lua_cpath, dir_path(deps_tree, "lib", "lua", lua_v, lib_pattern)) env_variables.LUA_CPATH = table.concat(lua_cpath, ";") .. ";" local path = { os.getenv("PATH") } table.insert(path, dir_path(tree, "bin")) table.insert(path, dir_path(sys_tree, "bin")) + table.insert(path, dir_path(deps_tree, "bin")) env_variables.PATH = table.concat(path, test_env.TARGET_OS == "windows" and ";" or ":") return env_variables end ---- Create md5sums of origin system and system-copy testing directory --- @param testing_paths table: table with paths to testing directory --- @return md5sums table: table of md5sums of system and system-copy testing directory -local function create_md5sums(testing_paths) - local md5sums = {} - md5sums.testing_tree_copy_md5 = hash_environment(testing_paths.testing_tree_copy) - md5sums.testing_sys_tree_copy_md5 = hash_environment(testing_paths.testing_sys_tree_copy) - - return md5sums -end - local function make_run_function(cmd_name, exec_function, with_coverage, do_print) local cmd_prefix = Q(test_env.testing_paths.lua) local testrun_dir = test_env.testing_paths.testrun_dir @@ -663,43 +642,23 @@ local function build_environment(rocks, env_variables) local testing_paths = test_env.testing_paths test_env.remove_dir(testing_paths.testing_tree) test_env.remove_dir(testing_paths.testing_sys_tree) - test_env.remove_dir(testing_paths.testing_tree_copy) - test_env.remove_dir(testing_paths.testing_sys_tree_copy) lfs.mkdir(testing_paths.testing_tree) lfs.mkdir(testing_paths.testing_sys_tree) + lfs.mkdir(testing_paths.testing_deps_tree) test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_server))) test_env.run.luarocks_admin_nocov(C("make_manifest", Q(testing_paths.testing_cache))) for _, rock in ipairs(rocks) do local only_server = "--only-server=" .. testing_paths.testing_cache - local tree = "--tree=" .. testing_paths.testing_sys_tree + local tree = "--tree=" .. testing_paths.testing_deps_tree if not test_env.run.luarocks_nocov(test_env.quiet(C("install", only_server, tree, Q(rock)), env_variables)) then assert(test_env.run.luarocks_nocov(C("build", tree, Q(rock)), env_variables)) assert(test_env.run.luarocks_nocov(C("pack", tree, Q(rock)), env_variables)) move_file(rock .. "-*.rock", testing_paths.testing_cache) end end - - test_env.copy_dir(testing_paths.testing_tree, testing_paths.testing_tree_copy) - test_env.copy_dir(testing_paths.testing_sys_tree, testing_paths.testing_sys_tree_copy) -end - ---- Reset testing environment -local function reset_environment(testing_paths, md5sums) - local testing_tree_md5 = hash_environment(testing_paths.testing_tree) - local testing_sys_tree_md5 = hash_environment(testing_paths.testing_sys_tree) - - if testing_tree_md5 ~= md5sums.testing_tree_copy_md5 then - test_env.remove_dir(testing_paths.testing_tree) - test_env.copy_dir(testing_paths.testing_tree_copy, testing_paths.testing_tree) - end - - if testing_sys_tree_md5 ~= md5sums.testing_sys_tree_copy_md5 then - test_env.remove_dir(testing_paths.testing_sys_tree) - test_env.copy_dir(testing_paths.testing_sys_tree_copy, testing_paths.testing_sys_tree) - end end local function find_lua() @@ -765,15 +724,15 @@ local function create_testing_paths(suffix) paths.testrun_dir = testrun_dir paths.testing_lrprefix = dir_path(testrun_dir, "testing_lrprefix-" .. suffix) paths.testing_tree = dir_path(testrun_dir, "testing-" .. suffix) - paths.testing_tree_copy = dir_path(testrun_dir, "testing_copy-" .. suffix) paths.testing_sys_tree = dir_path(testrun_dir, "testing_sys-" .. suffix) - paths.testing_sys_tree_copy = dir_path(testrun_dir, "testing_sys_copy-" .. suffix) + paths.testing_deps_tree = dir_path(testrun_dir, "testing_deps-" .. suffix) paths.testing_cache = dir_path(testrun_dir, "testing_cache-" .. suffix) paths.testing_server = dir_path(testrun_dir, "testing_server-" .. suffix) local rocks_v = "rocks-" .. test_env.lua_version - paths.testing_rocks = dir_path(paths.testing_tree, "lib", "luarocks", rocks_v) - paths.testing_sys_rocks = dir_path(paths.testing_sys_tree, "lib", "luarocks", rocks_v) + paths.testing_rocks = dir_path(paths.testing_tree, "lib", "luarocks", rocks_v) + paths.testing_sys_rocks = dir_path(paths.testing_sys_tree, "lib", "luarocks", rocks_v) + paths.testing_deps_rocks = dir_path(paths.testing_deps_tree, "lib", "luarocks", rocks_v) if test_env.TEST_TARGET_OS == "windows" then paths.luarocks_tmp = os.getenv("TEMP") @@ -853,7 +812,8 @@ local function create_configs() -- testing_config_no_downloader.lua local config_content = substitute([[ rocks_trees = { - "%{testing_tree}", + { name = "user", root = "%{testing_tree}" }, + { name = "deps", root = "%{testing_deps_tree}" }, { name = "system", root = "%{testing_sys_tree}" }, } rocks_servers = { @@ -870,6 +830,7 @@ local function create_configs() ]], { user = "testuser", testing_sys_tree = test_env.testing_paths.testing_sys_tree, + testing_deps_tree = test_env.testing_paths.testing_deps_tree, testing_tree = test_env.testing_paths.testing_tree, testing_server = test_env.testing_paths.testing_server, testing_cache = test_env.testing_paths.testing_cache @@ -885,6 +846,7 @@ local function create_configs() config_content = substitute([[ rocks_trees = { "%{testing_tree}", + "%{testing_deps_tree}", "%{testing_sys_tree}", } local_cache = "%{testing_cache}" @@ -898,6 +860,7 @@ local function create_configs() ]], { user = "testuser", testing_sys_tree = test_env.testing_paths.testing_sys_tree, + testing_deps_tree = test_env.testing_paths.testing_deps_tree, testing_tree = test_env.testing_paths.testing_tree, testing_cache = test_env.testing_paths.testing_cache }) @@ -1140,7 +1103,7 @@ function test_env.main() build_environment(rocks, env_vars) end ---- Function for initial setup of environment, variables, md5sums for spec files +--- Function for initial setup of environment and variables function test_env.setup_specs(extra_rocks, use_mock) test_env.unload_luarocks() @@ -1169,7 +1132,6 @@ function test_env.setup_specs(extra_rocks, use_mock) test_env.platform = get_luarocks_platform(test_env.env_variables) test_env.wrapper_extension = test_env.TEST_TARGET_OS == "windows" and ".bat" or "" - test_env.md5sums = create_md5sums(test_env.testing_paths) test_env.setup_done = true title("RUNNING TESTS") end @@ -1186,7 +1148,8 @@ function test_env.setup_specs(extra_rocks, use_mock) end if test_env.RESET_ENV then - reset_environment(test_env.testing_paths, test_env.md5sums, variables) + test_env.remove_dir(test_env.testing_paths.testing_tree) + test_env.remove_dir(test_env.testing_paths.testing_sys_tree) end lfs.chdir(testrun_dir) diff --git a/src/luarocks/cmd.lua b/src/luarocks/cmd.lua index 452237d2..200ec13b 100644 --- a/src/luarocks/cmd.lua +++ b/src/luarocks/cmd.lua @@ -63,6 +63,19 @@ do cfg.deploy_lib_dir = cfg.deploy_lib_dir:gsub("/+$", "") end + local function set_named_tree(args, name) + for _, tree in ipairs(cfg.rocks_trees) do + if type(tree) == "table" and name == tree.name then + if not tree.root then + return nil, "Configuration error: tree '"..tree.name.."' has no 'root' field." + end + replace_tree(args, tree.root, tree) + return true + end + end + return false + end + process_tree_args = function(args, project_dir) if args.global then @@ -70,17 +83,7 @@ do end if args.tree then - local named = false - for _, tree in ipairs(cfg.rocks_trees) do - if type(tree) == "table" and args.tree == tree.name then - if not tree.root then - return nil, "Configuration error: tree '"..tree.name.."' has no 'root' field." - end - replace_tree(args, tree.root, tree) - named = true - break - end - end + local named = set_named_tree(args, args.tree) if not named then local root_dir = fs.absolute_name(args.tree) replace_tree(args, root_dir) @@ -94,7 +97,7 @@ do "You are running as a superuser, which is intended for system-wide operation.\n".. "To force using the superuser's home, use --tree explicitly." else - replace_tree(args, cfg.home_tree) + set_named_tree(args, "user") end elseif args.project_tree then local tree = args.project_tree @@ -102,9 +105,7 @@ do manif.load_rocks_tree_manifests() path.use_tree(tree) elseif cfg.local_by_default then - if cfg.home_tree then - replace_tree(args, cfg.home_tree) - end + set_named_tree(args, "user") elseif project_dir then local project_tree = project_dir .. "/lua_modules" table.insert(cfg.rocks_trees, 1, { name = "project", root = project_tree } ) -- cgit v1.2.3-55-g6feb