Skip to content

Commit 4c1071b

Browse files
committed
Update documentation
1 parent 1a761d8 commit 4c1071b

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

README.md

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# PackTest
22
PackTest allows you to write game tests in a data pack. Tests are `*.mcfunction` files in a `tests` folder. They can be used to test custom data packs.
33

4+
[![modrinth](https://cdn.jsdelivr.net/npm/@intergrav/devins-badges@3/assets/cozy/available/modrinth_vector.svg)](https://modrinth.com/mod/packtest)
5+
46
## Example
57
**`data/example/tests/foo.mcfunction`**
68
```mcfunction
@@ -19,6 +21,19 @@ execute if block ~1 ~1 ~1 stone run succeed
1921
fail "Oh no"
2022
```
2123

24+
### Async tests
25+
Test functions can be asynchronous, using the `await` keyword!
26+
```mcfunction
27+
setblock ~ ~ ~ stone
28+
summon item ~ ~6 ~
29+
30+
await entity @e[type=item,distance=..2]
31+
32+
await delay 1s
33+
34+
data merge entity @e[type=item,distance=..2,limit=1] {Motion: [0.0, 0.01, 0.0]}
35+
```
36+
2237
## Running tests
2338
Tests can be run in-game using the `test` command.
2439
* `test runall`: runs all the tests
@@ -40,14 +55,27 @@ To run tests automatically in GitHub Actions, you can use the [packtest_runner](
4055

4156
### `succeed`
4257
* `succeed`: always succeeds the current test and returns from the function
43-
* `succeed when <condition>`: succeeds when the condition is successful, tries every tick until the test times out
44-
* `succeed when not <condition>`: succeeds when the condition is unsuccessful, tries every tick until the test times out
4558

4659
### `assert`
4760
* `assert <condition>`: if condition is unsuccessful, fails the current test and returns from the function
4861
* `assert not <condition>`: if condition is successful, fails the current test and returns from the function
4962

50-
### `dummy`
63+
### `await`
64+
* `await <condition>`: similar to assert, but keeps trying the condition every tick until the test times our or the condition succeeds
65+
* `await not <condition>`: keeps trying the condition until it fails
66+
* `await delay <time>`: waits for a specified time with unit
67+
68+
### Conditions
69+
* `block <pos> <block>`: checks if the block at the specified position matches the block predicate
70+
* `data ...`: checks NBT data using the same syntax as `execute if score`
71+
* `entity <selector>`: checks if the selector matches any entity (can also find entities outside the structure bounds)
72+
* `predicate <predicate>`: checks a predicate in a data pack
73+
* `score ...`: checks scores using the same syntax as `execute if score`
74+
* `chat <pattern> [<receivers>]`: checks whether a chat message was sent in the past tick matching a regex pattern
75+
76+
## Dummies
77+
Fake players can be spawned using the `/dummy` command. Dummies won't save or load their data from disk, they will also not load their skin.
78+
5179
* `dummy <name> spawn`: spawns a new dummy
5280
* `dummy <name> respawn`: respawns the dummy after it has been killed
5381
* `dummy <name> leave`: makes the dummy leave the server
@@ -63,13 +91,6 @@ To run tests automatically in GitHub Actions, you can use the [packtest_runner](
6391
* `dummy <name> attack <entity>`: makes the dummy attack an entity with its mainhand
6492
* `dummy <name> mine <pos>`: makes the dummy mine a block
6593

66-
## Conditions
67-
* `block <pos> <block>`: checks if the block at the specified position matches the block predicate
68-
* `data ...`: checks NBT data using the same syntax as `execute if score`
69-
* `entity <selector>`: checks if the selector matches any entity (can also find entities outside the structure bounds)
70-
* `predicate <predicate>`: checks a predicate in a data pack
71-
* `score ...`: checks scores using the same syntax as `execute if score`
72-
7394
## Directives
7495
Tests can be customized by placing certain directives as special comments at the start of the test function.
7596

0 commit comments

Comments
 (0)