Skip to content

Commit

Permalink
Accept short names for framework (#2116)
Browse files Browse the repository at this point in the history
* Adding the ability to take short name for framework.
* Adding the dll in the respective nuget packages.
* Added framework acceptance tests
  • Loading branch information
singhsarab authored Aug 19, 2019
1 parent e7a8d42 commit 9238308
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 20 deletions.
1 change: 1 addition & 0 deletions scripts/build/TestPlatform.Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<ChutzpahAdapterVersion>4.3.7</ChutzpahAdapterVersion>
<FileSystemGlobbingVersion>1.1.1</FileSystemGlobbingVersion>

<NuGetFrameworksVersion>5.0.0</NuGetFrameworksVersion>
<JsonNetVersion>9.0.1</JsonNetVersion>
<MoqVersion>4.7.63</MoqVersion>
<TestPlatformExternalsVersion>16.0.0-preview-2148743</TestPlatformExternalsVersion>
Expand Down
6 changes: 3 additions & 3 deletions scripts/verify-nupkgs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ function Verify-Nuget-Packages($packageDirectory)
Write-Log "Starting Verify-Nuget-Packages."
$expectedNumOfFiles = @{"Microsoft.CodeCoverage" = 29;
"Microsoft.NET.Test.Sdk" = 13;
"Microsoft.TestPlatform" = 422;
"Microsoft.TestPlatform" = 423;
"Microsoft.TestPlatform.Build" = 19;
"Microsoft.TestPlatform.CLI" = 301;
"Microsoft.TestPlatform.CLI" = 303;
"Microsoft.TestPlatform.Extensions.TrxLogger" = 33;
"Microsoft.TestPlatform.ObjectModel" = 62;
"Microsoft.TestPlatform.Portable" = 471;
"Microsoft.TestPlatform.Portable" = 474;
"Microsoft.TestPlatform.TestHost" = 140;
"Microsoft.TestPlatform.TranslationLayer" = 121}

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.TestPlatform.ObjectModel/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public static class Constants

public const string DotNetFrameworkCore10 = ".NETCoreApp,Version=v1.0";

public const string DotNetFrameworkUap10 = "Uap,Version=v10.0";
public const string DotNetFrameworkUap10 = "UAP,Version=v10.0";

public const string TargetFrameworkName = "TargetFrameworkName";
}
Expand Down
23 changes: 12 additions & 11 deletions src/Microsoft.TestPlatform.ObjectModel/Framework.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Microsoft.VisualStudio.TestPlatform.ObjectModel
{
using System;
using System.Runtime.Versioning;
using NuGet.Frameworks;
using static NuGet.Frameworks.FrameworkConstants;

/// <summary>
/// Class for target Framework for the test container
Expand Down Expand Up @@ -48,31 +48,32 @@ public static Framework FromString(string frameworkString)
return null;
}

FrameworkName frameworkName;
NuGetFramework nugetFramework;
try
{
// IDE always sends framework in form of ENUM, which always throws exception
// This throws up in first chance exception, refer Bug https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/591142
switch (frameworkString.Trim().ToLower())
{
case "framework35":
frameworkName = new FrameworkName(Constants.DotNetFramework35);
nugetFramework = CommonFrameworks.Net35;
break;
case "framework40":
frameworkName = new FrameworkName(Constants.DotNetFramework40);
nugetFramework = CommonFrameworks.Net4;
break;
case "framework45":
frameworkName = new FrameworkName(Constants.DotNetFramework45);
nugetFramework = CommonFrameworks.Net45;
break;
case "frameworkcore10":
frameworkName = new FrameworkName(Constants.DotNetFrameworkCore10);
nugetFramework = CommonFrameworks.NetCoreApp10;
break;
case "frameworkuap10":
frameworkName = new FrameworkName(Constants.DotNetFrameworkUap10);
nugetFramework = CommonFrameworks.UAP10;
break;
default:
// FrameworkName already trims the input identifier.
frameworkName = new FrameworkName(frameworkString);
nugetFramework = NuGetFramework.Parse(frameworkString);
if (nugetFramework.IsUnsupported)
return null;
break;
}
}
Expand All @@ -81,7 +82,7 @@ public static Framework FromString(string frameworkString)
return null;
}

return new Framework() { Name = frameworkName.FullName, Version = frameworkName.Version.ToString() };
return new Framework() { Name = nugetFramework.DotNetFrameworkName, Version = nugetFramework.Version.ToString() };
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ProjectReference Include="..\Microsoft.TestPlatform.CoreUtilities\Microsoft.TestPlatform.CoreUtilities.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NuGet.Frameworks" Version="$(NuGetFrameworksVersion)" />
<PackageReference Include="System.Reflection.Metadata">
<Version>1.6.0</Version>
</PackageReference>
Expand Down
6 changes: 5 additions & 1 deletion src/package/nuspec/Microsoft.TestPlatform.Portable.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
<file src="net451\$Runtime$\testhost.x86.exe.config" target="tools\net451\testhost.x86.exe.config" />
<file src="net451\$Runtime$\vstest.console.exe" target="tools\net451\vstest.console.exe" />
<file src="net451\$Runtime$\vstest.console.exe.config" target="tools\net451\vstest.console.exe.config" />
<file src="net451\$Runtime$\NuGet.Frameworks.dll" target="tools\net451\NuGet.Frameworks.dll" />

