Fix goMinorVersion on non-final Go releases

This should work for alpha/beta/rc releases.
This commit is contained in:
Elliott Sales de Andrade 2020-02-19 02:46:21 -05:00 committed by GitHub
parent b2dcd53e3c
commit c7975b48b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View file

@ -15,7 +15,7 @@ package hugo
import (
"fmt"
"strconv"
"io"
"runtime"
"strings"
@ -245,7 +245,15 @@ func goMinorVersion(version string) int {
if strings.HasPrefix(version, "devel") {
return 9999 // magic
}
i, _ := strconv.Atoi(strings.Split(version, ".")[1])
return i
var major, minor int
var trailing string
n, err := fmt.Sscanf(version, "go%d.%d%s", &major, &minor, &trailing)
if n == 2 && err == io.EOF {
// Means there were no trailing characters (i.e., not an alpha/beta)
err = nil
}
if err != nil {
return 0
}
return minor
}

View file

@ -84,5 +84,6 @@ func TestParseHugoVersion(t *testing.T) {
func TestGoMinorVersion(t *testing.T) {
c := qt.New(t)
c.Assert(goMinorVersion("go1.12.5"), qt.Equals, 12)
c.Assert(goMinorVersion("go1.14rc1"), qt.Equals, 14)
c.Assert(GoMinorVersion() >= 11, qt.Equals, true)
}