Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MessageWithDiff panics when the message is too long #401

Closed
mvladev opened this issue Nov 25, 2020 · 0 comments · Fixed by #402
Closed

MessageWithDiff panics when the message is too long #401

mvladev opened this issue Nov 25, 2020 · 0 comments · Fixed by #402

Comments

@mvladev
Copy link
Contributor

mvladev commented Nov 25, 2020

When running the following test

It("handles negative padding length", func() {
	stringWithB := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	stringWithZ := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
	longMessage := "to equal very long message"

	Expect(MessageWithDiff(stringWithB, longMessage, stringWithZ)).Should(Equal(expectedDiffLongMessage))
})

It panics with:

•! Panic [0.000 seconds]
Format
/gopath/github.com/gomega/format/format_test.go:95
  MessageWithDiff
  /gopath/github.com/gomega/format/format_test.go:133
    handles negative padding length [It]
    /gopath/github.com/gomega/format/format_test.go:177

    Test Panicked
    strings: negative Repeat count
    /usr/local/opt/go/libexec/src/strings/strings.go:529

    Full Stack Trace
    strings.Repeat(0x13bd790, 0x1, 0xfffffffffffffffd, 0x13, 0x9)
        /usr/local/opt/go/libexec/src/strings/strings.go:529 +0x5e5
    github.com/onsi/gomega/format.MessageWithDiff(0x13d9f7d, 0x65, 0x13cbbf7, 0x1a, 0x13d9eb3, 0x65, 0xc00039e001, 0x3f)
        /gopath/github.com/gomega/format/format.go:108 +0x3d7
    github.com/onsi/gomega/format_test.glob..func1.5.7()
        /gopath/github.com/gomega/format/format_test.go:182 +0x65
    github.com/onsi/ginkgo/internal/leafnodes.(*runner).runSync(0xc000028de0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /gopath/go/pkg/mod/github.com/onsi/[email protected]/internal/leafnodes/runner.go:113 +0xa3
    github.com/onsi/ginkgo/internal/leafnodes.(*runner).run(0xc000028de0, 0xc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /gopath/go/pkg/mod/github.com/onsi/[email protected]/internal/leafnodes/runner.go:64 +0xd7
    github.com/onsi/ginkgo/internal/leafnodes.(*ItNode).Run(0xc00000eec0, 0x1434600, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /gopath/go/pkg/mod/github.com/onsi/[email protected]/internal/leafnodes/it_node.go:26 +0x67
    github.com/onsi/ginkgo/internal/spec.(*Spec).runSample(0xc00035e870, 0x0, 0x1434600, 0xc000076900)
        /gopath/go/pkg/mod/github.com/onsi/[email protected]/internal/spec/spec.go:215 +0x691
    github.com/onsi/ginkgo/internal/spec.(*Spec).Run(0xc00035e870, 0x1434600, 0xc000076900)
        /gopath/go/pkg/mod/github.com/onsi/[email protected]/internal/spec/spec.go:138 +0xf2
    github.com/onsi/ginkgo/internal/specrunner.(*SpecRunner).runSpec(0xc0003272c0, 0xc00035e870, 0x8)
        /gopath/go/pkg/mod/github.com/onsi/[email protected]/internal/specrunner/spec_runner.go:200 +0x111
    github.com/onsi/ginkgo/internal/specrunner.(*SpecRunner).runSpecs(0xc0003272c0, 0x1)
        /gopath/go/pkg/mod/github.com/onsi/[email protected]/internal/specrunner/spec_runner.go:170 +0x127
    github.com/onsi/ginkgo/internal/specrunner.(*SpecRunner).Run(0xc0003272c0, 0xc00028d868)
        /gopath/go/pkg/mod/github.com/onsi/[email protected]/internal/specrunner/spec_runner.go:66 +0x117
    github.com/onsi/ginkgo/internal/suite.(*Suite).Run(0xc000100280, 0x1dbe160, 0xc00035c000, 0x13c4138, 0xc, 0xc00031e9a0, 0x1, 0x1, 0x143bca0, 0xc000076900, ...)
        /gopath/go/pkg/mod/github.com/onsi/[email protected]/internal/suite/suite.go:62 +0x426
    github.com/onsi/ginkgo.RunSpecsWithCustomReporters(0x1434ac0, 0xc00035c000, 0x13c4138, 0xc, 0xc00004c728, 0x1, 0x1, 0x100ff58)
        /gopath/go/pkg/mod/github.com/onsi/[email protected]/ginkgo_dsl.go:226 +0x238
    github.com/onsi/ginkgo.RunSpecs(0x1434ac0, 0xc00035c000, 0x13c4138, 0xc, 0x135e7b80655bf)
        /gopath/go/pkg/mod/github.com/onsi/[email protected]/ginkgo_dsl.go:207 +0x168
    github.com/onsi/gomega/format_test.TestFormat(0xc00035c000)
        /gopath/github.com/gomega/format/format_suite_test.go:12 +0x98
    testing.tRunner(0xc00035c000, 0x13e3308)
        /usr/local/opt/go/libexec/src/testing/testing.go:1123 +0xef
    created by testing.(*T).Run
        /usr/local/opt/go/libexec/src/testing/testing.go:1168 +0x2b3

The problem is that string.Repeat panics when count is negative which happens because the length of the message is longer than than 14:

gomega/format/format.go

Lines 106 to 108 in df70182

tabLength := 4
spaceFromMessageToActual := tabLength + len("<string>: ") - len(message)
padding := strings.Repeat(" ", spaceFromMessageToActual+spacesBeforeFormattedMismatch) + "|"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant