Skip to content

Commit

Permalink
Rename ensurer to ensuring
Browse files Browse the repository at this point in the history
  • Loading branch information
JosiahWitt committed Feb 8, 2023
1 parent 355c722 commit 28b4fb3
Show file tree
Hide file tree
Showing 24 changed files with 128 additions and 128 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestBasicExample(t *testing.T) {
...

// Methods can be called on ensure, for example, Run:
ensure.Run("my subtest", func(ensure ensurer.E) {
ensure.Run("my subtest", func(ensure ensuring.E) {
...

// To ensure a value is correct, use ensure as a function:
Expand Down
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ flags:
package:
paths:
- "*.go"
- "ensurer/**"
- "ensuring/**"
- "ensurepkg/**"
- "internal/**"
12 changes: 6 additions & 6 deletions ensure.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Package ensure is a balanced testing framework for Go 1.14+.
// It supports modern Go 1.13+ error comparisons (via errors.Is), and provides easy to read diffs (via deep.Equal).
//
// Most of the implementation is in the ensurer package.
// Most of the implementation is in the ensuring package.
// ensure.New should be used to create an instance of the ensure framework,
// which allows shadowing the "ensure" package (like with the t variable in tests).
// This provides easy test refactoring, while still being able to access the underlying types via the ensurer package.
// This provides easy test refactoring, while still being able to access the underlying types via the ensuring package.
//
// For example:
//
Expand All @@ -13,7 +13,7 @@
// ...
//
// // Methods can be called on ensure, for example, Run:
// ensure.Run("my subtest", func(ensure ensurer.Ensure) {
// ensure.Run("my subtest", func(ensure ensuring.Ensure) {
// ...
//
// // To ensure a value is correct, use ensure as a function:
Expand All @@ -30,9 +30,9 @@
// }
package ensure

import "github.com/JosiahWitt/ensure/ensurer"
import "github.com/JosiahWitt/ensure/ensuring"

// New creates an instance of the ensure test framework using the current testing context.
func New(t ensurer.T) ensurer.E {
return ensurer.InternalCreateDoNotCallDirectly(t)
func New(t ensuring.T) ensuring.E {
return ensuring.InternalCreateDoNotCallDirectly(t)
}
16 changes: 8 additions & 8 deletions ensurepkg/ensurepkg.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// Package ensurepkg contains the implementation for the ensure test framework.
// Use ensure.New to create a new instance of Ensure.
//
// Deprecated: Use the ensurer package instead.
// Deprecated: Use the ensuring package instead.
package ensurepkg

import "github.com/JosiahWitt/ensure/ensurer"
import "github.com/JosiahWitt/ensure/ensuring"

// T implements a subset of methods on [testing.T].
// More methods may be added to T with a minor ensure release.
//
// Deprecated: Use [ensurer.T] instead.
type T = ensurer.T
// Deprecated: Use [ensuring.T] instead.
type T = ensuring.T

// Ensure ensures the actual value is correct using [Chain].
// Ensure also has methods that can be called directly.
//
// Deprecated: Use [ensurer.E] instead.
type Ensure = ensurer.E
// Deprecated: Use [ensuring.E] instead.
type Ensure = ensuring.E

// Chain chains assertions to the ensure function call.
//
// Deprecated: Use [ensurer.Chain] instead.
type Chain = ensurer.Chain
// Deprecated: Use [ensuring.Chain] instead.
type Chain = ensuring.Chain
2 changes: 1 addition & 1 deletion ensurer/chain.go → ensuring/chain.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ensurer
package ensuring

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion ensurer/chain_error.go → ensuring/chain_error.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ensurer
package ensuring

import (
"errors"
Expand Down
10 changes: 5 additions & 5 deletions ensurer/chain_error_test.go → ensuring/chain_error_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ensurer_test
package ensuring_test

import (
"errors"
"fmt"
"testing"

"github.com/JosiahWitt/ensure"
"github.com/JosiahWitt/ensure/ensurer"
"github.com/JosiahWitt/ensure/ensuring"
"github.com/JosiahWitt/ensure/internal/mocks/mock_testctx"
"github.com/JosiahWitt/erk"
)
Expand All @@ -25,7 +25,7 @@ func TestChainIsError(t *testing.T) {
ensure(val).IsError(err)
})

sharedIsErrorTests(t, func(mockT *mock_testctx.MockT, chain *ensurer.Chain, expected error) {
sharedIsErrorTests(t, func(mockT *mock_testctx.MockT, chain *ensuring.Chain, expected error) {
chain.IsError(expected)
})
}
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestChainMatchesAllErrors(t *testing.T) {
})

t.Run("when one expected error", func(t *testing.T) {
sharedIsErrorTests(t, func(mockT *mock_testctx.MockT, chain *ensurer.Chain, expected error) {
sharedIsErrorTests(t, func(mockT *mock_testctx.MockT, chain *ensuring.Chain, expected error) {
mockT.EXPECT().Helper()

chain.MatchesAllErrors(expected)
Expand Down Expand Up @@ -343,7 +343,7 @@ func TestChainMatchesAllErrors(t *testing.T) {
})
}

func sharedIsErrorTests(t *testing.T, run func(mockT *mock_testctx.MockT, chain *ensurer.Chain, expected error)) {
func sharedIsErrorTests(t *testing.T, run func(mockT *mock_testctx.MockT, chain *ensuring.Chain, expected error)) {
const errorFormat = "\nActual error is not the expected error:\n\tActual: %s\n\tExpected: %s"

t.Run("when equal error by reference", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion ensurer/chain_test.go → ensuring/chain_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ensurer_test
package ensuring_test

import (
"sync"
Expand Down
6 changes: 3 additions & 3 deletions ensurer/ensurer.go → ensuring/ensuring.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Package ensurer contains the implementation for the ensure test framework.
// Package ensuring contains the implementation for the ensure test framework.
//
// It is in a separate package from ensure to allow shadowing the ensure package
// without losing access to the types. Use [ensure.New] to create a new instance of Ensure.
package ensurer
package ensuring

import (
"runtime"
Expand Down Expand Up @@ -45,7 +45,7 @@ func InternalCreateDoNotCallDirectly(t T) E {

if !strings.HasSuffix(callerFilePath, validWrapperFilePathSuffix) {
t.Helper()
t.Fatalf("Do not call `ensurer.InternalCreateDoNotCallDirectly(t)` directly. Instead use `ensure := ensure.New(t)`.")
t.Fatalf("Do not call `ensuring.InternalCreateDoNotCallDirectly(t)` directly. Instead use `ensure := ensure.New(t)`.")
}

return wrap(t)
Expand Down
12 changes: 6 additions & 6 deletions ensurer/ensurer_test.go → ensuring/ensuring_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package ensurer_test
package ensuring_test

import (
"testing"

"github.com/JosiahWitt/ensure"
"github.com/JosiahWitt/ensure/ensurer"
"github.com/JosiahWitt/ensure/ensurer/internal/testhelper"
"github.com/JosiahWitt/ensure/ensuring"
"github.com/JosiahWitt/ensure/ensuring/internal/testhelper"
"github.com/JosiahWitt/ensure/internal/mocks/mock_testctx"
"github.com/JosiahWitt/ensure/internal/testctx"
"github.com/golang/mock/gomock"
Expand All @@ -30,10 +30,10 @@ func TestNew(t *testing.T) {

gomock.InOrder(
mockT.EXPECT().Helper(),
mockT.EXPECT().Fatalf("Do not call `ensurer.InternalCreateDoNotCallDirectly(t)` directly. Instead use `ensure := ensure.New(t)`."),
mockT.EXPECT().Fatalf("Do not call `ensuring.InternalCreateDoNotCallDirectly(t)` directly. Instead use `ensure := ensure.New(t)`."),
)

ensurer.InternalCreateDoNotCallDirectly(mockT)
ensuring.InternalCreateDoNotCallDirectly(mockT)
})
}

Expand Down Expand Up @@ -116,7 +116,7 @@ func TestET(t *testing.T) {
ensure := ensure.New(t)
outerName := t.Name()

ensure.Run("inner", func(ensure ensurer.E) {
ensure.Run("inner", func(ensure ensuring.E) {
if ensure.T().Name() != outerName+"/inner" {
t.Fatalf("Expected to be able to use T() inside ensure.Run")
}
Expand Down
4 changes: 2 additions & 2 deletions ensurer/init_test.go → ensuring/init_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//nolint:testpackage // Only used for the init function below.
package ensurer
package ensuring

import "github.com/JosiahWitt/ensure/ensurer/internal/testhelper"
import "github.com/JosiahWitt/ensure/ensuring/internal/testhelper"

//nolint:gochecknoinits // Only to make testing easier.
func init() {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion ensurer/run.go → ensuring/run.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ensurer
package ensuring

import "github.com/JosiahWitt/ensure/internal/testctx"

Expand Down
2 changes: 1 addition & 1 deletion ensurer/run_table.go → ensuring/run_table.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ensurer
package ensuring

import (
"github.com/JosiahWitt/ensure/internal/plugins/all"
Expand Down
24 changes: 12 additions & 12 deletions ensurer/run_table_test.go → ensuring/run_table_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package ensurer_test
package ensuring_test

import (
"strings"
"testing"

"github.com/JosiahWitt/ensure"
"github.com/JosiahWitt/ensure/ensurer"
"github.com/JosiahWitt/ensure/ensurer/internal/testhelper"
"github.com/JosiahWitt/ensure/ensuring"
"github.com/JosiahWitt/ensure/ensuring/internal/testhelper"
"github.com/JosiahWitt/ensure/internal/mocks/mock_testctx"
"github.com/JosiahWitt/ensure/internal/testctx"
"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -91,14 +91,14 @@ func TestERunTableByIndex(t *testing.T) {
}).AnyTimes()

type entryCall struct {
ensure ensurer.E
ensure ensuring.E
i int
}

// Run table and save call details
actualEntryCalls := []entryCall{}
ensure := ensure.New(outerMockT)
ensure.RunTableByIndex(entry.Table, func(ensure ensurer.E, i int) {
ensure.RunTableByIndex(entry.Table, func(ensure ensuring.E, i int) {
actualEntryCalls = append(actualEntryCalls, entryCall{ensure: ensure, i: i})
})

Expand Down Expand Up @@ -639,7 +639,7 @@ func (runTableTests) mocksField() runTableTestEntryGroup {

{
Name: "when NEW method has an extra param",
FatalMessagesContain: []string{"Mocks.Invalid (*ensurer_test.ExampleMockNEWMethodExtraParam) must have a NEW method matching one of the following signatures"},
FatalMessagesContain: []string{"Mocks.Invalid (*ensuring_test.ExampleMockNEWMethodExtraParam) must have a NEW method matching one of the following signatures"},
Table: []struct {
Name string
Mocks *OneMockNEWMethodExtraParam
Expand All @@ -655,7 +655,7 @@ func (runTableTests) mocksField() runTableTestEntryGroup {

{
Name: "when NEW method has incorrect param",
FatalMessagesContain: []string{"Mocks.Invalid (*ensurer_test.ExampleMockNEWMethodIncorrectParam) must have a NEW method matching one of the following signatures"},
FatalMessagesContain: []string{"Mocks.Invalid (*ensuring_test.ExampleMockNEWMethodIncorrectParam) must have a NEW method matching one of the following signatures"},
Table: []struct {
Name string
Mocks *OneMockNEWMethodIncorrectParam
Expand All @@ -671,7 +671,7 @@ func (runTableTests) mocksField() runTableTestEntryGroup {

{
Name: "when NEW method has zero returns",
FatalMessagesContain: []string{"Mocks.Invalid (*ensurer_test.ExampleMockNEWMethodZeroReturns) must have a NEW method matching one of the following signatures"},
FatalMessagesContain: []string{"Mocks.Invalid (*ensuring_test.ExampleMockNEWMethodZeroReturns) must have a NEW method matching one of the following signatures"},
Table: []struct {
Name string
Mocks *OneMockNEWMethodZeroReturns
Expand All @@ -687,7 +687,7 @@ func (runTableTests) mocksField() runTableTestEntryGroup {

{
Name: "when NEW method has incorrect return",
FatalMessagesContain: []string{"Mocks.Invalid (*ensurer_test.ExampleMockNEWMethodIncorrectReturn) must have a NEW method matching one of the following signatures"},
FatalMessagesContain: []string{"Mocks.Invalid (*ensuring_test.ExampleMockNEWMethodIncorrectReturn) must have a NEW method matching one of the following signatures"},
Table: []struct {
Name string
Mocks *OneMockNEWMethodIncorrectReturn
Expand Down Expand Up @@ -839,7 +839,7 @@ func (runTableTests) setupMocksField() runTableTestEntryGroup {

{
Name: "function missing param",
FatalMessagesContain: []string{"expected SetupMocks field to be a func(*ensurer_test.TwoValidMocks)"},
FatalMessagesContain: []string{"expected SetupMocks field to be a func(*ensuring_test.TwoValidMocks)"},
Table: []struct {
Name string
Mocks *TwoValidMocks
Expand All @@ -858,7 +858,7 @@ func (runTableTests) setupMocksField() runTableTestEntryGroup {

{
Name: "function with invalid param",
FatalMessagesContain: []string{"expected SetupMocks field to be a func(*ensurer_test.TwoValidMocks)"},
FatalMessagesContain: []string{"expected SetupMocks field to be a func(*ensuring_test.TwoValidMocks)"},
Table: []struct {
Name string
Mocks *TwoValidMocks
Expand All @@ -877,7 +877,7 @@ func (runTableTests) setupMocksField() runTableTestEntryGroup {

{
Name: "function with a return",
FatalMessagesContain: []string{"expected SetupMocks field to be a func(*ensurer_test.TwoValidMocks)"},
FatalMessagesContain: []string{"expected SetupMocks field to be a func(*ensuring_test.TwoValidMocks)"},
Table: []struct {
Name string
Mocks *TwoValidMocks
Expand Down
10 changes: 5 additions & 5 deletions ensurer/run_test.go → ensuring/run_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package ensurer_test
package ensuring_test

import (
"testing"

"github.com/JosiahWitt/ensure"
"github.com/JosiahWitt/ensure/ensurer"
"github.com/JosiahWitt/ensure/ensurer/internal/testhelper"
"github.com/JosiahWitt/ensure/ensuring"
"github.com/JosiahWitt/ensure/ensuring/internal/testhelper"
"github.com/JosiahWitt/ensure/internal/mocks/mock_testctx"
"github.com/JosiahWitt/ensure/internal/testctx"
"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -34,9 +34,9 @@ func TestERun(t *testing.T) {
fn(innerMockCtx)
})

var innerEnsure ensurer.E
var innerEnsure ensuring.E
outerEnsure := ensure.New(outerMockT)
outerEnsure.Run(name, func(ensure ensurer.E) {
outerEnsure.Run(name, func(ensure ensuring.E) {
innerEnsure = ensure
})

Expand Down
Loading

0 comments on commit 28b4fb3

Please sign in to comment.