Skip to content

Commit

Permalink
Address style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
navijation committed Jun 23, 2024
1 parent 089ef78 commit 9e0c14d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
6 changes: 2 additions & 4 deletions linter/ginkgo_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,8 @@ func checkSucceedSync(
assertionExpCopy := astcopy.CallExpr(assertionExp)
matcherCopy := assertionExpCopy.Args[0].(*ast.CallExpr)

isAsync := false
return doCheckSucceed(
pass, assertionExpCopy, matcherCopy, actualArgs, handler, reportBuilder, isAsync,
pass, assertionExpCopy, matcherCopy, actualArgs, handler, reportBuilder, false,
suppressStyleIssue,
)
}
Expand Down Expand Up @@ -565,8 +564,7 @@ func checkSucceedAsync(
assertionExpCopy := astcopy.CallExpr(assertionExp)
matcherCopy := assertionExpCopy.Args[0].(*ast.CallExpr)

isAsync := true
return doCheckSucceed(pass, assertionExpCopy, matcherCopy, actualArgs, handler, reportBuilder, isAsync, suppressWarnings)
return doCheckSucceed(pass, assertionExpCopy, matcherCopy, actualArgs, handler, reportBuilder, false, suppressWarnings)
}

// Function that looks for Succeed matcher by recursively unwrapping the `matcher` argument and,
Expand Down
56 changes: 29 additions & 27 deletions testdata/src/a/succeed/succeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,67 @@ import (
. "github.com/onsi/gomega"
)

func safeDivide(num int, denom int) (int, error) {
if denom == 0 {
return 0, errors.New("divide by zero")
func returnsFloatAndErr(arg int) (float64, error) {
if arg == 0 {
return 0, errors.New("an error")
}
return num / denom, nil
return 1.0 / float64(arg), nil
}

func attemptToCallNetwork(shouldTry bool) error {
if !shouldTry {
func returnsErr(arg bool) error {
if !arg {
return nil
}
return errors.New("don't know how to connect to network")
return errors.New("an error")
}

var _ = Describe("Ensure succeed assertion is used correctly", Label("succeed"), func() {
Expect(safeDivide(0, 0)).To(Not(Succeed())) // want `ginkgo-linter: Succeed matcher must be asserted against exactly one error value or a function call returning the same, or it will always fail`
Expect(safeDivide(0, 0)).NotTo(Succeed()) // want `ginkgo-linter: Succeed matcher must be asserted against exactly one error value or a function call returning the same, or it will always fail`
Expect(safeDivide(0, 1)).To(Succeed()) // want `ginkgo-linter: Succeed matcher must be asserted against exactly one error value or a function call returning the same, or it will always fail`
Expect(returnsFloatAndErr(0)).To(Not(Succeed())) // want `ginkgo-linter: Succeed matcher must be asserted against exactly one error value or a function call returning the same, or it will always fail`
Expect(returnsFloatAndErr(0)).NotTo(Succeed()) // want `ginkgo-linter: Succeed matcher must be asserted against exactly one error value or a function call returning the same, or it will always fail`
Expect(returnsFloatAndErr(1)).To(Succeed()) // want `ginkgo-linter: Succeed matcher must be asserted against exactly one error value or a function call returning the same, or it will always fail`

value0, err0 := safeDivide(0, 0)
value1, _ := safeDivide(0, 1)
value0, err0 := returnsFloatAndErr(0)
value1, _ := returnsFloatAndErr(1)

Expect(value0, err0).ToNot(Succeed()) // want `ginkgo-linter: Succeed matcher must be asserted against exactly one error value or a function call returning the same, or it will always fail`
Expect(value1).To(Succeed()) // want `ginkgo-linter: Succeed matcher must be asserted against exactly one error value or a function call returning the same, or it will always fail`

wrap := struct {
err error
resp := struct {
response any
err error
}{
err: err0,
response: nil,
err: err0,
}

Expect(err0).ToNot(Succeed()) // want `ginkgo-linter: Succeed matcher should be asserted against a function call; consider replacing with Expect\(err0\).To\(HaveOccurred\(\)\)`
ExpectWithOffset(1, err0).NotTo(Succeed()) // want `ginkgo-linter: Succeed matcher should be asserted against a function call; consider replacing with ExpectWithOffset\(1, err0\).To\(HaveOccurred\(\)\)`
Expect(err0).NotTo(Not(Succeed())) // want `ginkgo-linter: Succeed matcher should be asserted against a function call; consider replacing with Expect\(err0\).To\(Not\(HaveOccurred\(\)\)\)`
Expect(wrap.err).To(Succeed()) // want `ginkgo-linter: Succeed matcher should be asserted against a function call; consider replacing with Expect\(wrap.err\).ToNot\(HaveOccurred\(\)\)`
Expect(resp.err).To(Succeed()) // want `ginkgo-linter: Succeed matcher should be asserted against a function call; consider replacing with Expect\(wrap.err\).ToNot\(HaveOccurred\(\)\)`
// ginkgo-linter:ignore-succeed-warning
Expect(err0).ToNot(Succeed())

Expect(attemptToCallNetwork(false)).To(Succeed())
Expect(attemptToCallNetwork(true)).To(Not(Succeed()))
Expect(attemptToCallNetwork(false)).NotTo(Succeed())
Expect(returnsErr(false)).To(Succeed())
Expect(returnsErr(true)).To(Not(Succeed()))
Expect(returnsErr(false)).NotTo(Succeed())

Eventually(func() error {
return attemptToCallNetwork(false)
return returnsErr(false)
}).Should(Succeed())

ConsistentlyWithOffset(2, func() error {
return attemptToCallNetwork(false)
return returnsErr(false)
}).Should(Succeed())

Eventually(func() (int, error) { // want `ginkgo-linter: Succeed matcher must be asserted against a function that returns exactly one error`
return safeDivide(0, 1)
Eventually(func() (float64, error) { // want `ginkgo-linter: Succeed matcher must be asserted against a function that returns exactly one error`
return returnsFloatAndErr(1)
}).Should(Succeed())

Consistently(func() (int, error) { // want `ginkgo-linter: Succeed matcher must be asserted against a function that returns exactly one error`
return safeDivide(0, 0)
Consistently(func() (float64, error) { // want `ginkgo-linter: Succeed matcher must be asserted against a function that returns exactly one error`
return returnsFloatAndErr(0)
}).ShouldNot(Succeed())

Consistently(func() (int, error) { // want `ginkgo-linter: Succeed matcher must be asserted against a function that returns exactly one error`
return safeDivide(0, 0)
Consistently(func() (float64, error) { // want `ginkgo-linter: Succeed matcher must be asserted against a function that returns exactly one error`
return returnsFloatAndErr(0)
}).ShouldNot(Not(Succeed()))
})

0 comments on commit 9e0c14d

Please sign in to comment.