forked from joejulian/gio-cmd
gogio: improve -version parse error message
Add a test while here. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+2
-5
@@ -91,11 +91,8 @@ func (s Semver) String() string {
|
|||||||
func parseSemver(v string) (Semver, error) {
|
func parseSemver(v string) (Semver, error) {
|
||||||
var sv Semver
|
var sv Semver
|
||||||
_, err := fmt.Sscanf(v, "%d.%d.%d.%d", &sv.Major, &sv.Minor, &sv.Patch, &sv.VersionCode)
|
_, err := fmt.Sscanf(v, "%d.%d.%d.%d", &sv.Major, &sv.Minor, &sv.Patch, &sv.VersionCode)
|
||||||
if err != nil {
|
if err != nil || sv.String() != v {
|
||||||
return Semver{}, fmt.Errorf("invalid semver: %q", v)
|
return Semver{}, fmt.Errorf("invalid semver: %q (must match major.minor.patch.versioncode)", v)
|
||||||
}
|
|
||||||
if sv.String() != v {
|
|
||||||
return Semver{}, fmt.Errorf("invalid semver: %q", v)
|
|
||||||
}
|
}
|
||||||
return sv, nil
|
return sv, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,12 @@ package main
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
type expval struct {
|
|
||||||
in, out string
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestAppID(t *testing.T) {
|
func TestAppID(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
tests := []expval{
|
tests := []struct {
|
||||||
|
in, out string
|
||||||
|
}{
|
||||||
{"example", "localhost.example"},
|
{"example", "localhost.example"},
|
||||||
{"example.com", "com.example"},
|
{"example.com", "com.example"},
|
||||||
{"www.example.com", "com.example.www"},
|
{"www.example.com", "com.example.www"},
|
||||||
@@ -30,3 +28,32 @@ func TestAppID(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVersion(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
version string
|
||||||
|
valid bool
|
||||||
|
}{
|
||||||
|
{"v1", false},
|
||||||
|
{"v10.21.333.12", false},
|
||||||
|
{"1.2.3", false},
|
||||||
|
{"1.2.3.4", true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, test := range tests {
|
||||||
|
ver, err := parseSemver(test.version)
|
||||||
|
if err != nil {
|
||||||
|
if test.valid {
|
||||||
|
t.Errorf("(%d): %q failed to parse: %v", i, test.version, err)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
} else if !test.valid {
|
||||||
|
t.Errorf("(%d): %q was unexpectedly accepted", i, test.version)
|
||||||
|
}
|
||||||
|
if got := ver.String(); got != test.version {
|
||||||
|
t.Errorf("(%d): %q parsed to %q", i, test.version, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+3
-2
@@ -47,8 +47,9 @@ The -appid flag specifies the package name for Android or the bundle id for
|
|||||||
iOS and tvOS. A bundle id must be provisioned through Xcode before the gogio
|
iOS and tvOS. A bundle id must be provisioned through Xcode before the gogio
|
||||||
tool can use it.
|
tool can use it.
|
||||||
|
|
||||||
The -version flag specifies the integer version code for Android and the last
|
The -version flag specifies the semantic version for -buildmode exe. It must
|
||||||
component of the 1.0.X version for iOS and tvOS.
|
be on the form major.minor.patch.versioncode where the version code is used for
|
||||||
|
the integer version number for Android, iOS and tvOS.
|
||||||
|
|
||||||
For Android builds the -minsdk flag specify the minimum SDK level. For example,
|
For Android builds the -minsdk flag specify the minimum SDK level. For example,
|
||||||
use -minsdk 22 to target Android 5.1 (Lollipop) and later.
|
use -minsdk 22 to target Android 5.1 (Lollipop) and later.
|
||||||
|
|||||||
Reference in New Issue
Block a user