Skip to content

Commit c717230

Browse files
authored
Cleanup to skip/flaky attributes (dotnet/extensions#2186)
\n\nCommit migrated from dotnet/extensions@cfef5e0
1 parent 9372816 commit c717230

30 files changed

+144
-27
lines changed

src/Testing/src/TestPlatformHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ public static class TestPlatformHelper
2020
public static bool IsMac =>
2121
RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
2222
}
23-
}
23+
}

src/Testing/src/xunit/ConditionalFactAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Xunit;
66
using Xunit.Sdk;
77

8-
namespace Microsoft.AspNetCore.Testing.xunit
8+
namespace Microsoft.AspNetCore.Testing
99
{
1010
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
1111
[XunitTestCaseDiscoverer("Microsoft.AspNetCore.Testing.xunit." + nameof(ConditionalFactDiscoverer), "Microsoft.AspNetCore.Testing")]

src/Testing/src/xunit/ConditionalFactDiscoverer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Xunit.Abstractions;
55
using Xunit.Sdk;
66

7-
namespace Microsoft.AspNetCore.Testing.xunit
7+
namespace Microsoft.AspNetCore.Testing
88
{
99
internal class ConditionalFactDiscoverer : FactDiscoverer
1010
{

src/Testing/src/xunit/ConditionalTheoryAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Xunit;
66
using Xunit.Sdk;
77

8-
namespace Microsoft.AspNetCore.Testing.xunit
8+
namespace Microsoft.AspNetCore.Testing
99
{
1010
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
1111
[XunitTestCaseDiscoverer("Microsoft.AspNetCore.Testing.xunit." + nameof(ConditionalTheoryDiscoverer), "Microsoft.AspNetCore.Testing")]

src/Testing/src/xunit/ConditionalTheoryDiscoverer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Xunit.Abstractions;
66
using Xunit.Sdk;
77

8-
namespace Microsoft.AspNetCore.Testing.xunit
8+
namespace Microsoft.AspNetCore.Testing
99
{
1010
internal class ConditionalTheoryDiscoverer : TheoryDiscoverer
1111
{

src/Testing/src/xunit/DockerOnlyAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Linq;
77
using System.Runtime.InteropServices;
88

9-
namespace Microsoft.AspNetCore.Testing.xunit
9+
namespace Microsoft.AspNetCore.Testing
1010
{
1111
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
1212
public sealed class DockerOnlyAttribute : Attribute, ITestCondition

src/Testing/src/xunit/EnvironmentVariableSkipConditionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System;
55
using System.Linq;
66

7-
namespace Microsoft.AspNetCore.Testing.xunit
7+
namespace Microsoft.AspNetCore.Testing
88
{
99
/// <summary>
1010
/// Skips a test when the value of an environment variable matches any of the supplied values.

src/Testing/src/xunit/FlakyAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using Xunit.Sdk;
44

5-
namespace Microsoft.AspNetCore.Testing.xunit
5+
namespace Microsoft.AspNetCore.Testing
66
{
77
/// <summary>
88
/// Marks a test as "Flaky" so that the build will sequester it and ignore failures.

src/Testing/src/xunit/FlakyTestDiscoverer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Xunit.Abstractions;
55
using Xunit.Sdk;
66

7-
namespace Microsoft.AspNetCore.Testing.xunit
7+
namespace Microsoft.AspNetCore.Testing
88
{
99
public class FlakyTestDiscoverer : ITraitDiscoverer
1010
{

src/Testing/src/xunit/FrameworkSkipConditionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System;
55

6-
namespace Microsoft.AspNetCore.Testing.xunit
6+
namespace Microsoft.AspNetCore.Testing
77
{
88
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
99
public class FrameworkSkipConditionAttribute : Attribute, ITestCondition

src/Testing/src/xunit/IEnvironmentVariable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
namespace Microsoft.AspNetCore.Testing.xunit
4+
namespace Microsoft.AspNetCore.Testing
55
{
66
internal interface IEnvironmentVariable
77
{

src/Testing/src/xunit/ITestCondition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
namespace Microsoft.AspNetCore.Testing.xunit
4+
namespace Microsoft.AspNetCore.Testing
55
{
66
public interface ITestCondition
77
{

src/Testing/src/xunit/MinimumOsVersionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Runtime.InteropServices;
66
using Microsoft.Win32;
77

8-
namespace Microsoft.AspNetCore.Testing.xunit
8+
namespace Microsoft.AspNetCore.Testing
99
{
1010
/// <summary>
1111
/// Skips a test if the OS is the given type (Windows) and the OS version is less than specified.

src/Testing/src/xunit/OSSkipConditionAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using System.Linq;
77
using System.Runtime.InteropServices;
88

9-
namespace Microsoft.AspNetCore.Testing.xunit
9+
namespace Microsoft.AspNetCore.Testing
1010
{
1111
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)]
1212
public class OSSkipConditionAttribute : Attribute, ITestCondition

src/Testing/src/xunit/OperatingSystems.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System;
55

6-
namespace Microsoft.AspNetCore.Testing.xunit
6+
namespace Microsoft.AspNetCore.Testing
77
{
88
[Flags]
99
public enum OperatingSystems

src/Testing/src/xunit/RuntimeFrameworks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System;
55

6-
namespace Microsoft.AspNetCore.Testing.xunit
6+
namespace Microsoft.AspNetCore.Testing
77
{
88
[Flags]
99
public enum RuntimeFrameworks
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
6+
namespace Microsoft.AspNetCore.Testing
7+
{
8+
/// <summary>
9+
/// Skip test if running on CI
10+
/// </summary>
11+
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false)]
12+
public class SkipOnCIAttribute : Attribute, ITestCondition
13+
{
14+
public SkipOnCIAttribute(string issueUrl = "")
15+
{
16+
IssueUrl = issueUrl;
17+
}
18+
19+
public string IssueUrl { get; }
20+
21+
public bool IsMet
22+
{
23+
get
24+
{
25+
return !OnCI();
26+
}
27+
}
28+
29+
public string SkipReason
30+
{
31+
get
32+
{
33+
return $"This test is skipped on CI";
34+
}
35+
}
36+
37+
public static bool OnCI() => OnHelix() || OnAzdo();
38+
public static bool OnHelix() => !string.IsNullOrEmpty(GetTargetHelixQueue());
39+
public static string GetTargetHelixQueue() => Environment.GetEnvironmentVariable("helix");
40+
public static bool OnAzdo() => !string.IsNullOrEmpty(GetIfOnAzdo());
41+
public static string GetIfOnAzdo() => Environment.GetEnvironmentVariable("AGENT_OS");
42+
}
43+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Linq;
6+
7+
namespace Microsoft.AspNetCore.Testing
8+
{
9+
/// <summary>
10+
/// Skip test if running on helix (or a particular helix queue).
11+
/// </summary>
12+
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false)]
13+
public class SkipOnHelixAttribute : Attribute, ITestCondition
14+
{
15+
public SkipOnHelixAttribute(string issueUrl)
16+
{
17+
if (string.IsNullOrEmpty(issueUrl))
18+
{
19+
throw new ArgumentException();
20+
}
21+
IssueUrl = issueUrl;
22+
}
23+
24+
public string IssueUrl { get; }
25+
26+
public bool IsMet
27+
{
28+
get
29+
{
30+
var skip = OnHelix() && (Queues == null || Queues.ToLowerInvariant().Split(';').Contains(GetTargetHelixQueue().ToLowerInvariant()));
31+
return !skip;
32+
}
33+
}
34+
35+
// Queues that should be skipped on, i.e. "Windows.10.Amd64.ClientRS4.VS2017.Open;OSX.1012.Amd64.Open"
36+
public string Queues { get; set; }
37+
38+
public string SkipReason
39+
{
40+
get
41+
{
42+
return $"This test is skipped on helix";
43+
}
44+
}
45+
46+
public static bool OnHelix() => !string.IsNullOrEmpty(GetTargetHelixQueue());
47+
48+
public static string GetTargetHelixQueue() => Environment.GetEnvironmentVariable("helix");
49+
}
50+
}

src/Testing/src/xunit/SkippedTestCase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Xunit.Abstractions;
66
using Xunit.Sdk;
77

8-
namespace Microsoft.AspNetCore.Testing.xunit
8+
namespace Microsoft.AspNetCore.Testing
99
{
1010
public class SkippedTestCase : XunitTestCase
1111
{

src/Testing/src/xunit/TestMethodExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using Xunit.Abstractions;
66
using Xunit.Sdk;
77

8-
namespace Microsoft.AspNetCore.Testing.xunit
8+
namespace Microsoft.AspNetCore.Testing
99
{
1010
public static class TestMethodExtensions
1111
{

src/Testing/src/xunit/WindowsVersions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
namespace Microsoft.AspNetCore.Testing.xunit
4+
namespace Microsoft.AspNetCore.Testing
55
{
66
public static class WindowsVersions
77
{

src/Testing/test/ConditionalFactTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using Microsoft.AspNetCore.Testing.xunit;
5+
using Microsoft.AspNetCore.Testing;
66
using Xunit;
77

88
namespace Microsoft.AspNetCore.Testing

src/Testing/test/ConditionalTheoryTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using Microsoft.AspNetCore.Testing.xunit;
5+
using Microsoft.AspNetCore.Testing;
66
using Xunit;
77
using Xunit.Abstractions;
88

src/Testing/test/DockerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using System;
55
using System.Runtime.InteropServices;
6-
using Microsoft.AspNetCore.Testing.xunit;
6+
using Microsoft.AspNetCore.Testing;
77
using Xunit;
88

99
namespace Microsoft.AspNetCore.Testing

src/Testing/test/EnvironmentVariableSkipConditionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using Xunit;
55

6-
namespace Microsoft.AspNetCore.Testing.xunit
6+
namespace Microsoft.AspNetCore.Testing
77
{
88
public class EnvironmentVariableSkipConditionTest
99
{

src/Testing/test/FlakyAttributeTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.AspNetCore.Testing.xunit;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
24
using System;
35
using System.Collections.Generic;
46
using Xunit;

src/Testing/test/OSSkipConditionAttributeTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Runtime.InteropServices;
66
using Xunit;
77

8-
namespace Microsoft.AspNetCore.Testing.xunit
8+
namespace Microsoft.AspNetCore.Testing
99
{
1010
public class OSSkipConditionAttributeTest
1111
{

src/Testing/test/OSSkipConditionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Runtime.InteropServices;
66
using Xunit;
77

8-
namespace Microsoft.AspNetCore.Testing.xunit
8+
namespace Microsoft.AspNetCore.Testing
99
{
1010
public class OSSkipConditionTest
1111
{

src/Testing/test/SkipOnCITests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using Microsoft.AspNetCore.Testing;
6+
using Xunit;
7+
8+
namespace Microsoft.AspNetCore.Testing.Tests
9+
{
10+
public class SkipOnCITests
11+
{
12+
[ConditionalFact]
13+
[SkipOnCI]
14+
public void AlwaysSkipOnCI()
15+
{
16+
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("HELIX")) || !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AGENT_OS")))
17+
{
18+
throw new Exception("Flaky!");
19+
}
20+
}
21+
}
22+
}

src/Testing/test/TestPlatformHelperTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using Microsoft.AspNetCore.Testing.xunit;
4+
using Microsoft.AspNetCore.Testing;
55
using Xunit;
66

77
namespace Microsoft.AspNetCore.Testing

0 commit comments

Comments
 (0)