Skip to content

ci: add code coverage #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
language: go
sudo: false
dist: trusty

os:
- linux
go:
- 1.8.7
- 1.9.3
- "1.10.1"
- tip
script:
- go test ./...
- GOARCH=386 go test ./...
- linux

env:
- TAGS="-tags travis"

matrix:
allow_failures:
- go: tip
fast_finish: true
allow_failures:
- go: master
include:
- go: 1.8.x
env:
- TAGS="-tags travis"
- go: 1.9.x
env:
- TAGS="-tags travis"
- go: 1.10.x
env:
- TAGS="-tags travis"
- COVERAGE="-cover"
- go: master
env:
- TAGS="-tags travis"

script:
- go install -v $TAGS ./...
- GOARCH=386 go test $TAGS ./...
- GOARCH=amd64 go run ./ci/run-tests.go -race $TAGS $COVERAGE

after_success:
- bash <(curl -s https://codecov.io/bash)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# gpython

[![Build Status](https://travis-ci.org/go-python/gpython.svg?branch=master)](https://travis-ci.org/go-python/gpython)
[![codecov](https://codecov.io/gh/go-python/gpython/branch/master/graph/badge.svg)](https://codecov.io/gh/go-python/gpython)
[![GoDoc](https://godoc.org/github.com/go-python/gpython?status.svg)](https://godoc.org/github.com/go-python/gpython)
[![License](https://img.shields.io/badge/License-BSD--3-blue.svg)](https://github.com/go-python/gpython/blob/master/LICENSE)

gpython is a part re-implementation / part port of the Python 3.4
interpreter to the Go language, "batteries not included".
Expand Down
19 changes: 19 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
build: off

clone_folder: c:\gopath\src\github.com\go-python\gpython

branches:
only:
- master

environment:
GOPATH: c:\gopath
PATH: '%GOPATH%\bin;%PATH%'

stack: go 1.10

build_script:
- go get -v -t -race ./...

test_script:
- go test -race ./...
94 changes: 94 additions & 0 deletions ci/run-tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Copyright 2018 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// +build ignore

package main

import (
"bufio"
"bytes"
"flag"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"
)

func main() {
log.SetPrefix("ci: ")
log.SetFlags(0)

var (
race = flag.Bool("race", false, "enable race detector")
cover = flag.Bool("cover", false, "enable code coverage")
tags = flag.String("tags", "", "build tags")
)

flag.Parse()

out := new(bytes.Buffer)
cmd := exec.Command("go", "list", "./...")
cmd.Stdout = out
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin

err := cmd.Run()
if err != nil {
log.Fatal(err)
}

f, err := os.Create("coverage.txt")
if err != nil {
log.Fatal(err)
}
defer f.Close()

args := []string{"test"}

if *cover {
args = append(args, "-coverprofile=profile.out", "-covermode=atomic")
}
if *tags != "" {
args = append(args, "-tags="+*tags)
}
if *race {
args = append(args, "-race")
}
args = append(args, "")

scan := bufio.NewScanner(out)
for scan.Scan() {
pkg := scan.Text()
if strings.Contains(pkg, "vendor") {
continue
}
args[len(args)-1] = pkg
cmd := exec.Command("go", args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
if *cover {
profile, err := ioutil.ReadFile("profile.out")
if err != nil {
log.Fatal(err)
}
_, err = f.Write(profile)
if err != nil {
log.Fatal(err)
}
os.Remove("profile.out")
}
}

err = f.Close()
if err != nil {
log.Fatal(err)
}
}
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module github.com/go-python/gpython

require (
github.com/mattn/go-runewidth v0.0.3 // indirect
github.com/peterh/liner v0.0.0-20180619022028-8c1271fcf47f
)