Skip to content

Commit

Permalink
Merge pull request #646 from smartystreets/removeGo12
Browse files Browse the repository at this point in the history
Remove >go1.2 detection logic.
  • Loading branch information
riannucci committed Oct 26, 2021
2 parents 2967ec0 + 44c3137 commit 3e04cfe
Showing 1 changed file with 3 additions and 32 deletions.
35 changes: 3 additions & 32 deletions goconvey.go
Expand Up @@ -15,9 +15,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -219,38 +217,9 @@ func activateServer(listener net.Listener) {

func coverageEnabled(cover bool, reports string) bool {
return (cover &&
goMinVersion(1, 2) &&
coverToolInstalled() &&
ensureReportDirectoryExists(reports))
}
func goMinVersion(wanted ...int) bool {
version := runtime.Version() // 'go1.2....'
s := regexp.MustCompile(`go([\d]+)\.([\d]+)\.?([\d]+)?`).FindAllStringSubmatch(version, 1)
if len(s) == 0 {
log.Printf("Cannot determine if newer than go1.2, disabling coverage.")
return false
}
for idx, str := range s[0][1:] {
if len(wanted) == idx {
break
}
if v, _ := strconv.Atoi(str); v < wanted[idx] {
log.Printf(pleaseUpgradeGoVersion, version)
return false
}
}
return true
}
func coverToolInstalled() bool {
working := getWorkDir()
command := system.NewCommand(working, "go", "tool", "cover").Execute()
installed := strings.Contains(command.Output, "Usage of 'go tool cover':")
if !installed {
log.Print(coverToolMissing)
return false
}
return true
}

func ensureReportDirectoryExists(reports string) bool {
result, err := exists(reports)
if err != nil {
Expand All @@ -267,6 +236,7 @@ func ensureReportDirectoryExists(reports string) bool {
log.Printf(reportDirectoryUnavailable, reports)
return false
}

func exists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
Expand All @@ -277,6 +247,7 @@ func exists(path string) (bool, error) {
}
return false, err
}

func getWorkDir() string {
working := ""
var err error
Expand Down

0 comments on commit 3e04cfe

Please sign in to comment.