Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dorssel committed Nov 21, 2024
1 parent 92a7486 commit 80d2427
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 16 deletions.
2 changes: 0 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ SPDX-License-Identifier: MIT
<IsPackable>false</IsPackable>
<IsPublishable>false</IsPublishable>
<IsTrimmable>true</IsTrimmable>
<!--
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)\strongname.snk</AssemblyOriginatorKeyFile>
-->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>CS1591</NoWarn>

Expand Down
39 changes: 39 additions & 0 deletions UnitTests/TaskTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: 2024 Frans van Dorsselaer
//
// SPDX-License-Identifier: MIT

using System.Reflection;

namespace UnitTests;

[TestClass]
sealed class TaskTests
{
public required TestContext TestContext { get; set; }

static string GetVersionFile()
{
for (var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
directory is not null; directory = Path.GetDirectoryName(directory))
{
var file = Path.Combine(directory, "obj", "gitversion.json");
if (File.Exists(file))
{
return file;
}
}
throw new FileNotFoundException("gitversion.json");
}

[TestMethod]
public void GenerateGitVersionInformation_WithIntermediateOutputPath()
{
var task = new Dorssel.GitVersion.MsBuild.GenerateGitVersionInformation
{
VersionFile = GetVersionFile(),
IntermediateOutputPath = TestContext.TestRunDirectory!
};
var result = task.Execute();
Assert.IsTrue(result);
}
}
14 changes: 0 additions & 14 deletions UnitTests/Test1.cs

This file was deleted.

13 changes: 13 additions & 0 deletions UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ SPDX-License-Identifier: MIT

<PropertyGroup>
<TargetFramework>$(MainTargetFramework)</TargetFramework>

<!-- Be strict when testing, even in Release (at the cost of performance) -->
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>

<SignAssembly>true</SignAssembly>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\GitVersion.MsBuild\GitVersion.MsBuild.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Utilities.Core" />
</ItemGroup>

</Project>
Binary file added strongname.snk
Binary file not shown.
3 changes: 3 additions & 0 deletions strongname.snk.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Frans van Dorsselaer

SPDX-License-Identifier: MIT

0 comments on commit 80d2427

Please sign in to comment.