Skip to content

Commit 781e94b

Browse files
committed
Merge branch 'microbuild_mtp' of https://github.com/aarnott/Library.Template into dev/andarno/libtemplateUpdate
2 parents 33adb64 + 07aab27 commit 781e94b

File tree

9 files changed

+82
-35
lines changed

9 files changed

+82
-35
lines changed

Directory.Packages.props

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<PropertyGroup>
55
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
66
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
7+
<MicrosoftTestingPlatformVersion>2.0.2</MicrosoftTestingPlatformVersion>
78

89
<MicroBuildVersion>2.0.208</MicroBuildVersion>
910
</PropertyGroup>
@@ -12,10 +13,12 @@
1213
<PackageVersion Include="Moq" Version="4.20.72" />
1314
</ItemGroup>
1415
<ItemGroup Label="Library.Template">
15-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
16+
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.1.0" />
17+
<PackageVersion Include="Microsoft.Testing.Extensions.CrashDump" Version="$(MicrosoftTestingPlatformVersion)" />
18+
<PackageVersion Include="Microsoft.Testing.Extensions.HangDump" Version="$(MicrosoftTestingPlatformVersion)" />
19+
<PackageVersion Include="Microsoft.Testing.Extensions.TrxReport" Version="$(MicrosoftTestingPlatformVersion)" />
1620
<PackageVersion Include="Microsoft.VisualStudio.Internal.MicroBuild.NonShipping" Version="$(MicroBuildVersion)" />
17-
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
18-
<PackageVersion Include="xunit.v3" Version="3.2.1" />
21+
<PackageVersion Include="xunit.v3.mtp-v2" Version="3.2.1" />
1922
</ItemGroup>
2023
<ItemGroup>
2124
<!-- Put repo-specific GlobalPackageReference items in this group. -->

