Skip to content

Commit

Permalink
GitTools#3341 - fix parsing loose version format
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Feb 18, 2023
1 parent 0d6bf96 commit a516965
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,32 @@ public void ReturnsNullWhenNoNextVersionIsInConfig()
baseVersion.ShouldBe(null);
}

[TestCase("1.0.0", "1.0.0")]
[TestCase("2.12.654651698", "2.12.654651698")]
public void ConfigNextVersionTest(string nextVersion, string expectedVersion)
[TestCase("1.0.0", "1.0.0", SemanticVersionFormat.Strict)]
[TestCase("1.0.0", "1.0.0", SemanticVersionFormat.Loose)]
[TestCase("2.12.654651698", "2.12.654651698", SemanticVersionFormat.Strict)]
[TestCase("2.12.654651698", "2.12.654651698", SemanticVersionFormat.Loose)]
[TestCase("0.1", "0.1.0", SemanticVersionFormat.Loose)]
public void ConfigNextVersionTest(string nextVersion, string expectedVersion, SemanticVersionFormat versionFormat)
{
var baseVersion = GetBaseVersion(new GitVersionConfiguration
{
NextVersion = nextVersion
});
var baseVersion = GetBaseVersion(new GitVersionConfiguration { NextVersion = nextVersion, SemanticVersionFormat = versionFormat });

baseVersion.ShouldNotBeNull();
baseVersion.ShouldIncrement.ShouldBe(false);
baseVersion.SemanticVersion.ToString().ShouldBe(expectedVersion);
}

[TestCase("0.1", SemanticVersionFormat.Strict)]
public void ConfigNextVersionTestShouldFail(string nextVersion, SemanticVersionFormat versionFormat)
=>
Should.Throw<WarningException>(()
=> GetBaseVersion(new GitVersionConfiguration
{
NextVersion = nextVersion,
SemanticVersionFormat = versionFormat
}))
.Message.ShouldBe($"Failed to parse {nextVersion} into a Semantic Version");


private static BaseVersion? GetBaseVersion(GitVersionConfiguration? configuration = null)
{
var contextBuilder = new GitVersionContextBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ public ConfigNextVersionVersionStrategy(Lazy<GitVersionContext> versionContext)

public override IEnumerable<BaseVersion> GetBaseVersions(EffectiveBranchConfiguration configuration)
{
var nextVersion = Context.Configuration.NextVersion;
var contextConfiguration = Context.Configuration;
var nextVersion = contextConfiguration.NextVersion;
if (!nextVersion.IsNullOrEmpty() && !Context.IsCurrentCommitTagged)
{
var semanticVersion = SemanticVersion.Parse(nextVersion, Context.Configuration.LabelPrefix);
var semanticVersion = SemanticVersion.Parse(nextVersion, contextConfiguration.LabelPrefix, contextConfiguration.SemanticVersionFormat);
yield return new BaseVersion("NextVersion in GitVersion configuration file", false, semanticVersion, null, null);
}
}
Expand Down

0 comments on commit a516965

Please sign in to comment.