Skip to content

Commit

Permalink
FQN work (#737)
Browse files Browse the repository at this point in the history
* Added support for `ManagedType` and `ManagedMethod`.

Added support for `ManagedType` and `ManagedMethod` into various classes. Also centralized TestPlarform version and done some refactoring.
  • Loading branch information
Haplois authored Nov 24, 2020
1 parent e9bc669 commit 76f0f89
Show file tree
Hide file tree
Showing 89 changed files with 777 additions and 308 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*.sln.metaproj
*.sln.metaproj.tmp
.vs/
.vscode/
*.cache

# Build results
Expand All @@ -29,6 +30,7 @@ msbuild*.err
build*.log
build*.wrn
build*.err
*.binlog

# MSTest test Results
[Tt]est[Rr]esult*/
Expand Down
11 changes: 8 additions & 3 deletions Nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
<add key="dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />

<add key="test-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/test-tools/nuget/v3/index.json" />
<add key="vstest.myget" value="https://dotnet.myget.org/F/vstest/api/v3/index.json" />
<add key="mstest.myget" value="https://dotnet.myget.org/F/mstestv2/api/v3/index.json" />


<add key="test-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/test-tools/nuget/v3/index.json" />
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />


<add key="pdb2pdb.myget" value="https://dotnet.myget.org/F/symreader-converter/api/v3/index.json" />

<add key="vsunittesting.myget" value="https://dotnet.myget.org/F/vsunittesting/api/v3/index.json" />
<add key="dotnet3.1" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1/nuget/v3/index.json" />
<add key="dotnet3.1-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet3.1-transport/nuget/v3/index.json" />
<add key="dotnet5" value="https://dnceng.pkgs.visualstudio.com/public/_packaging/dotnet5/nuget/v3/index.json" />
Expand All @@ -25,5 +27,8 @@
<!-- This path is relative as a workaround to https://github.com/NuGet/Home/issues/2831 -->
<!-- <add key="globalPackagesFolder" value="packages" /> -->
<add key="repositoryPath" value="packages" />

<!-- This is a workaround for Azure Artifacts, see: https://github.com/dotnet/arcade/issues/4190, https://github.com/dotnet/core-eng/issues/9681 -->
<add key='maxHttpRequestsPerSource' value='2' />
</config>
</configuration>
1 change: 1 addition & 0 deletions TestFx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "targets", "targets", "{F60B
ProjectSection(SolutionItems) = preProject
scripts\build\TestFx.Loc.targets = scripts\build\TestFx.Loc.targets
scripts\build\TestFx.Settings.targets = scripts\build\TestFx.Settings.targets
scripts\build\TestFx.Versions.targets = scripts\build\TestFx.Versions.targets
scripts\build\TestFx.targets = scripts\build\TestFx.targets
EndProjectSection
EndProject
Expand Down
88 changes: 53 additions & 35 deletions scripts/Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,49 @@

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

[Parameter(Mandatory=$false)]
[Alias("fv")]
[System.String] $FrameworkVersion = "99.99.99",
[string] $FrameworkVersion = "99.99.99",

[Parameter(Mandatory=$false)]
[Alias("av")]
[System.String] $AdapterVersion = "99.99.99",
[string] $AdapterVersion = "99.99.99",

[Parameter(Mandatory=$false)]
[Alias("vs")]
[System.String] $VersionSuffix = "dev",
[string] $VersionSuffix = "dev",

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

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

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

[Parameter(Mandatory=$false)]
[Alias("h")]
[Switch] $Help = $false,
[Switch] $Help,

[Parameter(Mandatory=$false)]
[Alias("cl")]
[Switch] $Clean = $false,
[Switch] $Clean,

[Parameter(Mandatory=$false)]
[Alias("sr")]
[Switch] $SkipRestore = $false,
[Switch] $SkipRestore,

[Parameter(Mandatory=$false)]
[Alias("cache")]
[Switch] $ClearPackageCache = $false,
[Switch] $ClearPackageCache,

[Parameter(Mandatory=$false)]
[Switch] $Official = $false,
[Switch] $Official,

[Parameter(Mandatory=$false)]
[Switch] $Full = $false,
[Switch] $Full,

[Parameter(Mandatory=$false)]
[Alias("uxlf")]
[Switch] $UpdateXlf = $false,
[Switch] $UpdateXlf,

[Parameter(Mandatory=$false)]
[Alias("loc")]
[Switch] $IsLocalizedBuild = $false
[Switch] $IsLocalizedBuild,

[Alias("tpv")]
[string] $TestPlatformVersion = $null
)

