|
| 1 | +//golangcitest:args --disable-all -Eginkgolinter |
| 2 | +//golangcitest:config_path configs/ginkgolinter_suppress_focused_containers.yml |
| 3 | +package ginkgolinter |
| 4 | + |
| 5 | +import ( |
| 6 | + "errors" |
| 7 | + "time" |
| 8 | + |
| 9 | + . "github.com/onsi/ginkgo/v2" |
| 10 | + . "github.com/onsi/gomega" |
| 11 | +) |
| 12 | + |
| 13 | +func LenUsecase_focus() { |
| 14 | + var fakeVarUnderTest []int |
| 15 | + Expect(fakeVarUnderTest).Should(BeEmpty()) // valid |
| 16 | + Expect(fakeVarUnderTest).ShouldNot(HaveLen(5)) // valid |
| 17 | + |
| 18 | + Expect(len(fakeVarUnderTest)).Should(Equal(0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.Should\\(BeEmpty\\(\\)\\). instead" |
| 19 | + Expect(len(fakeVarUnderTest)).ShouldNot(Equal(2)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ShouldNot\\(HaveLen\\(2\\)\\). instead" |
| 20 | + Expect(len(fakeVarUnderTest)).To(BeNumerically("==", 0)) // // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.To\\(BeEmpty\\(\\)\\). instead" |
| 21 | + |
| 22 | + fakeVarUnderTest = append(fakeVarUnderTest, 3) |
| 23 | + Expect(len(fakeVarUnderTest)).ShouldNot(Equal(0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ShouldNot\\(BeEmpty\\(\\)\\). instead" |
| 24 | + Expect(len(fakeVarUnderTest)).Should(Equal(1)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.Should\\(HaveLen\\(1\\)\\). instead" |
| 25 | + Expect(len(fakeVarUnderTest)).To(BeNumerically(">", 0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ToNot\\(BeEmpty\\(\\)\\). instead" |
| 26 | + Expect(len(fakeVarUnderTest)).To(BeNumerically(">=", 1)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ToNot\\(BeEmpty\\(\\)\\). instead" |
| 27 | + Expect(len(fakeVarUnderTest)).To(BeNumerically("!=", 0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(fakeVarUnderTest\\)\\.ToNot\\(BeEmpty\\(\\)\\). instead" |
| 28 | +} |
| 29 | + |
| 30 | +func NilUsecase_focus() { |
| 31 | + y := 5 |
| 32 | + x := &y |
| 33 | + Expect(x == nil).To(Equal(true)) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.To\\(BeNil\\(\\)\\). instead" |
| 34 | + Expect(nil == x).To(Equal(true)) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.To\\(BeNil\\(\\)\\). instead" |
| 35 | + Expect(x != nil).To(Equal(true)) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.ToNot\\(BeNil\\(\\)\\). instead" |
| 36 | + Expect(x == nil).To(BeTrue()) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.To\\(BeNil\\(\\)\\). instead" |
| 37 | + Expect(x == nil).To(BeFalse()) // want "ginkgo-linter: wrong nil assertion; consider using .Expect\\(x\\)\\.ToNot\\(BeNil\\(\\)\\). instead" |
| 38 | +} |
| 39 | +func BooleanUsecase_focus() { |
| 40 | + x := true |
| 41 | + Expect(x).To(Equal(true)) // want "ginkgo-linter: wrong boolean assertion; consider using .Expect\\(x\\)\\.To\\(BeTrue\\(\\)\\). instead" |
| 42 | + x = false |
| 43 | + Expect(x).To(Equal(false)) // want "ginkgo-linter: wrong boolean assertion; consider using .Expect\\(x\\)\\.To\\(BeFalse\\(\\)\\). instead" |
| 44 | +} |
| 45 | + |
| 46 | +func ErrorUsecase_focus() { |
| 47 | + err := errors.New("fake error") |
| 48 | + funcReturnsErr := func() error { return err } |
| 49 | + |
| 50 | + Expect(err).To(BeNil()) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(err\\)\\.ToNot\\(HaveOccurred\\(\\)\\). instead" |
| 51 | + Expect(err == nil).To(Equal(true)) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(err\\)\\.ToNot\\(HaveOccurred\\(\\)\\). instead" |
| 52 | + Expect(err == nil).To(BeFalse()) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(err\\)\\.To\\(HaveOccurred\\(\\)\\). instead" |
| 53 | + Expect(err != nil).To(BeTrue()) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(err\\)\\.To\\(HaveOccurred\\(\\)\\). instead" |
| 54 | + Expect(funcReturnsErr()).To(BeNil()) // want "ginkgo-linter: wrong error assertion; consider using .Expect\\(funcReturnsErr\\(\\)\\)\\.To\\(Succeed\\(\\)\\). instead" |
| 55 | +} |
| 56 | + |
| 57 | +func HaveLen0Usecase_focus() { |
| 58 | + x := make([]string, 0) |
| 59 | + Expect(x).To(HaveLen(0)) // want "ginkgo-linter: wrong length assertion; consider using .Expect\\(x\\)\\.To\\(BeEmpty\\(\\)\\). instead" |
| 60 | +} |
| 61 | + |
| 62 | +func WrongComparisonUsecase_focus() { |
| 63 | + x := 8 |
| 64 | + Expect(x == 8).To(BeTrue()) // want "ginkgo-linter: wrong comparison assertion; consider using .Expect\\(x\\)\\.To\\(Equal\\(8\\)\\). instead" |
| 65 | + Expect(x < 9).To(BeTrue()) // want "ginkgo-linter: wrong comparison assertion; consider using .Expect\\(x\\)\\.To\\(BeNumerically\\(\"<\", 9\\)\\). instead" |
| 66 | + Expect(x < 7).To(Equal(false)) // want "ginkgo-linter: wrong comparison assertion; consider using .Expect\\(x\\)\\.ToNot\\(BeNumerically\\(\"<\", 7\\)\\). instead" |
| 67 | + |
| 68 | + p1, p2 := &x, &x |
| 69 | + Expect(p1 == p2).To(Equal(true)) // want "ginkgo-linter: wrong comparison assertion; consider using .Expect\\(p1\\).To\\(BeIdenticalTo\\(p2\\)\\). instead" |
| 70 | +} |
| 71 | + |
| 72 | +func slowInt_focus() int { |
| 73 | + time.Sleep(time.Second) |
| 74 | + return 42 |
| 75 | +} |
| 76 | + |
| 77 | +func WrongEventuallyWithFunction_focus() { |
| 78 | + Eventually(slowInt_focus).Should(Equal(42)) // valid |
| 79 | + Eventually(slowInt_focus()).Should(Equal(42)) // want "ginkgo-linter: use a function call in Eventually. This actually checks nothing, because Eventually receives the function returned value, instead of function itself, and this value is never changed; consider using .Eventually\\(slowInt_focus\\)\\.Should\\(Equal\\(42\\)\\). instead" |
| 80 | +} |
| 81 | + |
| 82 | +var _ = FDescribe("Should warn for focused containers", func() { |
| 83 | + FContext("should not allow FContext", func() { |
| 84 | + FWhen("should not allow FWhen", func() { |
| 85 | + FIt("should not allow FIt", func() { |
| 86 | + |
| 87 | + }) |
| 88 | + }) |
| 89 | + }) |
| 90 | +}) |
0 commit comments