Skip to content

Commit 22db939

Browse files
Porting Fixes for 1.2.1 (#396)
* Fixing Key collision for test run parameters (#328) * Base commit * Adding Unit Test * PR comments * Adding logs for diagnostics * Ignoring Test Temporarily * Removing ignore # Conflicts: # test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs * Fixing the copyright in the nuspec files. (#350) * Today even if classInit wasnt called we used to call class cleanup. f… (#372) * Today even if classInit wasnt called we used to call class cleanup. fixing that and adding a test to cover the scenario # Conflicts: # src/Adapter/MSTest.CoreAdapter/Execution/TestClassInfo.cs * [Symbol archiving]Converting Portable pdb to full (#375) * COnverting portable pdbs to full for Symbol archiving * Fixing nuget package path * Test fix * Indent fix * Update Fileversion for adapter and framework dlls (#337) * File version update * Moving to 15.6 * PR comments * More PR comments * Throwing exception only if it is of type TestPlatformFormatException (#332) * Throwing exception only if it is of type TestPlatformFormatException * test * Fail discovery if any exception thrown in IDiscoveryContext.GetTestCaseFilter * Fix masking assembly load faolure error message (#382) # Conflicts: # src/Adapter/MSTest.CoreAdapter/Discovery/AssemblyEnumeratorWrapper.cs
1 parent 94997f1 commit 22db939

21 files changed

Lines changed: 219 additions & 95 deletions

Nuget.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
88
<add key="vstest" value="https://dotnet.myget.org/F/vstest/api/v3/index.json" />
99
<add key="mstestv2" value="https://dotnet.myget.org/F/mstestv2/auth/1e768268-8c95-4e7e-9fd2-0eb1b1b69b18/api/v3/index.json" />
10+
<add key="pdb2pdb.myget" value="https://dotnet.myget.org/F/symreader-converter/api/v3/index.json" />
1011
</packageSources>
1112
<activePackageSource>
1213
<add key="All" value="(Aggregate source)" />

scripts/Build.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Param(
2222
[Alias("vs")]
2323
[System.String] $VersionSuffix = "dev",
2424

25+
[Parameter(Mandatory=$false)]
26+
[System.String] $BuildVersionPrefix = "14.0",
27+
28+
[Parameter(Mandatory=$false)]
29+
[System.String] $BuildVersionSuffix = "9999.99",
30+
2531
[Parameter(Mandatory=$false)]
2632
[System.String] $Target = "Build",
2733

@@ -74,6 +80,7 @@ $TFB_Configuration = $Configuration
7480
$TFB_FrameworkVersion = $FrameworkVersion
7581
$TFB_AdapterVersion = $AdapterVersion
7682
$TFB_VersionSuffix = $VersionSuffix
83+
$TFB_BuildVersion = $BuildVersionPrefix + "." + $BuildVersionSuffix
7784
$TFB_SkipRestore = $SkipRestore
7885
$TFB_Clean = $Clean
7986
$TFB_ClearPackageCache = $ClearPackageCache
@@ -249,8 +256,8 @@ function Invoke-Build([string] $solution, $hasVsixExtension = "false")
249256
$solutionFailureLog = Join-Path -path $solutionDir -childPath "msbuild.err"
250257

251258
Write-Log " Building $solution..."
252-
Write-Verbose "$msbuild /t:$Target /p:Configuration=$configuration /tv:$msbuildVersion /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf $solutionPath"
253-
& $msbuild /t:$Target /p:Configuration=$configuration /tv:$msbuildVersion /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf $solutionPath
259+
Write-Verbose "$msbuild /t:$Target /p:Configuration=$configuration /tv:$msbuildVersion /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf /p:BuildVersion=$TFB_BuildVersion $solutionPath"
260+
& $msbuild /t:$Target /p:Configuration=$configuration /tv:$msbuildVersion /v:m /flp1:Summary`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionSummaryLog /flp2:WarningsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionWarningLog /flp3:ErrorsOnly`;Verbosity=diagnostic`;Encoding=UTF-8`;LogFile=$solutionFailureLog /p:IsLocalizedBuild=$TFB_IsLocalizedBuild /p:UpdateXlf=$TFB_UpdateXlf /p:BuildVersion=$TFB_BuildVersion $solutionPath
254261

255262
if ($lastExitCode -ne 0) {
256263
throw "Build failed with an exit code of '$lastExitCode'."

scripts/PortableToFullPdb.ps1

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright (c) Microsoft. All rights reserved.
2+
# Portable to Full PDB conversion script for Test Platform.
3+
4+
[CmdletBinding()]
5+
Param(
6+
[Parameter(Mandatory=$false)]
7+
[ValidateSet("Debug", "Release")]
8+
[System.String] $Configuration = "Release"
9+
)
10+
11+
#
12+
# Variables
13+
#
14+
Write-Verbose "Setup environment variables."
15+
$TF_ROOT_DIR = (Get-Item (Split-Path $MyInvocation.MyCommand.Path)).Parent.FullName
16+
$TF_PACKAGES_DIR = Join-Path $TF_ROOT_DIR "packages"
17+
$TF_OUT_DIR = Join-Path $TF_ROOT_DIR "artifacts"
18+
$TF_PortablePdbs =@("PlatformServices.NetCore\netstandard1.5\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.pdb")
19+
20+
$PdbConverterToolVersion = "1.1.0-beta1-62316-01"
21+
22+
function Locate-PdbConverterTool
23+
{
24+
$pdbConverter = Join-Path -path $TF_PACKAGES_DIR -ChildPath "Pdb2Pdb.$PdbConverterToolVersion\tools\Pdb2Pdb.exe"
25+
26+
if (!(Test-Path -path $pdbConverter))
27+
{
28+
throw "Unable to locate Pdb2Pdb converter exe in path '$pdbConverter'."
29+
}
30+
31+
Write-Verbose "Pdb2Pdb converter path is : $pdbConverter"
32+
return $pdbConverter
33+
34+
}
35+
36+
function ConvertPortablePdbToWindowsPdb
37+
{
38+
foreach($TF_PortablePdb in $TF_PortablePdbs)
39+
{
40+
$portablePdbs += Join-Path -path $TF_OUT_DIR\$Configuration -childPath $TF_PortablePdb
41+
}
42+
43+
$pdbConverter = Locate-PdbConverterTool
44+
45+
foreach($portablePdb in $portablePdbs)
46+
{
47+
# First check if corresponding dll exists
48+
$dllOrExePath = $portablePdb -replace ".pdb",".dll"
49+
50+
if(!(Test-Path -path $dllOrExePath))
51+
{
52+
# If no corresponding dll found, check if exe exists
53+
$dllOrExePath = $portablePdb -replace ".pdb",".exe"
54+
55+
if(!(Test-Path -path $dllOrExePath))
56+
{
57+
throw "Unable to locate dll/exe corresponding to $portablePdb"
58+
}
59+
}
60+
61+
$fullpdb = $portablePdb -replace ".pdb",".pdbfull"
62+
63+
Write-Verbose "$pdbConverter $dll /pdb $portablePdb /out $fullpdb"
64+
& $pdbConverter $dllOrExePath /pdb $portablePdb /out $fullpdb
65+
}
66+
}
67+
68+
Write-Verbose "Converting Portable pdbs to Windows(Full) Pdbs..."
69+
ConvertPortablePdbToWindowsPdb
70+

scripts/SetBuildNumber.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function Set_BuildNumber()
3030
Write-Verbose("Build number used: " + $buildNumber)
3131

3232
# This sets the build number.
33-
Write-Host("##vso[build.updatebuildnumber]$buildNumber")
33+
Write-Host("##vso[task.setvariable variable=BuildVersionSuffix]$buildNumber")
3434
}
3535

3636
Set_BuildNumber

scripts/build/TestFx.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
<TFBuildNumber Condition=" '$(TFBuildNumber)' == '' ">0.1</TFBuildNumber>
8787
<MajorVersion>14.0</MajorVersion>
8888
<AssemblyVersion>$(MajorVersion).0.0</AssemblyVersion>
89-
<BuildVersion>$(MajorVersion).$(TFBuildNumber)</BuildVersion>
89+
<BuildVersion Condition=" '$(BuildVersion)' == '' ">$(MajorVersion).$(TFBuildNumber)</BuildVersion>
9090
</PropertyGroup>
9191
<ItemGroup>
9292
<AssemblyVersionAttribute Include="System.Reflection.AssemblyVersionAttribute">

scripts/toolset/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
<package id="fmdev.xlftool" version="0.1.3" />
66
<package id="MSTest.Internal.TestFx.Localized.Documentation" version="1.0.0-build-20170420-1" />
77
<package id="vswhere" version="2.0.2" />
8+
<package id="Pdb2Pdb" version="1.1.0-beta1-62316-01" />
89
</packages>

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

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -76,41 +76,12 @@ internal ICollection<UnitTestElement> GetTests(
7676
fullFilePath,
7777
ex);
7878

79-
// Loading a WinPRT dll on the phone produces a
80-
// FileNotFoundException. We check if we get FileNotFoundException
81-
// in spite of the dll existing and try and load the dll from the full path in this case.
82-
try
83-
{
84-
if (PlatformServiceProvider.Instance.FileOperations.DoesFileExist(assemblyFileName))
85-
{
86-
var assembly = Assembly.Load(new AssemblyName(assemblyFileName));
87-
}
88-
}
89-
catch (Exception e)
90-
{
91-
warnings.Add(e.Message);
92-
return null;
93-
}
94-
95-
warnings.Add(ex.Message);
96-
return null;
97-
}
98-
catch (ReflectionTypeLoadException ex)
99-
{
100-
warnings.Add(ex.Message);
101-
PlatformServiceProvider.Instance.AdapterTraceLogger.LogWarning(
102-
"MSPhoneTestDiscoverer.TryGetTests: Failed to discover tests from {0}. Reason:{1}",
103-
assemblyFileName,
104-
ex);
105-
PlatformServiceProvider.Instance.AdapterTraceLogger.LogWarning("Exceptions thrown from the Loader :");
106-
107-
if (ex.LoaderExceptions != null)
108-
{
109-
foreach (var loaderEx in ex.LoaderExceptions)
110-
{
111-
PlatformServiceProvider.Instance.AdapterTraceLogger.LogWarning("{0}", loaderEx);
112-
}
113-
}
79+
var message = string.Format(
80+
CultureInfo.CurrentCulture,
81+
"Failed to discover tests from assembly {0}. Reason:{1}",
82+
fullFilePath,
83+
ex.Message);
84+
warnings.Add(message);
11485

11586
return null;
11687
}

src/Adapter/MSTest.CoreAdapter/Execution/TestClassInfo.cs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ internal set
101101
}
102102

103103
/// <summary>
104-
/// Gets a value indicating whether is class initialize executed.
104+
/// Gets a value indicating whether class initialize has executed.
105105
/// </summary>
106106
public bool IsClassInitializeExecuted { get; internal set; }
107107

@@ -295,37 +295,40 @@ public string RunClassCleanup()
295295
return null;
296296
}
297297

