Skip to content

Commit

Permalink
Add test for gobco.instrument
Browse files Browse the repository at this point in the history
  • Loading branch information
rillig committed Jul 27, 2019
1 parent 62ee795 commit 953de4c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
14 changes: 14 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"gopkg.in/check.v1"
"path/filepath"
)

func (s *Suite) Test_gobco_parseCommandLine(c *check.C) {
Expand Down Expand Up @@ -60,3 +61,16 @@ func (s *Suite) Test_gobco_parseCommandLine__two_packages(c *check.C) {
"src/github.com/rillig/gobco/pkg1",
"src/github.com/rillig/gobco/pkg2"})
}

func (s *Suite) Test_gobco_instrument__gobco_files(c *check.C) {
var g gobco
g.parseCommandLine([]string{"gobco", "sample"})
g.prepareTmpEnv()
g.instrument()

c.Check(listRegularFiles(filepath.Join(g.tmpdir, g.tmpItems[0])), check.DeepEquals, []string{
"foo.go",
"foo_test.go",
"gobco.go",
"gobco_test.go"})
}
26 changes: 26 additions & 0 deletions util_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"os"
"path/filepath"
"strings"
)

func listRegularFiles(basedir string) []string {
var files []string

err := filepath.Walk(basedir, func(path string, info os.FileInfo, err error) error {
if err == nil && info.Mode().IsRegular() {
rel := strings.TrimPrefix(path, basedir)
slashed := filepath.ToSlash(rel)
files = append(files, strings.TrimPrefix(slashed, "/"))
}
return err
})

if err != nil {
panic(err)
}

return files
}

0 comments on commit 953de4c

Please sign in to comment.