Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7965151

Browse files
committed
gpython: add code coverage support
1 parent 12248b4 commit 7965151

File tree

3 files changed

+114
-10
lines changed

3 files changed

+114
-10
lines changed

.travis.yml

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
language: go
22
sudo: false
33
dist: trusty
4+
45
os:
5-
- linux
6+
- linux
7+
68
go:
7-
- 1.8.x
8-
- 1.9.x
9-
- 1.10.x
10-
- master
11-
script:
12-
- go test ./...
13-
- GOARCH=386 go test ./...
9+
- 1.8.x
10+
- 1.9.x
11+
- 1.10.x
12+
- master
13+
1414
matrix:
15-
allow_failures:
16-
- go: master
15+
fast_finish: true
16+
allow_failures:
17+
- go: master
18+
19+
script:
20+
- go install -v $TAGS ./...
21+
- GOARCH=amd64 go run ./ci/run-tests.go -race -cover $TAGS
22+
- GOARCH=386 go run ./ci/run-tests.go -race -cover $TAGS
23+
24+
after_success:
25+
- bash <(curl -s https://codecov.io/bash)

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# gpython
22

33
[![Build Status](https://travis-ci.org/go-python/gpython.svg?branch=master)](https://travis-ci.org/go-python/gpython)
4+
[![codecov](https://codecov.io/gh/github.com/go-python/gpython/branch/master/graph/badge.svg)](https://codecov.io/gh/github.com/go-python/gpython)
45
[![GoDoc](https://godoc.org/github.com/go-python/gpython?status.svg)](https://godoc.org/github.com/go-python/gpython)
56

67
gpython is a part re-implementation / part port of the Python 3.4

ci/run-tests.go

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright 2018 The go-python Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build ignore
6+
7+
package main
8+
9+
import (
10+
"bufio"
11+
"bytes"
12+
"flag"
13+
"io/ioutil"
14+
"log"
15+
"os"
16+
"os/exec"
17+
"strings"
18+
)
19+
20+
func main() {
21+
log.SetPrefix("ci: ")
22+
log.SetFlags(0)
23+
24+
var (
25+
race = flag.Bool("race", false, "enable race detector")
26+
cover = flag.Bool("cover", false, "enable code coverage")
27+
tags = flag.String("tags", "", "build tags")
28+
)
29+
30+
flag.Parse()
31+
32+
out := new(bytes.Buffer)
33+
cmd := exec.Command("go", "list", "./...")
34+
cmd.Stdout = out
35+
cmd.Stderr = os.Stderr
36+
cmd.Stdin = os.Stdin
37+
38+
err := cmd.Run()
39+
if err != nil {
40+
log.Fatal(err)
41+
}
42+
43+
f, err := os.Create("coverage.txt")
44+
if err != nil {
45+
log.Fatal(err)
46+
}
47+
defer f.Close()
48+
49+
args := []string{"test"}
50+
51+
if *cover {
52+
args = append(args, "-coverprofile=profile.out", "-covermode=atomic")
53+
}
54+
if *tags != "" {
55+
args = append(args, "-tags="+*tags)
56+
}
57+
if *race {
58+
args = append(args, "-race")
59+
}
60+
args = append(args, "")
61+
62+
scan := bufio.NewScanner(out)
63+
for scan.Scan() {
64+
pkg := scan.Text()
65+
if strings.Contains(pkg, "vendor") {
66+
continue
67+
}
68+
args[len(args)-1] = pkg
69+
cmd := exec.Command("go", args...)
70+
cmd.Stdin = os.Stdin
71+
cmd.Stdout = os.Stdout
72+
cmd.Stderr = os.Stderr
73+
err := cmd.Run()
74+
if err != nil {
75+
log.Fatal(err)
76+
}
77+
if *cover {
78+
profile, err := ioutil.ReadFile("profile.out")
79+
if err != nil {
80+
log.Fatal(err)
81+
}
82+
_, err = f.Write(profile)
83+
if err != nil {
84+
log.Fatal(err)
85+
}
86+
os.Remove("profile.out")
87+
}
88+
}
89+
90+
err = f.Close()
91+
if err != nil {
92+
log.Fatal(err)
93+
}
94+
}

0 commit comments

Comments
 (0)