Skip to content

Commit

Permalink
Replace conditional test attributes with SkipOnArchitectureAttribute.
Browse files Browse the repository at this point in the history
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
vladimir-krestov authored and Dmitrii Drobotov committed Apr 13, 2022
1 parent 50bf961 commit 4898ff3
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 120 deletions.

This file was deleted.

This file was deleted.

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) { }
}
}
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 src/System.Windows.Forms/tests/TestUtilities/TestArchitectures.cs
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -861,8 +861,9 @@ public void Control_GetNextSelectableControl_MultipleComplexControls_CycleBackwa
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6730")]
[ConditionalWinFormsTheory(Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6730",
UnsupportedArchitecture = Runtime.InteropServices.Architecture.X64)]
[WinFormsTheory]
[SkipOnArchitecture(TestArchitectures.X64,
"Flaky tests, see: https://github.com/dotnet/winforms/issues/6730")]
[InlineData(RightToLeft.No)]
[InlineData(RightToLeft.Yes)]
public void Control_SelectNextControl_ToolStrips_CycleForwardExpected(RightToLeft rightToLeft)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms.TestUtilities;
using Xunit;

Expand Down Expand Up @@ -171,8 +170,9 @@ public static IEnumerable<object[]> ColumnHeadersHeight_SetWithHandle_TestData()
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[WinFormsTheory]
[SkipOnArchitecture(TestArchitectures.Arm64,
"Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[MemberData(nameof(ColumnHeadersHeight_SetWithHandle_TestData))]
public void DataGridView_ColumnHeadersHeight_SetWithHandle_GetReturnsExpected(DataGridViewColumnHeadersHeightSizeMode columnHeadersWidthSizeMode, bool columnHeadersVisible, bool autoSize, int value, int expectedValue, int expectedInvalidatedCallCount)
{
Expand Down Expand Up @@ -240,8 +240,9 @@ public static IEnumerable<object[]> ColumnHeadersHeight_SetWithParentWithHandle_
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[WinFormsTheory]
[SkipOnArchitecture(TestArchitectures.Arm64,
"Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[MemberData(nameof(ColumnHeadersHeight_SetWithParentWithHandle_TestData))]
public void DataGridView_ColumnHeadersHeight_SetWithParentWithHandle_GetReturnsExpected(DataGridViewColumnHeadersHeightSizeMode columnHeadersWidthSizeMode, bool columnHeadersVisible, bool autoSize, int value, int expectedValue, int expectedInvalidatedCallCount, int expectedLayoutCallCount, int expectedParentLayoutCallCount)
{
Expand Down Expand Up @@ -530,8 +531,9 @@ public static IEnumerable<object[]> ColumnHeadersHeightSizeMode_SetWithHandle_Te
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[WinFormsTheory]
[SkipOnArchitecture(TestArchitectures.Arm64,
"Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[MemberData(nameof(ColumnHeadersHeightSizeMode_SetWithHandle_TestData))]
public void DataGridView_ColumnHeadersHeightSizeMode_SetWithHandle_GetReturnsExpected(bool columnHeadersVisible, DataGridViewColumnHeadersHeightSizeMode value, int expectedColumnHeadersHeight, int expectedInvalidatedCallCount)
{
Expand Down Expand Up @@ -566,8 +568,9 @@ public void DataGridView_ColumnHeadersHeightSizeMode_SetWithHandle_GetReturnsExp
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[WinFormsTheory]
[SkipOnArchitecture(TestArchitectures.Arm64,
"Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[InlineData(DataGridViewColumnHeadersHeightSizeMode.DisableResizing, DataGridViewColumnHeadersHeightSizeMode.AutoSize)]
[InlineData(DataGridViewColumnHeadersHeightSizeMode.EnableResizing, DataGridViewColumnHeadersHeightSizeMode.AutoSize)]
public void DataGridView_ColumnHeadersHeightSizeMode_SetNonResizeThenResize_RestoresOldValue(DataGridViewColumnHeadersHeightSizeMode originalColumnHeadersHeightSizeMode, DataGridViewColumnHeadersHeightSizeMode value)
Expand Down Expand Up @@ -1474,8 +1477,9 @@ public static IEnumerable<object[]> RowHeadersWidthSizeMode_SetWithHandle_TestDa
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[WinFormsTheory]
[SkipOnArchitecture(TestArchitectures.Arm64,
"Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[MemberData(nameof(RowHeadersWidthSizeMode_SetWithHandle_TestData))]
public void DataGridView_RowHeadersWidthSizeMode_SetWithHandle_GetReturnsExpected(bool rowHeadersVisible, DataGridViewRowHeadersWidthSizeMode value, int expectedRowHeadersWidth, int expectedInvalidatedCallCount)
{
Expand Down Expand Up @@ -1510,8 +1514,9 @@ public void DataGridView_RowHeadersWidthSizeMode_SetWithHandle_GetReturnsExpecte
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[WinFormsTheory]
[SkipOnArchitecture(TestArchitectures.Arm64,
"Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[InlineData(DataGridViewRowHeadersWidthSizeMode.DisableResizing, DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders)]
[InlineData(DataGridViewRowHeadersWidthSizeMode.DisableResizing, DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders)]
[InlineData(DataGridViewRowHeadersWidthSizeMode.DisableResizing, DataGridViewRowHeadersWidthSizeMode.AutoSizeToFirstHeader)]
Expand Down Expand Up @@ -2446,8 +2451,9 @@ public void DataGridView_OnRowHeadersWidthChanged_Invoke_CallsRowHeadersWidthCha
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[WinFormsTheory]
[SkipOnArchitecture(TestArchitectures.Arm64,
"Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[MemberData(nameof(OnRowHeadersWidthChanged_TestData))]
public void DataGridView_OnRowHeadersWidthChanged_InvokeWithHandle_CallsRowHeadersWidthChanged(DataGridViewRowHeadersWidthSizeMode rowHeadersWidthSizeMode, bool rowHeadersVisible, EventArgs eventArgs)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6876,8 +6876,9 @@ public static IEnumerable<object[]> RichTextBox_Text_GetWithHandle_TestData()
// NOTE: do not convert this into a theory as it will run hundreds of tests
// and with that will cycle through hundreds of UI controls.
[ActiveIssue("https://github.com/dotnet/winforms/issues/6609")]
[ConditionalWinFormsFact(UnsupportedArchitecture = Architecture.X86,
Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6609")]
[WinFormsFact]
[SkipOnArchitecture(TestArchitectures.X86,
"Flaky tests, see: https://github.com/dotnet/winforms/issues/6609")]
public void RichTextBox_Text_GetWithHandle_ReturnsExpected()
{
using (var control = new RichTextBox())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using Moq;
using System.Windows.Forms.TestUtilities;
using Moq;
using Xunit;
using static Interop;

Expand Down Expand Up @@ -7105,8 +7105,9 @@ public void ToolStrip_SetItemLocation_ItemHasDifferentParent_ThrowsNotSupportedE
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6610")]
[ConditionalWinFormsFact(UnsupportedArchitecture = Architecture.X86,
Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6610")]
[WinFormsFact]
[SkipOnArchitecture(TestArchitectures.X86,
"Flaky tests, see: https://github.com/dotnet/winforms/issues/6610")]
public void ToolStrip_WndProc_InvokeMouseActivate_Success()
{
using var control = new SubToolStrip();
Expand Down

0 comments on commit 4898ff3

Please sign in to comment.