Fix MaxOsVersion on Ubuntu (dotnet/extensions#2738)

\n\nCommit migrated from e8491a2488
This commit is contained in:
Chris Ross 2019-12-02 14:21:43 -08:00 committed by GitHub
parent 4d04c24f5b
commit 73da7ca714
3 changed files with 31 additions and 1 deletions

View File

@ -35,7 +35,10 @@ namespace Microsoft.AspNetCore.Testing
_maxVersion = maxVersion;
_currentOS = currentOS;
// We drop the 4th field because it is not significant and it messes up the comparisons.
_currentVersion = new Version(currentVersion.Major, currentVersion.Minor, currentVersion.Build);
_currentVersion = new Version(currentVersion.Major, currentVersion.Minor,
// Major and Minor are required by the parser, but if Build isn't specified then it returns -1
// which the constructor rejects.
currentVersion.Build == -1 ? 0 : currentVersion.Build);
// Do not skip other OS's, Use OSSkipConditionAttribute or a separate MaximumOsVersionAttribute for that.
_skip = _targetOS == _currentOS && _maxVersion < _currentVersion;

View File

@ -26,6 +26,18 @@ namespace Microsoft.AspNetCore.Testing
Assert.Throws<NotImplementedException>(() => new MaximumOSVersionAttribute(OperatingSystems.Linux | OperatingSystems.Windows, "2.5"));
}
[Fact]
public void DoesNotSkip_ShortVersions()
{
var osSkipAttribute = new MaximumOSVersionAttribute(
OperatingSystems.Windows,
new Version("2.5"),
OperatingSystems.Windows,
new Version("2.0"));
Assert.True(osSkipAttribute.IsMet);
}
[Fact]
public void DoesNotSkip_EarlierVersions()
{

View File

@ -72,4 +72,19 @@ namespace Microsoft.AspNetCore.Testing
"Test should only be running on Win7 or Win2008R2.");
}
}
// Let this one run cross plat just to check the constructor logic.
[MaximumOSVersion(OperatingSystems.Windows, WindowsVersions.Win7)]
public class OSMaxVersionCrossPlatTest
{
[ConditionalFact]
public void TestSkipClass_Win7DoesRunOnWin7()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Assert.True(Environment.OSVersion.Version.ToString().StartsWith("6.1"),
"Test should only be running on Win7 or Win2008R2.");
}
}
}
}