<file src="net451\$Runtime$\cs\Microsoft.TestPlatform.CommunicationUtilities.resources.dll" target="tools\net451\cs\Microsoft.TestPlatform.CommunicationUtilities.resources.dll" />
<file src="net451\$Runtime$\cs\Microsoft.TestPlatform.CoreUtilities.resources.dll" target="tools\net451\cs\Microsoft.TestPlatform.CoreUtilities.resources.dll" />
<file src="net451\$Runtime$\cs\Microsoft.TestPlatform.CrossPlatEngine.resources.dll" target="tools\net451\cs\Microsoft.TestPlatform.CrossPlatEngine.resources.dll" />
Expand Down Expand Up @@ -243,6 +245,8 @@
<file src="netcoreapp2.1\vstest.console.dll" target="tools\netcoreapp2.1\vstest.console.dll" />
<file src="netcoreapp2.1\vstest.console.dll.config" target="tools\netcoreapp2.1\vstest.console.dll.config" />
<file src="netcoreapp2.1\vstest.console.runtimeconfig.json" target="tools\netcoreapp2.1\vstest.console.runtimeconfig.json" />
<file src="netcoreapp2.1\NuGet.Frameworks.dll" target="tools\netcoreapp2.1\NuGet.Frameworks.dll" />

<file src="netcoreapp2.1\cs\Microsoft.TestPlatform.CommunicationUtilities.resources.dll" target="tools\netcoreapp2.1\cs\Microsoft.TestPlatform.CommunicationUtilities.resources.dll" />
<file src="netcoreapp2.1\cs\Microsoft.TestPlatform.CoreUtilities.resources.dll" target="tools\netcoreapp2.1\cs\Microsoft.TestPlatform.CoreUtilities.resources.dll" />
<file src="netcoreapp2.1\cs\Microsoft.TestPlatform.CrossPlatEngine.resources.dll" target="tools\netcoreapp2.1\cs\Microsoft.TestPlatform.CrossPlatEngine.resources.dll" />
Expand Down Expand Up @@ -365,6 +369,7 @@
<file src="netcoreapp2.1\TestHost\Microsoft.TestPlatform.Utilities.dll" target="tools\netcoreapp2.1\TestHost\Microsoft.TestPlatform.Utilities.dll" />
<file src="netcoreapp2.1\TestHost\Microsoft.VisualStudio.TestPlatform.Common.dll" target="tools\netcoreapp2.1\TestHost\Microsoft.VisualStudio.TestPlatform.Common.dll" />
<file src="netcoreapp2.1\TestHost\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll" target="tools\netcoreapp2.1\TestHost\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll" />
<file src="netcoreapp2.1\TestHost\NuGet.Frameworks.dll" target="tools\netcoreapp2.1\TestHost\NuGet.Frameworks.dll" />
<file src="netcoreapp2.1\TestHost\msdia140typelib_clr0200.dll" target="tools\netcoreapp2.1\TestHost\msdia140typelib_clr0200.dll" />
<file src="netcoreapp2.1\TestHost\Newtonsoft.Json.dll" target="tools\netcoreapp2.1\TestHost\Newtonsoft.Json.dll" />
<file src="netcoreapp2.1\TestHost\System.Collections.Immutable.dll" target="tools\netcoreapp2.1\TestHost\System.Collections.Immutable.dll" />
Expand Down Expand Up @@ -488,6 +493,5 @@
<file src="netcoreapp2.1\Extensions\zh-Hant\Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.resources.dll" target="tools\netcoreapp2.1\Extensions\zh-Hant\Microsoft.VisualStudio.TestPlatform.Extensions.Trx.TestLogger.resources.dll" />
<file src="netcoreapp2.1\zh-Hant\Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll" target="tools\netcoreapp2.1\zh-Hant\Microsoft.VisualStudio.TestPlatform.ObjectModel.resources.dll" />
<file src="netcoreapp2.1\zh-Hant\vstest.console.resources.dll" target="tools\netcoreapp2.1\zh-Hant\vstest.console.resources.dll" />

