mirror of
https://git.sr.ht/~eliasnaur/gio-cmd
synced 2026-07-01 07:35:37 +00:00
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) {
|
||||
var sv Semver
|
||||
_, err := fmt.Sscanf(v, "%d.%d.%d.%d", &sv.Major, &sv.Minor, &sv.Patch, &sv.VersionCode)
|
||||
if err != nil {
|
||||
return Semver{}, fmt.Errorf("invalid semver: %q", v)
|
||||
}
|
||||
if sv.String() != v {
|
||||
return Semver{}, fmt.Errorf("invalid semver: %q", v)
|
||||
if err != nil || sv.String() != v {
|
||||
return Semver{}, fmt.Errorf("invalid semver: %q (must match major.minor.patch.versioncode)", v)
|
||||
}
|
||||
return sv, nil
|
||||
}
|
||||
|
||||
@@ -2,14 +2,12 @@ package main
|
||||
|
||||
import "testing"
|
||||
|
||||
type expval struct {
|
||||
in, out string
|
||||
}
|
||||
|
||||
func TestAppID(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []expval{
|
||||
tests := []struct {
|
||||
in, out string
|
||||
}{
|
||||
{"example", "localhost.example"},
|
||||
{"example.com", "com.example"},
|
||||
{"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
|
||||
tool can use it.
|
||||
|
||||
The -version flag specifies the integer version code for Android and the last
|
||||
component of the 1.0.X version for iOS and tvOS.
|
||||
The -version flag specifies the semantic version for -buildmode exe. It must
|
||||
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,
|
||||
use -minsdk 22 to target Android 5.1 (Lollipop) and later.
|
||||
|
||||
Reference in New Issue
Block a user