Skip to content

Commit

Permalink
Porting Fixes for 1.2.1 (#396)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mayankbansal018 authored Apr 3, 2018
1 parent 94997f1 commit 22db939
Show file tree
Hide file tree
Showing 21 changed files with 219 additions and 95 deletions.
1 change: 1 addition & 0 deletions Nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="vstest" value="https://dotnet.myget.org/F/vstest/api/v3/index.json" />
<add key="mstestv2" value="https://dotnet.myget.org/F/mstestv2/auth/1e768268-8c95-4e7e-9fd2-0eb1b1b69b18/api/v3/index.json" />
<add key="pdb2pdb.myget" value="https://dotnet.myget.org/F/symreader-converter/api/v3/index.json" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
Expand Down
11 changes: 9 additions & 2 deletions scripts/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ Param(
[Alias("vs")]
[System.String] $VersionSuffix = "dev",

[Parameter(Mandatory=$false)]
[System.String] $BuildVersionPrefix = "14.0",

[Parameter(Mandatory=$false)]
[System.String] $BuildVersionSuffix = "9999.99",

[Parameter(Mandatory=$false)]
[System.String] $Target = "Build",

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

Write-Log " Building $solution..."
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"
& $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
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"
& $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

if ($lastExitCode -ne 0) {
throw "Build failed with an exit code of '$lastExitCode'."
Expand Down
70 changes: 70 additions & 0 deletions scripts/PortableToFullPdb.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright (c) Microsoft. All rights reserved.
# Portable to Full PDB conversion script for Test Platform.

[CmdletBinding()]
Param(
[Parameter(Mandatory=$false)]
[ValidateSet("Debug", "Release")]
[System.String] $Configuration = "Release"
)

#
# Variables
#
Write-Verbose "Setup environment variables."
$TF_ROOT_DIR = (Get-Item (Split-Path $MyInvocation.MyCommand.Path)).Parent.FullName
$TF_PACKAGES_DIR = Join-Path $TF_ROOT_DIR "packages"
$TF_OUT_DIR = Join-Path $TF_ROOT_DIR "artifacts"
$TF_PortablePdbs =@("PlatformServices.NetCore\netstandard1.5\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.pdb")

$PdbConverterToolVersion = "1.1.0-beta1-62316-01"

function Locate-PdbConverterTool
{
$pdbConverter = Join-Path -path $TF_PACKAGES_DIR -ChildPath "Pdb2Pdb.$PdbConverterToolVersion\tools\Pdb2Pdb.exe"

if (!(Test-Path -path $pdbConverter))
{
throw "Unable to locate Pdb2Pdb converter exe in path '$pdbConverter'."
}

Write-Verbose "Pdb2Pdb converter path is : $pdbConverter"
return $pdbConverter

}

function ConvertPortablePdbToWindowsPdb
{
foreach($TF_PortablePdb in $TF_PortablePdbs)
{
$portablePdbs += Join-Path -path $TF_OUT_DIR\$Configuration -childPath $TF_PortablePdb
}

$pdbConverter = Locate-PdbConverterTool

foreach($portablePdb in $portablePdbs)
{
# First check if corresponding dll exists
$dllOrExePath = $portablePdb -replace ".pdb",".dll"

if(!(Test-Path -path $dllOrExePath))
{
# If no corresponding dll found, check if exe exists
$dllOrExePath = $portablePdb -replace ".pdb",".exe"

if(!(Test-Path -path $dllOrExePath))
{
throw "Unable to locate dll/exe corresponding to $portablePdb"
}
}

$fullpdb = $portablePdb -replace ".pdb",".pdbfull"

Write-Verbose "$pdbConverter $dll /pdb $portablePdb /out $fullpdb"
& $pdbConverter $dllOrExePath /pdb $portablePdb /out $fullpdb
}
}

Write-Verbose "Converting Portable pdbs to Windows(Full) Pdbs..."
ConvertPortablePdbToWindowsPdb

2 changes: 1 addition & 1 deletion scripts/SetBuildNumber.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function Set_BuildNumber()
Write-Verbose("Build number used: " + $buildNumber)

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

Set_BuildNumber
2 changes: 1 addition & 1 deletion scripts/build/TestFx.targets
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<TFBuildNumber Condition=" '$(TFBuildNumber)' == '' ">0.1</TFBuildNumber>
<MajorVersion>14.0</MajorVersion>
<AssemblyVersion>$(MajorVersion).0.0</AssemblyVersion>
<BuildVersion>$(MajorVersion).$(TFBuildNumber)</BuildVersion>
<BuildVersion Condition=" '$(BuildVersion)' == '' ">$(MajorVersion).$(TFBuildNumber)</BuildVersion>
</PropertyGroup>
<ItemGroup>
<AssemblyVersionAttribute Include="System.Reflection.AssemblyVersionAttribute">
Expand Down
1 change: 1 addition & 0 deletions scripts/toolset/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<package id="fmdev.xlftool" version="0.1.3" />
<package id="MSTest.Internal.TestFx.Localized.Documentation" version="1.0.0-build-20170420-1" />
<package id="vswhere" version="2.0.2" />
<package id="Pdb2Pdb" version="1.1.0-beta1-62316-01" />
</packages>
Original file line number Diff line number Diff line change
Expand Up @@ -76,41 +76,12 @@ internal ICollection<UnitTestElement> GetTests(
fullFilePath,
ex);

// Loading a WinPRT dll on the phone produces a
// FileNotFoundException. We check if we get FileNotFoundException
// in spite of the dll existing and try and load the dll from the full path in this case.
try
{
if (PlatformServiceProvider.Instance.FileOperations.DoesFileExist(assemblyFileName))
{
var assembly = Assembly.Load(new AssemblyName(assemblyFileName));
}
}
catch (Exception e)
{
warnings.Add(e.Message);
return null;
}

warnings.Add(ex.Message);
return null;
}
catch (ReflectionTypeLoadException ex)
{
warnings.Add(ex.Message);
PlatformServiceProvider.Instance.AdapterTraceLogger.LogWarning(
"MSPhoneTestDiscoverer.TryGetTests: Failed to discover tests from {0}. Reason:{1}",
assemblyFileName,
ex);
PlatformServiceProvider.Instance.AdapterTraceLogger.LogWarning("Exceptions thrown from the Loader :");

if (ex.LoaderExceptions != null)
{
foreach (var loaderEx in ex.LoaderExceptions)
{
PlatformServiceProvider.Instance.AdapterTraceLogger.LogWarning("{0}", loaderEx);
}
}
var message = string.Format(
CultureInfo.CurrentCulture,
"Failed to discover tests from assembly {0}. Reason:{1}",
fullFilePath,
ex.Message);
warnings.Add(message);

return null;
}
Expand Down
55 changes: 29 additions & 26 deletions src/Adapter/MSTest.CoreAdapter/Execution/TestClassInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ internal set
}

/// <summary>
/// Gets a value indicating whether is class initialize executed.
/// Gets a value indicating whether class initialize has executed.
/// </summary>
public bool IsClassInitializeExecuted { get; internal set; }

Expand Down Expand Up @@ -295,37 +295,40 @@ public string RunClassCleanup()
return null;
}

