Skip to content

Commit 4f24936

Browse files
Add common Fact and Theory attributes to Microsoft.DotNet.XUnitExtensions (#12313)
1 parent c4d6ac0 commit 4f24936

17 files changed

+351
-47
lines changed

src/Microsoft.DotNet.Build.Tasks.Workloads.Tests/Microsoft.DotNet.Build.Tasks.Workloads.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<ItemGroup>
88
<ProjectReference Include="..\Common\Microsoft.Arcade.Test.Common\Microsoft.Arcade.Test.Common.csproj" />
99
<ProjectReference Include="..\Microsoft.DotNet.Build.Tasks.Workloads\src\Microsoft.DotNet.Build.Tasks.Workloads.csproj" />
10+
<ProjectReference Include="..\Microsoft.DotNet.XUnitExtensions\src\Microsoft.DotNet.XUnitExtensions.csproj" />
1011

1112
<PackageReference Include="Microsoft.Build" Version="$(MicrosoftBuildVersion)" />
1213
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCoreVersion)" />

src/Microsoft.DotNet.Build.Tasks.Workloads.Tests/TestHelper.cs

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

src/Microsoft.DotNet.NuGetRepack/tests/Microsoft.DotNet.NuGetRepack.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
</EmbeddedResource>
8383
</ItemGroup>
8484
<ItemGroup>
85+
<ProjectReference Include="..\..\Microsoft.DotNet.XUnitExtensions\src\Microsoft.DotNet.XUnitExtensions.csproj" />
8586
<ProjectReference Include="..\tasks\Microsoft.DotNet.NuGetRepack.Tasks.csproj" />
8687
</ItemGroup>
8788
</Project>

src/Microsoft.DotNet.NuGetRepack/tests/TestHelpers/SkipIfNotWindows.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable enable
5+
6+
using Microsoft.DotNet.XUnitExtensions;
7+
8+
namespace Xunit
9+
{
10+
/// <summary>
11+
/// This test should be run only on .NET (.NET Core).
12+
/// </summary>
13+
public class DotNetOnlyFactAttribute : FactAttribute
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="DotNetOnlyFactAttribute"/> class.
17+
/// </summary>
18+
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
19+
public DotNetOnlyFactAttribute(string? additionalMessage = null)
20+
{
21+
if (!DiscovererHelpers.IsRunningOnNetCoreApp)
22+
{
23+
this.Skip = "This test only runs on .NET.".AppendAdditionalMessage(additionalMessage);
24+
}
25+
}
26+
}
27+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable enable
5+
6+
using Microsoft.DotNet.XUnitExtensions;
7+
8+
namespace Xunit
9+
{
10+
/// <summary>
11+
/// This test should be run only on .NET (.NET Core).
12+
/// </summary>
13+
public class DotNetOnlyTheoryAttribute : TheoryAttribute
14+
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="DotNetOnlyTheoryAttribute"/> class.
17+
/// </summary>
18+
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
19+
public DotNetOnlyTheoryAttribute(string? additionalMessage = null)
20+
{
21+
if (!DiscovererHelpers.IsRunningOnNetCoreApp)
22+
{
23+
this.Skip = "This test only runs on .NET.".AppendAdditionalMessage(additionalMessage);
24+
}
25+
}
26+
}
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable enable
5+
6+
using System.Runtime.InteropServices;
7+
using Microsoft.DotNet.XUnitExtensions;
8+
9+
namespace Xunit
10+
{
11+
/// <summary>
12+
/// This test should be run only on Linux.
13+
/// </summary>
14+
public class LinuxOnlyFactAttribute : FactAttribute
15+
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="LinuxOnlyFactAttribute"/> class.
18+
/// </summary>
19+
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
20+
public LinuxOnlyFactAttribute(string? additionalMessage = null)
21+
{
22+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
23+
{
24+
this.Skip = "This test requires Linux to run.".AppendAdditionalMessage(additionalMessage);
25+
}
26+
}
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable enable
5+
6+
using System.Runtime.InteropServices;
7+
using Microsoft.DotNet.XUnitExtensions;
8+
9+
namespace Xunit
10+
{
11+
/// <summary>
12+
/// This test should be run only on Windows.
13+
/// </summary>
14+
public class LinuxOnlyTheoryAttribute : TheoryAttribute
15+
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="LinuxOnlyTheoryAttribute"/> class.
18+
/// </summary>
19+
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
20+
public LinuxOnlyTheoryAttribute(string? additionalMessage = null)
21+
{
22+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
23+
{
24+
this.Skip = "This test requires Linux to run.".AppendAdditionalMessage(additionalMessage);
25+
}
26+
}
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable enable
5+
6+
using System.Runtime.InteropServices;
7+
using Microsoft.DotNet.XUnitExtensions;
8+
9+
namespace Xunit
10+
{
11+
/// <summary>
12+
/// This test should be run only on OSX.
13+
/// </summary>
14+
public class MacOSOnlyFactAttribute : FactAttribute
15+
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="MacOSOnlyFactAttribute"/> class.
18+
/// </summary>
19+
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
20+
public MacOSOnlyFactAttribute(string? additionalMessage = null)
21+
{
22+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
23+
{
24+
this.Skip = "This test requires macOS to run.".AppendAdditionalMessage(additionalMessage);
25+
}
26+
}
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable enable
5+
6+
using System.Runtime.InteropServices;
7+
using Microsoft.DotNet.XUnitExtensions;
8+
9+
namespace Xunit
10+
{
11+
/// <summary>
12+
/// This test should be run only on OSX.
13+
/// </summary>
14+
public class MacOSOnlyTheoryAttribute : TheoryAttribute
15+
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="MacOSOnlyTheoryAttribute"/> class.
18+
/// </summary>
19+
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
20+
public MacOSOnlyTheoryAttribute(string? additionalMessage = null)
21+
{
22+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
23+
{
24+
this.Skip = "This test requires macOS to run.".AppendAdditionalMessage(additionalMessage);
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)