Skip to content

Commit 5daf877

Browse files
Update documentation for writing tests for unstable MSCs (#784)
* Remove documentation surrounding MSC build tags We no longer use them as of #666 * Document test writing for unstable MSCs * Add currently-known blacklist tags So those adding new tests know what to blacklist out of the box.
1 parent 7675158 commit 5daf877

File tree

2 files changed

+75
-16
lines changed

2 files changed

+75
-16
lines changed

ONBOARDING.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,6 @@ To conditionally skip an entire *file* based on the homeserver being run, add a
185185
```go
186186
// +build !dendrite_blacklist
187187
```
188-
You can also do this based on features for MSC tests (which means you must run Complement *with* this tag for these tests *to run*):
189-
```go
190-
// +build msc_2836
191-
```
192188
See [GH Actions](https://github.com/matrix-org/complement/blob/master/.github/workflows/ci.yaml) for an example of how this is used for different homeservers in practice.
193189

194190
### Why do we use `t.Errorf` sometimes and `t.Fatalf` other times?
@@ -210,11 +206,11 @@ For Goland:
210206
* Under "Run"->"Edit Configurations..."->"Edit Configuration Templates..."->"Go Test", and add `COMPLEMENT_BASE_IMAGE=complement-dendrite:latest` to "Environment"
211207
* Then you can right-click on any test file or test case and "Run <test name>".
212208

213-
209+
214210
### How do I make the linter checks pass?
215211

216212
Use [`goimports`](https://pkg.go.dev/golang.org/x/tools/cmd/goimports) to sort imports and format in the style of `gofmt`.
217-
213+
218214
Set this up to run on save in VSCode as follows:
219215
- File -> Preferences -> Settings.
220216
- Search for "Format On Save" and enable it.

README.md

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,24 +140,87 @@ for an example of how to do this correctly.
140140

141141
To get started developing Complement tests, see [the onboarding documentation](ONBOARDING.md).
142142

143-
### Build tags
143+
### Build tags (test blacklisting)
144+
145+
Complement uses build tags to exclude tests for each homeserver implementation.
146+
Build tags are comments at the top of the file that look like:
144147

145-
Complement uses build tags to include or exclude tests for each homeserver. Build tags are comments at the top of the file that look
146-
like:
147148
```go
148-
// +build msc2403
149+
// +build !dendrite_blacklist
149150
```
150-
We have tags for MSCs (the above is in `msc2403_test.go`) as well as general blacklists for a homeserver implementation e.g Dendrite,
151-
which has the name `dendrite_blacklist`. These are implemented as inverted tags such that specifying the tag results in the file not
152-
being picked up by `go test`. For example, `apidoc_presence_test.go` has:
151+
152+
These are implemented as inverted tags, such that specifying the tag results in
153+
the file not being picked up by `go test`. This serves as a way to exclude
154+
known-broken tests per implementation.
155+
156+
For example, `apidoc_presence_test.go` has:
157+
153158
```go
154159
// +build !dendrite_blacklist
155160
```
156-
and all Dendrite tests run with `-tags="dendrite_blacklist"` to cause this file to be skipped. You can run tests with build tags like this:
161+
162+
and all Dendrite tests run with `-tags="dendrite_blacklist"` to cause this file
163+
to be skipped. You can run tests with build tags like this:
164+
157165
```
158-
COMPLEMENT_BASE_IMAGE=complement-synapse:latest go test -v -tags="synapse_blacklist,msc2403" ./tests/...
166+
COMPLEMENT_BASE_IMAGE=complement-synapse:latest go test -v -tags="synapse_blacklist" ./tests/...
159167
```
160-
This runs Complement with a Synapse HS and ignores tests which Synapse doesn't implement, and includes tests for MSC2403.
168+
169+
This runs Complement with a Synapse HS and ignores tests which Synapse doesn't implement.
170+
171+
The currently known blacklist tags are:
172+
173+
* `synapse_blacklist`
174+
* `dendrite_blacklist`
175+
* `conduit_blacklist`
176+
* `conduwuit_blacklist`
177+
178+
### Writing tests for unstable MSCs
179+
180+
Complement is frequently used to test homeserver implementations of unstable
181+
MSCs. As these features/changes often become stable eventually and for
182+
convenience, this repo accepts such tests.
183+
184+
Tests for a given MSC should be placed in a new directory under `tests/`. For
185+
example, to write tests for MSC9999, create a directory at `tests/msc9999`.
186+
187+
This creates a new go "package", and tests contained within will not be run
188+
unless explicitly noted. A package directory should contain the following
189+
files:
190+
191+
```
192+
tests/msc9999
193+
├── main_test.go
194+
└── msc9999_test.go
195+
```
196+
197+
where `main_test.go` sets up Complement and indicates that this is a package
198+
containing tests:
199+
200+
```go
201+
package tests
202+
203+
import (
204+
"testing"
205+
206+
"github.com/matrix-org/complement"
207+
)
208+
209+
func TestMain(m *testing.M) {
210+
complement.TestMain(m, "msc9999")
211+
}
212+
```
213+
214+
and `msc9999_test.go` contains your actual tests. See existing `tests/msc*`
215+
directories for examples.
216+
217+
You can create additional files to separate and organise logical chunks of
218+
tests. Just be sure each file is named `*_test.go` for `go test` to find it.
219+
220+
Once an MSC is accepted, the tests should be migrated out of the `msc*`
221+
directory, as the MSC is now considered stable. Consider adding the tests to
222+
the blacklist of other homeserver implementations (see above section) if they
223+
don't yet implement the new changes described by the MSC.
161224

162225
## Why 'Complement'?
163226

0 commit comments

Comments
 (0)