From a75d447e10bb7842cdbed0bb494697ddd88fd455 Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 21 Feb 2024 01:23:59 -0300 Subject: fix: handle error if test.command is not a string. Fixes #1055. --- spec/quick/test.q | 51 +++++++++++++++++++++++++++++++++++++++++++ src/luarocks/test/command.lua | 6 +++++ 2 files changed, 57 insertions(+) create mode 100644 spec/quick/test.q diff --git a/spec/quick/test.q b/spec/quick/test.q new file mode 100644 index 00000000..cb5ccd79 --- /dev/null +++ b/spec/quick/test.q @@ -0,0 +1,51 @@ +================================================================================ +TEST: luarocks test: handle if test.command is not a string + +Regression test for #1055. + +FILE: example-1.0-1.rockspec +-------------------------------------------------------------------------------- +rockspec_format = "3.0" +source = { + url = "", +} +package = "example" +version = "1.0-1" +test = { + type = "command", + command = {"./unit.lua"}, +} +-------------------------------------------------------------------------------- + +RUN: luarocks test +EXIT: 1 +STDERR: +-------------------------------------------------------------------------------- +'command' expects a string +-------------------------------------------------------------------------------- + + + +================================================================================ +TEST: luarocks test: handle if test.script is not a string + +FILE: example-1.0-1.rockspec +-------------------------------------------------------------------------------- +rockspec_format = "3.0" +source = { + url = "", +} +package = "example" +version = "1.0-1" +test = { + type = "command", + script = {"./unit.lua"}, +} +-------------------------------------------------------------------------------- + +RUN: luarocks test +EXIT: 1 +STDERR: +-------------------------------------------------------------------------------- +'script' expects a string +-------------------------------------------------------------------------------- diff --git a/src/luarocks/test/command.lua b/src/luarocks/test/command.lua index afdb5cb6..bed6744e 100644 --- a/src/luarocks/test/command.lua +++ b/src/luarocks/test/command.lua @@ -27,12 +27,18 @@ function command.run_tests(test, args) local ok if test.script then + if type(test.script) ~= "string" then + return nil, "Malformed rockspec: 'script' expects a string" + end if not fs.exists(test.script) then return nil, "Test script " .. test.script .. " does not exist" end local lua = fs.Q(cfg.variables["LUA"]) -- get lua interpreter configured ok = fs.execute(lua, test.script, unpack(args)) elseif test.command then + if type(test.command) ~= "string" then + return nil, "Malformed rockspec: 'command' expects a string" + end ok = fs.execute(test.command, unpack(args)) end -- cgit v1.2.3-55-g6feb