Skip to content

Commit

Permalink
Reworked conditional attributes to have ability
Browse files Browse the repository at this point in the history
to add several unsupported architectures
Fixes dotnet#6653
  • Loading branch information
vladimir-krestov authored and Dmitrii Drobotov committed Apr 12, 2022
1 parent 0f3c16c commit c1dda6f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ImageListTests(ITestOutputHelper testOutputHelper)
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6635")]
[ConditionalWinFormsFact(UnsupportedArchitecture = Architecture.X86,
[ConditionalWinFormsFact(Architecture.X86,
Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6635")]
public void ImageList_FinalizerReleasesNativeHandle_ReturnsExpected()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,34 @@

namespace System
{
/// <summary>
/// Extension of WinFormsFact attribute. Allows to skip specific test cases only,
/// depending on a runtime architecture. This attribute must have unsupported architectures.
/// </summary>
public class ConditionalWinFormsFactAttribute : WinFormsFactAttribute
{
private Architecture _unsupportedArchitecture;
private bool _isSkipRequired;
private string _skipReason;
private readonly bool _isSkipRequired;

/// <param name="unsupportedArchitectures">
/// Defines the architectures to skip the test on.
/// This is complementary to <see cref="Skip"/> property.
/// </param>
public ConditionalWinFormsFactAttribute(params Architecture[] unsupportedArchitectures)
{
if (unsupportedArchitectures.Length == 0)
{
throw new InvalidOperationException("The conditional attribute must have unsupported architectures. " +
"If you need to run a test in all artichectures, please use WinFormsFact");
}

_isSkipRequired = unsupportedArchitectures.Contains(RuntimeInformation.ProcessArchitecture);
}

public override string Skip
{
get => base.Skip;
set
{
_skipReason = value;

if (_isSkipRequired)
{
base.Skip = value;
Expand All @@ -28,22 +43,5 @@ public override string Skip
// Don't skip a test case if the skip condition is false.
}
}

/// <summary>
/// Defines the architecture to skip the test on. This is complementary to <see cref="Skip"/> parameter.
/// </summary>
public Architecture UnsupportedArchitecture
{
get => _unsupportedArchitecture;
set
{
_unsupportedArchitecture = value;
_isSkipRequired = RuntimeInformation.ProcessArchitecture == value;
if (_isSkipRequired && _skipReason is not null)
{
Skip = _skipReason;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,42 @@
// See the LICENSE file in the project root for more information.

using System.Runtime.InteropServices;
using System.Windows.Forms;
using Xunit;

namespace System
{
public class ConditionalWinFormsTheoryAttribute : WinFormsTheoryAttribute
{
private Architecture _unsupportedArchitecture;
private bool _isSkipRequired;
private Architecture[] _unsupportedArchitectures;
private string _skipReason;

public override string Skip
{
get => base.Skip;
set
{
_skipReason = value;

if (_isSkipRequired)
{
base.Skip = value;
}

// Don't skip a test case if the skip condition is false.
}
set => _skipReason = value;
}

/// <summary>
/// Defines the architecture to skip the test on. This is complementary to <see cref="Skip"/> parameter.
/// </summary>
public Architecture UnsupportedArchitecture
public Architecture[] UnsupportedArchitectures
{
get => _unsupportedArchitecture;
get => _unsupportedArchitectures;
set
{
_unsupportedArchitecture = value;
_isSkipRequired = RuntimeInformation.ProcessArchitecture == value;
if (_isSkipRequired && _skipReason is not null)
if (value is null || value.Length == 0)
{
throw new InvalidOperationException("The conditional attribute must have unsupported architectures. " +
"If you need to run a test in all artichectures, please use WinFormsFact");
}

_unsupportedArchitectures = value;

if (value.Contains(RuntimeInformation.ProcessArchitecture)) // If skipping is required
{
Skip = _skipReason;
_skipReason.ThrowIfNullOrEmpty(); // Conditional attribute must have a skip reason
base.Skip = _skipReason;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static IEnumerable<object[]> ColumnHeadersHeight_SetWithHandle_TestData()
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
[ConditionalWinFormsTheory(UnsupportedArchitectures = new[] { Architecture.Arm64 },
Skip = "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,7 +240,7 @@ public static IEnumerable<object[]> ColumnHeadersHeight_SetWithParentWithHandle_
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
[ConditionalWinFormsTheory(UnsupportedArchitectures = new[] { Architecture.Arm64 },
Skip = "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,7 +530,7 @@ public static IEnumerable<object[]> ColumnHeadersHeightSizeMode_SetWithHandle_Te
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
[ConditionalWinFormsTheory(UnsupportedArchitectures = new[] { Architecture.Arm64 },
Skip = "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,7 +566,7 @@ public void DataGridView_ColumnHeadersHeightSizeMode_SetWithHandle_GetReturnsExp
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
[ConditionalWinFormsTheory(UnsupportedArchitectures = new[] { Architecture.Arm64 },
Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[InlineData(DataGridViewColumnHeadersHeightSizeMode.DisableResizing, DataGridViewColumnHeadersHeightSizeMode.AutoSize)]
[InlineData(DataGridViewColumnHeadersHeightSizeMode.EnableResizing, DataGridViewColumnHeadersHeightSizeMode.AutoSize)]
Expand Down Expand Up @@ -1474,7 +1474,7 @@ public static IEnumerable<object[]> RowHeadersWidthSizeMode_SetWithHandle_TestDa
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
[ConditionalWinFormsTheory(UnsupportedArchitectures = new[] { Architecture.Arm64 },
Skip = "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,7 +1510,7 @@ public void DataGridView_RowHeadersWidthSizeMode_SetWithHandle_GetReturnsExpecte
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
[ConditionalWinFormsTheory(UnsupportedArchitectures = new[] { Architecture.Arm64 },
Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6597")]
[InlineData(DataGridViewRowHeadersWidthSizeMode.DisableResizing, DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders)]
[InlineData(DataGridViewRowHeadersWidthSizeMode.DisableResizing, DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders)]
Expand Down Expand Up @@ -2446,7 +2446,7 @@ public void DataGridView_OnRowHeadersWidthChanged_Invoke_CallsRowHeadersWidthCha
}

[ActiveIssue("https://github.com/dotnet/winforms/issues/6597")]
[ConditionalWinFormsTheory(UnsupportedArchitecture = Architecture.Arm64,
[ConditionalWinFormsTheory(UnsupportedArchitectures = new[] { Architecture.Arm64 },
Skip = "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,7 +6876,7 @@ 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,
[ConditionalWinFormsFact(Architecture.X86,
Skip = "Flaky tests, see: https://github.com/dotnet/winforms/issues/6609")]
public void RichTextBox_Text_GetWithHandle_ReturnsExpected()
{
Expand Down

0 comments on commit c1dda6f

Please sign in to comment.