diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-21 01:23:59 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2024-02-21 04:19:36 -0300 |
| commit | a75d447e10bb7842cdbed0bb494697ddd88fd455 (patch) | |
| tree | 6fb79505261f825ad1818f938d31a65c0d6b6409 | |
| parent | 28265438538f8298fdaa7a6e74f4ea3a40fb11a5 (diff) | |
| download | luarocks-a75d447e10bb7842cdbed0bb494697ddd88fd455.tar.gz luarocks-a75d447e10bb7842cdbed0bb494697ddd88fd455.tar.bz2 luarocks-a75d447e10bb7842cdbed0bb494697ddd88fd455.zip | |
fix: handle error if test.command is not a string.
Fixes #1055.
| -rw-r--r-- | spec/quick/test.q | 51 | ||||
| -rw-r--r-- | src/luarocks/test/command.lua | 6 |
2 files changed, 57 insertions, 0 deletions
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 @@ | |||
| 1 | ================================================================================ | ||
| 2 | TEST: luarocks test: handle if test.command is not a string | ||
| 3 | |||
| 4 | Regression test for #1055. | ||
| 5 | |||
| 6 | FILE: example-1.0-1.rockspec | ||
| 7 | -------------------------------------------------------------------------------- | ||
| 8 | rockspec_format = "3.0" | ||
| 9 | source = { | ||
| 10 | url = "", | ||
| 11 | } | ||
| 12 | package = "example" | ||
| 13 | version = "1.0-1" | ||
| 14 | test = { | ||
| 15 | type = "command", | ||
| 16 | command = {"./unit.lua"}, | ||
| 17 | } | ||
| 18 | -------------------------------------------------------------------------------- | ||
| 19 | |||
| 20 | RUN: luarocks test | ||
| 21 | EXIT: 1 | ||
| 22 | STDERR: | ||
| 23 | -------------------------------------------------------------------------------- | ||
| 24 | 'command' expects a string | ||
| 25 | -------------------------------------------------------------------------------- | ||
| 26 | |||
| 27 | |||
| 28 | |||
| 29 | ================================================================================ | ||
| 30 | TEST: luarocks test: handle if test.script is not a string | ||
| 31 | |||
| 32 | FILE: example-1.0-1.rockspec | ||
| 33 | -------------------------------------------------------------------------------- | ||
| 34 | rockspec_format = "3.0" | ||
| 35 | source = { | ||
| 36 | url = "", | ||
| 37 | } | ||
| 38 | package = "example" | ||
| 39 | version = "1.0-1" | ||
| 40 | test = { | ||
| 41 | type = "command", | ||
| 42 | script = {"./unit.lua"}, | ||
| 43 | } | ||
| 44 | -------------------------------------------------------------------------------- | ||
| 45 | |||
| 46 | RUN: luarocks test | ||
| 47 | EXIT: 1 | ||
| 48 | STDERR: | ||
| 49 | -------------------------------------------------------------------------------- | ||
| 50 | 'script' expects a string | ||
| 51 | -------------------------------------------------------------------------------- | ||
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) | |||
| 27 | local ok | 27 | local ok |
| 28 | 28 | ||
| 29 | if test.script then | 29 | if test.script then |
| 30 | if type(test.script) ~= "string" then | ||
| 31 | return nil, "Malformed rockspec: 'script' expects a string" | ||
| 32 | end | ||
| 30 | if not fs.exists(test.script) then | 33 | if not fs.exists(test.script) then |
| 31 | return nil, "Test script " .. test.script .. " does not exist" | 34 | return nil, "Test script " .. test.script .. " does not exist" |
| 32 | end | 35 | end |
| 33 | local lua = fs.Q(cfg.variables["LUA"]) -- get lua interpreter configured | 36 | local lua = fs.Q(cfg.variables["LUA"]) -- get lua interpreter configured |
| 34 | ok = fs.execute(lua, test.script, unpack(args)) | 37 | ok = fs.execute(lua, test.script, unpack(args)) |
| 35 | elseif test.command then | 38 | elseif test.command then |
| 39 | if type(test.command) ~= "string" then | ||
| 40 | return nil, "Malformed rockspec: 'command' expects a string" | ||
| 41 | end | ||
| 36 | ok = fs.execute(test.command, unpack(args)) | 42 | ok = fs.execute(test.command, unpack(args)) |
| 37 | end | 43 | end |
| 38 | 44 | ||
