Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch tests from 7z to zip and enable test #614

Merged
merged 2 commits into from Jun 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.