Skip to content

Commit 3474397

Browse files
committed
Merge pull request #311 from JakeGinnivan/TestImprovements
Test improvements
2 parents 4a6dccd + 2106c0a commit 3474397

File tree

9 files changed

+233
-292
lines changed

9 files changed

+233
-292
lines changed

GitVersionCore.Tests/ConfigReaderTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ public void CanReadDocument()
1414
assemblyVersioningScheme: MajorMinor
1515
develop-branch-tag: alpha
1616
release-branch-tag: rc
17+
tag-prefix: '[vV|version-]'
1718
";
1819
var config = ConfigReader.Read(new StringReader(text));
1920
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
2021
config.DevelopBranchTag.ShouldBe("alpha");
2122
config.ReleaseBranchTag.ShouldBe("rc");
23+
config.TagPrefix.ShouldBe("[vV|version-]");
2224
}
2325

2426
[Test]
@@ -29,5 +31,6 @@ public void CanReadDefaultDocument()
2931
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
3032
config.DevelopBranchTag.ShouldBe("unstable");
3133
config.ReleaseBranchTag.ShouldBe("beta");
34+
config.TagPrefix.ShouldBe("[vV]");
3235
}
3336
}

GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
<Compile Include="GitDirFinderTests.cs" />
7171
<Compile Include="Fixtures\BaseGitFlowRepositoryFixture.cs" />
7272
<Compile Include="IntegrationTests\GitFlow\DevelopScenarios.cs" />
73+
<Compile Include="IntegrationTests\GitFlow\SupportBranchScenarios.cs" />
7374
<Compile Include="IntegrationTests\GitFlow\MetaDataByCommitScenarios.cs" />
7475
<Compile Include="IntegrationTests\GitFlow\PatchScenarios.cs" />
7576
<Compile Include="IntegrationTests\GitFlow\ReleaseBranchTests.cs" />
@@ -79,8 +80,8 @@
7980
<Compile Include="Helpers\Constants.cs" />
8081
<Compile Include="Helpers\NextVersionWriter.cs" />
8182
<Compile Include="InformationalVersionBuilderTests.cs" />
83+
<Compile Include="IntegrationTests\GitHubFlow\SupportBranchScenarios.cs" />
8284
<Compile Include="JsonVersionBuilderTests.cs" />
83-
<Compile Include="LastVersionOnMasterFinderTests.cs" />
8485
<Compile Include="ModuleInitializer.cs" />
8586
<Compile Include="Fixtures\EmptyRepositoryFixture.cs" />
8687
<Compile Include="Helpers\GitHelper.cs" />

GitVersionCore.Tests/Helpers/GitHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public static Commit MakeACommit(this IRepository repository, DateTimeOffset dat
1919
return repository.Commit("Test Commit", Constants.Signature(dateTimeOffset), Constants.Signature(dateTimeOffset));
2020
}
2121

