Skip to content

Commit e467364

Browse files
authored
Remove version checks from OSSkipCondition (dotnet/extensions#2755)
\n\nCommit migrated from dotnet/extensions@0aa6213
1 parent b4e5921 commit e467364

6 files changed

+28
-127
lines changed

src/Testing/ref/Microsoft.AspNetCore.Testing.net46.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public enum OperatingSystems
193193
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
194194
public partial class OSSkipConditionAttribute : System.Attribute, Microsoft.AspNetCore.Testing.ITestCondition
195195
{
196+
public OSSkipConditionAttribute(Microsoft.AspNetCore.Testing.OperatingSystems operatingSystem) { }
197+
[System.ObsoleteAttribute("Use the Minimum/MaximumOSVersionAttribute for version checks.", true)]
196198
public OSSkipConditionAttribute(Microsoft.AspNetCore.Testing.OperatingSystems operatingSystem, params string[] versions) { }
197199
public bool IsMet { get { throw null; } }
198200
public string SkipReason { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
@@ -331,6 +333,7 @@ public static partial class WindowsVersions
331333
public const string Win10_20H1 = "10.0.19033";
332334
public const string Win10_RS4 = "10.0.17134";
333335
public const string Win10_RS5 = "10.0.17763";
336+
[System.ObsoleteAttribute("Use Win7 instead.", true)]
334337
public const string Win2008R2 = "6.1";
335338
public const string Win7 = "6.1";
336339
public const string Win8 = "6.2";

src/Testing/ref/Microsoft.AspNetCore.Testing.netstandard2.0.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public enum OperatingSystems
193193
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true)]
194194
public partial class OSSkipConditionAttribute : System.Attribute, Microsoft.AspNetCore.Testing.ITestCondition
195195
{
196+
public OSSkipConditionAttribute(Microsoft.AspNetCore.Testing.OperatingSystems operatingSystem) { }
197+
[System.ObsoleteAttribute("Use the Minimum/MaximumOSVersionAttribute for version checks.", true)]
196198
public OSSkipConditionAttribute(Microsoft.AspNetCore.Testing.OperatingSystems operatingSystem, params string[] versions) { }
197199
public bool IsMet { get { throw null; } }
198200
public string SkipReason { [System.Runtime.CompilerServices.CompilerGeneratedAttribute] get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute] set { } }
@@ -331,6 +333,7 @@ public static partial class WindowsVersions
331333
public const string Win10_20H1 = "10.0.19033";
332334
public const string Win10_RS4 = "10.0.17134";
333335
public const string Win10_RS5 = "10.0.17763";
336+
[System.ObsoleteAttribute("Use Win7 instead.", true)]
334337
public const string Win2008R2 = "6.1";
335338
public const string Win7 = "6.1";
336339
public const string Win8 = "6.2";

src/Testing/src/xunit/OSSkipConditionAttribute.cs

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
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 System.Collections.Generic;
6-
using System.Linq;
75
using System.Runtime.InteropServices;
86

97
namespace Microsoft.AspNetCore.Testing
@@ -12,46 +10,31 @@ namespace Microsoft.AspNetCore.Testing
1210
public class OSSkipConditionAttribute : Attribute, ITestCondition
1311
{
1412
private readonly OperatingSystems _excludedOperatingSystem;
15-
private readonly IEnumerable<string> _excludedVersions;
1613
private readonly OperatingSystems _osPlatform;
17-
private readonly string _osVersion;
1814

19-
public OSSkipConditionAttribute(OperatingSystems operatingSystem, params string[] versions) :
20-
this(
21-
operatingSystem,
22-
GetCurrentOS(),
23-
GetCurrentOSVersion(),
24-
versions)
15+
public OSSkipConditionAttribute(OperatingSystems operatingSystem) :
16+
this(operatingSystem, GetCurrentOS())
17+
{
18+
}
19+
20+
[Obsolete("Use the Minimum/MaximumOSVersionAttribute for version checks.", error: true)]
21+
public OSSkipConditionAttribute(OperatingSystems operatingSystem, params string[] versions) :
22+
this(operatingSystem, GetCurrentOS())
2523
{
2624
}
2725

2826
// to enable unit testing
29-
internal OSSkipConditionAttribute(
30-
OperatingSystems operatingSystem, OperatingSystems osPlatform, string osVersion, params string[] versions)
27+
internal OSSkipConditionAttribute(OperatingSystems operatingSystem, OperatingSystems osPlatform)
3128
{
3229
_excludedOperatingSystem = operatingSystem;
33-
_excludedVersions = versions ?? Enumerable.Empty<string>();
3430
_osPlatform = osPlatform;
35-
_osVersion = osVersion;
3631
}
3732

3833
public bool IsMet
3934
{
4035
get
4136
{
42-
var currentOSInfo = new OSInfo()
43-
{
44-
OperatingSystem = _osPlatform,
45-
Version = _osVersion,
46-
};
47-
48-
var skip = (_excludedOperatingSystem & currentOSInfo.OperatingSystem) == currentOSInfo.OperatingSystem;
49-
if (_excludedVersions.Any())
50-
{
51-
skip = skip
52-
&& _excludedVersions.Any(ex => _osVersion.StartsWith(ex, StringComparison.OrdinalIgnoreCase));
53-
}
54-
37+
var skip = (_excludedOperatingSystem & _osPlatform) == _osPlatform;
5538
// Since a test would be excuted only if 'IsMet' is true, return false if we want to skip
5639
return !skip;
5740
}
@@ -75,25 +58,5 @@ static private OperatingSystems GetCurrentOS()
7558
}
7659
throw new PlatformNotSupportedException();
7760
}
78-
79-
static private string GetCurrentOSVersion()
80-
{
81-
// currently not used on other OS's
82-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
83-
{
84-
return Environment.OSVersion.Version.ToString();
85-
}
86-
else
87-
{
88-
return string.Empty;
89-
}
90-
}
91-
92-
private class OSInfo
93-
{
94-
public OperatingSystems OperatingSystem { get; set; }
95-
96-
public string Version { get; set; }
97-
}
9861
}
9962
}

