Skip to content

Commit

Permalink
chore: fix some typos and style
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoVeille authored and shoenig committed Jun 7, 2024
1 parent b439466 commit b899fe0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ There are five key packages,

:ballot_box_with_check: v0.6.0 adds support for custom `cmp.Option` values

- Adds ability to customize cmp.Equal behavior via cmp.Option arguments
- Adds ability to customize `cmp.Equal` behavior via `cmp.Option` arguments
- Adds assertions for existence of single map key
- Fixes some error outputs

Expand Down Expand Up @@ -66,28 +66,28 @@ way - avoiding erroneous comparisons in the first place.

Generally there are 4 ways of asserting equivalence between types.

#### the == operator
#### the `==` operator

Functions like `EqOp` and `ContainsOp` work on types that are `comparable`, i.e. are
Functions like `EqOp` and `ContainsOp` work on types that are `comparable`, i.e., are
compatible with Go's built-in `==` and `!=` operators.

#### a comparator function

Functions like `EqFunc` and `ContainsFunc` work on any type, as the caller passes in a
function that takes two arguments of that type, returning a boolean indicating equivalence.

#### an .Equal method
#### an `.Equal` method

Functions like `Equal` and `ContainsEqual` work on types implementing the `EqualFunc`
generic interface (i.e. implement an `.Equal` method). The `.Equal` method is called
to determine equivalence.

#### the cmp.Equal or reflect.DeepEqual functions
#### the `cmp.Equal` or `reflect.DeepEqual` functions

Functions like `Eq` and `Contains` work on any type, using the `cmp.Equal` or `reflect.DeepEqual`
functions to determine equivalence. Although this is the easiest / most compatible way
to "just compare stuff", it the least deterministic way of comparing instances of a type.
Changes to the underlying types may cause unexpected changes in their equivalence (e.g.
to "just compare stuff", it's the least deterministic way of comparing instances of a type.
Changes to the underlying types may cause unexpected changes in their equivalence (e.g.,
the addition of unexported fields, function field types, etc.). Assertions that make
use of `cmp.Equal` configured with custom `cmp.Option` values.

Expand All @@ -98,16 +98,16 @@ is done via the `cmp.Diff` function. For incompatible types, their `GoString` va
printed instead.

All output is directed through `t.Log` functions, and is visible only if test verbosity is
turned on (e.g. `go test -v`).
turned on (e.g., `go test -v`).

#### fail fast vs. fail later

The `test` and `must` packages are identical, except for how test cases behave when encountering
a failure. Sometimes it is helpful for a test case to continue running even though a failure has
occurred (e.g. contains cleanup logic not captured via a `t.Cleanup` function). Other times it
make sense to fail immediately and stop the test case execution.
occurred (e.g., it contains cleanup logic not captured via a `t.Cleanup` function). Other times, it
makes sense to fail immediately and stop the test case execution.

### go-cmp Options
### `go-cmp` Options

The test assertions that rely on `cmp.Equal` can be customized in how objects
are compared by [specifying custom](https://github.com/google/go-cmp/blob/master/cmp/options.go#L16)
Expand Down Expand Up @@ -243,7 +243,7 @@ err := c.Run()
```go
import "github.com/shoenig/test/must"

// ...
// ...

e1 := Employee{ID: 100, Name: "Alice"}
e2 := Employee{ID: 101, Name: "Bob"}
Expand All @@ -265,7 +265,7 @@ must.Equal(t, e1, e2)

### Output

The `test` and `must` package attempt to create useful, readable output when an assertions goes awry. Some random examples below.
The `test` and `must` package attempt to create useful, readable output when an assertion goes awry. Some random examples below.

```text
test_test.go:779: expected different file permissions
Expand Down
8 changes: 4 additions & 4 deletions internal/assertions/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,19 +233,19 @@ func EqJSON(exp, val string) (s string) {
var expA, expB any

if err := json.Unmarshal([]byte(exp), &expA); err != nil {
s = fmt.Sprintf("failed to unmarshal first argument as json: %v\n", err)
s = fmt.Sprintf("failed to unmarshal first argument as JSON: %v\n", err)
return
}

if err := json.Unmarshal([]byte(val), &expB); err != nil {
s = fmt.Sprintf("failed to unmarshal second argument as json: %v\n", err)
s = fmt.Sprintf("failed to unmarshal second argument as JSON: %v\n", err)
return
}

if !reflect.DeepEqual(expA, expB) {
jsonA, _ := json.Marshal(expA)
jsonB, _ := json.Marshal(expB)
s = "expected equality via json marshalling\n"
s = "expected equality via JSON marshalling\n"
s += diff(string(jsonA), string(jsonB), nil)
return
}
Expand All @@ -263,7 +263,7 @@ func ValidJSONBytes(input []byte) (s string) {

func validJSON(input []byte) (s string) {
if !json.Valid([]byte(input)) {
return "expected input to be valid json\n"
return "expected input to be valid JSON\n"
}
return
}
Expand Down
6 changes: 3 additions & 3 deletions must/must.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion must/must_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion skip/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func MinimumCores(t T, num int) {
}

// MaximumCores will skip the test if the number of cores on the system
// exceeeds the given maximum.
// exceeds the given maximum.
func MaximumCores(t T, num int) {
cpus := runtime.NumCPU()
if cpus > num {
Expand Down
6 changes: 3 additions & 3 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/shoenig/test/wait"
)

// ErrorAssertionFunc allows to pass Error and NoError in table driven tests
// ErrorAssertionFunc allows passing Error and NoError in table driven tests
type ErrorAssertionFunc func(t T, err error, settings ...Setting)

// Nil asserts a is nil.
Expand Down Expand Up @@ -224,7 +224,7 @@ func SliceNotContains[A any](t T, slice []A, item A, settings ...Setting) {
invoke(t, assertions.SliceNotContains(slice, item), settings...)
}

// SliceNotContainsFunc asserts item does not exist inslice, using eq to compare
// SliceNotContainsFunc asserts item does not exist in slice, using eq to compare
// elements.
func SliceNotContainsFunc[A, B any](t T, slice []A, item B, eq func(a A, b B) bool, settings ...Setting) {
t.Helper()
Expand Down Expand Up @@ -415,7 +415,7 @@ func MapEqFunc[M1, M2 interfaces.Map[K, V], K comparable, V any](t T, exp M1, va
}

// MapEqual asserts maps exp and val contain the same key/val pairs, using Equal
// method to compare vals
// method to compare val
func MapEqual[M interfaces.MapEqualFunc[K, V], K comparable, V interfaces.EqualFunc[V]](t T, exp, val M, settings ...Setting) {
t.Helper()
invoke(t, assertions.MapEqual(exp, val), settings...)
Expand Down
2 changes: 1 addition & 1 deletion test_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func TestNotEqFunc_PS(t *testing.T) {
}

func TestEqJSON(t *testing.T) {
tc := newCase(t, `expected equality via json marshalling`)
tc := newCase(t, `expected equality via JSON marshalling`)
t.Cleanup(tc.assert)

EqJSON(tc, `{"a":1, "b":2}`, `{"b":2, "a":9}`)
Expand Down

0 comments on commit b899fe0

Please sign in to comment.