-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
Versions.cs
132 lines (112 loc) · 3.87 KB
/
Versions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System.Reflection;
using MinVer.Lib;
using MinVerTests.Infra;
using MinVerTests.Lib.Infra;
using Xunit;
using static MinVerTests.Infra.FileSystem;
using static MinVerTests.Infra.Git;
using static SimpleExec.Command;
namespace MinVerTests.Lib;
public static class Versions
{
[Fact]
public static async Task RepoWithHistory()
{
// arrange
var historicalCommands =
@"
git commit --allow-empty -m '.'
git commit --allow-empty -m '.'
git commit --allow-empty -m '.'
git tag 0.0.0-alpha.1
git commit --allow-empty -m '.'
git commit --allow-empty -m '.'
git tag 0.0.0
git commit --allow-empty -m '.'
git commit --allow-empty -m '.'
git tag 0.1.0-beta.1
git commit --allow-empty -m '.'
git commit --allow-empty -m '.'
git tag 0.1.0
git commit --allow-empty -m '.'
git commit --allow-empty -m '.'
git tag 1.0.0-alpha.1
git commit --allow-empty -m '.'
git commit --allow-empty -m '.'
git tag 1.0.0-rc.1
git tag 1.0.0
git checkout -b foo
git commit --allow-empty -m '.'
git commit --allow-empty -m '.'
git commit --allow-empty -m '.'
git tag 1.0.1-alpha.1
git commit --allow-empty -m '.'
git commit --allow-empty -m '.'
git tag 1.0.1
git commit --allow-empty -m '.'
git checkout main
git commit --allow-empty -m '.'
git commit --allow-empty -m '.'
git commit --allow-empty -m '.'
git tag 1.1.0-alpha.1
git commit --allow-empty -m '.'
git merge foo --no-edit
git commit --allow-empty -m '.'
git tag 1.1.0-beta.2
git tag 1.1.0-beta.10
git commit --allow-empty -m '.'
git commit --allow-empty -m '.'
git tag 1.1.0-rc.1
git tag 1.1.0 -a -m '.'
";
var path = MethodBase.GetCurrentMethod().GetTestDirectory();
await EnsureEmptyRepositoryAndCommit(path);
foreach (var command in historicalCommands.ToNonEmptyLines())
{
var nameAndArgs = command.Split(" ", 2);
_ = await ReadAsync(nameAndArgs[0], nameAndArgs[1], path);
await Task.Delay(200);
}
var log = new TestLogger();
// act
var versionCounts = new Dictionary<string, int>();
foreach (var sha in await GetCommitShas(path))
{
await Checkout(path, sha);
var version = Versioner.GetVersion(path, "", MajorMinor.Default, "", default, PreReleaseIdentifiers.Default, false, log);
var versionString = version.ToString();
var tagName = $"v/{versionString}";
_ = versionCounts.TryGetValue(versionString, out var oldVersionCount);
var versionCount = oldVersionCount + 1;
versionCounts[versionString] = versionCount;
tagName = versionCount > 1 ? $"v({versionCount})/{versionString}" : tagName;
await Tag(path, tagName, sha);
}
await Checkout(path, "main");
await File.WriteAllTextAsync(Path.Combine(path, "log.txt"), log.ToString());
// assert
await AssertFile.Contains("../../../versions.txt", await GetGraph(path));
}
[Fact]
public static async Task EmptyRepo()
{
// arrange
var path = MethodBase.GetCurrentMethod().GetTestDirectory();
await EnsureEmptyRepository(path);
// act
var version = Versioner.GetVersion(path, "", MajorMinor.Default, "", default, PreReleaseIdentifiers.Default, false, NullLogger.Instance);
// assert
Assert.Equal("0.0.0-alpha.0", version.ToString());
}
[Fact]
public static void NoRepo()
{
// arrange
var path = MethodBase.GetCurrentMethod().GetTestDirectory();
EnsureEmptyDirectory(path);
// act
var version = Versioner.GetVersion(path, "", MajorMinor.Default, "", default, PreReleaseIdentifiers.Default, false, NullLogger.Instance);
// assert
Assert.Equal("0.0.0-alpha.0", version.ToString());
}
}