diff options
Diffstat (limited to 'src/luarocks/test/command.tl')
-rw-r--r-- | src/luarocks/test/command.tl | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/luarocks/test/command.tl b/src/luarocks/test/command.tl new file mode 100644 index 00000000..217a34fc --- /dev/null +++ b/src/luarocks/test/command.tl | |||
@@ -0,0 +1,55 @@ | |||
1 | |||
2 | local record command | ||
3 | end | ||
4 | |||
5 | local fs = require("luarocks.fs") | ||
6 | local cfg = require("luarocks.core.cfg") | ||
7 | |||
8 | local type Test = require("luarocks.core.types.rockspec").Test | ||
9 | |||
10 | function command.detect_type(): boolean | ||
11 | if fs.exists("test.lua") then | ||
12 | return true | ||
13 | end | ||
14 | return false | ||
15 | end | ||
16 | |||
17 | function command.run_tests(test: Test, args: {string}): boolean, string | ||
18 | if not test then | ||
19 | test = { | ||
20 | script = "test.lua" | ||
21 | } | ||
22 | end | ||
23 | |||
24 | if not test.script and not test.command then | ||
25 | test.script = "test.lua" | ||
26 | end | ||
27 | |||
28 | local ok: boolean | ||
29 | |||
30 | if test.script then | ||
31 | local test_script = test.script | ||
32 | if not test_script is string then | ||
33 | return nil, "Malformed rockspec: 'script' expects a string" | ||
34 | end | ||
35 | if not fs.exists(test.script) then | ||
36 | return nil, "Test script " .. test.script .. " does not exist" | ||
37 | end | ||
38 | local lua = fs.Q(cfg.variables["LUA"]) -- get lua interpreter configured | ||
39 | ok = fs.execute(lua, test.script, table.unpack(args)) | ||
40 | elseif test.command then | ||
41 | local test_command = test.command | ||
42 | if not test_command is string then | ||
43 | return nil, "Malformed rockspec: 'command' expects a string" | ||
44 | end | ||
45 | ok = fs.execute(test.command, table.unpack(args)) | ||
46 | end | ||
47 | |||
48 | if ok then | ||
49 | return true | ||
50 | else | ||
51 | return nil, "tests failed with non-zero exit code" | ||
52 | end | ||
53 | end | ||
54 | |||
55 | return command | ||