1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# luarocks test
Run the test suite for the Lua project in the current directory.
## Usage
`luarocks test [-h] [--test-type <type>] [<rockspec>] [<args>] ...`
If the first argument is a rockspec, it will use it to determine the
parameters for running tests; otherwise, it will attempt to detect the
rockspec.
Any additional arguments are forwarded to the test suite. To make sure that
test suite flags are not interpreted as LuaRocks flags, use `--` to separate
LuaRocks arguments from test suite arguments.
### Arguments
* `rockspec` - Project rockspec.
* `args` - Test suite arguments.
### Options
* `--test-type <type>` - Specify the test suite type manually if it was not
specified in the rockspec and it could not be auto-detected.
## Test types
There are two test types that ship by default with LuaRocks: `busted` and
`command`. They can be specified explicitly in a rockspec in the `test.type`
field. Custom test types can be loaded using the `test_dependencies` field; a
dependency can declare a new test type by adding a module in the
`luarocks.test.*` namespace; it can then be used as a test type in the
rockspec.
### `busted` test type
You can enable the `busted` test type adding a top-level `test` table in a
rockspec and setting its `type` to `busted`. The `busted` type can be
auto-detected if the project's source contains a configuration file called
`.busted`, so if a project has that file `luarocks test` can be used to launch
Busted even if it doesn't have a `test` section in the rockspec.
Here's an example of a `busted` test section, also using the `flags` option to
pass extra flags to Busted, and using per-platform overrides.
```
test = {
type = "busted",
platforms = {
windows = {
flags = { "--exclude-tags=ssh,git,unix" }
},
unix = {
flags = { "--exclude-tags=ssh,git" }
}
}
}
```
### `command` test type
You can enable the `command` test type adding a top-level `test` table in a
rockspec and setting its `type` to `command`. The `command` type can be
auto-detected if the project's source contains a file called `test.lua` at the
root of the source tree, so if a project has that file `luarocks test` can be
used to run it using the default Lua interpreter even if it doesn't have a
`test` section in the rockspec.
The `test` block for a `command` test type can take either a `script`
argument, which is a Lua script to be launched using the configured Lua
interpreter, or a `command` argument, which is a command to be launched
directly on a shell. Both can take additional arguments via the `flags` array
entry.
Here is an example using a script:
```
test = {
type = "command",
script = "tests/test_all.lua",
}
```
And here is an example using a command:
```
test = {
type = "command",
command = "make test",
}
```
## Invocation example
In the following example, assume a project uses Busted as its test tool. The
current directory contains the source code of a Lua project with a rockspec in
its root, this will run Busted, pass any additional arguments specified in the
`test.flags` field of the rockspec, plus the `--exclude-tags=ssh` argument
given explicitly via the command-line:
```
luarocks test -- --exclude-tags=ssh
```
|