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

added common Fact and Theory attributes to Microsoft.DotNet.XUnitExtensions #12313

Merged
merged 2 commits into from
Feb 1, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 MacOSOnlyFactAttribute : FactAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="MacOSOnlyFactAttribute"/> class.
/// </summary>
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
public MacOSOnlyFactAttribute(string? additionalMessage = null)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
this.Skip = "This test requires macOS 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 MacOSOnlyTheoryAttribute : TheoryAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="MacOSOnlyTheoryAttribute"/> class.
/// </summary>
/// <param name="additionalMessage">The additional message that is appended to skip reason, when test is skipped.</param>
public MacOSOnlyTheoryAttribute(string? additionalMessage = null)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
this.Skip = "This test requires macOS 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