Skip to content

Commit

Permalink
Added failing tests for #1255, #1844, #2034, #2693, #2821, #2786
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Mar 19, 2023
1 parent 52994cb commit 3deab7a
Showing 1 changed file with 289 additions and 0 deletions.
289 changes: 289 additions & 0 deletions src/GitVersion.Core.Tests/IntegrationTests/FailingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
using GitVersion.Configuration;
using GitVersion.Core.Tests.Helpers;
using GitVersion.Extensions;
using GitVersion.VersionCalculation;
using LibGit2Sharp;

namespace GitVersion.Core.Tests.IntegrationTests;

[TestFixture]
public class FailingTests : TestBase
{
[Test(Description = "Failed test: Issue #1255, PR #1600, DevelopScenarios")]
public void ShouldProvideTheCorrectVersionEvenIfPreReleaseLabelExistsInTheGitTagDevelop()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeACommit();
fixture.ApplyTag("1.0.0-oreo.1");
fixture.BranchTo("develop");
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.1.0-alpha.1");
}

[Test(Description = "Failed test: Issue #1255, PR #1600, MainScenarios")]
public void ShouldProvideTheCorrectVersionEvenIfPreReleaseLabelExistsInTheGitTagMain()
{
var configuration = GitFlowConfigurationBuilder.New
.WithSemanticVersionFormat(SemanticVersionFormat.Loose)
.WithNextVersion("5.0")
.WithBranch(MainBranch,
branchBuilder => branchBuilder.WithLabel("beta")
.WithIncrement(IncrementStrategy.Patch)
.WithVersioningMode(VersioningMode.ContinuousDeployment))
.Build();

using EmptyRepositoryFixture fixture = new(MainBranch);
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("5.0.0-beta.0", configuration); // why not "5.0.0-beta.1"?
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("5.0.0-beta.1", configuration);
fixture.Repository.MakeATaggedCommit("v5.0.0-rc.1");
fixture.AssertFullSemver("5.0.0-rc.1", configuration);
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("5.0.1-beta.1", configuration); // test fails here, it generates "5.0.0-beta.1" which is not unique and lower than "5.0.0-rc.1"
}

[Test(Description = "Failed test: Issue #1844, PR #1845, VersionBumpingScenarios")]
public void AppliedPrereleaseTagAfterBranchTagCausesVersionBump()
{
var configuration = GitFlowConfigurationBuilder.New
.WithBranch(MainBranch,
branchBuilder => branchBuilder.WithLabel("pre")
.WithSourceBranches(ArraySegment<string>.Empty)
.WithVersioningMode(VersioningMode.ContinuousDeployment))
.Build();

using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeACommit();
fixture.Repository.MakeATaggedCommit("1.0.0-rc");
fixture.Repository.MakeACommit();

fixture.AssertFullSemver("1.0.1-pre.1", configuration);
}

[Test(Description = "Failed test: Issue #2034, PR #2059, MainlineDevelopmentMode")]
public void MergingMainBranchToDevelopWithInheritIncrementShouldIncrementDevelopPatch()
{
var configuration = GitFlowConfigurationBuilder.New
.WithAssemblyVersioningScheme(AssemblyVersioningScheme.MajorMinorPatch)
.WithVersioningMode(VersioningMode.Mainline)
.WithBranch(MainBranch, branchBuilder => branchBuilder.WithIncrement(IncrementStrategy.Patch))
.WithBranch("develop", branchBuilder => branchBuilder.WithIncrement(IncrementStrategy.Inherit))
.Build();

using var fixture = new EmptyRepositoryFixture();
fixture.MakeACommit($"initial in {MainBranch}");
fixture.AssertFullSemver("0.1.0", configuration);
fixture.MakeACommit($"{MainBranch} change");
fixture.AssertFullSemver("0.1.1", configuration);

fixture.BranchTo("develop");
fixture.AssertFullSemver("0.1.2-alpha.0", configuration);
fixture.MakeACommit("develop change");
fixture.AssertFullSemver("0.1.2-alpha.1", configuration);

fixture.Checkout(MainBranch);
fixture.MakeACommit($"{MainBranch} hotfix");
fixture.AssertFullSemver("0.1.2", configuration);

fixture.Checkout("develop");
fixture.MergeNoFF(MainBranch);
fixture.AssertFullSemver("0.1.3-alpha.1", configuration);
}

