public void fix_parsing_syntax_error_helper_max_prerelease_fix(string tag) { var error = string.Format("Fix Number must be between 1 and {0}.", ReleaseTagVersion.MaxPreReleaseFix); ReleaseTagVersion t = ReleaseTagVersion.TryParse(tag, true); Assert.That(t.ParseErrorMessage, Contains.Substring(error)); }
public void when_parsing_invalid_tags_can_detect_malformed_ones(string tag, bool isMalformed) { var t = ReleaseTagVersion.TryParse(tag, true); Assert.That(!t.IsValid); Assert.That(t.IsMalformed, Is.EqualTo(isMalformed)); //Console.WriteLine( t.ParseErrorMessage ); }
public void fumble_commit_scenario() { var repoTest = TestHelper.TestGitRepository; var cD = repoTest.Commits.First(sc => sc.Message.StartsWith("D-Commit.")); var cC = repoTest.Commits.First(sc => sc.Message.StartsWith("C-Commit.")); var cF = repoTest.Commits.First(sc => sc.Sha == "27a629754c6b9034f7ca580442b589a0241773c5"); var cB = repoTest.Commits.First(sc => sc.Message.StartsWith("B-Commit.")); var cA = repoTest.Commits.First(sc => sc.Message.StartsWith("Merge branch 'fumble-develop' into fumble-master")); var cFix = repoTest.Commits.First(sc => sc.Sha == "e6766d127f9a2df42567151222c6569601614626"); var cX = repoTest.Commits.First(sc => sc.Message.StartsWith("X-Commit.")); var overrides = new TagsOverride() .MutableAdd(cD.Sha, "v4.3.2") .MutableAdd(cC.Sha, "v4.4.0-alpha") .MutableAdd(cB.Sha, "v5.0.0-rc") .MutableAdd(cA.Sha, "v5.0.0"); var v5 = ReleaseTagVersion.TryParse("v5.0.0"); var v5rc = ReleaseTagVersion.TryParse("v5.0.0-rc"); var v5rc01 = ReleaseTagVersion.TryParse("v5.0.0-rc.0.1"); var v5rc1 = ReleaseTagVersion.TryParse("v5.0.0-rc.1"); { // On the fix of the fumble commit, only v5.0.0-rc.0.1 is possible in Restricted mode. // Restricted mode disallow rc.1 (next version below the first already released next one). RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cFix.Sha }); Assert.That(i.PreviousRelease.ThisTag, Is.EqualTo(v5rc)); Assert.That(i.PreviousMaxRelease.ThisTag, Is.SameAs(i.PreviousRelease.ThisTag)); CollectionAssert.AreEqual(new[] { v5rc01 }, i.PossibleVersionsStrict); // In default mode, the fix of the fumble commit, v5.0.0-rc.0.1 and rc.1 are possible. CollectionAssert.AreEqual(new[] { v5rc01, v5rc1 }, i.PossibleVersions); } { // Above the fix of the fumble commit, v5.0.0-rc.0.1 and any successor of the 5.0.0 is possible. RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cX.Sha }); Assert.That(i.PreviousRelease.ThisTag, Is.EqualTo(v5rc)); Assert.That(i.PreviousMaxRelease.ThisTag, Is.EqualTo(v5)); var possible = new List <ReleaseTagVersion>() { v5rc01, v5rc1 }; possible.AddRange(v5.GetDirectSuccessors()); CollectionAssert.AreEqual(possible, i.PossibleVersions); var possibleStrict = new List <ReleaseTagVersion>() { v5rc01 }; possibleStrict.AddRange(v5.GetDirectSuccessors()); CollectionAssert.AreEqual(possibleStrict, i.PossibleVersionsStrict); } }
public void parsing_valid_release(string tag) { ReleaseTagVersion t = ReleaseTagVersion.TryParse(tag); Assert.That(t.IsValid); Assert.That(t.IsPreRelease, Is.False); Assert.That(t.IsPreReleasePatch, Is.False); Assert.That(t.ToString(ReleaseTagFormat.SemVer), Is.EqualTo(tag)); Assert.That(t.ToString(ReleaseTagFormat.NuGetPackage), Is.EqualTo(tag)); }
public void to_string_pre_release_with_nonstandard_names_works_for_SemVer_but_throws_for_NuGetV2(string tag) { ReleaseTagVersion t = ReleaseTagVersion.TryParse(tag); Assert.That(t.IsValid); Assert.That(t.IsPreRelease); Assert.That(!t.IsPreReleaseNameStandard); Assert.That(t.IsPreReleasePatch); Assert.That(t.PreReleasePatch, Is.GreaterThan(0)); Assert.That(t.ToString(ReleaseTagFormat.SemVer, null, true), Is.EqualTo(tag)); Assert.Throws <ArgumentException>(() => t.ToString(ReleaseTagFormat.NugetPackageV2, null, true)); }
public void pre_release_with_standard_names_nugetV2_mappings(string tag, string nuget) { ReleaseTagVersion t = ReleaseTagVersion.TryParse(tag); Assert.That(t.IsValid); Assert.That(t.IsPreRelease); Assert.That(t.IsPreReleaseNameStandard); Assert.That(t.IsPreReleasePatch, Is.False); Assert.That(t.ToString(ReleaseTagFormat.SemVer), Is.EqualTo(tag)); Assert.That(t.ToString(ReleaseTagFormat.NuGetPackage), Is.EqualTo(nuget)); Assert.That(SemVersion.Parse(nuget).Prerelease.Length, Is.LessThanOrEqualTo(20)); }
//static int _greatersuccessorCount = 0; ReleaseTagVersion CheckMapping(long v) { if (v < 0 || v > ReleaseTagVersion.VeryLastVersion.OrderedVersion) { Assert.Throws <ArgumentException>(() => new ReleaseTagVersion(v)); return(null); } var t = new ReleaseTagVersion(v); Assert.That((v == 0) == !t.IsValid); Assert.That(t.OrderedVersion, Is.EqualTo(v)); var sSemVer = t.ToString(ReleaseTagFormat.SemVer); var tSemVer = ReleaseTagVersion.TryParse(sSemVer); var tNormalized = ReleaseTagVersion.TryParse(t.ToString(ReleaseTagFormat.Normalized)); Assert.That(tSemVer.OrderedVersion, Is.EqualTo(v)); Assert.That(tNormalized.OrderedVersion, Is.EqualTo(v)); Assert.That(tNormalized.Equals(t)); Assert.That(tSemVer.Equals(t)); Assert.That(tNormalized.Equals((object)t)); Assert.That(tSemVer.Equals((object)t)); Assert.That(tNormalized.CompareTo(t) == 0); Assert.That(tSemVer == t); Assert.That(tSemVer.ToString(), Is.EqualTo(t.ToString())); Assert.That(tNormalized.ToString(), Is.EqualTo(t.ToString())); // Successors/Predecessors check. var vSemVer = SemVersion.Parse(sSemVer, true); int count = 0; foreach (var succ in t.GetDirectSuccessors(false)) { ++count; Assert.That(succ.IsDirectPredecessor(t)); var vSemVerSucc = SemVersion.Parse(succ.ToString(ReleaseTagFormat.SemVer)); Assert.That(vSemVer < vSemVerSucc, "{0} < {1}", vSemVer, vSemVerSucc); } //if( count > _greatersuccessorCount ) //{ // Console.WriteLine( " -> - found {0} successors for '{1}':", count, t ); // Console.WriteLine( " " + string.Join( ", ", t.GetDirectSuccessors( false ).Select( s => s.ToString() ) ) ); // var closest = t.GetDirectSuccessors( true ).Select( s => s.ToString() ).ToList(); // Console.WriteLine( " - {0} closest successors:", closest.Count, t ); // Console.WriteLine( " " + string.Join( ", ", closest ) ); // _greatersuccessorCount = count; //} return(t); }
public void display_successors_samples(string v) { ReleaseTagVersion t = ReleaseTagVersion.TryParse(v); var succ = t.GetDirectSuccessors(false); Console.WriteLine(" -> - found {0} successors for '{1}' (Ordered Version = {2}, File = {3}):", succ.Count(), t, t.OrderedVersion, t.ToStringFileVersion(false)); Console.WriteLine(" " + string.Join(", ", succ.Select(s => s.ToString()))); var closest = t.GetDirectSuccessors(true).Select(s => s.ToString()).ToList(); Console.WriteLine(" - {0} next fixes:", closest.Count, t); Console.WriteLine(" " + string.Join(", ", closest)); }
public void checking_extreme_version_ordering(string tag, bool atEnd, int expectedRank) { var t = ReleaseTagVersion.TryParse(tag); if (atEnd) { Assert.That(t.OrderedVersion - (ReleaseTagVersion.VeryLastVersion.OrderedVersion - expectedRank), Is.EqualTo(0)); } else { Assert.That(t.OrderedVersion - (ReleaseTagVersion.VeryFirstVersion.OrderedVersion + expectedRank), Is.EqualTo(0)); } var t2 = new ReleaseTagVersion(t.OrderedVersion); Assert.That(t2.ToString(), Is.EqualTo(t.ToString())); Assert.That(t.Equals(t2)); }
public void version_ordering_starts_at_1_for_the_very_first_possible_version(string tag, int oMajor, int oMinor, int oBuild, int oRevision) { var t = ReleaseTagVersion.TryParse(tag, true); Assert.That(t.IsValid); Assert.That(t.OrderedVersionMajor, Is.EqualTo(oMajor)); Assert.That(t.OrderedVersionMinor, Is.EqualTo(oMinor)); Assert.That(t.OrderedVersionBuild, Is.EqualTo(oBuild)); Assert.That(t.OrderedVersionRevision, Is.EqualTo(oRevision)); long vf = t.OrderedVersion << 1; Assert.That(t.ToStringFileVersion(false), Is.EqualTo(string.Format("{0}.{1}.{2}.{3}", vf >> 48, (vf >> 32) & 0xFFFF, (vf >> 16) & 0xFFFF, vf & 0xFFFF))); vf |= 1; Assert.That(t.ToStringFileVersion(true), Is.EqualTo(string.Format("{0}.{1}.{2}.{3}", vf >> 48, (vf >> 32) & 0xFFFF, (vf >> 16) & 0xFFFF, vf & 0xFFFF))); }
public void display_name_and_successors_samples(string v) { ReleaseTagVersion t = ReleaseTagVersion.TryParse(v); var succ = t.GetDirectSuccessors(false); Console.WriteLine(" -> - found {0} successors for '{1}' (NuGetV2 = {2}, Ordered Version = {3}, File = {4}.{5}.{6}.{7}):", succ.Count(), t, t.ToString(ReleaseTagFormat.NugetPackageV2), t.OrderedVersion, t.OrderedVersionMajor, t.OrderedVersionMinor, t.OrderedVersionBuild, t.OrderedVersionRevision ); Console.WriteLine(" " + string.Join(", ", succ.Select(s => s.ToString()))); }
public void operators_overloads() { // Two variables to avoid Compiler Warning (level 3) CS1718 ReleaseTagVersion null2 = null; ReleaseTagVersion null1 = null; Assert.That(null1 == null2); Assert.That(null1 >= null2); Assert.That(null1 <= null2); Assert.That(null1 != null2, Is.False); Assert.That(null1 > null2, Is.False); Assert.That(null1 < null2, Is.False); NullIsAlwaysSmaller(ReleaseTagVersion.VeryFirstVersion); NullIsAlwaysSmaller(ReleaseTagVersion.TryParse("1.0.0")); NullIsAlwaysSmaller(ReleaseTagVersion.TryParse("bug")); }
public void checking_some_versions_predecessors(string targets, bool previous, string candidates) { var targ = targets.Split(',') .Select(v => v.Trim()) .Where(v => v.Length > 0) .Select(v => ReleaseTagVersion.TryParse(v)); var prev = candidates.Split(',') .Select(v => v.Trim()) .Where(v => v.Length > 0) .Select(v => ReleaseTagVersion.TryParse(v)); foreach (var vTarget in targ) { foreach (var p in prev) { Assert.That(vTarget.IsDirectPredecessor(p), Is.EqualTo(previous), p.ToString() + (previous ? " is a previous of " : " is NOT a previous of ") + vTarget.ToString()); } } }
public void checking_next_fixes_and_predecessors(string start, string nextVersions) { var next = nextVersions.Split(',') .Select(v => v.Trim()) .Where(v => v.Length > 0) .ToArray(); var rStart = ReleaseTagVersion.TryParse(start); Assert.That(rStart != null && rStart.IsValid); // Checks successors (and that they are ordered). var cNext = rStart.GetDirectSuccessors(true).Select(v => v.ToString()).ToArray(); CollectionAssert.AreEqual(next, cNext, start + " => " + string.Join(", ", cNext)); Assert.That(rStart.GetDirectSuccessors(true), Is.Ordered); // For each successor, check that the start is a predecessor. foreach (var n in rStart.GetDirectSuccessors(true)) { Assert.That(n.IsDirectPredecessor(rStart), "{0} < {1}", rStart, n); } }
public void display_name_for_CI_build_and_check_20_characters_limit(string versions, int range) { var buildInfo = new CIBuildDescriptor() { BranchName = "develop", BuildIndex = 21 }; foreach (var v in versions.Split(',').Select(s => s.Trim())) { ReleaseTagVersion t = ReleaseTagVersion.TryParse(v); Console.WriteLine(t); for (int i = -range; i <= range; ++i) { var num = t.OrderedVersion + i; if (num > 0m && num <= ReleaseTagVersion.VeryLastVersion.OrderedVersion) { ReleaseTagVersion tD = new ReleaseTagVersion(num); DumpVersionInfo(buildInfo, tD); } } } }
public void display_versions_and_CI_version(string version, string after) { var buildInfo = new CIBuildDescriptor() { BranchName = "develop", BuildIndex = 15 }; ReleaseTagVersion v = ReleaseTagVersion.TryParse(version); string vCI = v.ToString(ReleaseTagFormat.SemVer, buildInfo); ReleaseTagVersion vNext = new ReleaseTagVersion(v.OrderedVersion + 1); Console.WriteLine("Version = {0}, CI = {1}, Next = {2}", v, vCI, vNext); var vSemVer = SemVersion.Parse(v.ToString(ReleaseTagFormat.SemVer)); var vCISemVer = SemVersion.Parse(vCI); var vNextSemVer = SemVersion.Parse(vNext.ToString(ReleaseTagFormat.SemVer)); Assert.That(vSemVer < vCISemVer, "{0} < {1}", vSemVer, vCISemVer); Assert.That(vCISemVer < vNextSemVer, "{0} < {1}", vCISemVer, vNextSemVer); foreach (var vAfter in after.Split(',').Select(s => SemVersion.Parse(s.Trim()))) { Assert.That(vAfter.CompareTo(vCISemVer) > 0, "{0} > {1}", vAfter, vCISemVer); } }
public void propagation_through_multiple_hops() { var repoTest = TestHelper.TestGitRepository; var cAlpha = repoTest.Commits.First(sc => sc.Message.StartsWith("Real Dev in Alpha.")); // cReleased is "Merge branch 'gamma' into parallel-world" but there are two of them... // This is the head of parallel-world branch. var cReleased = repoTest.Commits.First(sc => sc.Sha == "fc9802013c23398978744de1618fb01638f7347e"); var v1beta = ReleaseTagVersion.TryParse("1.0.0-beta"); var overrides = new TagsOverride().MutableAdd(cAlpha.Sha, "1.0.0-beta"); // cReleased // | // | // cAlpha - v1.0.0-beta // This is "normal": cReleased has 1.0.0-beta in its parent. { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cReleased.Sha, OverriddenTags = overrides.Overrides }); Assert.That(i.ReleaseTagErrorText, Is.Null); Assert.That(i.PreviousRelease.ThisTag, Is.EqualTo(v1beta)); Assert.That(i.ValidReleaseTag, Is.Null); CollectionAssert.AreEqual(v1beta.GetDirectSuccessors(), i.PossibleVersions); CollectionAssert.AreEqual(v1beta.GetDirectSuccessors(), i.PossibleVersionsStrict); } var cAlphaContinue = repoTest.Commits.First(sc => sc.Message.StartsWith("Dev again in Alpha.")); // We set 2.0.0 on cReleased. Its content is the same as cAlpha (mege commits with no changes). // // cAlphaContinue // | // | cReleased - v2.0.0 // | / // |/ // cAlpha - v1.0.0-beta overrides.MutableAdd(cReleased.Sha, "2.0.0"); { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cReleased.Sha, OverriddenTags = overrides.Overrides }); Assert.That(i.ReleaseTagErrorText, Is.Null); Assert.That(i.ValidReleaseTag.ToString(), Is.EqualTo("v2.0.0")); } // Subsequent developments of alpha branch now starts after 2.0.0, for instance 2.1.0-beta. overrides.MutableAdd(cAlphaContinue.Sha, "2.1.0-beta"); { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cAlphaContinue.Sha, OverriddenTags = overrides.Overrides }); var tagged = ReleaseTagVersion.TryParse("2.1.0-beta"); Assert.That(i.ReleaseTagErrorText, Is.Null); Assert.That(i.ValidReleaseTag, Is.EqualTo(tagged)); CollectionAssert.AreEqual( new[] { ReleaseTagVersion.TryParse("1.0.0-beta.0.1") } .Concat(ReleaseTagVersion.TryParse("2.0.0").GetDirectSuccessors()), i.PossibleVersionsStrict); // In no strict mode, alpha branch can continue with any successors of // the 1.0.0-beta except the v2.0.0 of course. CollectionAssert.AreEqual( ReleaseTagVersion.TryParse("1.0.0-beta").GetDirectSuccessors() .Where(v => v != ReleaseTagVersion.TryParse("2.0.0")) .Concat(ReleaseTagVersion.TryParse("2.0.0").GetDirectSuccessors()), i.PossibleVersions); } }
public void checking_version_ordering() { var orderedTags = new[] { "0.0.0-alpha", "0.0.0-alpha.0.1", "0.0.0-alpha.0.2", "0.0.0-alpha.1", "0.0.0-alpha.1.1", "0.0.0-beta", "0.0.0-beta.1", "0.0.0-beta.1.1", "0.0.0-gamma", "0.0.0-gamma.0.1", "0.0.0-gamma.50", "0.0.0-gamma.50.20", "0.0.0-thisisnonstandard", "0.0.0-nonstandard.0.1", "0.0.0-anothernonstandard.2", "0.0.0-rc", "0.0.0-rc.0.1", "0.0.0-rc.2", "0.0.0-rc.2.58", "0.0.0-rc.3", "0.0.0", "0.0.1", "0.0.2", "1.0.0-alpha", "1.0.0-alpha.1", "1.0.0-alpha.2", "1.0.0-alpha.2.1", "1.0.0-alpha.3", "1.0.0", "99999.49999.0", "99999.49999.9999-alpha.99", "99999.49999.9999-alpha.99.99", "99999.49999.9999-rc", "99999.49999.9999-rc.0.1", "99999.49999.9999" }; var releasedTags = orderedTags .Select((tag, idx) => new { Tag = tag, Index = idx, ReleasedTag = ReleaseTagVersion.TryParse(tag) }) .Select(s => { Assert.That(s.ReleasedTag.IsValid, s.Tag); return(s); }); var orderedByFileVersion = releasedTags .OrderBy(s => s.ReleasedTag.OrderedVersion); var orderedByFileVersionParts = releasedTags .OrderBy(s => s.ReleasedTag.OrderedVersionMajor) .ThenBy(s => s.ReleasedTag.OrderedVersionMinor) .ThenBy(s => s.ReleasedTag.OrderedVersionBuild) .ThenBy(s => s.ReleasedTag.OrderedVersionRevision); Assert.That(orderedByFileVersion.Select((s, idx) => s.Index - idx).All(delta => delta == 0)); Assert.That(orderedByFileVersionParts.Select((s, idx) => s.Index - idx).All(delta => delta == 0)); }
public void StrictMode_content_based_decisions_saves_the_cherry_picks() { var repoTest = TestHelper.TestGitRepository; var cRoot = repoTest.Commits.Single(sc => sc.Message.StartsWith("First in parallel world.")); var cChange = repoTest.Commits.Single(sc => sc.Message.StartsWith("Change in parallel-world.txt content (1).")); var cReset = repoTest.Commits.Single(sc => sc.Message.StartsWith("Reset change in parallel-world.txt content (2).")); var cPickReset = repoTest.Commits.Single(sc => sc.Message.StartsWith("Cherry Pick - Reset change in parallel-world.txt content (2).")); var cPickChange = repoTest.Commits.Single(sc => sc.Message.StartsWith("Cherry Pick - Change in parallel-world.txt content (1).")); var cPostReset = repoTest.Commits.Single(sc => sc.Sha == "3035a581af1302293739e5caf7dfbc009a71454f"); // "Merge branch 'gamma' into parallel-world" (there are two of them); var cDevInGamma = repoTest.Commits.Single(sc => sc.Message.StartsWith("Dev in Gamma.")); var cMergeAll = repoTest.Commits.Single(sc => sc.Message.StartsWith("Merge branch 'parallel-world' into alpha")); var v1 = ReleaseTagVersion.TryParse("1.0.0"); var v2 = ReleaseTagVersion.TryParse("2.0.0"); var overrides = new TagsOverride() .MutableAdd(cRoot.Sha, v1.ToString()) .MutableAdd(cChange.Sha, v2.ToString()); // cMergeAll => succ(v2.0.0) // / \ // / \ // | | // cDevInGamma | => fixes(v1.0.0)+succ(v2.0.0). // | | // cPickReset | => fixes(v1.0.0)+succ(v2.0.0) because the cherry pick makes cPickChange content v2.0.0 // | | // cPickChange | => fixes(v1.0.0). (Its content is actually v2.0.0) // | | // | cPostReset => succ(v2.0.0) // | | // | cReset => succ(v2.0.0) // | | // | cChange - v2.0.0 // | / // | / // | / // |/ // cRoot - v1.0.0 Action <SimpleCommit> v1Successors = commit => { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = commit.Sha, OverriddenTags = overrides.Overrides }); CollectionAssert.AreEqual(v1.GetDirectSuccessors().Where(t => t.ToString() != "v2.0.0"), i.PossibleVersionsStrict); }; Action <SimpleCommit> v1FixSuccessors = commit => { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = commit.Sha, OverriddenTags = overrides.Overrides }); CollectionAssert.AreEqual(v1.GetDirectSuccessors(true).Where(t => t.ToString() != "v2.0.0"), i.PossibleVersionsStrict); }; Action <SimpleCommit> v1FixAndV2Successors = commit => { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = commit.Sha, OverriddenTags = overrides.Overrides }); CollectionAssert.AreEqual(v1.GetDirectSuccessors(true).Where(t => t.ToString() != "v2.0.0").Concat(v2.GetDirectSuccessors()), i.PossibleVersionsStrict); }; Action <SimpleCommit> v2Successors = commit => { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = commit.Sha, PossibleVersionsMode = PossibleVersionsMode.Restricted, OverriddenTags = overrides.Overrides }); CollectionAssert.AreEqual(v2.GetDirectSuccessors(), i.PossibleVersionsStrict); }; v2Successors(cReset); v1FixSuccessors(cPickChange); v1FixAndV2Successors(cPickReset); v2Successors(cPostReset); v1FixAndV2Successors(cDevInGamma); v2Successors(cMergeAll); }
public void CIBuildVersion_with_merged_tags() { var repoTest = TestHelper.TestGitRepository; var cRoot = repoTest.Commits.Single(sc => sc.Message.StartsWith("First in parallel world.")); var cDevInAlpha = repoTest.Commits.Single(sc => sc.Message.StartsWith("Dev in Alpha.")); var cDevInBeta = repoTest.Commits.Single(sc => sc.Message.StartsWith("Dev in Beta.")); var cDevInGamma = repoTest.Commits.Single(sc => sc.Message.StartsWith("Dev in Gamma.")); var overrides = new TagsOverride() .MutableAdd(cRoot.Sha, "v1.0.0") .MutableAdd(cDevInAlpha.Sha, "v2.0.0"); // cDevInBeta // | // | cDevInGamma // | / // |/ cDevInAlpha - v2.0.0 // | / // | / // | / // cRoot - v1.0.0 { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cDevInAlpha.Sha, OverriddenTags = overrides.Overrides }); Assert.That(i.ValidReleaseTag, Is.EqualTo(ReleaseTagVersion.TryParse("v2.0.0"))); } overrides.MutableAdd(cDevInBeta.Sha, "v1.0.1-beta"); // cDevInBeta - v1.0.1-beta // | // | cDevInGamma // | / // |/ cDevInAlpha - v2.0.0 // | / // | / // cRoot - v1.0.0 { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cDevInBeta.Sha, OverriddenTags = overrides.Overrides }); Assert.That(i.ValidReleaseTag, Is.EqualTo(ReleaseTagVersion.TryParse("v1.0.1-beta"))); } overrides.MutableAdd(cDevInGamma.Sha, "v1.0.1-alpha"); // cDevInBeta - v1.0.1-beta // | // | cDevInGamma - v1.0.1-alpha // | / // |/ cDevInAlpha - v2.0.0 // | / // | / // cRoot - v1.0.0 { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingCommitSha = cDevInGamma.Sha, OverriddenTags = overrides.Overrides }); Assert.That(i.ValidReleaseTag, Is.EqualTo(ReleaseTagVersion.TryParse("v1.0.1-alpha"))); } // On "gamma" branch, the head is 7 commits ahead of the v2.0.0 tag: this is the longest path. { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = "gamma", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "gamma", CIVersionMode = CIBranchVersionMode.LastReleaseBased } } }); Assert.That(i.ValidReleaseTag, Is.Null); Assert.That(i.CIRelease.BuildVersion, Is.EqualTo("2.0.1--ci-gamma.7")); } // Testing "gamma" branch in ZeroTimed mode. { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = "gamma", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "gamma", CIVersionMode = CIBranchVersionMode.ZeroTimed } } }); Assert.That(i.CIRelease.BuildVersionNuGet, Is.EqualTo("0.0.0-Cgamma-00185gh")); Assert.That(i.CIRelease.BuildVersion, Is.EqualTo("0.0.0--ci-gamma.2015-07-13T07-46-29-00+v2.0.0")); } // On "alpha" branch, the head is 6 commits ahead of the v2.0.0 tag (always the take the longest path). { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = "alpha", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "alpha", VersionName = "ALPHAAAA", CIVersionMode = CIBranchVersionMode.LastReleaseBased } } }); Assert.That(i.ValidReleaseTag, Is.Null); Assert.That(i.CIRelease.BuildVersion, Is.EqualTo("2.0.1--ci-ALPHAAAA.6")); } // Testing "alpha" branch in ZeroTimed mode. { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = "alpha", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "alpha", VersionName = "ALPH", CIVersionMode = CIBranchVersionMode.ZeroTimed } } }); Assert.That(i.CIRelease.BuildVersionNuGet, Is.EqualTo("0.0.0-CALPH-00187mq")); Assert.That(i.CIRelease.BuildVersion, Is.EqualTo("0.0.0--ci-ALPH.2015-07-13T10-00-58-00+v2.0.0")); } // On "beta" branch, the head is 6 commits ahead of the v2.0.0 tag. { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = "beta", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "beta", VersionName = "BBBBBB", CIVersionMode = CIBranchVersionMode.LastReleaseBased } } }); Assert.That(i.ValidReleaseTag, Is.Null); Assert.That(i.CIRelease.BuildVersion, Is.EqualTo("2.0.1--ci-BBBBBB.6")); } // Testing ZeroTimed mode on "beta" branch. { RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { StartingBranchName = "beta", OverriddenTags = overrides.Overrides, Branches = new RepositoryInfoOptionsBranch[] { new RepositoryInfoOptionsBranch() { Name = "beta", VersionName = "beta", CIVersionMode = CIBranchVersionMode.ZeroTimed } } }); Assert.That(i.CIRelease.BuildVersionNuGet, Is.EqualTo("0.0.0-Cbeta-00185fx")); Assert.That(i.CIRelease.BuildVersion, Is.EqualTo("0.0.0--ci-beta.2015-07-13T07-45-43-00+v2.0.0")); } }
public void fumble_commit_plus_an_extra_content_with_a_big_release_number() { var repoTest = TestHelper.TestGitRepository; var cD = repoTest.Commits.First(sc => sc.Message.StartsWith("D-Commit.")); var cC = repoTest.Commits.First(sc => sc.Message.StartsWith("C-Commit.")); var cF = repoTest.Commits.First(sc => sc.Sha == "27a629754c6b9034f7ca580442b589a0241773c5"); var cB = repoTest.Commits.First(sc => sc.Message.StartsWith("B-Commit.")); var cA = repoTest.Commits.First(sc => sc.Message.StartsWith("Merge branch 'fumble-develop' into fumble-master")); var cFix = repoTest.Commits.First(sc => sc.Sha == "e6766d127f9a2df42567151222c6569601614626"); var cX = repoTest.Commits.First(sc => sc.Message.StartsWith("X-Commit.")); var cExtra = repoTest.Commits.First(sc => sc.Message.StartsWith("C-Commit (cherry pick).")); var overrides = new TagsOverride() .MutableAdd(cD.Sha, "v4.3.2") .MutableAdd(cC.Sha, "v4.4.0-alpha") .MutableAdd(cB.Sha, "v5.0.0-rc") .MutableAdd(cA.Sha, "v5.0.0") .MutableAdd(cExtra.Sha, "v10.0.0"); var v5 = ReleaseTagVersion.TryParse("v5.0.0"); var v5rc = ReleaseTagVersion.TryParse("v5.0.0-rc"); var v5rc01 = ReleaseTagVersion.TryParse("v5.0.0-rc.0.1"); var v5rc1 = ReleaseTagVersion.TryParse("v5.0.0-rc.1"); var v10 = ReleaseTagVersion.TryParse("v10.0.0"); { // The injected v10 overrides everything except the possibilty to release the v5.0.0-rc.0.1. RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cFix.Sha }); Assert.That(i.PreviousRelease.ThisTag, Is.EqualTo(v5rc)); Assert.That(i.PreviousMaxRelease.ThisTag, Is.EqualTo(v10)); var possibleStrict = new List <ReleaseTagVersion>() { v5rc01 }; possibleStrict.AddRange(v10.GetDirectSuccessors()); CollectionAssert.AreEqual(possibleStrict, i.PossibleVersionsStrict); var possible = new List <ReleaseTagVersion>() { v5rc01, v5rc1 }; possible.AddRange(v10.GetDirectSuccessors()); CollectionAssert.AreEqual(possible, i.PossibleVersions); } { // On B-Commit: // Restricted Mode: it is the same, v4.4.0-alpha.0.1 and successors of v10. // AllSuccessors Mode: all successors of v4.4.0-alpha (except the v5.0.0) are allowed and successors of v10. var v44a = ReleaseTagVersion.TryParse("v4.4.0-alpha"); var v44a01 = ReleaseTagVersion.TryParse("v4.4.0-alpha.0.1"); var v44a1 = ReleaseTagVersion.TryParse("v4.4.0-alpha.1"); var v500 = ReleaseTagVersion.TryParse("v5.0.0"); RepositoryInfo i = repoTest.GetRepositoryInfo(new RepositoryInfoOptions { OverriddenTags = overrides.Overrides, StartingCommitSha = cB.Sha }); Assert.That(i.PreviousRelease.ThisTag, Is.EqualTo(v44a)); Assert.That(i.PreviousMaxRelease.ThisTag, Is.EqualTo(v10)); var possibleStrict = new List <ReleaseTagVersion>() { v44a01 }; possibleStrict.AddRange(v10.GetDirectSuccessors()); CollectionAssert.AreEqual(possibleStrict, i.PossibleVersionsStrict); var possible = new List <ReleaseTagVersion>(); possible.AddRange(v44a.GetDirectSuccessors().Where(v => v != v500)); possible.AddRange(v10.GetDirectSuccessors()); CollectionAssert.AreEqual(possible, i.PossibleVersions); } }
public void equal_release_tags_can_have_different_definition_strengths(string tag, int level, string message) { var t = ReleaseTagVersion.TryParse(tag, true); Assert.That(t.DefinitionStrength, Is.EqualTo(level), message); }
public void CIBuildVersion_LastReleaseBased_are_correctely_ordered(string tag) { ReleaseTagFormat formatV2 = ReleaseTagFormat.NugetPackageV2; var t = ReleaseTagVersion.TryParse(tag); var v = SemVersion.Parse(t.ToString(ReleaseTagFormat.SemVer), true); var tNext = new ReleaseTagVersion(t.OrderedVersion + 1); var vNext = SemVersion.Parse(tNext.ToString(ReleaseTagFormat.SemVer), true); var tPrev = new ReleaseTagVersion(t.OrderedVersion - 1); var vPrev = SemVersion.Parse(tPrev.ToString(ReleaseTagFormat.SemVer), true); Assert.That(vPrev < v, "{0} < {1}", vPrev, v); Assert.That(v < vNext, "{0} < {1}", v, vNext); var sNuGet = t.ToString(formatV2); var sNuGetPrev = tPrev.ToString(formatV2); var sNuGetNext = tNext.ToString(formatV2); Assert.That(NuGetV2StringComparer.DefaultComparer.Compare(sNuGetPrev, sNuGet) < 0, "{0} < {1}", sNuGetPrev, sNuGet); Assert.That(NuGetV2StringComparer.DefaultComparer.Compare(sNuGet, sNuGetNext) < 0, "{0} < {1}", sNuGet, sNuGetNext); CIBuildDescriptor ci = new CIBuildDescriptor { BranchName = "dev", BuildIndex = 1 }; string sCI = t.ToString(ReleaseTagFormat.SemVer, ci); SemVersion vCi = SemVersion.Parse(sCI, true); Assert.That(v < vCi, "{0} < {1}", v, vCi); Assert.That(vCi < vNext, "{0} < {1}", vCi, vNext); var sNuGetCI = t.ToString(formatV2, ci); Assert.That(NuGetV2StringComparer.DefaultComparer.Compare(sNuGet, sNuGetCI) < 0, "{0} < {1}", sNuGet, sNuGetCI); Assert.That(NuGetV2StringComparer.DefaultComparer.Compare(sNuGetCI, sNuGetNext) < 0, "{0} < {1}", sNuGetCI, sNuGetNext); string sCiNext = tNext.ToString(ReleaseTagFormat.SemVer, ci); SemVersion vCiNext = SemVersion.Parse(sCiNext, true); Assert.That(vCiNext > vCi, "{0} > {1}", vCiNext, vCi); Assert.That(vCiNext > vNext, "{0} > {1}", vCiNext, vNext); var sNuGetCINext = tNext.ToString(formatV2, ci); Assert.That(NuGetV2StringComparer.DefaultComparer.Compare(sNuGetCINext, sNuGetCI) > 0, "{0} > {1}", sNuGetCINext, sNuGetCI); Assert.That(NuGetV2StringComparer.DefaultComparer.Compare(sNuGetCINext, sNuGetNext) > 0, "{0} > {1}", sNuGetCINext, sNuGetNext); string sCiPrev = tPrev.ToString(ReleaseTagFormat.SemVer, ci); SemVersion vCiPrev = SemVersion.Parse(sCiPrev, true); Assert.That(vCiPrev > vPrev, "{0} > {1}", vCiPrev, vPrev); Assert.That(vCiPrev < v, "{0} < {1}", vCiPrev, v); Assert.That(vCiPrev < vCiNext, "{0} < {1}", vCiPrev, vCiNext); var sNuGetCIPrev = tPrev.ToString(formatV2, ci); Assert.That(NuGetV2StringComparer.DefaultComparer.Compare(sNuGetCIPrev, sNuGetPrev) > 0, "{0} > {1}", sNuGetCIPrev, sNuGetPrev); Assert.That(NuGetV2StringComparer.DefaultComparer.Compare(sNuGetCIPrev, sNuGet) < 0, "{0} < {1}", sNuGetCIPrev, sNuGet); Assert.That(NuGetV2StringComparer.DefaultComparer.Compare(sNuGetCIPrev, sNuGetCINext) < 0, "{0} < {1}", sNuGetCIPrev, sNuGetCINext); }