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