[Test(Description = "Failed test: Issue #2693, PR #2696, HotfixBranchScenarios")]
public void VersionNumberInHotfixBranchShouldBeConsideredWhenPreventIncrementOfMergedBranchVersion()
{
var configuration = GitFlowConfigurationBuilder.New
.WithAssemblyVersioningScheme(AssemblyVersioningScheme.MajorMinorPatchTag)
.WithAssemblyFileVersioningFormat("{MajorMinorPatch}.0")
.WithVersioningMode(VersioningMode.ContinuousDeployment)
.WithBranch("hotfix",
branchBuilder => branchBuilder
.WithPreventIncrementOfMergedBranchVersion(true)
.WithRegularExpression("r^(origin/)?hotfix[/-]")
)
.Build();

const string HotfixBranch = "hotfix/1.1.1";
const string ReleaseBranch = "release/1.1.0";

using var fixture = new BaseGitFlowRepositoryFixture("1.0.0");
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch(ReleaseBranch));
fixture.MakeACommit();
Commands.Checkout(fixture.Repository, MainBranch);
fixture.MergeNoFF(ReleaseBranch);
fixture.Repository.CreateBranch(HotfixBranch);
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.1.1-ci.1", configuration);
}

[TestFixture(Description = "Failed test: Issue #2821, PR #2830")]
public class XenoLibPackages : TestBase
{
private readonly GitVersionConfiguration configuration = GitFlowConfigurationBuilder.New
.WithVersioningMode(VersioningMode.Mainline)
.WithBranch("feature", branchBuilder => branchBuilder.WithIncrement(IncrementStrategy.Minor))
.WithBranch("pull-request", branchBuilder => branchBuilder.WithIncrement(IncrementStrategy.Minor))
.WithBranch("support",
branchBuilder => branchBuilder
.WithVersioningMode(VersioningMode.ContinuousDeployment)
.WithLabel("beta")
.WithIncrement(IncrementStrategy.Patch))
.Build();

[Test]
public void IncrementFeatureByMinor()
{
using var fixture = new EmptyRepositoryFixture();
fixture.MakeATaggedCommit("0.1.0");

// feature workflow
fixture.BranchTo("feature/foo", "foo");
fixture.MakeACommit();
fixture.AssertFullSemver("0.2.0-foo.1", this.configuration);
fixture.MakeACommit();
fixture.AssertFullSemver("0.2.0-foo.2", this.configuration);
fixture.Checkout(MainBranch);
fixture.MergeNoFF("feature/foo");
fixture.AssertFullSemver("0.2.0", this.configuration);
}

[Test]
public void CanCalculatePullRequestChanges()
{
using var fixture = new EmptyRepositoryFixture();
fixture.Repository.MakeATaggedCommit("1.0.0");
fixture.Repository.MakeATaggedCommit("1.1.0");
fixture.Repository.MakeATaggedCommit("2.0.0");

// feature branch
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/foo"));
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("2.1.0-foo.1", this.configuration);
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("2.1.0-foo.2", this.configuration);

// pull request
fixture.Repository.CreatePullRequestRef("feature/foo", MainBranch, normalise: true);
fixture.AssertFullSemver("2.1.0-PullRequest0002.3", this.configuration);
Commands.Checkout(fixture.Repository, MainBranch);
fixture.Repository.MergeNoFF("feature/foo", Generate.SignatureNow());
fixture.AssertFullSemver("2.1.0", this.configuration);
fixture.Repository.MakeATaggedCommit("2.1.0"); // must tag before pull of any hotfix otherwise hotfix stays at this version

// hotfix branch
var tag = fixture.Repository.Tags.Single(t => t.FriendlyName == "1.0.0");
var supportBranch = fixture.Repository.CreateBranch("support/1.0.0", (LibGit2Sharp.Commit)tag.Target);
Commands.Checkout(fixture.Repository, supportBranch);
fixture.AssertFullSemver("1.0.0", this.configuration);
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.0.1-beta.1", this.configuration);
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.0.1-beta.2", this.configuration);
fixture.Repository.MakeATaggedCommit("1.0.1");
fixture.Repository.MakeACommit();
fixture.AssertFullSemver("1.0.2-beta.1", this.configuration);

// pull request
fixture.Repository.CreatePullRequestRef("support/1.0.0", MainBranch, 3, normalise: true);
fixture.Repository.DumpGraph();
fixture.AssertFullSemver("2.1.1-PullRequest0003.6", this.configuration);
Commands.Checkout(fixture.Repository, MainBranch);
fixture.Repository.MergeNoFF("support/1.0.0", Generate.SignatureNow());
fixture.AssertFullSemver("2.1.1", this.configuration);
}
}

