Skip to content

Commit

Permalink
fix: don't return error for generated files (#31)
Browse files Browse the repository at this point in the history
* feat: don't return error for generated files

* Update main.go

Signed-off-by: Nikolay Dubina <nikolay.dubina.pub@gmail.com>

---------

Signed-off-by: Nikolay Dubina <nikolay.dubina.pub@gmail.com>
Co-authored-by: Nikolay Dubina <nikolay.dubina.pub@gmail.com>
  • Loading branch information
matino and nikolaydubina authored Aug 8, 2024
1 parent 66fd9f3 commit 0b991c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"go/parser"
"go/token"
"io"
"log"
"os"

"github.com/nikolaydubina/go-instrument/instrument"
Expand Down Expand Up @@ -57,7 +58,8 @@ func process(fileName, app string, overwrite, defaultSelect, skipGenerated bool)
return err
}
if skipGenerated && ast.IsGenerated(file) {
return errors.New("skipping generated file")
log.Printf("skipping generated file: %s\n", fileName)
return nil
}

directives := processor.GoBuildDirectivesFromFile(*file)
Expand Down
6 changes: 3 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ func TestApp(t *testing.T) {
assertEqFile(t, "./internal/testdata/instrumented/basic_include_only.go.exp", f)
})

t.Run("when generated file, then err", func(t *testing.T) {
t.Run("when generated file, then ok", func(t *testing.T) {
cmd := exec.Command(testbin, "-app", "app", "-w", "-skip-generated=true", "-filename", "./internal/testdata/skipped_generated.go")
cmd.Env = append(cmd.Environ(), "GOCOVERDIR=./coverage")
out, err := cmd.CombinedOutput()
if err == nil {
t.Errorf("expected exit code 1")
if err != nil {
t.Errorf(err.Error())
}
if !strings.Contains(string(out), "skipping generated file") {
t.Errorf("expected skipping generated file")
Expand Down

0 comments on commit 0b991c9

Please sign in to comment.