Skip to content

Commit 2cdea39

Browse files
marioevzEikix
authored andcommitted
hivesim: dd documentation generation (ethereum#948)
1 parent d45fed7 commit 2cdea39

File tree

9 files changed

+746
-52
lines changed

9 files changed

+746
-52
lines changed

docs/simulators.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,40 @@ Now create the simulator program file `my-simulation.go`.
152152
// write your test code here
153153
}
154154

155+
### Generating Test Case Documentation
156+
157+
The [package hivesim] provides automatic test case generation that can be used to compile all the
158+
test cases that a given simulator runs into a markdown file.
159+
160+
The documentation can be generated by executing the simulator binary with the environment variable
161+
`HIVE_DOCS_MODE` set to "true".
162+
163+
The document generator recurses into every test suite and test function that the simulator defines
164+
and collects their names and descriptions, as defined in the `hivesim.Suite`, `hivesim.TestSpec`
165+
or `hivesim.ClientTestSpec` objects.
166+
167+
If the test object contains no description, it will not be listed in the documentation generated.
168+
169+
A `TESTS.md` file that serves as an index document will be generated, inside of it a listing of
170+
all the test suites will be included, along with the links to all test suite markdown files.
171+
172+
For every test suite a `TESTS-<Suite Name>.md` file will be generated, containing the listing of
173+
all test cases included in the suite.
174+
175+
The `Location` field of the `hivesim.Suite` can be used to specify a subdirectory where the
176+
markdown file for this given suite will be placed.
177+
178+
The `Category` field of `hivesim.TestSpec` or `hivesim.ClientTestSpec` can be used to generate
179+
test categories in which the test cases will be grouped for readability purposes.
180+
181+
The following environment variables can be used to configure document generation:
182+
- `HIVE_DOCS_MODE`: Enable test case documentation generation (set to "true").
183+
- `HIVE_SIMULATOR_NAME`: Name of the simulator for which the documentation is being generated.
184+
If unset, the path of the simulator executable will be used to parse the simulator's name.
185+
- `HIVE_DOCS_OUTPUT_DIR`: Output root directory for all generated markdown files.
186+
If unset, the current working directory will be used.
187+
188+
155189
### Creating the Dockerfile
156190

157191
The simulator needs to have a Dockerfile in order to run.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/evanw/esbuild v0.18.11
1010
github.com/fsouza/go-dockerclient v1.9.8
1111
github.com/gorilla/mux v1.8.0
12+
github.com/lithammer/dedent v1.1.0
1213
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
1314
golang.org/x/net v0.17.0
1415
gopkg.in/inconshreveable/log15.v2 v2.0.0-20200109203555-b30bc20e4fd1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
226226
github.com/labstack/echo/v4 v4.5.0/go.mod h1:czIriw4a0C1dFun+ObrXp7ok03xON0N1awStJ6ArI7Y=
227227
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
228228
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
229+
github.com/lithammer/dedent v1.1.0 h1:VNzHMVCBNG1j0fh3OrsFRkVUwStdDArbgBWoPAffktY=
230+
github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc=
229231
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
230232
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
231233
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=

0 commit comments

Comments
 (0)