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

Unfocus command excludes vendor folder #459

Merged
merged 2 commits into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
2 changes: 1 addition & 1 deletion integration/fail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var _ = Describe("Failing Specs", func() {

BeforeEach(func() {
pathToTest = tmpPath("failing")
copyIn("fail_fixture", pathToTest)
copyIn(fixturePath("fail_fixture"), pathToTest, false)
})

It("should fail in all the possible ways", func() {
Expand Down
8 changes: 4 additions & 4 deletions integration/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var _ = Describe("Flags Specs", func() {

BeforeEach(func() {
pathToTest = tmpPath("flags")
copyIn("flags_tests", pathToTest)
copyIn(fixturePath("flags_tests"), pathToTest, false)
})

getRandomOrders := func(output string) []int {
Expand Down Expand Up @@ -158,7 +158,7 @@ var _ = Describe("Flags Specs", func() {

It("should fail fast when told to", func() {
pathToTest = tmpPath("fail")
copyIn("fail_fixture", pathToTest)
copyIn(fixturePath("fail_fixture"), pathToTest, false)
session := startGinkgo(pathToTest, "--failFast")
Eventually(session).Should(gexec.Exit(1))
output := string(session.Out.Contents())
Expand All @@ -181,7 +181,7 @@ var _ = Describe("Flags Specs", func() {

It("should perform a dry run when told to", func() {
pathToTest = tmpPath("fail")
copyIn("fail_fixture", pathToTest)
copyIn(fixturePath("fail_fixture"), pathToTest, false)
session := startGinkgo(pathToTest, "--dryRun", "-v")
Eventually(session).Should(gexec.Exit(0))
output := string(session.Out.Contents())
Expand All @@ -194,7 +194,7 @@ var _ = Describe("Flags Specs", func() {

regextest := func(regexOption string, skipOrFocus string) string {
pathToTest = tmpPath("passing")
copyIn("passing_ginkgo_tests", pathToTest)
copyIn(fixturePath("passing_ginkgo_tests"), pathToTest, false)
session := startGinkgo(pathToTest, regexOption, "--dryRun", "-v", skipOrFocus)
Eventually(session).Should(gexec.Exit(0))
return string(session.Out.Contents())
Expand Down
61 changes: 47 additions & 14 deletions integration/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,62 @@ func tmpPath(destination string) string {
return filepath.Join(tmpDir, destination)
}

func copyIn(fixture string, destination string) {
err := os.MkdirAll(destination, 0777)
Ω(err).ShouldNot(HaveOccurred())
func fixturePath(name string) string {
return filepath.Join("_fixtures", name)
}

func copyIn(sourcePath, destinationPath string, recursive bool) {
err := os.MkdirAll(destinationPath, 0777)
Expect(err).NotTo(HaveOccurred())

filepath.Walk(filepath.Join("_fixtures", fixture), func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
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() {
if recursive {
copyIn(srcPath, dstPath, recursive)
}
continue
}

base := filepath.Base(path)
src, err := os.Open(srcPath)

src, err := os.Open(path)
Ω(err).ShouldNot(HaveOccurred())
Expect(err).NotTo(HaveOccurred())
defer src.Close()

dst, err := os.Create(filepath.Join(destination, base))
Ω(err).ShouldNot(HaveOccurred())
dst, err := os.Create(dstPath)
Expect(err).NotTo(HaveOccurred())
defer dst.Close()

_, err = io.Copy(dst, src)
Ω(err).ShouldNot(HaveOccurred())
return nil
})
Expect(err).NotTo(HaveOccurred())
}
}

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 {
Expand Down
2 changes: 1 addition & 1 deletion integration/interrupt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var _ = Describe("Interrupt", func() {
var pathToTest string
BeforeEach(func() {
pathToTest = tmpPath("hanging")
copyIn("hanging_suite", pathToTest)
copyIn(fixturePath("hanging_suite"), pathToTest, false)
})

Context("when interrupting a suite", func() {
Expand Down
2 changes: 1 addition & 1 deletion integration/precompiled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ = Describe("ginkgo build", func() {

BeforeEach(func() {
pathToTest = tmpPath("passing_ginkgo_tests")
copyIn("passing_ginkgo_tests", pathToTest)
copyIn(fixturePath("passing_ginkgo_tests"), pathToTest, false)
session := startGinkgo(pathToTest, "build")
Eventually(session).Should(gexec.Exit(0))
output := string(session.Out.Contents())
Expand Down
2 changes: 1 addition & 1 deletion integration/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var _ = Describe("Emitting progress", func() {
BeforeEach(func() {
args = []string{"--noColor"}
pathToTest = tmpPath("progress")
copyIn("progress_fixture", pathToTest)
copyIn(fixturePath("progress_fixture"), pathToTest, false)
})

JustBeforeEach(func() {
Expand Down
Loading