Skip to content

Commit 141fdc8

Browse files
authored
Some code clean-up and refactoring (#800)
Moved the code clean-up and refactoring done in #794 to here.
1 parent 327ab68 commit 141fdc8

File tree

27 files changed

+200
-286
lines changed

27 files changed

+200
-286
lines changed

TestFx.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSTest.Core", "src\TestFram
2121
EndProject
2222
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlatformServices.Desktop", "src\Adapter\PlatformServices.Desktop\PlatformServices.Desktop.csproj", "{B0FCE474-14BC-449A-91EA-A433342C0D63}"
2323
EndProject
24+
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "PlatformServices.Shared", "src\Adapter\PlatformServices.Shared\PlatformServices.Shared.shproj", "{2177C273-AE07-43B3-B87A-443E47A23C5A}"
25+
EndProject
2426
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Extension.Desktop", "src\TestFramework\Extension.Desktop\Extension.Desktop.csproj", "{A7EA583B-A2B0-47DA-A058-458F247C7575}"
2527
EndProject
2628
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Extension.Core", "src\TestFramework\Extension.Core\Extension.Core.csproj", "{6C9FE494-8315-4667-B3F6-75DC62A62319}"
@@ -189,6 +191,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NetCore", "NetCore", "{D11C
189191
EndProject
190192
Global
191193
GlobalSection(SharedMSBuildProjectFiles) = preSolution
194+
src\Adapter\PlatformServices.Shared\PlatformServices.Shared.projitems*{2177c273-ae07-43b3-b87a-443e47a23c5a}*SharedItemsImports = 13
192195
src\TestFramework\Extension.Shared\Extension.Shared.projitems*{272ca5e1-8e81-4825-9e47-86cce02f700d}*SharedItemsImports = 13
193196
src\TestFramework\Extension.Shared\Extension.Shared.projitems*{df131865-84ee-4540-8112-e88acebdea09}*SharedItemsImports = 4
194197
EndGlobalSection
@@ -1180,6 +1183,7 @@ Global
11801183
{E48AC786-E150-4F41-9A16-32F02E4493D8} = {FF8B1B72-55A1-4FFE-809E-7B79323ED8D0}
11811184
{7252D9E3-267D-442C-96BC-C73AEF3241D6} = {E48AC786-E150-4F41-9A16-32F02E4493D8}
11821185
{B0FCE474-14BC-449A-91EA-A433342C0D63} = {24088844-2107-4DB2-8F3F-CBCA94FC4B28}
1186+
{2177C273-AE07-43B3-B87A-443E47A23C5A} = {24088844-2107-4DB2-8F3F-CBCA94FC4B28}
11831187
{A7EA583B-A2B0-47DA-A058-458F247C7575} = {E48AC786-E150-4F41-9A16-32F02E4493D8}
11841188
{6C9FE494-8315-4667-B3F6-75DC62A62319} = {E48AC786-E150-4F41-9A16-32F02E4493D8}
11851189
{F2D0BF2C-38F2-4244-80E3-4AAD1C3F4C89} = {A9596292-7E67-4566-9096-143DDAA4E8D8}

scripts/build/TestFx.Settings.targets

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<TestFxRoot Condition="$(TestFxRoot) == ''">..\..\</TestFxRoot>
5-
<RepoRoot>..\..\</RepoRoot>
5+
<RepoRoot Condition="$(RepoRoot) == ''">$(TestFxRoot)</RepoRoot>
6+
<IncludeMicrosoftCommon Condition="$(IncludeMicrosoftCommon) == ''">true</IncludeMicrosoftCommon>
67
</PropertyGroup>
7-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props') and $(FrameworkIdentifier) != 'NetCore'" />
8+
9+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props') and $(FrameworkIdentifier) != 'NetCore' and $(IncludeMicrosoftCommon) == 'true'" />
810
<!-- Import props/targets with $(RepoRoot) since msbuild takes the relative path based on settings.targets and not with respect to the project. -->
911
<Import Project="$(RepoRoot)packages\MicroBuild.Core.0.2.0\build\MicroBuild.Core.props" Condition="Exists('$(RepoRoot)packages\MicroBuild.Core.0.2.0\build\MicroBuild.Core.props')" />
1012
<Import Project="TestFx.Versions.targets" />

scripts/build/TestFx.targets

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" Condition="$(TargetFrameworkProfile) == 'Profile259'" />
44
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" Condition="$(TargetPlatformIdentifier) == 'UAP'" />
5-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition="($(TargetFrameworkProfile) == '' or $(TargetFrameworkProfile) != 'Profile259') and $(TargetPlatformIdentifier) != 'UAP' and $(FrameworkIdentifier) != 'NetCore'"/>
5+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition="($(TargetFrameworkProfile) == '' or $(TargetFrameworkProfile) != 'Profile259') and $(TargetPlatformIdentifier) != 'UAP' and $(FrameworkIdentifier) != 'NetCore' and $(IncludeMicrosoftCommon) == 'true'"/>
66

77
<PropertyGroup>
88
<TestFxRoot Condition="$(TestFxRoot) == ''">..\..\</TestFxRoot>
@@ -84,12 +84,12 @@
8484
</AssemblyVersionAttribute>
8585
</ItemGroup>
8686
<Target Name="GenerateAssemblyInfoFile">
87-
<WriteCodeFragment AssemblyAttributes="@(AssemblyVersionAttribute)" Language="C#" OutputFile="$(MSBuildProjectDirectory)\GlobalAssemblyInfo.cs">
87+
<WriteCodeFragment AssemblyAttributes="@(AssemblyVersionAttribute)" Language="C#" OutputFile="$(MSBuildProjectDirectory)\GlobalAssemblyInfo.cs" Condition="$(SkipAppendingVersion) != 'true'">
8888
<Output TaskParameter="OutputFile" ItemName="Compile" />
8989
<Output TaskParameter="OutputFile" ItemName="FileWrites" />
9090
</WriteCodeFragment>
9191
</Target>
9292
<PropertyGroup>
9393
<CompileDependsOn>GenerateAssemblyInfoFile;$(CompileDependsOn)</CompileDependsOn>
9494
</PropertyGroup>
95-
</Project>
95+
</Project>

scripts/common.lib.ps1

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $env:TF_PACKAGES_DIR = Join-Path $env:TF_ROOT_DIR "packages"
2222

2323
$TF_VERSIONS_FILE = "$PSScriptRoot\build\TestFx.Versions.targets"
2424
if ([String]::IsNullOrWhiteSpace($TestPlatformVersion)) {
25-
$TestPlatformVersion = (([XML](Get-Content $TF_VERSIONS_FILE)).Project.PropertyGroup.TestPlatformVersion).InnerText
25+
$TestPlatformVersion = (([XML](Get-Content $TF_VERSIONS_FILE)).Project.PropertyGroup.TestPlatformVersion).InnerText
2626
}
2727

2828
function Create-Directory([string[]] $path) {
@@ -180,64 +180,64 @@ function Write-Log ([string] $message, $messageColor = "Green") {
180180
$Host.UI.RawUI.ForegroundColor = $currentColor
181181
}
182182

183-
function Install-DotNetCli
184-
{
185-
Write-Log "Install-DotNetCli: Get dotnet-install.ps1 script..."
186-
$dotnetInstallRemoteScript = "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1"
187-
$dotnetInstallScript = Join-Path $env:TF_TOOLS_DIR "dotnet-install.ps1"
188-
if (-not (Test-Path $env:TF_TOOLS_DIR)) {
189-
New-Item $env:TF_TOOLS_DIR -Type Directory | Out-Null
190-
}
183+
function Install-DotNetCli {
184+
Write-Log "Install-DotNetCli: Get dotnet-install.ps1 script..."
185+
$dotnetInstallRemoteScript = "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain/dotnet-install.ps1"
186+
$dotnetInstallScript = Join-Path $env:TF_TOOLS_DIR "dotnet-install.ps1"
187+
if (-not (Test-Path $env:TF_TOOLS_DIR)) {
188+
New-Item $env:TF_TOOLS_DIR -Type Directory | Out-Null
189+
}
191190

192-
$dotnet_dir= Join-Path $env:TF_TOOLS_DIR "dotnet"
191+
$dotnet_dir = Join-Path $env:TF_TOOLS_DIR "dotnet"
193192

194-
if (-not (Test-Path $dotnet_dir)) {
195-
New-Item $dotnet_dir -Type Directory | Out-Null
196-
}
193+
if (-not (Test-Path $dotnet_dir)) {
194+
New-Item $dotnet_dir -Type Directory | Out-Null
195+
}
197196

198-
(New-Object System.Net.WebClient).DownloadFile($dotnetInstallRemoteScript, $dotnetInstallScript)
197+
(New-Object System.Net.WebClient).DownloadFile($dotnetInstallRemoteScript, $dotnetInstallScript)
199198

200-
if (-not (Test-Path $dotnetInstallScript)) {
201-
Write-Error "Failed to download dotnet install script."
202-
}
199+
if (-not (Test-Path $dotnetInstallScript)) {
200+
Write-Error "Failed to download dotnet install script."
201+
}
203202

204-
Unblock-File $dotnetInstallScript
203+
Unblock-File $dotnetInstallScript
205204

206-
Write-Log "Install-DotNetCli: Get the latest dotnet cli toolset..."
207-
$dotnetInstallPath = Join-Path $env:TF_TOOLS_DIR "dotnet"
208-
New-Item -ItemType directory -Path $dotnetInstallPath -Force | Out-Null
209-
& $dotnetInstallScript -Channel "master" -InstallDir $dotnetInstallPath -Version $env:DOTNET_CLI_VERSION
205+
Write-Log "Install-DotNetCli: Get the latest dotnet cli toolset..."
206+
$dotnetInstallPath = Join-Path $env:TF_TOOLS_DIR "dotnet"
207+
New-Item -ItemType directory -Path $dotnetInstallPath -Force | Out-Null
208+
& $dotnetInstallScript -Channel "master" -InstallDir $dotnetInstallPath -Version $env:DOTNET_CLI_VERSION
210209

211-
& $dotnetInstallScript -InstallDir "$dotnetInstallPath" -Runtime 'dotnet' -Version '2.1.0' -Channel '2.1.0' -Architecture x64 -NoPath
212-
$env:DOTNET_ROOT= $dotnetInstallPath
210+
& $dotnetInstallScript -InstallDir "$dotnetInstallPath" -Runtime 'dotnet' -Version '2.1.0' -Channel '2.1.0' -Architecture x64 -NoPath
211+
$env:DOTNET_ROOT = $dotnetInstallPath
213212

214-
& $dotnetInstallScript -InstallDir "${dotnetInstallPath}_x86" -Runtime 'dotnet' -Version '2.1.0' -Channel '2.1.0' -Architecture x86 -NoPath
215-
${env:DOTNET_ROOT(x86)} = "${dotnetInstallPath}_x86"
213+
& $dotnetInstallScript -InstallDir "${dotnetInstallPath}_x86" -Runtime 'dotnet' -Version '2.1.0' -Channel '2.1.0' -Architecture x86 -NoPath
214+
${env:DOTNET_ROOT(x86)} = "${dotnetInstallPath}_x86"
216215

217-
& $dotnetInstallScript -InstallDir "$dotnetInstallPath" -Runtime 'dotnet' -Version '3.1.0' -Channel '3.1.0' -Architecture x64 -NoPath
218-
$env:DOTNET_ROOT= $dotnetInstallPath
216+
& $dotnetInstallScript -InstallDir "$dotnetInstallPath" -Runtime 'dotnet' -Version '3.1.0' -Channel '3.1.0' -Architecture x64 -NoPath
217+
$env:DOTNET_ROOT = $dotnetInstallPath
219218

220-
& $dotnetInstallScript -InstallDir "${dotnetInstallPath}_x86" -Runtime 'dotnet' -Version '3.1.0' -Channel '3.1.0' -Architecture x86 -NoPath
221-
${env:DOTNET_ROOT(x86)} = "${dotnetInstallPath}_x86"
219+
& $dotnetInstallScript -InstallDir "${dotnetInstallPath}_x86" -Runtime 'dotnet' -Version '3.1.0' -Channel '3.1.0' -Architecture x86 -NoPath
220+
${env:DOTNET_ROOT(x86)} = "${dotnetInstallPath}_x86"
222221

223-
& $dotnetInstallScript -InstallDir "$dotnetInstallPath" -Runtime 'dotnet' -Version '5.0.1' -Channel '5.0.1' -Architecture x64 -NoPath
224-
$env:DOTNET_ROOT= $dotnetInstallPath
222+
& $dotnetInstallScript -InstallDir "$dotnetInstallPath" -Runtime 'dotnet' -Version '5.0.1' -Channel '5.0.1' -Architecture x64 -NoPath
223+
$env:DOTNET_ROOT = $dotnetInstallPath
225224

226-
& $dotnetInstallScript -InstallDir "${dotnetInstallPath}_x86" -Runtime 'dotnet' -Version '5.0.1' -Channel '5.0.1' -Architecture x86 -NoPath
227-
${env:DOTNET_ROOT(x86)} = "${dotnetInstallPath}_x86"
225+
& $dotnetInstallScript -InstallDir "${dotnetInstallPath}_x86" -Runtime 'dotnet' -Version '5.0.1' -Channel '5.0.1' -Architecture x86 -NoPath
226+
${env:DOTNET_ROOT(x86)} = "${dotnetInstallPath}_x86"
228227

229-
$env:DOTNET_MULTILEVEL_LOOKUP=0
228+
$env:DOTNET_MULTILEVEL_LOOKUP = 0
230229

231-
"---- dotnet environment variables"
232-
Get-ChildItem "Env:\dotnet_*"
230+
"---- dotnet environment variables"
231+
Get-ChildItem "Env:\dotnet_*"
233232

234-
"`n`n---- x64 dotnet"
235-
& "$env:DOTNET_ROOT\dotnet.exe" --info
236-
237-
"`n`n---- x86 dotnet"
238-
# avoid erroring out because we don't have the sdk for x86 that global.json requires
239-
try {
240-
& "${env:DOTNET_ROOT(x86)}\dotnet.exe" --info 2> $null
241-
} catch {}
242-
Write-Log "Install-DotNetCli: Complete."
233+
"`n`n---- x64 dotnet"
234+
& "$env:DOTNET_ROOT\dotnet.exe" --info
235+
236+
"`n`n---- x86 dotnet"
237+
# avoid erroring out because we don't have the sdk for x86 that global.json requires
238+
try {
239+
& "${env:DOTNET_ROOT(x86)}\dotnet.exe" --info 2> $null
240+
}
241+
catch {}
242+
Write-Log "Install-DotNetCli: Complete."
243243
}

src/Adapter/MSTest.CoreAdapter/Constants.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ internal static class Constants
2929
internal static readonly Uri ExecutorUri = new Uri(ExecutorUriString);
3030

3131
#region Test Property registration
32-
3332
internal static readonly TestProperty DescriptionProperty = TestProperty.Register("Description", DescriptionLabel, typeof(string), TestPropertyAttributes.Hidden, typeof(TestCase));
3433

3534
internal static readonly TestProperty WorkItemIdsProperty = TestProperty.Register("WorkItemIds", WorkItemIdsLabel, typeof(string[]), TestPropertyAttributes.Hidden, typeof(TestCase));

src/Adapter/MSTest.CoreAdapter/Discovery/AssemblyEnumerator.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ public override object InitializeLifetimeService()
5555
/// <summary>
5656
/// Enumerates through all types in the assembly in search of valid test methods.
5757
/// </summary>
58-
/// <param name="assemblyFileName"> The assembly file name. </param>
59-
/// <param name="warnings"> Contains warnings if any, that need to be passed back to the caller. </param>
60-
/// <returns> A collection of Test Elements. </returns>
61-
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Catching a generic exception since it is a requirement to not abort discovery in case of any errors.")]
58+
/// <param name="assemblyFileName">The assembly file name.</param>
59+
/// <param name="warnings">Contains warnings if any, that need to be passed back to the caller.</param>
60+
/// <returns>A collection of Test Elements.</returns>
6261
internal ICollection<UnitTestElement> EnumerateAssembly(string assemblyFileName, out ICollection<string> warnings)
6362
{
6463
Debug.Assert(!string.IsNullOrWhiteSpace(assemblyFileName), "Invalid assembly file name.");
@@ -73,9 +72,7 @@ internal ICollection<UnitTestElement> EnumerateAssembly(string assemblyFileName,
7372
// For normal test assemblies continue loading it in the default context since:
7473
// 1. There isn't much benefit in terms of Performance loading the assembly in a Reflection Only context during discovery.
7574
// 2. Loading it in Reflection only context entails a bunch of custom logic to identify custom attributes which is over-kill for normal desktop users.
76-
assembly = PlatformServiceProvider.Instance.FileOperations.LoadAssembly(
77-
assemblyFileName,
78-
isReflectionOnly: true);
75+
assembly = PlatformServiceProvider.Instance.FileOperations.LoadAssembly(assemblyFileName, isReflectionOnly: true);
7976
}
8077
else
8178
{

0 commit comments

Comments
 (0)