try
if (this.IsClassInitializeExecuted || this.ClassInitializeMethod == null)
{
this.ClassCleanupMethod.InvokeAsSynchronousTask(null);

return null;
}
catch (Exception exception)
{
var realException = exception.InnerException ?? exception;

string errorMessage;

// special case AssertFailedException to trim off part of the stack trace
if (realException is AssertFailedException ||
realException is AssertInconclusiveException)
try
{
errorMessage = realException.Message;
this.ClassCleanupMethod.InvokeAsSynchronousTask(null);
}
else
catch (Exception exception)
{
errorMessage = StackTraceHelper.GetExceptionMessage(realException);
var realException = exception.InnerException ?? exception;

string errorMessage;

// special case AssertFailedException to trim off part of the stack trace
if (realException is AssertFailedException ||
realException is AssertInconclusiveException)
{
errorMessage = realException.Message;
}
else
{
errorMessage = StackTraceHelper.GetExceptionMessage(realException);
}

return string.Format(
CultureInfo.CurrentCulture,
Resource.UTA_ClassCleanupMethodWasUnsuccesful,
this.ClassType.Name,
this.ClassCleanupMethod.Name,
errorMessage,
StackTraceHelper.GetStackTraceInformation(realException)?.ErrorStackTrace);
}

return string.Format(
CultureInfo.CurrentCulture,
Resource.UTA_ClassCleanupMethodWasUnsuccesful,
this.ClassType.Name,
this.ClassCleanupMethod.Name,
errorMessage,
StackTraceHelper.GetStackTraceInformation(realException)?.ErrorStackTrace);
}

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ private void CacheSessionParameters(IRunContext runContext, ITestExecutionRecord
var testRunParameters = RunSettingsUtilities.GetTestRunParameters(runContext.RunSettings.SettingsXml);
if (testRunParameters != null)
{
// Clear sessionParameters to prevent key collisions of test run parameters in case
// "Keep Test Execution Engine Alive" is selected in VS.
this.sessionParameters.Clear();
foreach (var kvp in testRunParameters)
{
this.sessionParameters.Add(kvp);
Expand Down
17 changes: 13 additions & 4 deletions src/Adapter/MSTest.CoreAdapter/TestMethodFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal ITestCaseFilterExpression GetFilterExpression(IDiscoveryContext context
{
try
{
filter = (context is IRunContext) ? this.GetTestCaseFilterFromRunContext(context as IRunContext) : this.GetTestCaseFilterFromDiscoveryContext(context);
filter = (context is IRunContext) ? this.GetTestCaseFilterFromRunContext(context as IRunContext) : this.GetTestCaseFilterFromDiscoveryContext(context, logger);
}
catch (TestPlatformFormatException ex)
{
Expand Down Expand Up @@ -111,18 +111,27 @@ private ITestCaseFilterExpression GetTestCaseFilterFromRunContext(IRunContext co
/// </summary>
/// <param name="context">Discovery context</param>
/// <returns>Filter expression.</returns>
private ITestCaseFilterExpression GetTestCaseFilterFromDiscoveryContext(IDiscoveryContext context)
private ITestCaseFilterExpression GetTestCaseFilterFromDiscoveryContext(IDiscoveryContext context, IMessageLogger logger)
{
try
{
// GetTestCaseFilter is present in DiscoveryContext but not in IDiscoveryContext interface.
MethodInfo methodGetTestCaseFilter = context.GetType().GetRuntimeMethod("GetTestCaseFilter", new[] { typeof(IEnumerable<string>), typeof(Func<string, TestProperty>) });
return (ITestCaseFilterExpression)methodGetTestCaseFilter?.Invoke(context, new object[] { this.supportedProperties.Keys, (Func<string, TestProperty>)this.PropertyProvider });
}
catch (TargetInvocationException ex)
catch (Exception ex)
{
throw ex.InnerException;
// In case of UWP .Net Native Tool Chain compilation. Invoking methods via Reflection doesn't work, hence discovery always fails.
// Hence throwing exception only if it is of type TargetInvocationException(i.e. Method got invoked but something went wrong in GetTestCaseFilter Method)
if (ex is TargetInvocationException)
{
throw ex.InnerException;
}

logger.SendMessage(TestMessageLevel.Warning, ex.Message);
}

return null;
}
}
}
2 changes: 1 addition & 1 deletion src/Package/MSTest.Internal.TestFx.Documentation.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<projectUrl>https://github.com/microsoft/testfx</projectUrl>
<licenseUrl>http://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm</licenseUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<copyright>Copyright © Microsoft Corporation</copyright>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<tags>MSTest TestFramework MSTestV2</tags>
</metadata>
<files>
Expand Down
2 changes: 1 addition & 1 deletion src/Package/MSTest.TestAdapter.Dotnet.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<projectUrl>https://github.com/microsoft/testfx</projectUrl>
<licenseUrl>http://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm</licenseUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<copyright>Copyright © Microsoft Corporation</copyright>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
</metadata>
<files>
<file src="MSTest.CoreAdapter\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll" target="lib\dotnet\" />
Expand Down
2 changes: 1 addition & 1 deletion src/Package/MSTest.TestAdapter.Enu.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<projectUrl>https://github.com/microsoft/testfx</projectUrl>
<licenseUrl>http://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm</licenseUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<copyright>Copyright © Microsoft Corporation</copyright>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<tags>MSTest TestFramework TestAdapter VisualStudio Unittest MSTestV2 Microsoft</tags>
<dependencies>
<group targetFramework="netcoreapp1.0">
Expand Down
2 changes: 1 addition & 1 deletion src/Package/MSTest.TestAdapter.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<projectUrl>https://github.com/microsoft/testfx</projectUrl>
<licenseUrl>http://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm</licenseUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<copyright>Copyright © Microsoft Corporation</copyright>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<tags>MSTest TestFramework TestAdapter VisualStudio Unittest MSTestV2 Microsoft</tags>
<dependencies>
<group targetFramework="netcoreapp1.0">
Expand Down
2 changes: 1 addition & 1 deletion src/Package/MSTest.TestAdapter.symbols.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<projectUrl>https://github.com/microsoft/testfx</projectUrl>
<licenseUrl>http://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm</licenseUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<copyright>Copyright © Microsoft Corporation</copyright>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<tags>MSTest TestFramework TestAdapter VisualStudio Unittest MSTestV2 Microsoft</tags>
<dependencies>
<group targetFramework="netcoreapp1.0">
Expand Down
2 changes: 1 addition & 1 deletion src/Package/MSTest.TestFramework.enu.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<projectUrl>https://github.com/microsoft/testfx</projectUrl>
<licenseUrl>http://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm</licenseUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<copyright>Copyright © Microsoft Corporation</copyright>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<tags>MSTest TestFramework Unittest MSTestV2 Microsoft Test Testing TDD Framework </tags>
</metadata>
<files>
Expand Down
2 changes: 1 addition & 1 deletion src/Package/MSTest.TestFramework.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<projectUrl>https://github.com/microsoft/testfx</projectUrl>
<licenseUrl>http://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm</licenseUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<copyright>Copyright © Microsoft Corporation</copyright>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<tags>MSTest TestFramework Unittest MSTestV2 Microsoft Test Testing TDD Framework </tags>
</metadata>
<files>
Expand Down
2 changes: 1 addition & 1 deletion src/Package/MSTest.TestFramework.symbols.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<projectUrl>https://github.com/microsoft/testfx</projectUrl>
<licenseUrl>http://www.microsoft.com/web/webpi/eula/net_library_eula_enu.htm</licenseUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288859</iconUrl>
<copyright>Copyright © Microsoft Corporation</copyright>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<tags>MSTest TestFramework Unittest MSTestV2 Microsoft Test Testing TDD Framework </tags>
</metadata>
<files>
Expand Down
Loading

0 comments on commit 22db939

Please sign in to comment.