Skip to content

Commit 73da7ca

Browse files
authored
Fix MaxOsVersion on Ubuntu (dotnet/extensions#2738)
\n\nCommit migrated from dotnet/extensions@e8491a2
1 parent 4d04c24 commit 73da7ca

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/Testing/src/xunit/MaximumOSVersionAttribute.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ internal MaximumOSVersionAttribute(OperatingSystems targetOS, Version maxVersion
3535
_maxVersion = maxVersion;
3636
_currentOS = currentOS;
3737
// We drop the 4th field because it is not significant and it messes up the comparisons.
38-
_currentVersion = new Version(currentVersion.Major, currentVersion.Minor, currentVersion.Build);
38+
_currentVersion = new Version(currentVersion.Major, currentVersion.Minor,
39+
// Major and Minor are required by the parser, but if Build isn't specified then it returns -1
40+
// which the constructor rejects.
41+
currentVersion.Build == -1 ? 0 : currentVersion.Build);
3942

4043
// Do not skip other OS's, Use OSSkipConditionAttribute or a separate MaximumOsVersionAttribute for that.
4144
_skip = _targetOS == _currentOS && _maxVersion < _currentVersion;

src/Testing/test/MaximumOSVersionAttributeTest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ public void WindowsOrLinux_ThrowsNotImplemeneted()
2626
Assert.Throws<NotImplementedException>(() => new MaximumOSVersionAttribute(OperatingSystems.Linux | OperatingSystems.Windows, "2.5"));
2727
}
2828

29+
[Fact]
30+
public void DoesNotSkip_ShortVersions()
31+
{
32+
var osSkipAttribute = new MaximumOSVersionAttribute(
33+
OperatingSystems.Windows,
34+
new Version("2.5"),
35+
OperatingSystems.Windows,
36+
new Version("2.0"));
37+
38+
Assert.True(osSkipAttribute.IsMet);
39+
}
40+
2941
[Fact]
3042
public void DoesNotSkip_EarlierVersions()
3143
{

src/Testing/test/MaximumOSVersionTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,19 @@ public void TestSkipClass_Win7DoesRunOnWin7()
7272
"Test should only be running on Win7 or Win2008R2.");
7373
}
7474
}
75+
76+
// Let this one run cross plat just to check the constructor logic.
77+
[MaximumOSVersion(OperatingSystems.Windows, WindowsVersions.Win7)]
78+
public class OSMaxVersionCrossPlatTest
79+
{
80+
[ConditionalFact]
81+
public void TestSkipClass_Win7DoesRunOnWin7()
82+
{
83+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
84+
{
85+
Assert.True(Environment.OSVersion.Version.ToString().StartsWith("6.1"),
86+
"Test should only be running on Win7 or Win2008R2.");
87+
}
88+
}
89+
}
7590
}

0 commit comments

Comments
 (0)