Skip to content
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

Remove >go1.2 detection logic. #646

Merged
merged 1 commit into from Oct 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this will also be refactored in the next PR

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