forked from dotnet/winforms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace conditional test attributes with SkipOnArchitectureAttribute.
It is implemented in a similar way to existing SkipOn* attributes from Microsoft.DotNet.XUnitExtensions library, allowing to set several unsupported architectures. Fixes dotnet#6653
- Loading branch information
1 parent
50bf961
commit 4898ff3
Showing
9 changed files
with
109 additions
and
120 deletions.
There are no files selected for viewing
49 changes: 0 additions & 49 deletions
49
src/System.Windows.Forms/tests/TestUtilities/ConditionalWinFormsFactAttribute.cs
This file was deleted.
Oops, something went wrong.
49 changes: 0 additions & 49 deletions
49
src/System.Windows.Forms/tests/TestUtilities/ConditionalWinFormsTheoryAttribute.cs
This file was deleted.
Oops, something went wrong.
21 changes: 21 additions & 0 deletions
21
src/System.Windows.Forms/tests/TestUtilities/SkipOnArchitectureAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Xunit.Sdk; | ||
|
||
namespace System | ||
{ | ||
/// <summary> | ||
/// Apply this attribute to your test method or class to skip it on a certain architecture. | ||
/// </summary> | ||
/// <remarks> | ||
/// This doesn't work for <see cref="TestArchitectures.Arm64"/>. See https://github.com/dotnet/winforms/issues/7013. | ||
/// </remarks> | ||
[TraitDiscoverer("System.SkipOnArchitectureDiscoverer", "System.Windows.Forms.TestUtilities")] | ||
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true, Inherited = true)] | ||
public class SkipOnArchitectureAttribute : Attribute, ITraitAttribute | ||
{ | ||
public SkipOnArchitectureAttribute(TestArchitectures testArchitectures, string reason) { } | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/System.Windows.Forms/tests/TestUtilities/SkipOnArchitectureDiscoverer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
using Microsoft.DotNet.XUnitExtensions; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace System | ||
{ | ||
/// <summary> | ||
/// This class discovers all of the tests and test classes that have | ||
/// applied the <see cref="SkipOnArchitectureAttribute"/>. | ||
/// </summary> | ||
public class SkipOnArchitectureDiscoverer : ITraitDiscoverer | ||
{ | ||
/// <summary> | ||
/// Gets the trait values from the Category attribute. | ||
/// </summary> | ||
/// <param name="traitAttribute">The trait attribute containing the trait values.</param> | ||
/// <returns>The trait values.</returns> | ||
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute) | ||
{ | ||
TestArchitectures testArchitectures = 0; | ||
|
||
if (traitAttribute.GetConstructorArguments().FirstOrDefault() is TestArchitectures ta) | ||
{ | ||
testArchitectures = ta; | ||
} | ||
|
||
if ((testArchitectures.HasFlag(TestArchitectures.X86) && RuntimeInformation.ProcessArchitecture == Architecture.X86) || | ||
(testArchitectures.HasFlag(TestArchitectures.X64) && RuntimeInformation.ProcessArchitecture == Architecture.X64) || | ||
(testArchitectures.HasFlag(TestArchitectures.Arm64) && RuntimeInformation.ProcessArchitecture == Architecture.Arm64)) | ||
{ | ||
return new[] { new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.IgnoreForCI) }; | ||
} | ||
|
||
return Array.Empty<KeyValuePair<string, string>>(); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/System.Windows.Forms/tests/TestUtilities/TestArchitectures.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace System | ||
{ | ||
[Flags] | ||
public enum TestArchitectures | ||
{ | ||
X86 = 1, | ||
X64 = 2, | ||
Arm64 = 4, | ||
Any = ~0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters