Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- run: ./.ci.readme.fmt.sh
- run: ./.ci.govet.sh
- run: go test -v -race ./...
- run: go test -tags testify_no_objx ./...
test:
runs-on: ubuntu-latest
strategy:
Expand All @@ -41,3 +42,4 @@ jobs:
with:
go-version: ${{ matrix.go_version }}
- run: go test -v -race ./...
- run: go test -tags testify_no_objx ./...
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ module github.com/stretchr/testify
// .github/workflows/main.yml
go 1.17

require (
github.com/stretchr/objx v0.5.2 // To avoid a cycle the version of testify used by objx should be excluded below
gopkg.in/yaml.v3 v3.0.1
)
require gopkg.in/yaml.v3 v3.0.1

// Break dependency cycle with objx.
// See https://github.com/stretchr/objx/pull/140
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
14 changes: 1 addition & 13 deletions mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"sync"
"time"

"github.com/stretchr/objx"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/internal/difflib"
"github.com/stretchr/testify/internal/spew"
Expand Down Expand Up @@ -311,7 +309,7 @@ type Mock struct {

// TestData holds any data that might be useful for testing. Testify ignores
// this data completely allowing you to do whatever you like with it.
testData objx.Map
testData testData

mutex sync.Mutex
}
Expand All @@ -324,16 +322,6 @@ func (m *Mock) String() string {
return fmt.Sprintf("%[1]T<%[1]p>", m)
}

// TestData holds any data that might be useful for testing. Testify ignores
// this data completely allowing you to do whatever you like with it.
func (m *Mock) TestData() objx.Map {
if m.testData == nil {
m.testData = make(objx.Map)
}

return m.testData
}

/*
Setting expectations
*/
Expand Down
5 changes: 5 additions & 0 deletions mock/mock_no_objx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//go:build testify_no_objx || testify_no_deps

package mock

type testData = struct{}
68 changes: 68 additions & 0 deletions mock/mock_objx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// This source file isolates the uses of the objx module to ease
// maintenance of downstream forks that remove that dependency.
// See https://github.com/stretchr/testify/issues/1752

//go:build !testify_no_objx && !testify_no_deps

package mock

import (
"reflect"
)

type testData = TestData

// TestData holds any data that might be useful for testing. Testify ignores
// this data completely allowing you to do whatever you like with it.
//
// Deprecated: do not use. The new TestData do not return an [github.com/stretchr/objx.Map] anymore.
// See https://github.com/stretchr/testify/issues/1852.
func (m *Mock) TestData() TestData {
if m.testData == nil {
m.testData = make(TestData)
}

return m.testData
}

// TestData replaces [github.com/stretchr/objx.Map].
type TestData map[string]interface{}

type reflectValue = reflect.Value

// TestDataValue replaces [github.com/stretchr/objx.Value] and exposes the same methods as [reflect.Value].
// Only a subset of objx.Value methods are available.
type TestDataValue struct {
reflectValue
}

// Set replaces [github.com/stretchr/objx.Map.Set].
func (td TestData) Set(selector string, v interface{}) {
td[selector] = v
}

// Get replaces [github.com/stretchr/objx.Map.Get].
func (td TestData) Get(selector string) *TestDataValue {
v, ok := td[selector]
if !ok {
return nil
}
return &TestDataValue{reflectValue: reflect.ValueOf(&v).Elem()}
}

// MustInter replaces [github.com/stretchr/objx.Value.MustInter].
func (v *TestDataValue) MustInter() interface{} {
if v == nil {
return nil
}
// v.reflectValue contains an interface (ex: error), so dereference it
return v.reflectValue.Elem()
}

// MustInter replaces [github.com/stretchr/objx.Value.Data].
func (v *TestDataValue) Data() interface{} {
if v == nil {
return nil
}
return v.reflectValue.Interface()
}
21 changes: 21 additions & 0 deletions mock/mock_objx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//go:build !testify_no_objx && !testify_no_deps

package mock

import (
"testing"

"github.com/stretchr/testify/assert"
)

func Test_Mock_TestData(t *testing.T) {
t.Parallel()

var mockedService = new(TestExampleImplementation)

if assert.NotNil(t, mockedService.TestData()) {

mockedService.TestData().Set("something", 123)
assert.Equal(t, 123, mockedService.TestData().Get("something").Data())
}
}
12 changes: 0 additions & 12 deletions mock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,6 @@ func (m *MockTestingT) FailNow() {
Mock
*/

func Test_Mock_TestData(t *testing.T) {
t.Parallel()

var mockedService = new(TestExampleImplementation)

if assert.NotNil(t, mockedService.TestData()) {

mockedService.TestData().Set("something", 123)
assert.Equal(t, 123, mockedService.TestData().Get("something").Data())
}
}

func Test_Mock_On(t *testing.T) {
t.Parallel()

Expand Down