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

ginkgo unfocus should not remove the actual ginkgo functions #424

Closed
nodo opened this issue Jan 26, 2018 · 3 comments
Closed

ginkgo unfocus should not remove the actual ginkgo functions #424

nodo opened this issue Jan 26, 2018 · 3 comments

Comments

@nodo
Copy link
Collaborator

nodo commented Jan 26, 2018

The problem

ginkgo unfocus replace every occurrence of a ginkgo component name with the component name without the F. For instance, every FDescribe in a project will be replaced with Describe. This is not usually a problem, however, when ginkgo appears in vendor/, unfocus changes the actual ginkgo functions, which is not desirable.

ginkgo unfocus uses gofmt -r to replace the occurrences of the focused components.
(https://github.com/onsi/ginkgo/blob/master/ginkgo/unfocus_command.go#L33). The problem appears because gofmt does not exclude vendor/ and recursively replace every occurrence of the component name.

Step to reproduce:

  1. Create a dummy main.go
  2. Create an example package
  3. Run ginkgo bootstrap and ginkgo generate
  4. Edit the test file so that ginkgo example run successfully
  5. Run dep init
  6. You should see ginkgo and gomega in the Gopkg.toml
  7. Run ginkgo unfocus

In a git project, this is the output:

$ git status
[...]
        modified:   vendor/github.com/onsi/ginkgo/ginkgo_dsl.go
        modified:   vendor/github.com/onsi/ginkgo/internal/remote/syscall_dup_linux_arm64.go
        modified:   vendor/github.com/onsi/ginkgo/internal/remote/syscall_dup_solaris.go
        modified:   vendor/github.com/onsi/ginkgo/internal/remote/syscall_dup_unix.go
$ git diff vendor/github.com/onsi/ginkgo/ginkgo_dsl.go
//You can focus the tests within a describe block using FDescribe
-func FDescribe(text string, body func()) bool {
+func Describe(text string, body func()) bool {
        globalSuite.PushContainerNode(text, body, types.FlagTypeFocused, codelocation.New(1))
        return true
 }
@@ -313,7 +313,7 @@ func Context(text string, body func()) bool {
 }

 //You can focus the tests within a describe block using FContext
-func FContext(text string, body func()) bool {
+func Context(text string, body func()) bool {
        globalSuite.PushContainerNode(text, body, types.FlagTypeFocused, codelocation.New(1))
        return true
 }
@@ -341,7 +341,7 @@ func It(text string, body interface{}, timeout ...float64) bool {
 }

 //You can focus individual Its using FIt
-func FIt(text string, body interface{}, timeout ...float64) bool {
+func It(text string, body interface{}, timeout ...float64) bool {
        globalSuite.PushItNode(text, body, types.FlagTypeFocused, codelocation.New(1), parseTimeout(timeout...))
        return true
 }
@@ -367,7 +367,7 @@ func Specify(text string, body interface{}, timeout ...float64) bool {

 //You can focus individual Specifys using FSpecify
 func FSpecify(text string, body interface{}, timeout ...float64) bool {
-       return FIt(text, body, timeout...)
+       return It(text, body, timeout...)
 }

 //You can mark Specifys as pending using PSpecify
@@ -412,7 +412,7 @@ func Measure(text string, body interface{}, samples int) bool {
 }

 //You can focus individual Measures using FMeasure
-func FMeasure(text string, body interface{}, samples int) bool {
+func Measure(text string, body interface{}, samples int) bool {
        globalSuite.PushMeasureNode(text, body, types.FlagTypeFocused, codelocation.New(1), samples)
        return true
 }

Possible solutions

  1. This issue could be fixed upstream, but it seems it has been abandoned (cmd/gofmt: ignore vendor directory golang/go#22173)
  2. Change unfocus to specifically ignore vendor/ (still calling gofmt)
  3. Change unfocus to specifically replace the ginkgo components in test files.
  4. Add an argument to unfocus allow to specify the directory. This would make explicit the "scope" of the unfocus command.

What do you think?

@nodo
Copy link
Collaborator Author

nodo commented Jan 26, 2018

I have seen the issue has been raised before #113 . The go fmt issue is open for quite some time now. Do you still think that we should wait?

@onsi
Copy link
Owner

onsi commented Jan 27, 2018

Option 2 makes sense to me @nodo - how much effort would it be?

@nodo
Copy link
Collaborator Author

nodo commented Jan 27, 2018

Sounds good to me. I'll give it a try, thanks @onsi!

nodo pushed a commit that referenced this issue Feb 25, 2018
nodo pushed a commit that referenced this issue Feb 25, 2018
nodo pushed a commit that referenced this issue Apr 17, 2018
nodo pushed a commit that referenced this issue Apr 19, 2018
blgm pushed a commit that referenced this issue Jul 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants