mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-11-28 07:21:21 +08:00
pkg/buildinfo: Split devVersionWithVariant into two functions.
This makes it a bit simpler to change the code for release branches.
This commit is contained in:
parent
34b115d7af
commit
db89959a41
|
@ -46,12 +46,13 @@ func (Type) IsStructMap() {}
|
|||
|
||||
// Value contains all the build information.
|
||||
var Value = Type{
|
||||
Version: devVersionWithVariant(VersionBase, VCSOverride, BuildVariant),
|
||||
// On a release branch, change to addVariant(VersionBase, BuildVariant) and
|
||||
// remove unneeded code.
|
||||
Version: addVariant(devVersion(VersionBase, VCSOverride), BuildVariant),
|
||||
GoVersion: runtime.Version(),
|
||||
}
|
||||
|
||||
func devVersionWithVariant(next, vcsOverride, variant string) string {
|
||||
version := devVersion(next, vcsOverride)
|
||||
func addVariant(version, variant string) string {
|
||||
if variant != "" {
|
||||
version += "+" + variant
|
||||
}
|
||||
|
|
|
@ -27,12 +27,11 @@ func TestProgram(t *testing.T) {
|
|||
)
|
||||
}
|
||||
|
||||
var devVersionWithVariantTests = []struct {
|
||||
var devVersionTests = []struct {
|
||||
name string
|
||||
next string
|
||||
vcsOverride string
|
||||
buildInfo *debug.BuildInfo
|
||||
variant string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
|
@ -88,22 +87,16 @@ var devVersionWithVariantTests = []struct {
|
|||
vcsOverride: "20220401235958-123456789012",
|
||||
want: "0.42.0-dev.0.20220401235958-123456789012",
|
||||
},
|
||||
{
|
||||
name: "variant",
|
||||
next: "0.42.0",
|
||||
variant: "distro",
|
||||
want: "0.42.0-dev.unknown+distro",
|
||||
},
|
||||
}
|
||||
|
||||
func TestDevVersionWithVariant(t *testing.T) {
|
||||
for _, test := range devVersionWithVariantTests {
|
||||
func TestDevVersion(t *testing.T) {
|
||||
for _, test := range devVersionTests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
testutil.Set(t, &readBuildInfo,
|
||||
func() (*debug.BuildInfo, bool) {
|
||||
return test.buildInfo, test.buildInfo != nil
|
||||
})
|
||||
got := devVersionWithVariant(test.next, test.vcsOverride, test.variant)
|
||||
got := devVersion(test.next, test.vcsOverride)
|
||||
if got != test.want {
|
||||
t.Errorf("got %q, want %q", got, test.want)
|
||||
}
|
||||
|
@ -111,6 +104,20 @@ func TestDevVersionWithVariant(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAddVariant(t *testing.T) {
|
||||
got := addVariant("0.42.0", "")
|
||||
want := "0.42.0"
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
|
||||
got = addVariant("0.42.0", "distro")
|
||||
want = "0.42.0+distro"
|
||||
if got != want {
|
||||
t.Errorf("got %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValue(t *testing.T) {
|
||||
vals.TestValue(t, Value).
|
||||
Index("version", Value.Version).
|
||||
|
|
Loading…
Reference in New Issue
Block a user