Skip to content

Commit

Permalink
Unfocus command ignores "vendor" folder
Browse files Browse the repository at this point in the history
Fixes #424
  • Loading branch information
Andrea Nodari authored and Andrea Nodari committed Apr 19, 2018
1 parent 5b0165e commit c556e43
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 5 deletions.
29 changes: 25 additions & 4 deletions ginkgo/unfocus_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os/exec"
"strings"
)

func BuildUnfocusCommand() *Command {
Expand Down Expand Up @@ -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))
}
}
}
1 change: 1 addition & 0 deletions integration/_fixtures/focused_fixture/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file should remain the same, regardless the fact that contains FIt, FDescribe, or FWhen.
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -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"),
)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package vendored

func FContext() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package vendored

func FIt() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package vendored

func FDescribe() int {
return 42
}
24 changes: 24 additions & 0 deletions integration/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 25 additions & 1 deletion integration/subcommand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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())
})
})

Expand Down

0 comments on commit c556e43

Please sign in to comment.