</files>
</package>
1 change: 1 addition & 0 deletions src/package/nuspec/Microsoft.TestPlatform.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<file src="net451\$Runtime$\LegacyTypes.testtype" target="tools\net451\Common7\IDE\Extensions\TestPlatform\LegacyTypes.testtype" />
<file src="net451\$Runtime$\ManualTests.testtype" target="tools\net451\Common7\IDE\Extensions\TestPlatform\ManualTests.testtype" />
<file src="net451\$Runtime$\Microsoft.DiaSymReader.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Microsoft.DiaSymReader.dll" />
<file src="net451\$Runtime$\NuGet.Frameworks.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\NuGet.Frameworks.dll" />
<file src="net451\$Runtime$\Microsoft.Extensions.DependencyModel.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Microsoft.Extensions.DependencyModel.dll" />
<file src="net451\$Runtime$\Microsoft.Extensions.FileSystemGlobbing.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Microsoft.Extensions.FileSystemGlobbing.dll" />
<file src="net451\$Runtime$\Microsoft.IntelliTrace.Core.dll" target="tools\net451\Common7\IDE\Extensions\TestPlatform\Microsoft.IntelliTrace.Core.dll" />
Expand Down
4 changes: 4 additions & 0 deletions src/package/nuspec/TestPlatform.ObjectModel.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<group targetFramework="net451">
<dependency id="System.Runtime.InteropServices.RuntimeInformation" version="[4.0.0, )" />
<dependency id="System.Reflection.Metadata" version="[1.6.0, )" />
<dependency id="NuGet.Frameworks" version="[5.0.0, )" />
</group>
<group targetFramework="netstandard2.0">
<dependency id="NuGet.Frameworks" version="[5.0.0, )" />
</group>
</dependencies>
<frameworkAssemblies>
Expand Down
14 changes: 14 additions & 0 deletions test/Microsoft.TestPlatform.AcceptanceTests/FrameworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ public void FrameworkArgumentShouldWork(RunnerInfo runnerInfo)
this.ValidateSummaryStatus(1, 1, 1);
}

[TestMethod]
[NetFullTargetFrameworkDataSource]
[NetCoreTargetFrameworkDataSource]
public void FrameworkShortNameArgumentShouldWork(RunnerInfo runnerInfo)
{
AcceptanceTestBase.SetTestEnvironment(this.testEnvironment, runnerInfo);

var arguments = PrepareArguments(GetSampleTestAssembly(), string.Empty, string.Empty, this.testEnvironment.TargetFramework);
arguments = string.Concat(arguments, " ", $"/Framework:{this.testEnvironment.TargetFramework}");

this.InvokeVsTest(arguments);
this.ValidateSummaryStatus(1, 1, 1);
}

[TestMethod]
[NetFullTargetFrameworkDataSource]
[NetCoreTargetFrameworkDataSource]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void FrameworkFromStringShouldIgnoreCase()
Assert.AreEqual(".NETCoreApp,Version=v1.0", fx.Name);

fx = Framework.FromString("frameworkUAP10");
Assert.AreEqual("Uap,Version=v10.0", fx.Name);
Assert.AreEqual("UAP,Version=v10.0", fx.Name);
}

[TestMethod]
Expand All @@ -54,7 +54,19 @@ public void FrameworkFromStringShouldTrimSpacesAroundFrameworkString()
var fx = Framework.FromString(" Framework35");

Assert.AreEqual(".NETFramework,Version=v3.5", fx.Name);
Assert.AreEqual("3.5", fx.Version);
Assert.AreEqual("3.5.0.0", fx.Version);
}

[TestMethod]
public void FrameworkFromStringShouldWorkForShortNames()
{
var fx = Framework.FromString("net451");
Assert.AreEqual(".NETFramework,Version=v4.5.1", fx.Name);
Assert.AreEqual("4.5.1.0", fx.Version);

var corefx = Framework.FromString("netcoreapp2.0");
Assert.AreEqual(".NETCoreApp,Version=v2.0", corefx.Name);
Assert.AreEqual("2.0.0.0", corefx.Version);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public void InitializeShouldSetCommandLineOptionsFrameworkForOlderFrameworks()
public void InitializeShouldSetCommandLineOptionsFrameworkForCaseInsensitiveFramework()
{
this.executor.Initialize(".netcoreApp,Version=v1.0");
Assert.AreEqual(".netcoreApp,Version=v1.0", CommandLineOptions.Instance.TargetFrameworkVersion.Name);
Assert.AreEqual(".netcoreApp,Version=v1.0", this.runSettingsProvider.QueryRunSettingsNode(FrameworkArgumentExecutor.RunSettingsPath));
Assert.AreEqual(".NETCoreApp,Version=v1.0", CommandLineOptions.Instance.TargetFrameworkVersion.Name);
Assert.AreEqual(".NETCoreApp,Version=v1.0", this.runSettingsProvider.QueryRunSettingsNode(FrameworkArgumentExecutor.RunSettingsPath));
}

[TestMethod]
Expand Down

0 comments on commit 9238308

Please sign in to comment.