Skip to content

Commit 8b7d45f

Browse files
committed
Add real git submodule test
And replace the reflection-based mini test.
1 parent 2aeed51 commit 8b7d45f

File tree

6 files changed

+77
-77
lines changed

6 files changed

+77
-77
lines changed

src/NerdBank.GitVersioning.Tests/NerdBank.GitVersioning.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@
5050
<Compile Include="GitExtensionsTests.cs" />
5151
<Compile Include="MSBuildExtensions.cs" />
5252
<Compile Include="Properties\AssemblyInfo.cs" />
53-
<Compile Include="RepoFinderTests.cs" />
5453
<Compile Include="RepoTestBase.cs" />
5554
<Compile Include="SemanticVersionTests.cs" />
5655
<Compile Include="TestUtilities.cs" />
5756
<Compile Include="VersionExtensionsTests.cs" />
5857
<Compile Include="VersionFileTests.cs" />
5958
<Compile Include="VersionOptionsTests.cs" />
59+
<Compile Include="VersionOracleTests.cs" />
6060
</ItemGroup>
6161
<ItemGroup>
6262
<EmbeddedResource Include="..\Nerdbank.GitVersioning.NuGet\build\*.targets">
@@ -83,6 +83,7 @@
8383
<EmbeddedResource Include="Keys\protectedPair.pfx" />
8484
<None Include="project.json" />
8585
<EmbeddedResource Include="test.proj" />
86+
<EmbeddedResource Include="repos\submodules.7z" />
8687
</ItemGroup>
8788
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
8889
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

src/NerdBank.GitVersioning.Tests/RepoFinderTests.cs

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/NerdBank.GitVersioning.Tests/TestUtilities.cs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Validation;
1+
using SevenZipNET;
2+
using Validation;
3+
24
namespace Nerdbank.GitVersioning.Tests
35
{
46
using System;
@@ -54,5 +56,45 @@ internal static void ExtractEmbeddedResource(string resourcePath, string extract
5456
}
5557
}
5658
}
59+
60+
internal static ExpandedRepo ExtractRepoArchive(string repoArchiveName)
61+
{
62+
string archiveFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
63+
string expandedFolderPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
64+
65+
ExtractEmbeddedResource($"repos.{repoArchiveName}.7z", archiveFilePath);
66+
try
67+
{
68+
var extractor = new SevenZipExtractor(archiveFilePath);
69+
extractor.ExtractAll(expandedFolderPath);
70+
return new ExpandedRepo(expandedFolderPath);
71+
}
72+
finally
73+
{
74+
if (File.Exists(archiveFilePath))
75+
{
76+
File.Delete(archiveFilePath);
77+
}
78+
}
79+
}
80+
81+
internal class ExpandedRepo : IDisposable
82+
{
83+
internal ExpandedRepo(string repoPath)
84+
{
85+
Requires.NotNullOrEmpty(repoPath, nameof(repoPath));
86+
this.RepoPath = repoPath;
87+
}
88+
89+
public string RepoPath { get; private set; }
90+
91+
public void Dispose()
92+
{
93+
if (Directory.Exists(this.RepoPath))
94+
{
95+
DeleteDirectory(this.RepoPath);
96+
}
97+
}
98+
}
5799
}
58100
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.IO;
2+
using LibGit2Sharp;
3+
using Nerdbank.GitVersioning;
4+
using Nerdbank.GitVersioning.Tests;
5+
using Xunit;
6+
using Xunit.Abstractions;
7+
8+
public class VersionOracleTests : RepoTestBase
9+
{
10+
public VersionOracleTests(ITestOutputHelper logger)
11+
: base(logger)
12+
{
13+
}
14+
15+
[Fact]
16+
public void Submodule_RecognizedWithCorrectVersion()
17+
{
18+
using (var expandedRepo = TestUtilities.ExtractRepoArchive("submodules"))
19+
{
20+
this.Repo = new Repository(expandedRepo.RepoPath);
21+
22+
var oracleA = VersionOracle.Create(Path.Combine(expandedRepo.RepoPath, "a"));
23+
Assert.Equal("1.3.1", oracleA.SimpleVersion.ToString());
24+
Assert.Equal("e238b03e75", oracleA.GitCommitIdShort);
25+
26+
var oracleB = VersionOracle.Create(Path.Combine(expandedRepo.RepoPath, "b", "projB"));
27+
Assert.Equal("2.5.2", oracleB.SimpleVersion.ToString());
28+
Assert.Equal("3ea7f010c3", oracleB.GitCommitIdShort);
29+
}
30+
}
31+
}

src/NerdBank.GitVersioning.Tests/project.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"dependencies": {
3+
"7z.NET": "1.0.3",
34
"Microsoft.CodeAnalysis.CSharp": "1.1.1",
45
"System.Collections.Immutable": "1.1.37",
56
"xunit": "2.1.0",
9.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)