298-
try
298+
if (this.IsClassInitializeExecuted || this.ClassInitializeMethod == null)
299299
{
300-
this.ClassCleanupMethod.InvokeAsSynchronousTask(null);
301-
302-
return null;
303-
}
304-
catch (Exception exception)
305-
{
306-
var realException = exception.InnerException ?? exception;
307-
308-
string errorMessage;
309-
310-
// special case AssertFailedException to trim off part of the stack trace
311-
if (realException is AssertFailedException ||
312-
realException is AssertInconclusiveException)
300+
try
313301
{
314-
errorMessage = realException.Message;
302+
this.ClassCleanupMethod.InvokeAsSynchronousTask(null);
315303
}
316-
else
304+
catch (Exception exception)
317305
{
318-
errorMessage = StackTraceHelper.GetExceptionMessage(realException);
306+
var realException = exception.InnerException ?? exception;
307+
308+
string errorMessage;
309+
310+
// special case AssertFailedException to trim off part of the stack trace
311+
if (realException is AssertFailedException ||
312+
realException is AssertInconclusiveException)
313+
{
314+
errorMessage = realException.Message;
315+
}
316+
else
317+
{
318+
errorMessage = StackTraceHelper.GetExceptionMessage(realException);
319+
}
320+
321+
return string.Format(
322+
CultureInfo.CurrentCulture,
323+
Resource.UTA_ClassCleanupMethodWasUnsuccesful,
324+
this.ClassType.Name,
325+
this.ClassCleanupMethod.Name,
326+
errorMessage,
327+
StackTraceHelper.GetStackTraceInformation(realException)?.ErrorStackTrace);
319328
}
320-
321-
return string.Format(
322-
CultureInfo.CurrentCulture,
323-
Resource.UTA_ClassCleanupMethodWasUnsuccesful,
324-
this.ClassType.Name,
325-
this.ClassCleanupMethod.Name,
326-
errorMessage,
327-
StackTraceHelper.GetStackTraceInformation(realException)?.ErrorStackTrace);
328329
}
330+
331+
return null;
329332
}
330333
}
331334
}