. $PSScriptRoot\common.lib.ps1
Expand Down Expand Up @@ -188,10 +176,10 @@ function Perform-Restore {
Write-Verbose "Starting restore for NetCore Projects"
foreach($project in $TFB_NetCoreProjects)
{
$projectPath = Locate-Item -relativePath $project
$projectPath = Locate-Item -relativePath $project

Write-Verbose "$msbuild /t:restore -verbosity:minimal $projectPath"
& $msbuild /t:restore -verbosity:minimal $projectPath
Write-Verbose "$msbuild /t:restore -verbosity:minimal $projectPath /m"
& $msbuild /t:restore -verbosity:minimal $projectPath /m
}

if ($lastExitCode -ne 0) {
Expand Down Expand Up @@ -240,8 +228,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 /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 /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
Write-Verbose "$msbuild /t:$Target /p:Configuration=$configuration /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 /bl /m"
& $msbuild /t:$Target /p:Configuration=$configuration /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 /bl /m

if ($lastExitCode -ne 0) {
throw "Build failed with an exit code of '$lastExitCode'."
Expand Down Expand Up @@ -307,7 +295,37 @@ function Create-NugetPackages
Write-Log "Create-NugetPackages: Complete. {$(Get-ElapsedTime($timer))}"
}

function Replace-InFile($File, $RegEx, $ReplaceWith) {
$content = Get-Content -Raw -Encoding utf8 $File
$newContent = ($content -replace $RegEx,$ReplaceWith)
if(-not $content.Equals($newContent)) {
Write-Log "Updating TestPlatform version in $File"
$newContent | Set-Content -Encoding utf8 $File -NoNewline
}
}

function Sync-PackageVersions {
$versionsFile = "$PSScriptRoot\build\TestFx.Versions.targets"

$versionsRegex = '(?mi)<(TestPlatformVersion.*?)>(.*?)<\/TestPlatformVersion>'
$packageRegex = '(?mi)<package id="Microsoft\.TestPlatform([0-9a-z.]+)?" version="([0-9a-z.-]*)"'
$sourceRegex = '(?mi)(.+[a-z =]+\@\")Microsoft\.TestPlatform\.([0-9.-a-z]+)\";'

if ([String]::IsNullOrWhiteSpace($TestPlatformVersion)) {
$TestPlatformVersion = (([XML](Get-Content $versionsFile)).Project.PropertyGroup.TestPlatformVersion).InnerText
} else {
Replace-InFile -File $versionsFile -RegEx $versionsRegex -ReplaceWith "<`$1>$TestPlatformVersion</TestPlatformVersion>"
}

(Get-ChildItem "$PSScriptRoot\..\src\*packages.config","$PSScriptRoot\..\test\*packages.config" -Recurse) | ForEach-Object {
Replace-InFile -File $_ -RegEx $packageRegex -ReplaceWith ('<package id="Microsoft.TestPlatform$1" version="{0}"' -f $TestPlatformVersion)
}

Replace-InFile -File "$PSScriptRoot\..\test\E2ETests\Automation.CLI\CLITestBase.cs" -RegEx $sourceRegex -ReplaceWith ('$1Microsoft.TestPlatform.{0}";' -f $TestPlatformVersion)
}

Print-Help
Sync-PackageVersions
Perform-Restore
Perform-Build
Create-NugetPackages
2 changes: 1 addition & 1 deletion scripts/build/TestFx.Settings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props') and $(FrameworkIdentifier) != 'NetCore'" />
<!-- Import props/targets with $(RepoRoot) since msbuild takes the relative path based on settings.targets and not with respect to the project. -->
<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')" />
<Import Project="TestFx.Versions.targets" />

<PropertyGroup>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<DefaultLanguage>en-US</DefaultLanguage>
Expand Down
7 changes: 7 additions & 0 deletions scripts/build/TestFx.Versions.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TestPlatformVersion Condition=" '$(TestPlatformVersion)' == '' ">16.9.0-preview-20201123-04</TestPlatformVersion>
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
</PropertyGroup>
</Project>
58 changes: 24 additions & 34 deletions scripts/common.lib.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,66 +122,56 @@ function Locate-VsWhere {
return $vswhere
}

function Locate-VsInstallPath($hasVsixExtension ="false"){
function Locate-VsInstallPath($hasVsixExtension = "false") {
$vswhere = Locate-VsWhere
$requiredPackageIds = @()

$requiredPackageIds += "Microsoft.Component.MSBuild"
$requiredPackageIds += "Microsoft.Net.Component.4.6.TargetingPack"
$requiredPackageIds += "Microsoft.Net.Component.4.5.2.TargetingPack"
$requiredPackageIds += "Microsoft.VisualStudio.Windows.Build"

if($hasVsixExtension -eq 'true')
{
if ($hasVsixExtension -eq 'true') {
$requiredPackageIds += "Microsoft.VisualStudio.Component.VSSDK"
}

Write-Verbose "$vswhere -latest -products * -requires $requiredPackageIds -property installationPath"
try
{
if ($Official)
{
$vsInstallPath = & $vswhere -latest -products * -requires $requiredPackageIds -property installationPath
}
else
{
# Allow using pre release versions of VS for dev builds
$vsInstallPath = & $vswhere -latest -prerelease -products * -requires $requiredPackageIds -property installationPath
}
try {
if ($Official) {
$vsInstallPath = & $vswhere -latest -products * -requires $requiredPackageIds -property installationPath
}
else {
# Allow using pre release versions of VS for dev builds
$vsInstallPath = & $vswhere -latest -prerelease -products * -requires $requiredPackageIds -property installationPath
}
}
catch [System.Management.Automation.MethodInvocationException]
{
catch [System.Management.Automation.MethodInvocationException] {
Write-Error "Failed to find VS installation with requirements : $requiredPackageIds."
}

Write-Verbose "VSInstallPath is : $vsInstallPath"
return Resolve-Path -path $vsInstallPath
}


function Locate-Item([string] $relativePath) {
$rootPath = $env:TF_ROOT_DIR
$itemPath = Join-Path -path $rootPath -childPath $relativePath
return Resolve-Path -path $itemPath
}

function Start-Timer
{
return [System.Diagnostics.Stopwatch]::StartNew()
function Start-Timer {
return [System.Diagnostics.Stopwatch]::StartNew()
}

function Get-ElapsedTime([System.Diagnostics.Stopwatch] $timer)
{
$timer.Stop()
return $timer.Elapsed
function Get-ElapsedTime([System.Diagnostics.Stopwatch] $timer) {
$timer.Stop()
return $timer.Elapsed
}

function Write-Log ([string] $message, $messageColor = "Green")
{
$currentColor = $Host.UI.RawUI.ForegroundColor
$Host.UI.RawUI.ForegroundColor = $messageColor
if ($message)
{
Write-Output "... $message"
}
$Host.UI.RawUI.ForegroundColor = $currentColor
function Write-Log ([string] $message, $messageColor = "Green") {
$currentColor = $Host.UI.RawUI.ForegroundColor
$Host.UI.RawUI.ForegroundColor = $messageColor
if ($message) {
Write-Output "... $message"
}
$Host.UI.RawUI.ForegroundColor = $currentColor
}
35 changes: 17 additions & 18 deletions scripts/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ $TFT_Configuration = $Configuration
$TFT_Pattern = $Pattern
$TFT_Parallel = $Parallel
$TFT_All = $All
$TestFramework = ".NETCoreApp,Version=v1.0"
$VSTestConsoleRelativePath = "Microsoft.TestPlatform.15.0.1\tools\net46\vstest.console.exe"
$TestFramework = ".NETCoreApp,Version=v2.1"

#
# Prints help text for the switches this script supports.
Expand Down Expand Up @@ -148,28 +147,28 @@ function Run-Test([string[]] $testContainers, [string[]] $netCoreTestContainers)
$additionalArguments += "/parallel"
}

if($testContainers.Count -gt 0)
{
if(!(Test-Path $vstestPath))
{
Write-Error "Unable to find vstest.console.exe at $vstestPath. Test aborted."
}
if($testContainers.Count -gt 0)
{
if(!(Test-Path $vstestPath))
{
Write-Error "Unable to find vstest.console.exe at $vstestPath. Test aborted."
}

Write-Verbose "$vstestPath $testContainers $additionalArguments /logger:trx"
& $vstestPath $testContainers $additionalArguments /logger:trx

if ($lastExitCode -ne 0)
{
throw "Tests failed."
}
}
Write-Verbose "$vstestPath $testContainers $additionalArguments /logger:trx"
& $vstestPath $testContainers $additionalArguments /logger:trx

if ($lastExitCode -ne 0)
{
throw "Tests failed."
}
}

if($netCoreTestContainers.Count -gt 0)
{
Try
{
Write-Verbose "dotnet vstest $netCoreTestContainers /framework:$TestFramework $additionalArguments /logger:trx"
& dotnet vstest $netCoreTestContainers /framework:$TestFramework $additionalArguments /logger:trx
Write-Verbose "dotnet test $netCoreTestContainers /framework:$TestFramework $additionalArguments /logger:trx"
& dotnet test $netCoreTestContainers /framework:$TestFramework $additionalArguments /logger:trx
}

Catch [System.Management.Automation.CommandNotFoundException]
Expand Down
2 changes: 1 addition & 1 deletion scripts/toolset/packages.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MicroBuild.Core" version="0.2.0" />
<package id="Microsoft.Internal.Dia.Interop" version="14.0.1" />
<package id="Microsoft.Internal.Dia.Interop" version="14.0.0" />
<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" />
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/MSTest.CoreAdapter/Discovery/TypeEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal UnitTestElement GetTestFromMethod(MethodInfo method, bool isDeclaredInT
// This allows void returning async test method to be valid test method. Though they will be executed similar to non-async test method.
var isAsync = ReflectHelper.MatchReturnType(method, typeof(Task));

var testMethod = new TestMethod(method.Name, this.type.FullName, this.assemblyName, isAsync);
var testMethod = new TestMethod(method, method.Name, this.type.FullName, this.assemblyName, isAsync);

if (!method.DeclaringType.FullName.Equals(this.type.FullName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ private void Dispose(bool disposing)
{
try
{
this.traceListenerManager.Remove(this.traceListener);
if (this.traceListener != null)
{
this.traceListenerManager.Remove(this.traceListener);
}

// Restore the previous LogMessageListener's TraceListener (if there was one)
if (this.previousRedirector != null && this.previousRedirector.traceListener != null)
Expand Down
Loading

0 comments on commit 76f0f89

Please sign in to comment.