From bbfd1dd0c01e0e120e3bec4d66457282a07d6e9d Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 16 Jan 2016 13:23:45 +0100 Subject: [PATCH 1/6] Fix ignore tip build failure --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b7642f015..38f7414f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,10 @@ os: matrix: allow_failures: - go: tip + - go: tip + os: linux + - go: tip + os: osx notifications: irc: From 172c31ff459a9a6d6d46e775294ce0b87471c01d Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 16 Jan 2016 13:32:23 +0100 Subject: [PATCH 2/6] Use gotestcover instead of homebrew run_tests.go --- run_integration_tests.go | 5 +- run_tests.go | 184 --------------------------------------- 2 files changed, 3 insertions(+), 186 deletions(-) delete mode 100644 run_tests.go diff --git a/run_integration_tests.go b/run_integration_tests.go index 0ae59ec6f..db4c09de6 100644 --- a/run_integration_tests.go +++ b/run_integration_tests.go @@ -26,6 +26,7 @@ func (env *TravisEnvironment) Prepare() { run("go", "get", "golang.org/x/tools/cmd/cover") run("go", "get", "github.com/mattn/goveralls") + run("go", "get", "github.com/pierrre/gotestcover") run("go", "get", "github.com/mitchellh/gox") if runtime.GOOS == "darwin" { @@ -76,8 +77,8 @@ func (env *TravisEnvironment) RunTests() { // run the build script run("go", "run", "build.go") - // gather coverage information - run("go", "run", "run_tests.go", "all.cov") + // run tests and gather coverage information + run("gotestcover", "-coverprofile", "all.cov", "./...") runGofmt() } diff --git a/run_tests.go b/run_tests.go deleted file mode 100644 index 1a6bdec67..000000000 --- a/run_tests.go +++ /dev/null @@ -1,184 +0,0 @@ -// +build ignore - -package main - -import ( - "bufio" - "fmt" - "io" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" -) - -func specialDir(name string) bool { - if name == "." { - return false - } - - base := filepath.Base(name) - return base[0] == '_' || base[0] == '.' -} - -func emptyDir(name string) bool { - dir, err := os.Open(name) - defer dir.Close() - if err != nil { - fmt.Fprintf(os.Stderr, "unable to open directory %v: %v\n", name, err) - return true - } - - fis, err := dir.Readdir(-1) - if err != nil { - fmt.Fprintf(os.Stderr, "Readdirnames(%v): %v\n", name, err) - return true - } - - for _, fi := range fis { - if fi.IsDir() { - continue - } - - if filepath.Ext(fi.Name()) == ".go" { - return false - } - } - - return true -} - -func forceRelativeDirname(dirname string) string { - if dirname == "." { - return dirname - } - - if strings.HasPrefix(dirname, "./") { - return dirname - } - - return "./" + dirname -} - -func mergeCoverprofile(file *os.File, out io.Writer) error { - _, err := file.Seek(0, 0) - if err != nil { - return err - } - - rd := bufio.NewReader(file) - _, err = rd.ReadString('\n') - if err == io.EOF { - return nil - } - - if err != nil { - return err - } - - _, err = io.Copy(out, rd) - if err != nil { - return err - } - - err = file.Close() - if err != nil { - return err - } - - return err -} - -func testPackage(pkg string, params []string, out io.Writer) error { - file, err := ioutil.TempFile("", "test-coverage-") - defer os.Remove(file.Name()) - defer file.Close() - if err != nil { - return err - } - - args := []string{"test", "-cover", "-covermode", "set", "-coverprofile", - file.Name(), pkg} - args = append(args, params...) - cmd := exec.Command("go", args...) - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout - - err = cmd.Run() - if err != nil { - return err - } - - return mergeCoverprofile(file, out) -} - -func main() { - if len(os.Args) < 2 { - fmt.Fprintln(os.Stderr, "USAGE: run_tests COVERPROFILE [TESTFLAGS] [-- [PATHS]]") - os.Exit(1) - } - - target := os.Args[1] - args := os.Args[2:] - - paramsForTest := []string{} - dirs := []string{} - for i, arg := range args { - if arg == "--" { - dirs = args[i+1:] - break - } - - paramsForTest = append(paramsForTest, arg) - } - - if len(dirs) == 0 { - dirs = append(dirs, ".") - } - - file, err := os.Create(target) - if err != nil { - fmt.Fprintf(os.Stderr, "create coverprofile failed: %v\n", err) - os.Exit(1) - } - - fmt.Fprintln(file, "mode: set") - - failedTests := false - for _, dir := range dirs { - err := filepath.Walk(dir, - func(p string, fi os.FileInfo, e error) error { - if e != nil { - return e - } - - if !fi.IsDir() { - return nil - } - - if specialDir(p) { - return filepath.SkipDir - } - - if emptyDir(p) { - return nil - } - - return testPackage(forceRelativeDirname(p), paramsForTest, file) - }) - - if err != nil { - fmt.Fprintf(os.Stderr, "walk(%q): %v\n", dir, err) - failedTests = true - } - } - - err = file.Close() - - fmt.Printf("coverprofile: %v\n", file.Name()) - - if failedTests { - os.Exit(1) - } -} From f90381910b20b63774614c3c8184b923a3f43480 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 16 Jan 2016 13:39:12 +0100 Subject: [PATCH 3/6] Remove Go tip, add 1.6beta2 --- .travis.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 38f7414f1..52530bac2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,19 +5,12 @@ go: - 1.3.3 - 1.4.3 - 1.5.3 - - tip + - 1.6beta2 os: - linux - osx -matrix: - allow_failures: - - go: tip - os: linux - - go: tip - os: osx - notifications: irc: channels: From 7c70d5c1bd469b7794098cb943b7901cc75cd51c Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 16 Jan 2016 13:40:16 +0100 Subject: [PATCH 4/6] Build toolchain for gox only on older Versions of Go --- run_integration_tests.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/run_integration_tests.go b/run_integration_tests.go index db4c09de6..ed0618807 100644 --- a/run_integration_tests.go +++ b/run_integration_tests.go @@ -51,7 +51,8 @@ func (env *TravisEnvironment) Prepare() { msg("gox: OS %v, ARCH %v\n", env.goxOS, env.goxArch) - if !strings.HasPrefix(runtime.Version(), "go1.5") { + v := runtime.Version() + if !strings.HasPrefix(v, "go1.5") && !strings.HasPrefix(v, "go1.6") { run("gox", "-build-toolchain", "-os", strings.Join(env.goxOS, " "), "-arch", strings.Join(env.goxArch, " ")) From 2499bbb09d06c44e6cf5d9e96eb9d8d587415fcc Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 16 Jan 2016 14:08:13 +0100 Subject: [PATCH 5/6] Also specify new `-X` syntax for go1.6 --- build.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.go b/build.go index f92bc3301..f77e396d6 100644 --- a/build.go +++ b/build.go @@ -256,7 +256,8 @@ type Constants map[string]string func (cs Constants) LDFlags() string { l := make([]string, 0, len(cs)) - if strings.HasPrefix(runtime.Version(), "go1.5") { + v := runtime.Version() + if strings.HasPrefix(v, "go1.5") || strings.HasPrefix(v, "go1.6") { for k, v := range cs { l = append(l, fmt.Sprintf(`-X "%s=%s"`, k, v)) } From b8c300e61e74cfbbc98fcb98c30689608cb85774 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 16 Jan 2016 14:37:23 +0100 Subject: [PATCH 6/6] Remove run_tests.go from Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9052c8d46..6c365c1e0 100644 --- a/Makefile +++ b/Makefile @@ -9,4 +9,4 @@ clean: rm -rf restic test: $(SOURCE) - go run run_tests.go /dev/null + go test ./...