Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Track location of focused specs correctly in unfocus
`ginkgo unfocus` was, previously, incorrectly computing the offset for the token to remove.  This generally only failed if there was a comment (or build tag) _before_ the `package ...` declaration in the spec file.

Fixed #899
  • Loading branch information
onsi committed Feb 11, 2022
1 parent 8fbfa02 commit a612ff1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ginkgo/unfocus/unfocus_command.go
Expand Up @@ -84,7 +84,7 @@ func unfocusFile(path string) {
return
}

ast, err := parser.ParseFile(token.NewFileSet(), path, bytes.NewReader(data), 0)
ast, err := parser.ParseFile(token.NewFileSet(), path, bytes.NewReader(data), parser.ParseComments)
if err != nil {
fmt.Printf("error parsing file '%s': %s\n", path, err.Error())
return
Expand Down Expand Up @@ -135,7 +135,7 @@ func updateFile(path string, data []byte, eliminations [][]int64) error {
from := bytes.NewReader(data)
var cursor int64
for _, eliminationRange := range eliminations {
positionToEliminate, lengthToEliminate := eliminationRange[0], eliminationRange[1]
positionToEliminate, lengthToEliminate := eliminationRange[0]-1, eliminationRange[1]
if _, err := io.CopyN(to, from, positionToEliminate-cursor); err != nil {
return fmt.Errorf("error copying data: %w", err)
}
Expand All @@ -159,14 +159,14 @@ func scanForFocus(file *ast.File) (eliminations [][]int64) {
if c, ok := n.(*ast.CallExpr); ok {
if i, ok := c.Fun.(*ast.Ident); ok {
if isFocus(i.Name) {
eliminations = append(eliminations, []int64{int64(i.Pos() - file.Pos()), 1})
eliminations = append(eliminations, []int64{int64(i.Pos()), 1})
}
}
}

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

Expand Down
2 changes: 2 additions & 0 deletions integration/_fixtures/focused_fixture/focused_fixture_test.go
@@ -1,3 +1,5 @@
// some long comment that might actually break things if we aren't careful

package focused_fixture_test

import (
Expand Down

0 comments on commit a612ff1

Please sign in to comment.