...

Source file src/gotest.tools/v3/internal/source/version.go

Documentation: gotest.tools/v3/internal/source

     1  package source
     2  
     3  import (
     4  	"runtime"
     5  	"strconv"
     6  	"strings"
     7  )
     8  
     9  // GoVersionLessThan returns true if runtime.Version() is semantically less than
    10  // version major.minor. Returns false if a release version can not be parsed from
    11  // runtime.Version().
    12  func GoVersionLessThan(major, minor int64) bool {
    13  	version := runtime.Version()
    14  	// not a release version
    15  	if !strings.HasPrefix(version, "go") {
    16  		return false
    17  	}
    18  	version = strings.TrimPrefix(version, "go")
    19  	parts := strings.Split(version, ".")
    20  	if len(parts) < 2 {
    21  		return false
    22  	}
    23  	rMajor, err := strconv.ParseInt(parts[0], 10, 32)
    24  	if err != nil {
    25  		return false
    26  	}
    27  	if rMajor != major {
    28  		return rMajor < major
    29  	}
    30  	rMinor, err := strconv.ParseInt(parts[1], 10, 32)
    31  	if err != nil {
    32  		return false
    33  	}
    34  	return rMinor < minor
    35  }
    36  

View as plain text