From 4117ad5045b310a7902edb6a78c1c1386ddeaea0 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 13 Mar 2024 15:32:35 -0300 Subject: tests: convert most pack tests --- spec/pack_spec.lua | 67 +-------------------------- spec/quick/pack.q | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/quick_spec.lua | 4 +- spec/util/quick.lua | 2 + 4 files changed, 135 insertions(+), 66 deletions(-) create mode 100644 spec/quick/pack.q diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index 20a2b3ef..2a2fb3a5 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua @@ -4,60 +4,10 @@ local run = test_env.run local testing_paths = test_env.testing_paths local write_file = test_env.write_file -local extra_rocks = { - "/luassert-1.7.0-1.src.rock", - "/luasocket-${LUASOCKET}.src.rock", - "/luasocket-${LUASOCKET}.rockspec", - "/say-1.2-1.src.rock", - "/say-1.0-1.src.rock" -} - describe("luarocks pack #integration", function() - before_each(function() - test_env.setup_specs(extra_rocks) - end) - - it("with no flags/arguments", function() - assert.is_false(run.luarocks_bool("pack")) - end) - - it("basic", function() - assert(run.luarocks_bool("pack luacov")) - assert(test_env.remove_files(lfs.currentdir(), "luacov%-")) - end) - - it("invalid rockspec", function() - assert.is_false(run.luarocks_bool("pack " .. testing_paths.fixtures_dir .. "/invalid_say-1.3-1.rockspec")) - end) - - it("not installed rock", function() - assert.is_false(run.luarocks_bool("pack cjson")) - end) - - it("not installed rock from non existing manifest", function() - assert.is_false(run.luarocks_bool("pack /non/exist/temp.manif")) - end) - - it("detects latest version version of rock", function() - assert(run.luarocks_bool("install say 1.2")) - assert(run.luarocks_bool("install luassert")) - assert(run.luarocks_bool("install say 1.0")) - assert(run.luarocks_bool("pack say")) - assert.is_truthy(lfs.attributes("say-1.2-1.all.rock")) - assert(test_env.remove_files(lfs.currentdir(), "say%-")) - end) - - pending("#gpg --sign", function() - assert(run.luarocks_bool("install say 1.2")) - assert(run.luarocks_bool("install luassert")) - assert(run.luarocks_bool("install say 1.0")) - os.delete("say-1.2-1.all.rock") - os.delete("say-1.2-1.all.rock.asc") - assert(run.luarocks_bool("pack say --sign")) - assert.is_truthy(lfs.attributes("say-1.2-1.all.rock")) - assert.is_truthy(lfs.attributes("say-1.2-1.all.rock.asc")) - assert(test_env.remove_files(lfs.currentdir(), "say%-")) + lazy_setup(function() + test_env.setup_specs() end) describe("#mock", function() @@ -149,17 +99,4 @@ describe("luarocks pack #integration", function() end) end) end) - - describe("#namespaces", function() - it("packs a namespaced rock", function() - finally(function() - os.remove("a_rock-2.0-1.all.rock") - end) - assert(run.luarocks_bool("build a_user/a_rock --server=" .. testing_paths.fixtures_dir .. "/a_repo" )) - assert(run.luarocks_bool("build a_rock --keep --server=" .. testing_paths.fixtures_dir .. "/a_repo" )) - assert(run.luarocks_bool("pack a_user/a_rock" )) - assert(lfs.attributes("a_rock-2.0-1.all.rock")) - end) - end) - end) diff --git a/spec/quick/pack.q b/spec/quick/pack.q new file mode 100644 index 00000000..ee44a45f --- /dev/null +++ b/spec/quick/pack.q @@ -0,0 +1,128 @@ +SUITE: luarocks pack + +================================================================================ +TEST: fails no arguments + +RUN: luarocks pack +EXIT: 1 + + + +================================================================================ +TEST: fails with invalid rockspec + +RUN: luarocks pack $%{fixtures_dir}/invalid_say-1.3-1.rockspec +EXIT: 1 + + + +================================================================================ +TEST: fails with rock that is not installed + +RUN: luarocks pack notinstalled +EXIT: 1 + + + +================================================================================ +TEST: fails with non existing path + +RUN: luarocks pack /notexists/notinstalled +EXIT: 1 + + + +================================================================================ +TEST: packs latest version version of rock + +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 = { rock = "rock.lua" } +} +-------------------------------------------------------------------------------- + +FILE: myrock-2.0-1.rockspec +-------------------------------------------------------------------------------- +rockspec_format = "3.0" +package = "myrock" +version = "2.0-1" +source = { + url = "file://%{url(%{tmpdir})}/rock.lua" +} +build = { + modules = { rock = "rock.lua" } +} +-------------------------------------------------------------------------------- + +FILE: rock.lua +-------------------------------------------------------------------------------- +return "hello" +-------------------------------------------------------------------------------- + +RUN: luarocks build myrock-1.0-1.rockspec +RUN: luarocks build myrock-2.0-1.rockspec --keep +RUN: luarocks pack myrock + +EXISTS: myrock-2.0-1.all.rock + + + +================================================================================ +TEST: --sign #gpg +PENDING: true + +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 = { rock = "rock.lua" } +} +-------------------------------------------------------------------------------- + +FILE: myrock-2.0-1.rockspec +-------------------------------------------------------------------------------- +rockspec_format = "3.0" +package = "myrock" +version = "2.0-1" +source = { + url = "file://%{url(%{tmpdir})}/rock.lua" +} +build = { + modules = { rock = "rock.lua" } +} +-------------------------------------------------------------------------------- + +FILE: rock.lua +-------------------------------------------------------------------------------- +return "hello" +-------------------------------------------------------------------------------- + +RUN: luarocks build myrock-1.0-1.rockspec +RUN: luarocks build myrock-2.0-1.rockspec --keep +RUN: luarocks pack myrock --sign + +EXISTS: myrock-2.0-1.all.rock +EXISTS: myrock-2.0-1.all.rock.asc + + + +================================================================================ +TEST: packs a namespaced rock #namespaces + +RUN: luarocks build a_user/a_rock --server=%{fixtures_dir}/a_repo +RUN: luarocks build a_rock --keep --server=%{fixtures_dir}/a_repo +RUN: luarocks pack a_user/a_rock + +EXISTS: a_rock-2.0-1.all.rock diff --git a/spec/quick_spec.lua b/spec/quick_spec.lua index 8b8206cf..c2d8bb59 100644 --- a/spec/quick_spec.lua +++ b/spec/quick_spec.lua @@ -12,7 +12,9 @@ describe("quick tests: #quick", function() if f:match("%.q$") then local tests = quick.compile(spec_quick .. "/" .. f, getfenv and getfenv() or _ENV) for _, t in ipairs(tests) do - it(t.name, t.fn) + if not t.pending then + it(t.name, t.fn) + end end end end diff --git a/spec/util/quick.lua b/spec/util/quick.lua index 80c75848..257f570e 100644 --- a/spec/util/quick.lua +++ b/spec/util/quick.lua @@ -245,6 +245,8 @@ local function parse(filename) block_start_arg("STDOUT", cur_op, "stdout") elseif cmd == "NOT_STDOUT" then block_start_arg("NOT_STDOUT", cur_op, "not_stdout") + elseif cmd == "PENDING" then + bool_arg("PENDING", cur_test, "pending", arg) elseif cmd == "TEST" then table.remove(stack) start_test(arg) -- cgit v1.2.3-55-g6feb