Skip to content

Commit 80d2427

Browse files
committed
Add unit tests
1 parent 92a7486 commit 80d2427

File tree

6 files changed

+55
-16
lines changed

6 files changed

+55
-16
lines changed

Directory.Build.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ SPDX-License-Identifier: MIT
3333
<IsPackable>false</IsPackable>
3434
<IsPublishable>false</IsPublishable>
3535
<IsTrimmable>true</IsTrimmable>
36-
<!--
3736
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)\strongname.snk</AssemblyOriginatorKeyFile>
38-
-->
3937
<GenerateDocumentationFile>true</GenerateDocumentationFile>
4038
<NoWarn>CS1591</NoWarn>
4139

UnitTests/TaskTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-FileCopyrightText: 2024 Frans van Dorsselaer
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
using System.Reflection;
6+
7+
namespace UnitTests;
8+
9+
[TestClass]
10+
sealed class TaskTests
11+
{
12+
public required TestContext TestContext { get; set; }
13+
14+
static string GetVersionFile()
15+
{
16+
for (var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
17+
directory is not null; directory = Path.GetDirectoryName(directory))
18+
{
19+
var file = Path.Combine(directory, "obj", "gitversion.json");
20+
if (File.Exists(file))
21+
{
22+
return file;
23+
}
24+
}
25+
throw new FileNotFoundException("gitversion.json");
26+
}
27+
28+
[TestMethod]
29+
public void GenerateGitVersionInformation_WithIntermediateOutputPath()
30+
{
31+
var task = new Dorssel.GitVersion.MsBuild.GenerateGitVersionInformation
32+
{
33+
VersionFile = GetVersionFile(),
34+
IntermediateOutputPath = TestContext.TestRunDirectory!
35+
};
36+
var result = task.Execute();
37+
Assert.IsTrue(result);
38+
}
39+
}

UnitTests/Test1.cs

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

UnitTests/UnitTests.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ SPDX-License-Identifier: MIT
88

99
<PropertyGroup>
1010
<TargetFramework>$(MainTargetFramework)</TargetFramework>
11+
12+
<!-- Be strict when testing, even in Release (at the cost of performance) -->
13+
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
14+
15+
<SignAssembly>true</SignAssembly>
1116
</PropertyGroup>
1217

18+
<ItemGroup>
19+
<ProjectReference Include="..\GitVersion.MsBuild\GitVersion.MsBuild.csproj" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<PackageReference Include="Microsoft.Build.Utilities.Core" />
24+
</ItemGroup>
25+
1326
</Project>

strongname.snk

1.71 KB
Binary file not shown.

strongname.snk.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2024 Frans van Dorsselaer
2+
3+
SPDX-License-Identifier: MIT

0 commit comments

Comments
 (0)