diff options
Diffstat (limited to 'docs/luarocks_test.md')
-rw-r--r-- | docs/luarocks_test.md | 104 |
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 | |||
3 | Run 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 | |||
9 | If the first argument is a rockspec, it will use it to determine the | ||
10 | parameters for running tests; otherwise, it will attempt to detect the | ||
11 | rockspec. | ||
12 | |||
13 | Any additional arguments are forwarded to the test suite. To make sure that | ||
14 | test suite flags are not interpreted as LuaRocks flags, use `--` to separate | ||
15 | LuaRocks 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 | |||
29 | There 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` | ||
31 | field. Custom test types can be loaded using the `test_dependencies` field; a | ||
32 | dependency 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 | ||
34 | rockspec. | ||
35 | |||
36 | ### `busted` test type | ||
37 | |||
38 | You can enable the `busted` test type adding a top-level `test` table in a | ||
39 | rockspec and setting its `type` to `busted`. The `busted` type can be | ||
40 | auto-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 | ||
42 | Busted even if it doesn't have a `test` section in the rockspec. | ||
43 | |||
44 | Here's an example of a `busted` test section, also using the `flags` option to | ||
45 | pass extra flags to Busted, and using per-platform overrides. | ||
46 | |||
47 | ``` | ||
48 | test = { | ||
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 | |||
63 | You can enable the `command` test type adding a top-level `test` table in a | ||
64 | rockspec and setting its `type` to `command`. The `command` type can be | ||
65 | auto-detected if the project's source contains a file called `test.lua` at the | ||
66 | root of the source tree, so if a project has that file `luarocks test` can be | ||
67 | used to run it using the default Lua interpreter even if it doesn't have a | ||
68 | `test` section in the rockspec. | ||
69 | |||
70 | The `test` block for a `command` test type can take either a `script` | ||
71 | argument, which is a Lua script to be launched using the configured Lua | ||
72 | interpreter, or a `command` argument, which is a command to be launched | ||
73 | directly on a shell. Both can take additional arguments via the `flags` array | ||
74 | entry. | ||
75 | |||
76 | Here is an example using a script: | ||
77 | |||
78 | ``` | ||
79 | test = { | ||
80 | type = "command", | ||
81 | script = "tests/test_all.lua", | ||
82 | } | ||
83 | ``` | ||
84 | |||
85 | And here is an example using a command: | ||
86 | |||
87 | ``` | ||
88 | test = { | ||
89 | type = "command", | ||
90 | command = "make test", | ||
91 | } | ||
92 | ``` | ||
93 | |||
94 | ## Invocation example | ||
95 | |||
96 | In the following example, assume a project uses Busted as its test tool. The | ||
97 | current directory contains the source code of a Lua project with a rockspec in | ||
98 | its 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 | ||
100 | given explicitly via the command-line: | ||
101 | |||
102 | ``` | ||
103 | luarocks test -- --exclude-tags=ssh | ||
104 | ``` | ||