Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: onsi/gomega
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.31.0
Choose a base ref
...
head repository: onsi/gomega
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.31.1
Choose a head ref
  • 6 commits
  • 7 files changed
  • 3 contributors

Commits on Jan 18, 2024

  1. Inverted arguments order of FailureMessage of BeComparableToMatcher

    BeComparableTo behaved differently between Match and FailureMessage which made asymmetric go-cmp Options (e.g. https://pkg.go.dev/k8s.io/apimachinery/pkg/util/diff#IgnoreUnset) print a nonsensical error message.
    
    Fixed this issue by inverting order or comparison, and improved a bit messages.
    antonincms authored and onsi committed Jan 18, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e0dd999 View commit details
  2. Copy the full SHA
    ad1a367 View commit details

Commits on Jan 19, 2024

  1. Show how to import the format sub package

    I find this useful for developers that are less familiar with Go and Gomega.
    luistm authored and onsi committed Jan 19, 2024
    Copy the full SHA
    24e958d View commit details
  2. bump dependencies

    onsi committed Jan 19, 2024
    Copy the full SHA
    bde8f7a View commit details
  3. tidy up go.sum

    onsi committed Jan 19, 2024
    Copy the full SHA
    26661b8 View commit details
  4. v1.31.1

    onsi committed Jan 19, 2024
    Copy the full SHA
    762b171 View commit details
Showing with 29 additions and 13 deletions.
  1. +11 −0 CHANGELOG.md
  2. +7 −1 docs/index.md
  3. +2 −2 go.mod
  4. +4 −5 go.sum
  5. +1 −1 gomega_dsl.go
  6. +2 −2 matchers/be_comparable_to_matcher.go
  7. +2 −2 matchers/be_comparable_to_matcher_test.go
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 1.31.1

### Fixes
- Inverted arguments order of FailureMessage of BeComparableToMatcher [e0dd999]
- Update test in case keeping msg is desired [ad1a367]

### Maintenance
- Show how to import the format sub package [24e958d]
- tidy up go.sum [26661b8]
- bump dependencies [bde8f7a]

## 1.31.0

### Features
8 changes: 7 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -215,7 +215,13 @@ to be false

When a failure occurs, Gomega prints out a recursive description of the objects involved in the failed assertion. This output can be very verbose, but Gomega's philosophy is to give as much output as possible to aid in identifying the root cause of a test failure.

These recursive object renditions are performed by the `format` subpackage. `format` provides some globally adjustable settings to tune Gomega's output:
These recursive object renditions are performed by the `format` subpackage. Import the format subpackage in your test code:

```go
import "github.com/onsi/gomega/format"
```

`format` provides some globally adjustable settings to tune Gomega's output:

- `format.MaxLength = 4000`: Gomega will recursively traverse nested data structures as it produces output. If the length of this string representation is more than MaxLength, it will be truncated to MaxLength. To disable this behavior, set the MaxLength to `0`.
- `format.MaxDepth = 10`: Gomega will recursively traverse nested data structures as it produces output. By default the maximum depth of this recursion is set to `10` you can adjust this to see deeper or shallower representations of objects.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ go 1.20
require (
github.com/golang/protobuf v1.5.3
github.com/google/go-cmp v0.6.0
github.com/onsi/ginkgo/v2 v2.13.2
github.com/onsi/ginkgo/v2 v2.15.0
golang.org/x/net v0.19.0
gopkg.in/yaml.v3 v3.0.1
)
@@ -16,6 +16,6 @@ require (
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/tools v0.16.1 // indirect
google.golang.org/protobuf v1.28.0 // indirect
)
9 changes: 4 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -17,23 +17,22 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs=
github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM=
github.com/onsi/ginkgo/v2 v2.15.0 h1:79HwNRBAZHOEwrczrgSOPy+eFTTlIGELKy5as+ClttY=
github.com/onsi/ginkgo/v2 v2.15.0/go.mod h1:HlxMHtYF57y6Dpf+mc5529KKmSq9h2FpCF+/ZkwUxKM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc=
golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg=
golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
2 changes: 1 addition & 1 deletion gomega_dsl.go
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ import (
"github.com/onsi/gomega/types"
)

const GOMEGA_VERSION = "1.31.0"
const GOMEGA_VERSION = "1.31.1"

const nilGomegaPanic = `You are trying to make an assertion, but haven't registered Gomega's fail handler.
If you're using Ginkgo then you probably forgot to put your assertion in an It().
4 changes: 2 additions & 2 deletions matchers/be_comparable_to_matcher.go
Original file line number Diff line number Diff line change
@@ -41,9 +41,9 @@ func (matcher *BeComparableToMatcher) Match(actual interface{}) (success bool, m
}

func (matcher *BeComparableToMatcher) FailureMessage(actual interface{}) (message string) {
return cmp.Diff(matcher.Expected, actual, matcher.Options)
return fmt.Sprint("Expected object to be comparable, diff: ", cmp.Diff(actual, matcher.Expected, matcher.Options...))
}

func (matcher *BeComparableToMatcher) NegatedFailureMessage(actual interface{}) (message string) {
return format.Message(actual, "not to equal", matcher.Expected)
return format.Message(actual, "not to be comparable to", matcher.Expected)
}
4 changes: 2 additions & 2 deletions matchers/be_comparable_to_matcher_test.go
Original file line number Diff line number Diff line change
@@ -138,12 +138,12 @@ var _ = Describe("BeComparableTo", func() {
Exported string
}

It("should produce failure message according to paseed cmp.Option", func() {
It("should produce failure message according to passed cmp.Option", func() {
actual := structWithUnexportedFields{unexported: "xxx", Exported: "exported field value"}
expectedEqual := structWithUnexportedFields{unexported: "yyy", Exported: "exported field value"}
matcherWithEqual := BeComparableTo(expectedEqual, cmpopts.IgnoreUnexported(structWithUnexportedFields{}))

Expect(matcherWithEqual.FailureMessage(actual)).To(BeEmpty())
Expect(matcherWithEqual.FailureMessage(actual)).To(BeEquivalentTo("Expected object to be comparable, diff: "))

expectedDiffernt := structWithUnexportedFields{unexported: "xxx", Exported: "other value"}
matcherWithDifference := BeComparableTo(expectedDiffernt, cmpopts.IgnoreUnexported(structWithUnexportedFields{}))