Skip to content

Commit

Permalink
ginkgo unfocus now removes Focus decorations
Browse files Browse the repository at this point in the history
  • Loading branch information
onsi committed Oct 11, 2021
1 parent d621736 commit ecfa6e1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
21 changes: 14 additions & 7 deletions ginkgo/unfocus/unfocus_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func writeBackup(path string, data []byte) (string, error) {
return t.Name(), nil
}

func updateFile(path string, data []byte, eliminations []int64) error {
func updateFile(path string, data []byte, eliminations [][]int64) error {
to, err := os.Create(path)
if err != nil {
return fmt.Errorf("error opening file for writing '%s': %w\n", path, err)
Expand All @@ -134,14 +134,15 @@ func updateFile(path string, data []byte, eliminations []int64) error {

from := bytes.NewReader(data)
var cursor int64
for _, byteToEliminate := range eliminations {
if _, err := io.CopyN(to, from, byteToEliminate-cursor); err != nil {
for _, eliminationRange := range eliminations {
positionToEliminate, lengthToEliminate := eliminationRange[0], eliminationRange[1]
if _, err := io.CopyN(to, from, positionToEliminate-cursor); err != nil {
return fmt.Errorf("error copying data: %w", err)
}

cursor = byteToEliminate + 1
cursor = positionToEliminate + lengthToEliminate

if _, err := from.Seek(1, io.SeekCurrent); err != nil {
if _, err := from.Seek(lengthToEliminate, io.SeekCurrent); err != nil {
return fmt.Errorf("error seeking to position in buffer: %w", err)
}
}
Expand All @@ -153,16 +154,22 @@ func updateFile(path string, data []byte, eliminations []int64) error {
return nil
}

func scanForFocus(file *ast.File) (eliminations []int64) {
func scanForFocus(file *ast.File) (eliminations [][]int64) {
ast.Inspect(file, func(n ast.Node) bool {
if c, ok := n.(*ast.CallExpr); ok {
if i, ok := c.Fun.(*ast.Ident); ok {
if isFocus(i.Name) {
eliminations = append(eliminations, int64(i.Pos()-file.Pos()))
eliminations = append(eliminations, []int64{int64(i.Pos() - file.Pos()), 1})
}
}
}

if i, ok := n.(*ast.Ident); ok {
if i.Name == "Focus" {
eliminations = append(eliminations, []int64{int64(i.Pos() - file.Pos()), 6})
}
}

return true
})

Expand Down
4 changes: 4 additions & 0 deletions integration/_fixtures/focused_fixture/focused_fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var _ = Describe("FocusedFixture", func() {

})

It("focused", Focus, func() {

})

FSpecify("focused", func() {

})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ var _ = Describe("FocusedFixture", func() {

})

It("focused", Focus, func() {

})

FSpecify("focused", func() {

})
Expand Down
3 changes: 0 additions & 3 deletions integration/integration_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ var _ = SynchronizedBeforeSuite(func() []byte {

var _ = BeforeEach(func() {
fm = NewFixtureManager(fmt.Sprintf("tmp_%d", GinkgoParallelNode()))
if !DEBUG {
DeferCleanup(fm.Cleanup)
}
})

var _ = AfterEach(func() {
Expand Down

0 comments on commit ecfa6e1

Please sign in to comment.