src/Adapter/MSTest.CoreAdapter/Execution/TestExecutionManager.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,9 @@ private void CacheSessionParameters(IRunContext runContext, ITestExecutionRecord
322322
var testRunParameters = RunSettingsUtilities.GetTestRunParameters(runContext.RunSettings.SettingsXml);
323323
if (testRunParameters != null)
324324
{
325+
// Clear sessionParameters to prevent key collisions of test run parameters in case
326+
// "Keep Test Execution Engine Alive" is selected in VS.
327+
this.sessionParameters.Clear();
325328
foreach (var kvp in testRunParameters)
326329
{
327330
this.sessionParameters.Add(kvp);

src/Adapter/MSTest.CoreAdapter/TestMethodFilter.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ internal ITestCaseFilterExpression GetFilterExpression(IDiscoveryContext context
4646
{
4747
try
4848
{
49-
filter = (context is IRunContext) ? this.GetTestCaseFilterFromRunContext(context as IRunContext) : this.GetTestCaseFilterFromDiscoveryContext(context);
49+
filter = (context is IRunContext) ? this.GetTestCaseFilterFromRunContext(context as IRunContext) : this.GetTestCaseFilterFromDiscoveryContext(context, logger);
5050
}
5151
catch (TestPlatformFormatException ex)
5252
{
@@ -111,18 +111,27 @@ private ITestCaseFilterExpression GetTestCaseFilterFromRunContext(IRunContext co
111111
/// </summary>
112112
/// <param name="context">Discovery context</param>
113113
/// <returns>Filter expression.</returns>
114-
private ITestCaseFilterExpression GetTestCaseFilterFromDiscoveryContext(IDiscoveryContext context)
114+
private ITestCaseFilterExpression GetTestCaseFilterFromDiscoveryContext(IDiscoveryContext context, IMessageLogger logger)
115115
{
116116
try
117117
{
118118
// GetTestCaseFilter is present in DiscoveryContext but not in IDiscoveryContext interface.
119119
MethodInfo methodGetTestCaseFilter = context.GetType().GetRuntimeMethod("GetTestCaseFilter", new[] { typeof(IEnumerable<string>), typeof(Func<string, TestProperty>) });
120120
return (ITestCaseFilterExpression)methodGetTestCaseFilter?.Invoke(context, new object[] { this.supportedProperties.Keys, (Func<string, TestProperty>)this.PropertyProvider });
121121
}
122-
catch (TargetInvocationException ex)
122+
catch (Exception ex)
123123
{
124-
throw ex.InnerException;
124+
// In case of UWP .Net Native Tool Chain compilation. Invoking methods via Reflection doesn't work, hence discovery always fails.
125+
// Hence throwing exception only if it is of type TargetInvocationException(i.e. Method got invoked but something went wrong in GetTestCaseFilter Method)
126+
if (ex is TargetInvocationException)
127+
{
128+
throw ex.InnerException;
129+
}
130+
131+
logger.SendMessage(TestMessageLevel.Warning, ex.Message);
125132
}
133+
134+
return null;
126135
}
127136
}
128137
}

0 commit comments

Comments
 (0)