diff --git a/main_test.go b/main_test.go index 4bed922..292a20f 100644 --- a/main_test.go +++ b/main_test.go @@ -2,6 +2,7 @@ package main import ( "gopkg.in/check.v1" + "path/filepath" ) func (s *Suite) Test_gobco_parseCommandLine(c *check.C) { @@ -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"}) +} diff --git a/util_test.go b/util_test.go new file mode 100644 index 0000000..f3ee583 --- /dev/null +++ b/util_test.go @@ -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 +}