on master help sign in
add example of one-arm test
d8fdb5dTinnus Napbus
content/docs/hoon/guides/unit-tests.md+24−3
@@ -4,6 +4,8 @@ weight = 10
4template = "doc.html"
4template = "doc.html"
5+++
5+++
6
6
7+## Structure
8+
7The `%base` desk includes a `-test` thread which can run unit tests you've
9The `%base` desk includes a `-test` thread which can run unit tests you've
8written. A test is a Hoon file which produces a `core`. The `-test` thread will
10written. A test is a Hoon file which produces a `core`. The `-test` thread will
9look for any arms in the core whose name begin with `test-`, e.g:
11look for any arms in the core whose name begin with `test-`, e.g:
@@ -53,9 +55,15 @@ expressions in the test file itself. To do that, you'd just import the file with
53You're free to do any compositions, import types, etc, as long as the file
55You're free to do any compositions, import types, etc, as long as the file
54ultimately produces a `core` with `test-*` arms.
56ultimately produces a `core` with `test-*` arms.
55
57
58+## Running
59+
56The `-test` thread takes a `(list path)` in the Dojo, where each path is a path
60The `-test` thread takes a `(list path)` in the Dojo, where each path is a path
57−to a test file. The `path` must include the full path prefix
61+to a test file. The `path` _must_ include the full path prefix
62+(`/[ship]/[desk]/[case]`). The `path` _may_ omit the mark, since a `.hoon` file
63+is assumed. The `path` _may_ include the name of a test arm after the filename.
64+In that case, only the specified test arm will be run.
65+
58−(`/[ship]/[desk]/[case]`). The conventional location for tests is a `/tests`
66+The conventional location for tests is a `/tests`
59directory in the root of a desk.
67directory in the root of a desk.
60
68
61The output of the `-test` thread will note which arms were tested and whether
69The output of the `-test` thread will note which arms were tested and whether
@@ -68,7 +76,7 @@ they succeeded. It will also include:
68Here's an example of running the tests for the `naive.hoon` library:
76Here's an example of running the tests for the `naive.hoon` library:
69
77
70```
78```
71−> -test ~[%/tests/lib/naive/hoon]
79+> -test %/tests/lib/naive ~
72built /tests/lib/naive/hoon
80built /tests/lib/naive/hoon
73> test-zod-spawn-to-zero: took 81359µs
81> test-zod-spawn-to-zero: took 81359µs
74OK /lib/naive/test-zod-spawn-to-zero
82OK /lib/naive/test-zod-spawn-to-zero
@@ -84,6 +92,19 @@ OK /lib/naive/test-address-padding
84ok=%.y
92ok=%.y
85```
93```
86
94
95+Here's an example of running just a single test for `naive.hoon`, the
96+`++test-deposit` arm:
97+
98+```
99+> -test %/tests/lib/naive/test-deposit ~
100+built /tests/lib/naive/hoon
101+> test-deposit: took ms/45.542
102+OK /lib/naive/test-deposit
103+ok=%.y
104+```
105+
106+## More info
107+
87A good reference example is the test file for the `/lib/number-to-words.hoon`
108A good reference example is the test file for the `/lib/number-to-words.hoon`
88library, located in `/tests/lib/number-to-words.hoon`. Note that the `/tests`
109library, located in `/tests/lib/number-to-words.hoon`. Note that the `/tests`
89directory is not typically included in standard pills. If you want to have a
110directory is not typically included in standard pills. If you want to have a