github.com/neilgarb/delve@v1.9.2-nobreaks/pkg/goversion/version_test.go (about)

     1  package goversion
     2  
     3  import (
     4  	"runtime"
     5  	"testing"
     6  )
     7  
     8  func versionAfterOrEqual(t *testing.T, verStr string, ver GoVersion) {
     9  	pver, ok := Parse(verStr)
    10  	if !ok {
    11  		t.Fatalf("Could not parse version string <%s>", verStr)
    12  	}
    13  	if !pver.AfterOrEqual(ver) {
    14  		t.Fatalf("Version <%s> parsed as %v not after %v", verStr, pver, ver)
    15  	}
    16  	t.Logf("version string <%s> → %v", verStr, ver)
    17  }
    18  
    19  func TestParseVersionString(t *testing.T) {
    20  	versionAfterOrEqual(t, "go1.4", GoVersion{1, 4, 0, 0, 0, ""})
    21  	versionAfterOrEqual(t, "go1.5.0", GoVersion{1, 5, 0, 0, 0, ""})
    22  	versionAfterOrEqual(t, "go1.4.2", GoVersion{1, 4, 2, 0, 0, ""})
    23  	versionAfterOrEqual(t, "go1.5beta2", GoVersion{1, 5, -1, 2, 0, ""})
    24  	versionAfterOrEqual(t, "go1.5rc2", GoVersion{1, 5, -1, 0, 2, ""})
    25  	versionAfterOrEqual(t, "go1.6.1 (appengine-1.9.37)", GoVersion{1, 6, 1, 0, 0, ""})
    26  	versionAfterOrEqual(t, "go1.8.1.typealias", GoVersion{1, 6, 1, 0, 0, ""})
    27  	versionAfterOrEqual(t, "go1.8b1", GoVersion{1, 8, -1, 0, 0, ""})
    28  	versionAfterOrEqual(t, "go1.16.4b7", GoVersion{1, 16, 4, 0, 0, ""})
    29  	ver, ok := Parse("devel +17efbfc Tue Jul 28 17:39:19 2015 +0000 linux/amd64")
    30  	if !ok {
    31  		t.Fatalf("Could not parse devel version string")
    32  	}
    33  	if !ver.IsDevel() {
    34  		t.Fatalf("Devel version string not correctly recognized")
    35  	}
    36  }
    37  
    38  func TestInstalled(t *testing.T) {
    39  	installedVersion, ok := Installed()
    40  	if !ok {
    41  		t.Fatalf("could not parse output of go version")
    42  	}
    43  	runtimeVersion, ok := Parse(runtime.Version())
    44  	if !ok {
    45  		t.Fatalf("could not parse output of runtime.Version() %q", runtime.Version())
    46  	}
    47  
    48  	t.Logf("installed: %v", installedVersion)
    49  	t.Logf("runtime: %v", runtimeVersion)
    50  
    51  	if installedVersion != runtimeVersion {
    52  		t.Fatalf("version mismatch %#v %#v", installedVersion, runtimeVersion)
    53  	}
    54  }