Use valid Semver versions for pre-releases (#5636)

* Fix ProjectVersion handling of pre-releases

* Add workaround for old, non-standard version

* Attempt to fix versioning

* More consistent comments

* Apply suggestions from code review

- Set CompareType's underlying type to int and revert change to ProjectVersion::compare's parameters
- Add "None" and "All" as names elements of CompareType enum
- Preserve hyphens in prerelease identifiers
- Pad invalid (too short) versions to prevent crashes or nasty behavior
- Compare numeric identifiers to non-numeric ones correctly
- Don't interpret identifiers of form "-#" as numeric (where '#' is any number of digits)
- Add tests to ensure fixes in this commit work and won't regress in the future

* CMAKE fixes from code review

Co-authored-by: Tres Finocchiaro <tres.finocchiaro@gmail.com>

* Remove unnecessary changes to CMake logic

* More const, more reference

* Apply suggestions from code review

Co-authored-by: Tres Finocchiaro <tres.finocchiaro@gmail.com>
This commit is contained in:
Spekular
2020-09-17 17:23:35 +02:00
committed by GitHub
parent f211c192e8
commit af328003a0
6 changed files with 159 additions and 122 deletions

View File

@@ -39,9 +39,39 @@ private slots:
QVERIFY(ProjectVersion("1.1.0", ProjectVersion::Minor) == "1.1.5");
QVERIFY( ! ( ProjectVersion("3.1.0", ProjectVersion::Minor) < "2.2.5" ) );
QVERIFY( ! ( ProjectVersion("2.5.0", ProjectVersion::Release) < "2.2.5" ) );
//A pre-release version has lower precedence than a normal version
QVERIFY(ProjectVersion("1.1.0") > "1.1.0-alpha");
//But higher precedence than the previous version
QVERIFY(ProjectVersion("1.1.0-alpha") > "1.0.0");
//Identifiers with letters or hyphens are compare lexically in ASCII sort order
QVERIFY(ProjectVersion("1.1.0-alpha") < "1.1.0-beta");
QVERIFY(ProjectVersion("1.2.0-rc1") < "1.2.0-rc2");
//Build metadata MUST be ignored when determining version precedence
QVERIFY(ProjectVersion("1.2.2") == "1.2.2+metadata");
QVERIFY(ProjectVersion("1.0.0-alpha") < "1.0.0-alpha.1");
QVERIFY(ProjectVersion("1.0.0-alpha.1") < "1.0.0-alpha.beta");
QVERIFY(ProjectVersion("1.0.0-alpha.beta") < "1.0.0-beta");
QVERIFY(ProjectVersion("1.0.0-beta.2") < "1.0.0-beta.11");
//Test workaround for old, nonstandard version numbers
QVERIFY(ProjectVersion("1.2.2.42") == "1.2.3-42");
QVERIFY(ProjectVersion("1.2.2.42") > "1.2.2.21");
//Ensure that newer versions of the same format aren't upgraded
//in order to discourage use of incorrect versioning
QVERIFY(ProjectVersion("1.2.3.42") == "1.2.3");
//CompareVersion "All" should compare every identifier
QVERIFY(
ProjectVersion("1.0.0-a.b.c.d.e.f.g.h.i.j.k.l", ProjectVersion::All)
< "1.0.0-a.b.c.d.e.f.g.h.i.j.k.m"
);
//Prerelease identifiers may contain hyphens
QVERIFY(ProjectVersion("1.0.0-Alpha-1.2") > "1.0.0-Alpha-1.1");
//We shouldn't crash on invalid versions
QVERIFY(ProjectVersion("1-invalid") == "1.0.0-invalid");
QVERIFY(ProjectVersion("") == "0.0.0");
//Numeric identifiers are smaller than non-numeric identiiers
QVERIFY(ProjectVersion("1.0.0-alpha") > "1.0.0-1");
//An identifier of the form "-x" is non-numeric, not negative
QVERIFY(ProjectVersion("1.0.0-alpha.-1") > "1.0.0-alpha.1");
}
} ProjectVersionTests;