aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/gotest.tools/v3/internal/source/version.go
blob: 5fa8a90312dd0adce2b1651d21ff5c117443213b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package source

import (
	"runtime"
	"strconv"
	"strings"
)

// GoVersionLessThan returns true if runtime.Version() is semantically less than
// version major.minor. Returns false if a release version can not be parsed from
// runtime.Version().
func GoVersionLessThan(major, minor int64) bool {
	version := runtime.Version()
	// not a release version
	if !strings.HasPrefix(version, "go") {
		return false
	}
	version = strings.TrimPrefix(version, "go")
	parts := strings.Split(version, ".")
	if len(parts) < 2 {
		return false
	}
	rMajor, err := strconv.ParseInt(parts[0], 10, 32)
	if err != nil {
		return false
	}
	if rMajor != major {
		return rMajor < major
	}
	rMinor, err := strconv.ParseInt(parts[1], 10, 32)
	if err != nil {
		return false
	}
	return rMinor < minor
}