Skip to content

Commit 162bf51

Browse files
authored
docs: lx test (#11)
1 parent 90753b2 commit 162bf51

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

docs/guides/lux-toml.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,5 +442,46 @@ If you want your rock to be compatible with luarocks, you should test an install
442442
before publishing.
443443
:::
444444

445-
<!-- ## Test specification -->
446-
<!-- TODO -->
445+
## Test specification
446+
447+
Lux supports the following test backends, specified by the `[test]` table in the lux.toml:
448+
449+
### [`busted`](https://lunarmodules.github.io/busted/)
450+
451+
Example:
452+
453+
```toml
454+
[test]
455+
type = "busted"
456+
flags = [ ] # Optional CLI flags to pass to busted
457+
```
458+
459+
:::note
460+
`lx test` will default to using `busted`
461+
if there is a `.busted` file in the project root
462+
and no test backend is specified.
463+
:::
464+
465+
### `command`
466+
467+
Name/file name of a shell command that will run the test suite.
468+
Example:
469+
470+
```toml
471+
[test]
472+
type = "command"
473+
command = "make"
474+
flags = [ "test" ]
475+
```
476+
477+
### `script`
478+
479+
Relative path to a Lua script that will run the test suite.
480+
Example:
481+
482+
```toml
483+
[test]
484+
type = "script"
485+
script = "tests.lua" # Expects a tests.lua file in the project root
486+
flags = [ ] # Optional arguments passed to the test script
487+
```

docs/guides/testing.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,24 @@ In this guide, we'll learn how to set up a testing suite for a Lua project.
77

88
## Creating Spec Files
99

10-
By default, Lux uses [`busted`](https://github.com/lunarmodules/busted) as its testing suite.
11-
Tests are stored in a `spec/` directory in the root of your project, and only files
10+
By default, will try to auto-detect your test suite.
11+
If there is a `.busted` file in your project root,
12+
Lux will use[`busted`](https://github.com/lunarmodules/busted) as its test backend.
13+
Otherwise, you must specify the test backend in your `lux.toml`:
14+
15+
```toml title="test specification"
16+
[test]
17+
type = "busted"
18+
```
19+
20+
With busted, tests are stored in a `spec/` directory in the root of your project, and only files
1221
ending in `_spec.lua` are considered tests.
1322

1423
The type of tests you will make will vary greatly depending on the type of project at hand.
1524
Nevertheless, refrain from making trivial tests - they bring little value to a codebase.
1625

1726
Below is an example of a test:
27+
1828
```lua title="spec/request_parse_spec.lua"
1929
local request = require("mylib.request")
2030
local json = require("mylib.json")
@@ -76,3 +86,9 @@ return {
7686
```
7787

7888
For full reference, see [the `busted` website](https://lunarmodules.github.io/busted).
89+
90+
## Alternate test backends
91+
92+
You don't have to use `busted` as a test backend.
93+
See the test section in [How to declare a lux.toml file](/guides/lux-toml)
94+
for alternate test backends.

0 commit comments

Comments
 (0)