src/Testing/src/xunit/WindowsVersions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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 System;
5+
46
namespace Microsoft.AspNetCore.Testing
57
{
68
/// <summary>
@@ -10,6 +12,7 @@ public static class WindowsVersions
1012
{
1113
public const string Win7 = "6.1";
1214

15+
[Obsolete("Use Win7 instead.", error: true)]
1316
public const string Win2008R2 = Win7;
1417

1518
public const string Win8 = "6.2";

src/Testing/test/OSSkipConditionAttributeTest.cs

Lines changed: 9 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ namespace Microsoft.AspNetCore.Testing
1010
public class OSSkipConditionAttributeTest
1111
{
1212
[Fact]
13-
public void Skips_WhenOnlyOperatingSystemIsSupplied()
13+
public void Skips_WhenOperatingSystemMatches()
1414
{
1515
// Act
1616
var osSkipAttribute = new OSSkipConditionAttribute(
1717
OperatingSystems.Windows,
18-
OperatingSystems.Windows,
19-
"2.5");
18+
OperatingSystems.Windows);
2019

2120
// Assert
2221
Assert.False(osSkipAttribute.IsMet);
@@ -28,77 +27,18 @@ public void DoesNotSkip_WhenOperatingSystemDoesNotMatch()
2827
// Act
2928
var osSkipAttribute = new OSSkipConditionAttribute(
3029
OperatingSystems.Linux,
31-
OperatingSystems.Windows,
32-
"2.5");
30+
OperatingSystems.Windows);
3331

3432
// Assert
3533
Assert.True(osSkipAttribute.IsMet);
3634
}
3735

38-
[Fact]
39-
public void DoesNotSkip_WhenVersionsDoNotMatch()
40-
{
41-
// Act
42-
var osSkipAttribute = new OSSkipConditionAttribute(
43-
OperatingSystems.Windows,
44-
OperatingSystems.Windows,
45-
"2.5",
46-
"10.0");
47-
48-
// Assert
49-
Assert.True(osSkipAttribute.IsMet);
50-
}
51-
52-
[Fact]
53-
public void DoesNotSkip_WhenOnlyVersionsMatch()
54-
{
55-
// Act
56-
var osSkipAttribute = new OSSkipConditionAttribute(
57-
OperatingSystems.Linux,
58-
OperatingSystems.Windows,
59-
"2.5",
60-
"2.5");
61-
62-
// Assert
63-
Assert.True(osSkipAttribute.IsMet);
64-
}
65-
66-
[Theory]
67-
[InlineData("2.5", "2.5")]
68-
[InlineData("blue", "Blue")]
69-
public void Skips_WhenVersionsMatches(string currentOSVersion, string skipVersion)
70-
{
71-
// Act
72-
var osSkipAttribute = new OSSkipConditionAttribute(
73-
OperatingSystems.Windows,
74-
OperatingSystems.Windows,
75-
currentOSVersion,
76-
skipVersion);
77-
78-
// Assert
79-
Assert.False(osSkipAttribute.IsMet);
80-
}
81-
82-
[Fact]
83-
public void Skips_WhenVersionsMatchesOutOfMultiple()
84-
{
85-
// Act
86-
var osSkipAttribute = new OSSkipConditionAttribute(
87-
OperatingSystems.Windows,
88-
OperatingSystems.Windows,
89-
"2.5",
90-
"10.0", "3.4", "2.5");
91-
92-
// Assert
93-
Assert.False(osSkipAttribute.IsMet);
94-
}
95-
9636
[Fact]
9737
public void Skips_BothMacOSXAndLinux()
9838
{
9939
// Act
100-
var osSkipAttributeLinux = new OSSkipConditionAttribute(OperatingSystems.Linux | OperatingSystems.MacOSX, OperatingSystems.Linux, string.Empty);
101-
var osSkipAttributeMacOSX = new OSSkipConditionAttribute(OperatingSystems.Linux | OperatingSystems.MacOSX, OperatingSystems.MacOSX, string.Empty);
40+
var osSkipAttributeLinux = new OSSkipConditionAttribute(OperatingSystems.Linux | OperatingSystems.MacOSX, OperatingSystems.Linux);
41+
var osSkipAttributeMacOSX = new OSSkipConditionAttribute(OperatingSystems.Linux | OperatingSystems.MacOSX, OperatingSystems.MacOSX);
10242

10343
// Assert
10444
Assert.False(osSkipAttributeLinux.IsMet);
@@ -109,8 +49,8 @@ public void Skips_BothMacOSXAndLinux()
10949
public void Skips_BothMacOSXAndWindows()
11050
{
11151
// Act
112-
var osSkipAttribute = new OSSkipConditionAttribute(OperatingSystems.Windows | OperatingSystems.MacOSX, OperatingSystems.Windows, string.Empty);
113-
var osSkipAttributeMacOSX = new OSSkipConditionAttribute(OperatingSystems.Windows | OperatingSystems.MacOSX, OperatingSystems.MacOSX, string.Empty);
52+
var osSkipAttribute = new OSSkipConditionAttribute(OperatingSystems.Windows | OperatingSystems.MacOSX, OperatingSystems.Windows);
53+
var osSkipAttributeMacOSX = new OSSkipConditionAttribute(OperatingSystems.Windows | OperatingSystems.MacOSX, OperatingSystems.MacOSX);
11454

11555
// Assert
11656
Assert.False(osSkipAttribute.IsMet);
@@ -121,8 +61,8 @@ public void Skips_BothMacOSXAndWindows()
12161
public void Skips_BothWindowsAndLinux()
12262
{
12363
// Act
124-
var osSkipAttribute = new OSSkipConditionAttribute(OperatingSystems.Linux | OperatingSystems.Windows, OperatingSystems.Windows, string.Empty);
125-
var osSkipAttributeLinux = new OSSkipConditionAttribute(OperatingSystems.Linux | OperatingSystems.Windows, OperatingSystems.Linux, string.Empty);
64+
var osSkipAttribute = new OSSkipConditionAttribute(OperatingSystems.Linux | OperatingSystems.Windows, OperatingSystems.Windows);
65+
var osSkipAttributeLinux = new OSSkipConditionAttribute(OperatingSystems.Linux | OperatingSystems.Windows, OperatingSystems.Linux);
12666

12767
// Assert
12868
Assert.False(osSkipAttribute.IsMet);

src/Testing/test/OSSkipConditionTest.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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 System;
54
using System.Runtime.InteropServices;
65
using Xunit;
76

@@ -27,16 +26,6 @@ public void TestSkipMacOSX()
2726
"Test should not be running on MacOSX.");
2827
}
2928

30-
[ConditionalFact]
31-
[OSSkipCondition(OperatingSystems.Windows, WindowsVersions.Win7, WindowsVersions.Win2008R2)]
32-
public void RunTest_DoesNotRunOnWin7OrWin2008R2()
33-
{
34-
Assert.False(
35-
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
36-
Environment.OSVersion.Version.ToString().StartsWith("6.1"),
37-
"Test should not be running on Win7 or Win2008R2.");
38-
}
39-
4029
[ConditionalFact]
4130
[OSSkipCondition(OperatingSystems.Windows)]
4231
public void TestSkipWindows()

0 commit comments

Comments
 (0)