Permalink
Browse files

Allow separation of coverage run from push to coveralls

  • Loading branch information...
1 parent 86ca61e commit a90b49ae66b3f1faea21158517f5fb6f3ae38fe6 @dustin dustin committed Nov 17, 2013
Showing with 30 additions and 3 deletions.
  1. +12 −3 goveralls.go
  2. +17 −0 goveralls_test.go
  3. +1 −0 tester/cov.json
View
@@ -30,8 +30,9 @@ import (
*/
var (
- pkg = flag.String("package", "", "Go package")
- verbose = flag.Bool("v", false, "Pass '-v' argument to 'gocov test'")
+ pkg = flag.String("package", "", "Go package")
+ verbose = flag.Bool("v", false, "Pass '-v' argument to 'gocov test'")
+ gocovjson = flag.String("gocovdata", "", "If supplied, use existing gocov.json")
)
// usage supplants package flag's Usage variable
@@ -172,7 +173,7 @@ func collectGitInfo() *Git {
return &g
}
-func loadCoverage() (io.ReadCloser, error) {
+func runGocov() (io.ReadCloser, error) {
cmd := exec.Command("gocov")
args := []string{"gocov", "test"}
if *verbose {
@@ -191,6 +192,14 @@ func loadCoverage() (io.ReadCloser, error) {
return ioutil.NopCloser(bytes.NewReader(ret)), nil
}
+func loadCoverage() (io.ReadCloser, error) {
+ if *gocovjson == "" {
+ return runGocov()
+ } else {
+ return os.Open(*gocovjson)
+ }
+}
+
func main() {
log.SetFlags(log.Ltime | log.Lshortfile)
//
View
@@ -47,6 +47,23 @@ func TestGoveralls(t *testing.T) {
}
}
+func TestGoverallsExisting(t *testing.T) {
+ p := myImportPath()
+ t.Logf("My import path is %q", p)
+
+ tmp := prepareTest(t)
+ defer os.RemoveAll(tmp)
+ runCmd(t, "go", "get", p+"/tester")
+ runCmd(t, "go", "get", "github.com/axw/gocov/gocov")
+ b := runCmd(t, "goveralls", "-gocovdata=tester/cov.json",
+ "-package="+p+"/tester", "")
+ lines := strings.Split(strings.TrimSpace(string(b)), "\n")
+ s := lines[len(lines)-1]
+ if s != "Succeeded" {
+ t.Fatalf("Expected test of tester are succeeded, but failured")
+ }
+}
+
func prepareTest(t *testing.T) (tmpPath string) {
tmp := os.TempDir()
tmp = filepath.Join(tmp, uuid.New())
View
@@ -0,0 +1 @@
+{"Packages":[{"Name":"github.com/dustin/goveralls/tester","Functions":[{"Name":"GoverallsTester","File":"/Users/dustin/go/src/github.com/dustin/goveralls/tester/tester.go","Start":34,"End":150,"Statements":[{"Start":67,"End":101,"Reached":1},{"Start":103,"End":138,"Reached":1},{"Start":118,"End":135,"Reached":1},{"Start":140,"End":148,"Reached":1}],"Entered":0,"Left":0}]}]}

0 comments on commit a90b49a

Please sign in to comment.