Skip to content

Commit

Permalink
Merge pull request #614 from dotnet/fix125
Browse files Browse the repository at this point in the history
Switch tests from 7z to zip and enable test
  • Loading branch information
AArnott committed Jun 12, 2021
2 parents b7707b3 + daa0303 commit 07964f8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 32 deletions.
Expand Up @@ -25,14 +25,13 @@
<EmbeddedResource Include="ManagedGit\tree*" />
<EmbeddedResource Include="test.vcprj" />
<EmbeddedResource Include="test.prj" />
<EmbeddedResource Include="repos\submodules.7z" />
<EmbeddedResource Include="repos\*" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Nerdbank.GitVersioning.Tasks\Nerdbank.GitVersioning.Tasks.csproj" />
<ProjectReference Include="..\NerdBank.GitVersioning\NerdBank.GitVersioning.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="7z.NET" Version="1.0.3" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.10" />
<PackageReference Include="System.Collections.Immutable" Version="1.5.0" />
<PackageReference Include="Microsoft.Build" Version="15.1.548" ExcludeAssets="runtime" />
Expand Down
30 changes: 5 additions & 25 deletions src/NerdBank.GitVersioning.Tests/TestUtilities.cs
@@ -1,7 +1,4 @@
#if NET461
using SevenZipNET;
#endif
using Validation;
using Validation;

using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -67,36 +64,19 @@ internal static void ExtractEmbeddedResource(string resourcePath, string extract

internal static ExpandedRepo ExtractRepoArchive(string repoArchiveName)
{
#if NET461
string archiveFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
string expandedFolderPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

ExtractEmbeddedResource($"repos.{repoArchiveName}.7z", archiveFilePath);
ExtractEmbeddedResource($"repos.{repoArchiveName}.zip", archiveFilePath);
try
{
for (int retryCount = 0; ; retryCount++)
{
try
{
var extractor = new SevenZipExtractor(archiveFilePath);
extractor.ExtractAll(expandedFolderPath);
return new ExpandedRepo(expandedFolderPath);
}
catch (System.ComponentModel.Win32Exception) when (retryCount < 2)
{
}
}
System.IO.Compression.ZipFile.ExtractToDirectory(archiveFilePath, expandedFolderPath);
return new ExpandedRepo(expandedFolderPath);
}
finally
{
if (File.Exists(archiveFilePath))
{
File.Delete(archiveFilePath);
}
File.Delete(archiveFilePath);
}
#else
throw new PlatformNotSupportedException();
#endif
}

internal class ExpandedRepo : IDisposable
Expand Down
8 changes: 3 additions & 5 deletions src/NerdBank.GitVersioning.Tests/VersionOracleTests.cs
Expand Up @@ -49,19 +49,17 @@ public void NotRepo()
Assert.Equal(0, oracle.VersionHeight);
}

[Fact(Skip = "Unstable test. See issue #125")]
[Fact]
public void Submodule_RecognizedWithCorrectVersion()
{
using (var expandedRepo = TestUtilities.ExtractRepoArchive("submodules"))
{
this.Context = this.CreateGitContext(expandedRepo.RepoPath);

this.Context.RepoRelativeProjectDirectory = "a";
this.Context = this.CreateGitContext(Path.Combine(expandedRepo.RepoPath, "a"));
var oracleA = new VersionOracle(this.Context);
Assert.Equal("1.3.1", oracleA.SimpleVersion.ToString());
Assert.Equal("e238b03e75", oracleA.GitCommitIdShort);

this.Context.RepoRelativeProjectDirectory = Path.Combine("b", "projB");
this.Context = this.CreateGitContext(Path.Combine(expandedRepo.RepoPath, "b", "projB"));
var oracleB = new VersionOracle(this.Context);
Assert.Equal("2.5.2", oracleB.SimpleVersion.ToString());
Assert.Equal("3ea7f010c3", oracleB.GitCommitIdShort);
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 07964f8

Please sign in to comment.