Skip to content

Commit

Permalink
added common extended Fact and Theory attributes to `Microsoft.Do…
Browse files Browse the repository at this point in the history
…tNet.XUnitExtensions`
  • Loading branch information
vlada-shubina committed Feb 1, 2023
1 parent 7ed56fa commit 1511d34
Show file tree
Hide file tree
Showing 17 changed files with 351 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ItemGroup>
<ProjectReference Include="..\Common\Microsoft.Arcade.Test.Common\Microsoft.Arcade.Test.Common.csproj" />
<ProjectReference Include="..\Microsoft.DotNet.Build.Tasks.Workloads\src\Microsoft.DotNet.Build.Tasks.Workloads.csproj" />
<ProjectReference Include="..\Microsoft.DotNet.XUnitExtensions\src\Microsoft.DotNet.XUnitExtensions.csproj" />

<PackageReference Include="Microsoft.Build" Version="$(MicrosoftBuildVersion)" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCoreVersion)" />
Expand Down
30 changes: 0 additions & 30 deletions src/Microsoft.DotNet.Build.Tasks.Workloads.Tests/TestHelper.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Microsoft.DotNet.XUnitExtensions\src\Microsoft.DotNet.XUnitExtensions.csproj" />
<ProjectReference Include="..\tasks\Microsoft.DotNet.NuGetRepack.Tasks.csproj" />
</ItemGroup>
</Project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using Microsoft.DotNet.XUnitExtensions;

namespace Xunit
{
/// <summary>
/// This test should be run only on .NET (.NET Core).
/// </summary>
public class DotNetOnlyFactAttribute : FactAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="DotNetOnlyFactAttribute"/> class.
/// </summary>
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
public DotNetOnlyFactAttribute(string? additionalMessage = null)
{
if (!DiscovererHelpers.IsRunningOnNetCoreApp)
{
this.Skip = "This test only runs on .NET.".AppendAdditionalMessage(additionalMessage);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using Microsoft.DotNet.XUnitExtensions;

namespace Xunit
{
/// <summary>
/// This test should be run only on .NET (.NET Core).
/// </summary>
public class DotNetOnlyTheoryAttribute : TheoryAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="DotNetOnlyTheoryAttribute"/> class.
/// </summary>
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
public DotNetOnlyTheoryAttribute(string? additionalMessage = null)
{
if (!DiscovererHelpers.IsRunningOnNetCoreApp)
{
this.Skip = "This test only runs on .NET.".AppendAdditionalMessage(additionalMessage);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.Runtime.InteropServices;
using Microsoft.DotNet.XUnitExtensions;

namespace Xunit
{
/// <summary>
/// This test should be run only on Linux.
/// </summary>
public class LinuxOnlyFactAttribute : FactAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="LinuxOnlyFactAttribute"/> class.
/// </summary>
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
public LinuxOnlyFactAttribute(string? additionalMessage = null)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
this.Skip = "This test requires Linux to run.".AppendAdditionalMessage(additionalMessage);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.Runtime.InteropServices;
using Microsoft.DotNet.XUnitExtensions;

namespace Xunit
{
/// <summary>
/// This test should be run only on Windows.
/// </summary>
public class LinuxOnlyTheoryAttribute : TheoryAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="LinuxOnlyTheoryAttribute"/> class.
/// </summary>
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
public LinuxOnlyTheoryAttribute(string? additionalMessage = null)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
this.Skip = "This test requires Linux to run.".AppendAdditionalMessage(additionalMessage);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.Runtime.InteropServices;
using Microsoft.DotNet.XUnitExtensions;

namespace Xunit
{
/// <summary>
/// This test should be run only on OSX.
/// </summary>
public class OsxOnlyFactAttribute : FactAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="OsxOnlyFactAttribute"/> class.
/// </summary>
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
public OsxOnlyFactAttribute(string? additionalMessage = null)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
this.Skip = "This test requires OSX to run.".AppendAdditionalMessage(additionalMessage);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.Runtime.InteropServices;
using Microsoft.DotNet.XUnitExtensions;

namespace Xunit
{
/// <summary>
/// This test should be run only on OSX.
/// </summary>
public class OsxOnlyTheoryAttribute : TheoryAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="OsxOnlyTheoryAttribute"/> class.
/// </summary>
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
public OsxOnlyTheoryAttribute(string? additionalMessage = null)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
this.Skip = "This test requires OSX to run.".AppendAdditionalMessage(additionalMessage);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.Runtime.InteropServices;
using Microsoft.DotNet.XUnitExtensions;

namespace Xunit
{
/// <summary>
/// This test should be run only on Unix (Linux, OSX platforms).
/// </summary>
public class UnixOnlyFactAttribute : FactAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="UnixOnlyFactAttribute"/> class.
/// </summary>
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
public UnixOnlyFactAttribute(string? additionalMessage = null)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
this.Skip = "This test requires Unix to run.".AppendAdditionalMessage(additionalMessage);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.Runtime.InteropServices;
using Microsoft.DotNet.XUnitExtensions;

namespace Xunit
{
/// <summary>
/// This test should be run only on Unix (Linux, OSX platforms).
/// </summary>
public class UnixOnlyTheoryAttribute : TheoryAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="UnixOnlyTheoryAttribute"/> class.
/// </summary>
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
public UnixOnlyTheoryAttribute(string? additionalMessage = null)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
this.Skip = "This test requires Unix to run.".AppendAdditionalMessage(additionalMessage);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.Runtime.InteropServices;
using Microsoft.DotNet.XUnitExtensions;

namespace Xunit
{
/// <summary>
/// This test should be run only on Windows on .NET Framework.
/// </summary>
public class WindowsFullFrameworkOnlyFactAttribute : FactAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="WindowsFullFrameworkOnlyFactAttribute"/> class.
/// </summary>
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
public WindowsFullFrameworkOnlyFactAttribute(string? additionalMessage = null)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
this.Skip = "This test only runs on Windows on .NET Framework.".AppendAdditionalMessage(additionalMessage);
return;
}
if (!DiscovererHelpers.IsRunningOnNetFramework)
{
this.Skip = "This test only runs on .NET Framework.".AppendAdditionalMessage(additionalMessage);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.Runtime.InteropServices;
using Microsoft.DotNet.XUnitExtensions;

namespace Xunit
{
/// <summary>
/// This test should be run only on Windows on full .NET Framework.
/// </summary>
public class WindowsFullFrameworkOnlyTheoryAttribute : TheoryAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="WindowsFullFrameworkOnlyTheoryAttribute"/> class.
/// Creates the attribute.
/// </summary>
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
public WindowsFullFrameworkOnlyTheoryAttribute(string? additionalMessage = null)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
this.Skip = "This test only runs on Windows on full framework.".AppendAdditionalMessage(additionalMessage);
return;
}
if (!DiscovererHelpers.IsRunningOnNetFramework)
{
this.Skip = "This test only runs on full framework.".AppendAdditionalMessage(additionalMessage);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

using System.Runtime.InteropServices;
using Microsoft.DotNet.XUnitExtensions;

namespace Xunit
{
/// <summary>
/// This test should be run only on Windows.
/// </summary>
public class WindowsOnlyFactAttribute : FactAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="WindowsOnlyFactAttribute"/> class.
/// </summary>
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
public WindowsOnlyFactAttribute(string? additionalMessage = null)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
this.Skip = "This test requires Windows to run.".AppendAdditionalMessage(additionalMessage);
}
}
}
}
Loading

0 comments on commit 1511d34

Please sign in to comment.