[TestFixture(Description = "Failed test: Issue #2786, PR #2787, MainlineDevelopmentMode")]
public class HotfixBranchesWithTaggedCommits
{
[Test]
public void HotfixBranchesWithTaggedCommitsOnMain()
{
using var fixture = new EmptyRepositoryFixture();
var configuration = GitFlowConfigurationBuilder.New
.WithVersioningMode(VersioningMode.Mainline)
.WithIncrement(IncrementStrategy.Minor)
.WithBranch(ConfigurationConstants.MainBranchKey,
branchBuilder => branchBuilder
.WithRegularExpression(ConfigurationConstants.MainBranchRegex)
.WithSourceBranches(ConfigurationConstants.DevelopBranchKey, ConfigurationConstants.ReleaseBranchKey)
.WithLabel("")
.WithPreventIncrementOfMergedBranchVersion(true)
.WithIncrement(IncrementStrategy.Minor)
.WithIsMainline(true)
.WithPreReleaseWeight(55000)
)
.WithBranch(ConfigurationConstants.HotfixBranchKey, branchBuilder => branchBuilder.WithLabel(""))
.Build();

fixture.Repository.MakeACommit("1");
fixture.MakeATaggedCommit("1.0.0");

fixture.MakeACommit(); // 1.1.0
fixture.AssertFullSemver("1.1.0", configuration);
fixture.ApplyTag("1.1.0");
fixture.AssertFullSemver("1.1.0", configuration);

fixture.BranchTo("hotfix/may");
fixture.AssertFullSemver("1.1.1", configuration);

// Move main on
fixture.Checkout(MainBranch);
fixture.MakeACommit();
fixture.AssertFullSemver("1.2.0", configuration);

// Continue on hotfix
fixture.Checkout("hotfix/may");
fixture.MakeACommit(); // 1.2.1
fixture.AssertFullSemver("1.1.1", configuration);
}

[Test]
public void HotfixBranchesWithTaggedCommitsOnHotfix()
{
using var fixture = new EmptyRepositoryFixture();
var configuration = GitFlowConfigurationBuilder.New
.WithVersioningMode(VersioningMode.Mainline)
.WithIncrement(IncrementStrategy.Minor)
.WithBranch(ConfigurationConstants.MainBranchKey,
branchBuilder => branchBuilder
.WithRegularExpression(ConfigurationConstants.MainBranchRegex)
.WithSourceBranches(ConfigurationConstants.DevelopBranchKey, ConfigurationConstants.ReleaseBranchKey)
.WithLabel("")
.WithPreventIncrementOfMergedBranchVersion(true)
.WithIncrement(IncrementStrategy.Minor)
.WithIsMainline(true)
.WithPreReleaseWeight(55000)
)
.WithBranch(ConfigurationConstants.HotfixBranchKey, branchBuilder => branchBuilder.WithLabel(""))
.Build();

fixture.Repository.MakeACommit("1");
fixture.MakeATaggedCommit("1.0.0");

fixture.MakeACommit(); // 1.1.0
fixture.AssertFullSemver("1.1.0", configuration);
fixture.ApplyTag("1.1.0");
fixture.AssertFullSemver("1.1.0", configuration);
fixture.MakeACommit(); // 1.2.0
fixture.AssertFullSemver("1.2.0", configuration);

fixture.BranchTo("hotfix/may");
fixture.AssertFullSemver("1.2.1", configuration);

// Move main on
fixture.Checkout(MainBranch);
fixture.MakeACommit();
fixture.AssertFullSemver("1.3.0", configuration);

// Continue on hotfix
fixture.Checkout("hotfix/may");
fixture.MakeACommit(); // 1.2.1
fixture.MakeATaggedCommit("1.2.2");
fixture.MakeACommit(); // 1.2.3
fixture.AssertFullSemver("1.2.3", configuration);
}
}
}

0 comments on commit 3deab7a

Please sign in to comment.