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

[Bug] --focus handles some regexes incorrectly #1126

Open
meln5674 opened this issue Jan 30, 2023 · 1 comment
Open

[Bug] --focus handles some regexes incorrectly #1126

meln5674 opened this issue Jan 30, 2023 · 1 comment

Comments

@meln5674
Copy link

Given

package test_test

import (
	"testing"

	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"
)

func TestTest(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Test Suite")
}

var _ = Describe("foo", func() {
	It("should print foo", func() {
		GinkgoWriter.Println("foo")
	})
})

var _ = Describe("foobar", func() {
	It("should print foobar", func() {
		GinkgoWriter.Println("foobar")
	})
})

running

ginkgo run -v --focus 'foo' .

produces

Running Suite: Test Suite - /home/andrew/git/src/github.com/meln5674/test
==============================================================================
Random Seed: 1675107707

Will run 2 of 2 specs
------------------------------
foo should print foo
/home/andrew/git/src/github.com/meln5674/test/test_suite_test.go:16
  foo
• [0.000 seconds]
------------------------------
foobar should print foobar
/home/andrew/git/src/github.com/meln5674/test/test_suite_test.go:22
  foobar
• [0.000 seconds]
------------------------------

Ran 2 of 2 Specs in 0.000 seconds
SUCCESS! -- 2 Passed | 0 Failed | 0 Pending | 0 Skipped
PASS

Ginkgo ran 1 suite in 665.589296ms
Test Suite Passed

while running

ginkgo run -v --focus '^foo$' .

produces

Running Suite: Test Suite - /home/andrew/git/src/github.com/meln5674/test
==============================================================================
Random Seed: 1675107815

Will run 0 of 2 specs
SS

Ran 0 of 2 Specs in 0.000 seconds
SUCCESS! -- 0 Passed | 0 Failed | 0 Pending | 2 Skipped
PASS

Ginkgo ran 1 suite in 723.955755ms
Test Suite Passed

There doesn't appear to be a way to run foo but not foobar using --focus.

@onsi
Copy link
Owner

onsi commented Jan 30, 2023

hey - thanks for posting this here in addition to slack.

It took me a minute to recall why this wouldn't work, but - in short: when given a --focus filter Ginkgo will apply the regexp to the "full text" of a spec, which is the concatenation of the container strings + spec string. In this case there are two specs with full texts that look like:

"foo it should print foo"
"foobar should print foobar"

The regexp foo matches both of these. but ^foo$ matches neither.

I looked into it and, thankfully, you can use the word boundary regexp to require matching specs to strictly contain only foo:

ginkgo run -v --focus '\bfoo\b'

produces

Running Suite: Bar Suite - /Users/onsi/code/ginkgo/bar
======================================================
Random Seed: 1675108347

Will run 1 of 2 specs
------------------------------
foo should print foo
/Users/onsi/code/ginkgo/bar/bar_suite_test.go:16
  foo
• [0.000 seconds]
------------------------------
S

Ran 1 of 2 Specs in 0.001 seconds
SUCCESS! -- 1 Passed | 0 Failed | 0 Pending | 1 Skipped
PASS

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

No branches or pull requests

2 participants