diff --git a/ginkgo/unfocus_command.go b/ginkgo/unfocus_command.go index 203b039c2..cedc2b59c 100644 --- a/ginkgo/unfocus_command.go +++ b/ginkgo/unfocus_command.go @@ -3,7 +3,9 @@ package main import ( "flag" "fmt" + "io/ioutil" "os/exec" + "strings" ) func BuildUnfocusCommand() *Command { @@ -32,9 +34,28 @@ func unfocusSpecs([]string, []string) { func unfocus(component string) { fmt.Printf("Removing F%s...\n", component) - cmd := exec.Command("gofmt", fmt.Sprintf("-r=F%s -> %s", component, component), "-w", ".") - out, _ := cmd.CombinedOutput() - if string(out) != "" { - println(string(out)) + files, err := ioutil.ReadDir(".") + if err != nil { + fmt.Println(err.Error()) + return + } + for _, f := range files { + // Exclude "vendor" directory + if f.IsDir() && f.Name() == "vendor" { + continue + } + // Exclude non-go files in the current directory + if !f.IsDir() && !strings.HasSuffix(f.Name(), ".go") { + continue + } + // Recursively run `gofmt` otherwise + cmd := exec.Command("gofmt", fmt.Sprintf("-r=F%s -> %s", component, component), "-w", f.Name()) + out, err := cmd.CombinedOutput() + if err != nil { + fmt.Println(err.Error()) + } + if string(out) != "" { + fmt.Println(string(out)) + } } } diff --git a/integration/_fixtures/focused_fixture/README.md b/integration/_fixtures/focused_fixture/README.md new file mode 100644 index 000000000..2b501a25d --- /dev/null +++ b/integration/_fixtures/focused_fixture/README.md @@ -0,0 +1 @@ +This file should remain the same, regardless the fact that contains FIt, FDescribe, or FWhen. diff --git a/integration/_fixtures/focused_fixture_with_vendor/focused_fixture_suite_test.go b/integration/_fixtures/focused_fixture_with_vendor/focused_fixture_suite_test.go new file mode 100644 index 000000000..92d0c6e48 --- /dev/null +++ b/integration/_fixtures/focused_fixture_with_vendor/focused_fixture_suite_test.go @@ -0,0 +1,13 @@ +package focused_fixture_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "testing" +) + +func TestFocused_fixture(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Focused_fixture Suite") +} diff --git a/integration/_fixtures/focused_fixture_with_vendor/focused_fixture_test.go b/integration/_fixtures/focused_fixture_with_vendor/focused_fixture_test.go new file mode 100644 index 000000000..ea500eaf0 --- /dev/null +++ b/integration/_fixtures/focused_fixture_with_vendor/focused_fixture_test.go @@ -0,0 +1,73 @@ +package focused_fixture_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/ginkgo/extensions/table" +) + +var _ = Describe("FocusedFixture", func() { + FDescribe("focused", func() { + It("focused", func() { + + }) + }) + + FContext("focused", func() { + It("focused", func() { + + }) + }) + + FWhen("focused", func() { + It("focused", func() { + + }) + }) + + FIt("focused", func() { + + }) + + FSpecify("focused", func() { + + }) + + FMeasure("focused", func(b Benchmarker) { + + }, 2) + + FDescribeTable("focused", + func() {}, + Entry("focused"), + ) + + DescribeTable("focused", + func() {}, + FEntry("focused"), + ) + + Describe("not focused", func() { + It("not focused", func() { + + }) + }) + + Context("not focused", func() { + It("not focused", func() { + + }) + }) + + It("not focused", func() { + + }) + + Measure("not focused", func(b Benchmarker) { + + }, 2) + + DescribeTable("not focused", + func() {}, + Entry("not focused"), + ) +}) diff --git a/integration/_fixtures/focused_fixture_with_vendor/vendor/foo/bar/bar.go b/integration/_fixtures/focused_fixture_with_vendor/vendor/foo/bar/bar.go new file mode 100644 index 000000000..19a235363 --- /dev/null +++ b/integration/_fixtures/focused_fixture_with_vendor/vendor/foo/bar/bar.go @@ -0,0 +1,4 @@ +package vendored + +func FContext() { +} diff --git a/integration/_fixtures/focused_fixture_with_vendor/vendor/foo/foo.go b/integration/_fixtures/focused_fixture_with_vendor/vendor/foo/foo.go new file mode 100644 index 000000000..b51baadad --- /dev/null +++ b/integration/_fixtures/focused_fixture_with_vendor/vendor/foo/foo.go @@ -0,0 +1,4 @@ +package vendored + +func FIt() { +} diff --git a/integration/_fixtures/focused_fixture_with_vendor/vendor/vendored.go b/integration/_fixtures/focused_fixture_with_vendor/vendor/vendored.go new file mode 100644 index 000000000..9c9a546e3 --- /dev/null +++ b/integration/_fixtures/focused_fixture_with_vendor/vendor/vendored.go @@ -0,0 +1,5 @@ +package vendored + +func FDescribe() int { + return 42 +} diff --git a/integration/integration_suite_test.go b/integration/integration_suite_test.go index b2e113b92..0a8fac44c 100644 --- a/integration/integration_suite_test.go +++ b/integration/integration_suite_test.go @@ -85,6 +85,30 @@ func copyIn(sourcePath, destinationPath string, recursive bool) { } } +func sameFile(filePath, otherFilePath string) bool { + content, readErr := ioutil.ReadFile(filePath) + Expect(readErr).NotTo(HaveOccurred()) + otherContent, readErr := ioutil.ReadFile(otherFilePath) + Expect(readErr).NotTo(HaveOccurred()) + Expect(string(content)).To(Equal(string(otherContent))) + return true +} + +func sameFolder(sourcePath, destinationPath string) bool { + files, err := ioutil.ReadDir(sourcePath) + Expect(err).NotTo(HaveOccurred()) + for _, f := range files { + srcPath := filepath.Join(sourcePath, f.Name()) + dstPath := filepath.Join(destinationPath, f.Name()) + if f.IsDir() { + sameFolder(srcPath, dstPath) + continue + } + Expect(sameFile(srcPath, dstPath)).To(BeTrue()) + } + return true +} + func ginkgoCommand(dir string, args ...string) *exec.Cmd { cmd := exec.Command(pathToGinkgo, args...) cmd.Dir = dir diff --git a/integration/subcommand_test.go b/integration/subcommand_test.go index aa808a00e..fec197f56 100644 --- a/integration/subcommand_test.go +++ b/integration/subcommand_test.go @@ -348,7 +348,8 @@ var _ = Describe("Subcommand", func() { Describe("ginkgo blur", func() { It("should unfocus tests", func() { pathToTest := tmpPath("focused") - copyIn(fixturePath("focused_fixture"), pathToTest, false) + fixture := fixturePath("focused_fixture") + copyIn(fixture, pathToTest, false) session := startGinkgo(pathToTest, "--noColor") Eventually(session).Should(gexec.Exit(types.GINKGO_FOCUS_EXIT_CODE)) @@ -359,12 +360,35 @@ var _ = Describe("Subcommand", func() { session = startGinkgo(pathToTest, "blur") Eventually(session).Should(gexec.Exit(0)) + output = session.Out.Contents() + Ω(string(output)).ShouldNot(ContainSubstring("expected 'package'")) session = startGinkgo(pathToTest, "--noColor") Eventually(session).Should(gexec.Exit(0)) output = session.Out.Contents() Ω(string(output)).Should(ContainSubstring("13 Passed")) Ω(string(output)).Should(ContainSubstring("0 Skipped")) + + Expect(sameFile(filepath.Join(pathToTest, "README.md"), filepath.Join(fixture, "README.md"))).To(BeTrue()) + }) + + It("should ignore the 'vendor' folder", func() { + pathToTest := tmpPath("focused_fixture_with_vendor") + copyIn(fixturePath("focused_fixture_with_vendor"), pathToTest, true) + + session := startGinkgo(pathToTest, "blur") + Eventually(session).Should(gexec.Exit(0)) + + session = startGinkgo(pathToTest, "--noColor") + Eventually(session).Should(gexec.Exit(0)) + output := session.Out.Contents() + Expect(string(output)).To(ContainSubstring("13 Passed")) + Expect(string(output)).To(ContainSubstring("0 Skipped")) + + vendorPath := fixturePath("focused_fixture_with_vendor/vendor") + otherVendorPath := filepath.Join(pathToTest, "vendor") + + Expect(sameFolder(vendorPath, otherVendorPath)).To(BeTrue()) }) })