From cda1078b7cfa7d9bc822074a54aa4f54e7a3eb27 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 26 Feb 2024 12:31:19 -0300 Subject: tests: replace some more tests with quick tests --- spec/install_spec.lua | 69 -------------- spec/quick/install.q | 257 +++++++++++++++++++++++++++++++++++++++++++++++++- spec/util/quick.lua | 45 ++++++--- 3 files changed, 287 insertions(+), 84 deletions(-) diff --git a/spec/install_spec.lua b/spec/install_spec.lua index d410ca97..45979b9c 100644 --- a/spec/install_spec.lua +++ b/spec/install_spec.lua @@ -20,14 +20,11 @@ local extra_rocks = { "/lxsh-${LXSH}.rockspec", "/say-1.2-1.src.rock", "/say-1.0-1.src.rock", - "/wsapi-1.6-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", - "spec/fixtures/a_repo/non_lua_file-1.0-1.src.rock", - "spec/fixtures/a_repo/non_lua_file-1.0-2.src.rock", } describe("luarocks install #integration", function() @@ -37,22 +34,6 @@ describe("luarocks install #integration", function() end) describe("basic tests", function() - it("fails with no flags/arguments", function() - assert.is_false(run.luarocks_bool("install")) - end) - - it("fails with invalid argument", function() - assert.is_false(run.luarocks_bool("install invalid")) - end) - - it("fails invalid patch", function() - assert.is_false(run.luarocks_bool("install " .. testing_paths.fixtures_dir .. "/invalid_patch-0.1-1.rockspec")) - end) - - it("fails invalid rock", function() - assert.is_false(run.luarocks_bool("install \"invalid.rock\" ")) - end) - it("fails with local flag as root #unix", function() if test_env.TYPE_TEST_ENV ~= "full" then assert.is_false(run.luarocks_bool("install --local luasocket ", { USER = "root" } )) @@ -71,38 +52,15 @@ describe("luarocks install #integration", function() end end) - it("fails not a zip file", function() - test_env.run_in_tmp(function(tmpdir) - write_file("not_a_zipfile-1.0-1.src.rock", [[ - I am not a .zip file! - ]], finally) - assert.is_false(run.luarocks_bool("install not_a_zipfile-1.0-1.src.rock")) - end, finally) - end) - it("only-deps of lxsh show there is no lxsh", function() assert.is_true(run.luarocks_bool("install lxsh ${LXSH} --only-deps")) assert.is_false(run.luarocks_bool("show lxsh")) end) - it("fails with incompatible architecture", function() - assert.is_false(run.luarocks_bool("install \"foo-1.0-1.impossible-x86.rock\" ")) - end) - - it("installs a package with an executable", function() - assert(run.luarocks_bool("install wsapi")) - end) - it("installs a package with a dependency", function() assert.is_true(run.luarocks_bool("install has_build_dep")) assert.is_true(run.luarocks_bool("show a_rock")) end) - - it("installs a package without its documentation", function() - assert.is_true(run.luarocks_bool("install wsapi 1.6 --no-doc")) - assert.is_true(run.luarocks_bool("show wsapi 1.6")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_rocks .. "/wsapi/1.6-1/doc")) - end) end) describe("#namespaces", function() @@ -172,33 +130,6 @@ describe("luarocks install #integration", function() assert.is.falsy(lfs.attributes(relative_path)) 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(libdir .."/lfs."..test_env.lib_extension)) - - local suffix = (V"${LUAFILESYSTEM_OLD}"):gsub("[%.%-]", "_") - - 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(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() - assert.is_true(run.luarocks_bool("install non_lua_file 1.0-1 --deps-mode=none")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION.."/sailor/blank-app/.htaccess")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION.."/sailor/blank-app/.htaccess~")) - - assert.is_true(run.luarocks_bool("install non_lua_file 1.0-2 --deps-mode=none")) - assert.is.truthy(lfs.attributes(testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION.."/sailor/blank-app/.htaccess")) - assert.is.falsy(lfs.attributes(testing_paths.testing_sys_tree .. "/share/lua/"..env_variables.LUA_VERSION.."/sailor/blank-app/.htaccess~")) - end) - it("only-deps of luasocket packed rock", function() 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") diff --git a/spec/quick/install.q b/spec/quick/install.q index 2bccf2f1..ab576605 100644 --- a/spec/quick/install.q +++ b/spec/quick/install.q @@ -1,5 +1,91 @@ +SUITE: luarocks install + +=============================================================================== +TEST: fails with no flags or arguments +RUN: luarocks install +EXIT: 1 + + + +=============================================================================== +TEST: fails with an unknown rock +RUN: luarocks install aoeuaoeuaoeiaoeuaoeua +EXIT: 1 + + + +=============================================================================== +TEST: fails with an invalid .rock argument +RUN: luarocks install "invalid.rock" +EXIT: 1 + + + +=============================================================================== +TEST: fails with incompatible architecture +RUN: luarocks install foo-1.0-1.impossible-x86.rock +EXIT: 1 +STDERR: +-------------------------------------------------------------------------------- +Incompatible architecture +-------------------------------------------------------------------------------- + + + =============================================================================== -TEST: luarocks install: handle versioned modules when installing another version with --keep #268 +TEST: fails if not a zip file + +FILE: not_a_zipfile-1.0-1.src.rock +-------------------------------------------------------------------------------- +I am not a zip file! +-------------------------------------------------------------------------------- +RUN: luarocks install not_a_zipfile-1.0-1.src.rock +EXIT: 1 + + + +=============================================================================== +TEST: fails with an invalid patch + +FILE: invalid_patch-0.1-1.rockspec +-------------------------------------------------------------------------------- +package = "invalid_patch" +version = "0.1-1" +source = { + -- any valid URL + url = "https://raw.github.com/keplerproject/luarocks/master/src/luarocks/build.lua" +} +description = { + summary = "A rockspec with an invalid patch", +} +dependencies = { + "lua >= 5.1" +} +build = { + type = "builtin", + modules = { + build = "build.lua" + }, + patches = { + ["I_am_an_invalid_patch.patch"] = +[[ +diff -Naur luadoc-3.0.1/src/luadoc/doclet/html.lua luadoc-3.0.1-new/src/luadoc/doclet/html.lua +--- luadoc-3.0.1/src/luadoc/doclet/html.lua2007-12-21 15:50:48.000000000 -0200 ++++ luadoc-3.0.1-new/src/luadoc/doclet/html.lua2008-02-28 01:59:53.000000000 -0300 +@@ -18,6 +18,7 @@ +- gabba gabba gabba ++ gobo gobo gobo +]] + } +} +-------------------------------------------------------------------------------- +RUN: luarocks invalid_patch-0.1-1.rockspec +EXIT: 1 + + + +================================================================================ +TEST: handle versioned modules when installing another version with --keep #268 FILE: myrock-1.0-1.rockspec -------------------------------------------------------------------------------- @@ -56,8 +142,8 @@ NOT_EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/myrock_1_0_1-rock.lua -=============================================================================== -TEST: luarocks install: handle versioned libraries when installing another version with --keep #268 +================================================================================ +TEST: handle versioned libraries when installing another version with --keep #268 FILE: myrock-1.0-1.rockspec -------------------------------------------------------------------------------- @@ -122,3 +208,168 @@ RUN: luarocks install ./myrock-2.0-1.%{platform}.rock EXISTS: %{testing_sys_tree}/lib/lua/%{LUA_VERSION}/c_module.%{lib_extension} NOT_EXISTS: %{testing_sys_tree}/lib/lua/%{LUA_VERSION}/myrock_1_0_1-c_module.%{lib_extension} + + + +================================================================================ +TEST: installs a package with a bin entry + +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" }, + install = { + bin = { + ["scripty"] = "rock.lua", + } + } +} +-------------------------------------------------------------------------------- + +FILE: rock.lua +-------------------------------------------------------------------------------- +return "hello" +-------------------------------------------------------------------------------- + +RUN: luarocks build myrock-1.0-1.rockspec +EXISTS: %{testing_sys_tree}/bin/scripty%{wrapper_extension} +RUN: luarocks pack myrock +RUN: luarocks remove myrock +NOT_EXISTS: %{testing_sys_tree}/bin/scripty%{wrapper_extension} + +RUN: luarocks install myrock-1.0-1.all.rock +EXISTS: %{testing_sys_tree}/bin/scripty%{wrapper_extension} + + + +================================================================================ +TEST: installs a package without its documentation using --no-doc + +FILE: myrock-1.0-1.rockspec +-------------------------------------------------------------------------------- +rockspec_format = "3.0" +package = "myrock" +version = "1.0-1" +source = { + url = "." +} +build = { + modules = { rock = "rock.lua" }, + install = { + bin = { + ["scripty"] = "rock.lua", + } + } +} +-------------------------------------------------------------------------------- + +FILE: rock.lua +-------------------------------------------------------------------------------- +return "hello" +-------------------------------------------------------------------------------- + +FILE: doc/something +-------------------------------------------------------------------------------- +a doc +-------------------------------------------------------------------------------- + +RUN: luarocks make +EXISTS: %{testing_sys_rocks}/myrock/1.0-1/doc/something +RUN: luarocks pack myrock +RUN: luarocks remove myrock +NOT_EXISTS: %{testing_sys_rocks}/myrock/1.0-1/doc/something + +RUN: luarocks install myrock-1.0-1.all.rock +EXISTS: %{testing_sys_rocks}/myrock/1.0-1/doc/something +RUN: luarocks remove myrock +NOT_EXISTS: %{testing_sys_rocks}/myrock/1.0-1/doc/something + +RUN: luarocks install myrock-1.0-1.all.rock --no-doc +NOT_EXISTS: %{testing_sys_rocks}/myrock/1.0-1/doc/something + + + +================================================================================ +TEST: handle non-Lua files in build.install.lua when upgrading sailorproject/sailor#138 + +FILE: myrock-1.0-1.rockspec +-------------------------------------------------------------------------------- +rockspec_format = "3.0" +package = "myrock" +version = "1.0-1" +source = { + url = "." +} +build = { + modules = { + rock = "rock.lua", + }, + install = { + lua = { + ["sailor.blank-app.htaccess"] = "src/sailor/blank-app/.htaccess", + } + } +} +-------------------------------------------------------------------------------- + +FILE: myrock-1.0-2.rockspec +-------------------------------------------------------------------------------- +rockspec_format = "3.0" +package = "myrock" +version = "1.0-2" +source = { + url = "." +} +build = { + modules = { + rock = "rock.lua", + }, + install = { + lua = { + ["sailor.blank-app.htaccess"] = "src/sailor/blank-app/.htaccess", + } + } +} +-------------------------------------------------------------------------------- + +FILE: rock.lua +-------------------------------------------------------------------------------- +return "hello" +-------------------------------------------------------------------------------- + +FILE: src/sailor/blank-app/.htaccess +-------------------------------------------------------------------------------- +# I am just a file +-------------------------------------------------------------------------------- + +Prepare two versions as .rock packages with the same non-Lua asset: + +RUN: luarocks make ./myrock-1.0-1.rockspec +RUN: luarocks pack myrock +RUN: luarocks remove myrock + +RUN: luarocks make ./myrock-1.0-2.rockspec +RUN: luarocks pack myrock +RUN: luarocks remove myrock + +Now install the first one, and check that the asset was installed, with no "~" +backup leftover: + +RUN: luarocks install myrock-1.0-1.all.rock --no-doc + +EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess +NOT_EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess~ + +Then install the second one, and the asset should be replaced, again with no +"~" backup leftover: + +RUN: luarocks install myrock-1.0-2.all.rock --no-doc + +EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess +NOT_EXISTS: %{testing_sys_tree}/share/lua/%{LUA_VERSION}/sailor/blank-app/.htaccess~ diff --git a/spec/util/quick.lua b/spec/util/quick.lua index 1fcf2b36..d7df7bb1 100644 --- a/spec/util/quick.lua +++ b/spec/util/quick.lua @@ -46,6 +46,7 @@ local function parse(filename) local tests = {} local cur_line = 0 + local cur_suite = "" local cur_test local cur_op local cur_block @@ -54,7 +55,7 @@ local function parse(filename) local function start_test(arg) cur_test = { - name = arg, + name = cur_suite .. arg, ops = {}, } cur_op = nil @@ -137,6 +138,8 @@ local function parse(filename) local cmd, arg = parse_cmd(line) if cmd == "TEST" then start_test(arg) + elseif cmd == "SUITE" then + cur_suite = arg .. ": " elseif cmd then fail("expected TEST, got " .. cmd) elseif is_blank(line) then @@ -175,12 +178,14 @@ local function parse(filename) cur_op = { op = "EXISTS", file = dir.normalize(arg), + line = cur_line, } table.insert(cur_test.ops, cur_op) elseif cmd == "NOT_EXISTS" then cur_op = { op = "NOT_EXISTS", file = dir.normalize(arg), + line = cur_line, } table.insert(cur_test.ops, cur_op) elseif cmd == "MKDIR" then @@ -271,6 +276,12 @@ function quick.compile(filename, env) table.insert(code, table.concat({...})) end + write(([=[ ]=])) + write(([=[ -- **************************************** ]=])) + write(([=[ -- %s ]=]):format(t.name)) + write(([=[ -- **************************************** ]=])) + write(([=[ ]=])) + write([=[ local test_env = require("spec.util.test_env") ]=]) write([=[ local lfs = require("lfs") ]=]) write([=[ local fs = require("lfs") ]=]) @@ -278,6 +289,18 @@ function quick.compile(filename, env) write([=[ local luarocks_cmd = test_env.execute_helper(test_env.Q(test_env.testing_paths.lua) .. " " .. test_env.testing_paths.src_dir .. "/bin/luarocks", false, test_env.env_variables):sub(1, -5) ]=]) write([=[ local luarocks_admin_cmd = test_env.execute_helper(test_env.Q(test_env.testing_paths.lua) .. " " .. test_env.testing_paths.src_dir .. "/bin/luarocks-admin", false, test_env.env_variables):sub(1, -5) ]=]) + write([=[ local function make_dir(dirname) ]=]) + write([=[ local bits = {} ]=]) + write([=[ if dirname:sub(1, 1) == dir_sep then bits[1] = "" end ]=]) + write([=[ local ok, err ]=]) + write([=[ for p in dirname:gmatch("[^" .. dir_sep .. "]+") do ]=]) + write([=[ table.insert(bits, p) ]=]) + write([=[ ok, err = lfs.mkdir(table.concat(bits, dir_sep)) ]=]) + write([=[ end ]=]) + write([=[ local exists = (lfs.attributes(dirname) or {}).mode == "directory" ]=]) + write([=[ return exists, (not exists) and err ]=]) + write([=[ end ]=]) + write(([=[ local function error_message(line, msg, input) ]=])) write(([=[ local out = {"\n\n", %q, ":", line, ": ", msg} ]=]):format(filename)) write(([=[ if input then ]=])) @@ -302,27 +325,25 @@ function quick.compile(filename, env) write([=[ return (s:gsub("%%{url%(tmpdir%)}", (tmpdir:gsub("\\", "/"))) ]=]) write([=[ :gsub("%%{tmpdir}", (tmpdir:gsub("[\\/]", dir_sep)))) ]=]) write([=[ end ]=]) + write([=[ local ok, err ]=]) for _, op in ipairs(t.ops) do if op.op == "FILE" then + if op.name:match("[\\/]") then + write(([=[ make_dir(%q) ]=]):format(dir.dir_name(op.name))) + end write(([=[ test_env.write_file(handle_tmpdir(%q), handle_tmpdir([=====[ ]=]):format(op.name)) for _, line in ipairs(op.data) do write(line) end write([=[ ]=====]), finally) ]=]) elseif op.op == "EXISTS" then - write(([=[ assert.truthy(lfs.attributes(%q)) ]=]):format(op.file)) + write(([=[ ok, err = lfs.attributes(%q) ]=]):format(op.file)) + write(([=[ assert.truthy(ok, error_message(%d, "EXISTS failed: " .. %q .. " - " .. (err or "") )) ]=]):format(op.line, op.file)) elseif op.op == "NOT_EXISTS" then - write(([=[ assert.falsy(lfs.attributes(%q)) ]=]):format(op.file)) + write(([=[ assert.falsy(lfs.attributes(%q), error_message(%d, "NOT_EXISTS failed: " .. %q .. " exists" )) ]=]):format(op.file, op.line, op.file)) elseif op.op == "MKDIR" then - local bits = {} op.file = native_slash(op.file) - if op.file:sub(1, 1) == dir_sep then bits[1] = "" end - write([=[ local ok, err ]=]) - for p in op.file:gmatch("[^" .. dir_sep .. "]+") do - table.insert(bits, p) - local d = table.concat(bits, dir_sep) - write(([=[ ok, err = lfs.mkdir(%q) ]=]):format(d, d)) - end + 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 == "RUN" then local cmd_helper = cmd_helpers[op.program] or op.program @@ -411,7 +432,7 @@ function quick.compile(filename, env) write([=[ end ]=]) local program = table.concat(code, "\n") - local chunk = assert(load(program, "@" .. filename .. ": test " .. tn, "t", env or _ENV)) + local chunk = assert(load(program, "@" .. filename .. ":[TEST " .. tn .. "]", "t", env or _ENV)) if env and setfenv then setfenv(chunk, env) end -- cgit v1.2.3-55-g6feb