azure-pipelines/Merge-CodeCoverage.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ try {
2828
if ($reports) {
2929
$reports |% { $_.FullName } |% {
3030
# In addition to replacing {reporoot}, we also normalize on one kind of slash so that the report aggregates data for a file whether data was collected on Windows or not.
31+
Write-Verbose "Processing $_"
3132
$xml = [xml](Get-Content -LiteralPath $_)
3233
$xml.coverage.packages.package.classes.class |? { $_.filename} |% {
3334
$_.filename = $_.filename.Replace('{reporoot}', $RepoRoot).Replace([IO.Path]::AltDirectorySeparatorChar, [IO.Path]::DirectorySeparatorChar)

global.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
22
"sdk": {
3-
"version": "10.0.100",
3+
"version": "10.0.101",
44
"rollForward": "patch",
55
"allowPrerelease": false
66
},
7+
"test": {
8+
"runner": "Microsoft.Testing.Platform"
9+
},
710
"msbuild-sdks": {
811
"Microsoft.Build.NoTargets": "3.7.134"
912
}

test/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<PropertyGroup>
66
<IsPackable>false</IsPackable>
77
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
8+
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
89
</PropertyGroup>
910

1011
<ItemGroup>

test/Directory.Build.targets

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project>
3+
<ItemGroup Condition="'$(IsTestProject)' == 'true'">
4+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" />
5+
<PackageReference Include="Microsoft.Testing.Extensions.CrashDump" />
6+
<PackageReference Include="Microsoft.Testing.Extensions.HangDump" />
7+
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" />
8+
</ItemGroup>
39
<ItemGroup>
410
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" Condition="Exists('xunit.runner.json')" />
511
</ItemGroup>

test/Microsoft.VisualStudio.Validation.Tests/Microsoft.VisualStudio.Validation.Tests.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
<OutputType>Exe</OutputType>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="Microsoft.NET.Test.Sdk" />
98
<PackageReference Include="Moq" />
10-
<PackageReference Include="xunit.runner.visualstudio" />
11-
<PackageReference Include="xunit.v3" />
9+
<PackageReference Include="xunit.v3.mtp-v2" />
1210
</ItemGroup>
1311

1412
<ItemGroup>
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
$RepoRoot = [System.IO.Path]::GetFullPath("$PSScriptRoot\..\..")
1+
$RepoRoot = Resolve-Path "$PSScriptRoot\..\.."
22

3-
$coverageFiles = @(Get-ChildItem "$RepoRoot/test/*.cobertura.xml" -Recurse | Where {$_.FullName -notlike "*/In/*" -and $_.FullName -notlike "*\In\*" })
3+
$coverageFilesUnderRoot = @(Get-ChildItem "$RepoRoot/*.cobertura.xml" -Recurse | Where-Object {$_.FullName -notlike "*/In/*" -and $_.FullName -notlike "*\In\*" })
4+
5+
# Under MTP, coverage files are written directly to the artifacts output directory,
6+
# so we need to look there too.
7+
$ArtifactStagingFolder = & "$PSScriptRoot/../Get-ArtifactsStagingDirectory.ps1"
8+
$directTestLogs = Join-Path $ArtifactStagingFolder test_logs
9+
$coverageFilesUnderArtifacts = if (Test-Path $directTestLogs) { @(Get-ChildItem "$directTestLogs/*.cobertura.xml" -Recurse) } else { @() }
410

511
# Prepare code coverage reports for merging on another machine
6-
$repoRoot = $env:SYSTEM_DEFAULTWORKINGDIRECTORY
7-
if (!$repoRoot) { $repoRoot = $env:GITHUB_WORKSPACE }
8-
if ($repoRoot) {
9-
Write-Host "Substituting $repoRoot with `"{reporoot}`""
10-
$coverageFiles |% {
11-
$content = Get-Content -LiteralPath $_ |% { $_ -Replace [regex]::Escape($repoRoot), "{reporoot}" }
12-
Set-Content -LiteralPath $_ -Value $content -Encoding UTF8
13-
}
14-
} else {
15-
Write-Warning "coverageResults: Cloud build not detected. Machine-neutral token replacement skipped."
12+
Write-Host "Substituting $repoRoot with `"{reporoot}`""
13+
@($coverageFilesUnderRoot + $coverageFilesUnderArtifacts) |? { $_ }|% {
14+
$content = Get-Content -LiteralPath $_ |% { $_ -Replace [regex]::Escape($repoRoot), "{reporoot}" }
15+
Set-Content -LiteralPath $_ -Value $content -Encoding UTF8
1616
}
1717

1818
if (!((Test-Path $RepoRoot\bin) -and (Test-Path $RepoRoot\obj))) { return }
1919

2020
@{
21+
$directTestLogs = $coverageFilesUnderArtifacts;
2122
$RepoRoot = (
22-
$coverageFiles +
23+
$coverageFilesUnderRoot +
2324
(Get-ChildItem "$RepoRoot\obj\*.cs" -Recurse)
2425
);
2526
}

tools/artifacts/testResults.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Param(
44

55
$result = @{}
66

7-
$testRoot = Resolve-Path "$PSScriptRoot\..\..\test"
7+
$RepoRoot = Resolve-Path "$PSScriptRoot\..\.."
8+
$testRoot = Join-Path $RepoRoot test
89
$result[$testRoot] = (Get-ChildItem "$testRoot\TestResults" -Recurse -Directory | Get-ChildItem -Recurse -File)
910

1011
$artifactStaging = & "$PSScriptRoot/../Get-ArtifactsStagingDirectory.ps1"

tools/dotnet-test-cloud.ps1

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Param(
2525

2626
$RepoRoot = (Resolve-Path "$PSScriptRoot/..").Path
2727
$ArtifactStagingFolder = & "$PSScriptRoot/Get-ArtifactsStagingDirectory.ps1"
28+
$OnCI = ($env:CI -or $env:TF_BUILD)
2829

2930
$dotnet = 'dotnet'
3031
if ($x86) {
@@ -45,23 +46,55 @@ if ($x86) {
4546
}
4647

4748
$testBinLog = Join-Path $ArtifactStagingFolder (Join-Path build_logs test.binlog)
48-
$testDiagLog = Join-Path $ArtifactStagingFolder (Join-Path test_logs diag.log)
49+
$testLogs = Join-Path $ArtifactStagingFolder test_logs
4950

50-
& $dotnet test $RepoRoot `
51-
--no-build `
52-
-c $Configuration `
53-
--filter "TestCategory!=FailsInCloudTest" `
54-
--collect "Code Coverage;Format=cobertura" `
55-
--settings "$PSScriptRoot/test.runsettings" `
56-
--blame-hang-timeout 60s `
57-
--blame-crash `
58-
-bl:"$testBinLog" `
59-
--diag "$testDiagLog;TraceLevel=info" `
60-
--logger trx `
51+
$globalJson = Get-Content $PSScriptRoot/../global.json | ConvertFrom-Json
52+
$isMTP = $globalJson.test.runner -eq 'Microsoft.Testing.Platform'
53+
if ($isMTP) {
54+
$extraArgs = @()
55+
if ($OnCI) { $extraArgs += '--no-progress' }
56+
& $dotnet test --solution $RepoRoot `
57+
--no-build `
58+
-c $Configuration `
59+
-bl:"$testBinLog" `
60+
--filter-not-trait 'TestCategory=FailsInCloudTest' `
61+
--coverage `
62+
--coverage-output-format cobertura `
63+
--coverage-settings "$PSScriptRoot/test.runsettings" `
64+
--hangdump `
65+
--hangdump-timeout 60s `
66+
--crashdump `
67+
--diagnostic `
68+
--diagnostic-output-directory $testLogs `
69+
--diagnostic-verbosity Information `
70+
--results-directory $testLogs `
71+
--report-trx `
72+
@extraArgs
73+
74+
$trxFiles = Get-ChildItem -Recurse -Path $testLogs\*.trx
75+
} else {
76+
$testDiagLog = Join-Path $ArtifactStagingFolder (Join-Path test_logs diag.log)
77+
& $dotnet test $RepoRoot `
78+
--no-build `
79+
-c $Configuration `
80+
--filter "TestCategory!=FailsInCloudTest" `
81+
--collect "Code Coverage;Format=cobertura" `
82+
--settings "$PSScriptRoot/test.runsettings" `
83+
--blame-hang-timeout 60s `
84+
--blame-crash `
85+
-bl:"$testBinLog" `
86+
--diag "$testDiagLog;TraceLevel=info" `
87+
--logger trx
88+
89+
$trxFiles = Get-ChildItem -Recurse -Path $RepoRoot\test\*.trx
90+
}
6191

6292
$unknownCounter = 0
63-
Get-ChildItem -Recurse -Path $RepoRoot\test\*.trx |% {
64-
Copy-Item $_ -Destination $ArtifactStagingFolder/test_logs/
93+
$trxFiles |% {
94+
New-Item $testLogs -ItemType Directory -Force | Out-Null
95+
if (!($_.FullName.StartsWith($testLogs))) {
96+
Copy-Item $_ -Destination $testLogs
97+
}
6598

6699
if ($PublishResults) {
67100
$x = [xml](Get-Content -LiteralPath $_)

0 commit comments

Comments
 (0)