22+
public static void MergeNoFF(this IRepository repository, string branch)
23+
{
24+
MergeNoFF(repository, branch, Constants.SignatureNow());
25+
}
26+
2227
public static void MergeNoFF(this IRepository repository, string branch, Signature sig)
2328
{
2429
repository.Merge(repository.FindBranch(branch), sig, new MergeOptions

GitVersionCore.Tests/IntegrationTests/GitFlow/MetaDataByCommitScenarios.cs

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using LibGit2Sharp;
1+
using System;
2+
using GitVersion;
3+
using LibGit2Sharp;
24
using NUnit.Framework;
35
using Shouldly;
46

@@ -26,7 +28,7 @@ public class MetaDataByCommitScenarios
2628
*/
2729

2830
[Test]
29-
public void CanCorrectlyDetectCommitCountsAndReleaseDataWhenThatApplies()
31+
public void CanCorrectlyDetectCommitCountsSemVer()
3032
{
3133
using (var f = new CommitCountingRepoFixture())
3234
{
@@ -77,6 +79,89 @@ public void CanCorrectlyDetectCommitCountsAndReleaseDataWhenThatApplies()
7779
}
7880
}
7981

82+
83+
/*
84+
* hotfix-1.2.1 -----------C--
85+
* / \
86+
* master A----------------F-----H-------N
87+
* \ / \ /
88+
* hotfix-1.3.1 \ / ----L
89+
* \ / \
90+
* release-1.3.0 \ -D----G--- \
91+
* \ / \ \
92+
* develop -----B----E-------I-----M--O--P
93+
* \ /
94+
* feature -------J-K-
95+
*
96+
*
97+
* - A is tagged `1.2.0`
98+
* - F is tagged `1.2.1`
99+
* - H is tagged `1.3.0`
100+
* - N is tagged `1.3.1`
101+
*/
102+
103+
[Test]
104+
public void CanCorrectlyDetectCommitCountsAndReleaseDataWhenThatApplies()
105+
{
106+
using (var f = new CommitCountingRepoFixture())
107+
{
108+
ResetToP(f.Repository);
109+
EnsureBranchMatch(f, "develop");
110+
111+
ResetToO(f.Repository);
112+
EnsureBranchMatch(f, "develop");
113+
114+
ResetToN(f.Repository);
115+
EnsureBranchMatch(f, "master", r => (Commit)r.Tags["1.3.0"].Target);
116+
117+
ResetToM(f.Repository);
118+
EnsureBranchMatch(f, "develop");
119+
120+
ResetToL(f.Repository);
121+
EnsureBranchMatch(f, "hotfix-1.3.1", r => (Commit)r.Tags["1.3.0"].Target);
122+
123+
ResetToK(f.Repository);
124+
EnsureBranchMatch(f, "feature");
125+
126+
ResetToJ(f.Repository);
127+
EnsureBranchMatch(f, "feature");
128+
129+
ResetToI(f.Repository);
130+
EnsureBranchMatch(f, "develop");
131+
132+
ResetToH(f.Repository);
133+
EnsureBranchMatch(f, "master", r => (Commit)r.Tags["1.3.0"].Target);
134+
135+
ResetToG(f.Repository);
136+
EnsureBranchMatch(f, "release-1.3.0");
137+
138+
ResetToF(f.Repository);
139+
EnsureBranchMatch(f, "master", r => (Commit)r.Tags["1.2.0"].Target);
140+
141+
ResetToE(f.Repository);
142+
EnsureBranchMatch(f, "develop");
143+
144+
ResetToD(f.Repository);
145+
EnsureBranchMatch(f, "release-1.3.0");
146+
147+
ResetToC(f.Repository);
148+
EnsureBranchMatch(f, "hotfix-1.2.1", r => (Commit)r.Tags["1.2.0"].Target);
149+
150+
ResetToB(f.Repository);
151+
EnsureBranchMatch(f, "develop");
152+
}
153+
}
154+
155+
static void EnsureBranchMatch(CommitCountingRepoFixture fixture, string branchName, Func<IRepository, Commit> commitFinder = null)
156+
{
157+
var referenceCommitFinder = commitFinder ?? (r => r.FindBranch(branchName).Tip);
158+
159+
var commit = referenceCommitFinder(fixture.Repository);
160+
var releaseDate = LastMinorVersionFinder.Execute(fixture.Repository, commit);
161+
releaseDate.ShouldBe(commit.When());
162+
}
163+
164+
80165
static void EnsureMetaDataMatch(CommitCountingRepoFixture fixture,string expectedSemVer)
81166
{
82167
var result = fixture.ExecuteGitVersion();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
namespace GitVersionCore.Tests.IntegrationTests.GitFlow
2+
{
3+
using LibGit2Sharp;
4+
using NUnit.Framework;
5+
6+
[TestFixture]
7+
public class SupportBranchScenarios
8+
{
9+
[Test]
10+
public void SupportIsCalculatedCorrectly()
11+
{
12+
using (var fixture = new BaseGitFlowRepositoryFixture("1.1.0"))
13+
{
14+
// Create 2.0.0 release
15+
fixture.Repository.CreateBranch("release-2.0.0").Checkout();
16+
fixture.Repository.MakeCommits(2);
17+
18+
// Merge into develop and master
19+
fixture.Repository.Checkout("master");
20+
fixture.Repository.MergeNoFF("release-2.0.0");
21+
fixture.Repository.ApplyTag("2.0.0");
22+
fixture.Repository.Checkout("develop");
23+
fixture.Repository.MergeNoFF("release-2.0.0");
24+
fixture.AssertFullSemver("2.1.0-unstable.0+0");
25+
26+
// Now lets support 1.x release
27+
fixture.Repository.Checkout("1.1.0");
28+
fixture.Repository.CreateBranch("support/1.0.0").Checkout();
29+
fixture.AssertFullSemver("1.1.0");
30+
31+
// Create release branch from support branch
32+
fixture.Repository.CreateBranch("release/1.2.0").Checkout();
33+
fixture.Repository.MakeACommit();
34+
fixture.AssertFullSemver("1.2.0-beta.1+1");
35+
36+
// Create 1.2.0 release
37+
fixture.Repository.Checkout("support/1.0.0");
38+
fixture.Repository.MergeNoFF("release/1.2.0");
39+
fixture.AssertFullSemver("1.2.0");
40+
fixture.Repository.ApplyTag("1.2.0");
41+
42+
// Create 1.2.1 hotfix
43+
fixture.Repository.CreateBranch("hotfix/1.2.1").Checkout();
44+
fixture.Repository.MakeACommit();
45+
fixture.AssertFullSemver("1.2.1-beta.1+3"); // TODO This should be +1
46+
fixture.Repository.Checkout("support/1.0.0");
47+
fixture.Repository.MergeNoFF("hotfix/1.2.1");
48+
fixture.AssertFullSemver("1.2.1");
49+
}
50+
}
51+
}
52+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
namespace GitVersionCore.Tests.IntegrationTests.GitHubFlow
2+
{
3+
using GitVersion;
4+
using LibGit2Sharp;
5+
using NUnit.Framework;
6+
7+
[TestFixture]
8+
public class SupportBranchScenarios
9+
{
10+
[Test]
11+
public void SupportIsCalculatedCorrectly()
12+
{
13+
using (var fixture = new EmptyRepositoryFixture(new Config()))
14+
{
15+
// Start at 1.0.0
16+
fixture.Repository.MakeACommit();
17+
fixture.Repository.ApplyTag("1.1.0");
18+
19+
// Create 2.0.0 release
20+
fixture.Repository.CreateBranch("release-2.0.0").Checkout();
21+
fixture.Repository.MakeCommits(2);
22+
23+
// Merge into develop and master
24+
fixture.Repository.Checkout("master");
25+
fixture.Repository.MergeNoFF("release-2.0.0");
26+
fixture.Repository.ApplyTag("2.0.0");
27+
fixture.AssertFullSemver("2.0.0+0");
28+
29+
// Now lets support 1.x release
30+
fixture.Repository.Checkout("1.1.0");
31+
fixture.Repository.CreateBranch("support/1.0.0").Checkout();
32+
fixture.AssertFullSemver("1.1.0+0");
33+
34+
// Create release branch from support branch
35+
fixture.Repository.CreateBranch("release/1.2.0").Checkout();
36+
fixture.Repository.MakeACommit();
37+
fixture.AssertFullSemver("1.2.0-beta.1+1");
38+
39+
// Create 1.2.0 release
40+
fixture.Repository.Checkout("support/1.0.0");
41+
fixture.Repository.MergeNoFF("release/1.2.0");
42+
fixture.AssertFullSemver("1.2.0+2");
43+
fixture.Repository.ApplyTag("1.2.0");
44+
45+
// Create 1.2.1 hotfix
46+
fixture.Repository.CreateBranch("hotfix/1.2.1").Checkout();
47+
fixture.Repository.MakeACommit();
48+
fixture.AssertFullSemver("1.2.1+1");
49+
fixture.Repository.Checkout("support/1.0.0");
50+
fixture.Repository.MergeNoFF("hotfix/1.2.1");
51+
fixture.AssertFullSemver("1.2.1+2");
52+
}
53+
}
54+
55+
56+
57+
[Test]
58+
public void WhenSupportIsBranchedAndTaggedFromAnotherSupportEnsureNewMinorIsUsed()
59+
{
60+
using (var fixture = new EmptyRepositoryFixture(new Config()))
61+
{
62+
fixture.Repository.MakeACommit();
63+
fixture.Repository.CreateBranch("Support-1.2.0");
64+
fixture.Repository.Checkout("Support-1.2.0");
65+
fixture.Repository.MakeACommit();
66+
fixture.Repository.ApplyTag("1.2.0");
67+
68+
fixture.Repository.CreateBranch("Support-1.3.0");
69+
fixture.Repository.Checkout("Support-1.3.0");
70+
fixture.Repository.ApplyTag("1.3.0");
71+
72+
//Move On
73+
fixture.Repository.MakeACommit();
74+
fixture.Repository.MakeACommit();
75+
76+
fixture.AssertFullSemver("1.3.1+2");
77+
}
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)