Skip to content

Commit

Permalink
Document line comment
Browse files Browse the repository at this point in the history
  • Loading branch information
FollowTheProcess committed Oct 18, 2024
1 parent 597eb1e commit dfcced3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,30 @@ func TestSomething(t *testing.T) {
}
```

### Self Documenting Tests

> [!TIP]
> Line comments on the line you call most `test` functions on will be shown in failure messages as additional context
That means you can have additional context in the failure message, as well as helpful comments explaining the assertion to readers of your code

```go
func TestSomething(t *testing.T) {
test.Equal(t, "apples", "oranges") // Fruits are not equal
}
```

Will get you a failure message like:

```shell
--- FAIL: TestSomething (0.00s)
something_test.go:1:
Not Equal // Fruits are not equal
---------
Got: apples
Wanted: oranges
```

### Non Comparable Types

`test` uses Go 1.18+ generics under the hood for most of the comparison, which is great, but what if your types don't satisfy `comparable`. We also provide
Expand Down
4 changes: 4 additions & 0 deletions test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,3 +578,7 @@ func TestCapture(t *testing.T) {
test.Equal(t, stderr, "")
})
}

func TestSomething(t *testing.T) {
test.Equal(t, "apples", "oranges") // Fruits are not equal
}

0 comments on commit dfcced3

Please sign in to comment.