Skip to content

Commit

Permalink
Improve terminal logger (#4877)
Browse files Browse the repository at this point in the history
* Fix terminal logger encoding

* Update src/Microsoft.TestPlatform.Build/Tasks/VSTestTask2.cs

Co-authored-by: Amaury Levé <amaury.leve@gmail.com>

* Fix error output

* Fix typo

* Revert playground

* Suppress new logger via environment variable

* Test suppression

* Fix tests and source build

* happy?

* happy?

* huh

* Fix tests

* Build .NET on Playground build

* work

* Use extended messages

* Rename messages

* Fix names

* downgrade messages to low prio

* Polish logger

* Fix build upgrade

* Source build fix

* Rename to Escape

* ref only

* Update src/vstest.console/Internal/MSBuildLogger.cs

---------

Co-authored-by: Amaury Levé <amaury.leve@gmail.com>
  • Loading branch information
nohwnd and Evangelink authored Feb 13, 2024
1 parent 845df98 commit 8013ffe
Show file tree
Hide file tree
Showing 8 changed files with 531 additions and 159 deletions.
13 changes: 11 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@
</PropertyGroup>
<PropertyGroup Label="VSTest dependencies">
<CoverletCoverageVersion>1.2.0</CoverletCoverageVersion>
<MicrosoftBuildFrameworkPackageVersion>16.0.461</MicrosoftBuildFrameworkPackageVersion>
<!--
When updating the version of Microsoft.Build.Utilities.Core, go check on nuget.org which TFMs it targets.
Because you will need to update Microsoft.TestPlatform.Build.UnitTests to build using that concrete .NET TFM, e.g. net8.0 for 17.8.3.
Otherwise it will restore the netstandard2.0 *reference* library into test project bin, and the test project will fail
with File not found error.
-->
<MicrosoftBuildFrameworkPackageVersion>17.8.3</MicrosoftBuildFrameworkPackageVersion>
<MicrosoftBuildPackageVersion>$(MicrosoftBuildFrameworkPackageVersion)</MicrosoftBuildPackageVersion>
<MicrosoftBuildUtilitiesCorePackageVersion>$(MicrosoftBuildPackageVersion)</MicrosoftBuildUtilitiesCorePackageVersion>
<MicrosoftBuildUtilitiesCorePackageVersion>$(MicrosoftBuildFrameworkPackageVersion)</MicrosoftBuildUtilitiesCorePackageVersion>
<MicrosoftBuildFrameworkReferenceOnly>$(MicrosoftBuildFrameworkPackageVersion)</MicrosoftBuildFrameworkReferenceOnly>
<MicrosoftBuildReferenceOnly>$(MicrosoftBuildFrameworkPackageVersion)</MicrosoftBuildReferenceOnly>
<MicrosoftBuildUtilitiesCoreReferenceOnly>$(MicrosoftBuildFrameworkPackageVersion)</MicrosoftBuildUtilitiesCoreReferenceOnly>
<MicrosoftCodeAnalysisVersion>3.11.0</MicrosoftCodeAnalysisVersion>
<MicrosoftCodeAnalysisBannedApiAnalyzersVersion>3.11.0-beta1.23525.2</MicrosoftCodeAnalysisBannedApiAnalyzersVersion>
<MicrosoftCodeAnalysisPublicApiAnalyzersVersion>3.11.0-beta1.23525.2</MicrosoftCodeAnalysisPublicApiAnalyzersVersion>
Expand Down
4 changes: 2 additions & 2 deletions playground/TestPlatform.Playground/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void Main()
{
// This project references TranslationLayer, vstest.console, TestHostProvider, testhost and MSTest1 projects, to make sure
// we build all the dependencies of that are used to run tests via VSTestConsoleWrapper. It then copies the components from
// their original build locations, to $(TargetDir)\vstest.console directory, and its subfolders to create an executable
// their original build locations, to $(TargetDir)\netfx\vstest.console directory, and its subfolders to create an executable
// copy of TestPlatform that is similar to what we ship.
//
// The copying might trigger only on re-build, if you see outdated dependencies, Rebuild this project instead of just Build.
Expand All @@ -37,7 +37,7 @@ static void Main()
var here = Path.GetDirectoryName(thisAssemblyPath)!;
var playground = Path.GetFullPath(Path.Combine(here, "..", "..", "..", ".."));

var console = Path.Combine(here, "vstest.console", "vstest.console.exe");
var console = Path.Combine(here, "vstest.console", "netfx", "vstest.console.exe");

var sourceSettings = $$$"""
<RunSettings>
Expand Down
63 changes: 43 additions & 20 deletions playground/TestPlatform.Playground/TestPlatform.Playground.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
<ProjectReference Include="$(RepoRoot)src\vstest.console\vstest.console.csproj" />
<ProjectReference Include="$(RepoRoot)playground\MSTest1\MSTest1.csproj" />
<ProjectReference Include="$(RepoRoot)src\AttachVS\AttachVS.csproj" />
<ProjectReference Include="..\..\src\Microsoft.TestPlatform.Extensions.HtmlLogger\Microsoft.TestPlatform.Extensions.HtmlLogger.csproj" />
<ProjectReference Include="$(RepoRoot)src\Microsoft.TestPlatform.Build\Microsoft.TestPlatform.Build.csproj" />
<ProjectReference Include="$(RepoRoot)src\Microsoft.TestPlatform.Extensions.HtmlLogger\Microsoft.TestPlatform.Extensions.HtmlLogger.csproj" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) AND '$(OS)' != 'Windows_NT' ">
<Reference Include="System" />
Expand All @@ -47,31 +48,53 @@
</PropertyGroup>

<ItemGroup>
<FileToCopy Include="$(SourcePath)bin\vstest.console\$(Configuration)\$(NetFrameworkMinimum)\win7-x64\**\*.*" SubFolder="" />
<FileToCopy Include="$(SourcePath)bin\Microsoft.TestPlatform.TestHostProvider\$(Configuration)\$(NetFrameworkMinimum)\**\*.*" SubFolder="Extensions\" />
<!-- .NET Framework console -->
<FileToCopy Include="$(SourcePath)bin\vstest.console\$(Configuration)\$(NetFrameworkMinimum)\win7-x64\**\*.*" SubFolder="netfx" />
<FileToCopy Include="$(SourcePath)bin\Microsoft.TestPlatform.TestHostProvider\$(Configuration)\$(NetFrameworkMinimum)\**\*.*" SubFolder="netfx\Extensions\" />

<!-- copy net462, net47, net471, net472 and net48 testhosts -->
<FileToCopy Include="$(SourcePath)bin\testhost.x86\$(Configuration)\$(NetFrameworkMinimum)\win7-x86\**\*.*" SubFolder="TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost\$(Configuration)\$(NetFrameworkMinimum)\win7-x64\**\*.*" SubFolder="TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost.x86\$(Configuration)\net47\win7-x86\**\*.*" SubFolder="TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost\$(Configuration)\net47\win7-x64\**\*.*" SubFolder="TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost.x86\$(Configuration)\net471\win7-x86\**\*.*" SubFolder="TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost\$(Configuration)\net471\win7-x64\**\*.*" SubFolder="TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost.x86\$(Configuration)\net472\win7-x86\**\*.*" SubFolder="TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost\$(Configuration)\net472\win7-x64\**\*.*" SubFolder="TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost.x86\$(Configuration)\net48\win7-x86\**\*.*" SubFolder="TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost\$(Configuration)\net48\win7-x64\**\*.*" SubFolder="TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost.x86\$(Configuration)\$(NetFrameworkMinimum)\win7-x86\**\*.*" SubFolder="netfx\TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost\$(Configuration)\$(NetFrameworkMinimum)\win7-x64\**\*.*" SubFolder="netfx\TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost.x86\$(Configuration)\net47\win7-x86\**\*.*" SubFolder="netfx\TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost\$(Configuration)\net47\win7-x64\**\*.*" SubFolder="netfx\TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost.x86\$(Configuration)\net471\win7-x86\**\*.*" SubFolder="netfx\TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost\$(Configuration)\net471\win7-x64\**\*.*" SubFolder="netfx\TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost.x86\$(Configuration)\net472\win7-x86\**\*.*" SubFolder="netfx\TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost\$(Configuration)\net472\win7-x64\**\*.*" SubFolder="netfx\TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost.x86\$(Configuration)\net48\win7-x86\**\*.*" SubFolder="netfx\TestHostNetFramework\" />
<FileToCopy Include="$(SourcePath)bin\testhost\$(Configuration)\net48\win7-x64\**\*.*" SubFolder="netfx\TestHostNetFramework\" />

<!-- copy datacollectors -->
<FileToCopy Include="$(SourcePath)bin\datacollector\$(Configuration)\net472\win7-x64\**\*.*" SubFolder="" />
<FileToCopy Include="$(SourcePath)bin\Microsoft.TestPlatform.Extensions.BlameDataCollector\$(Configuration)\net472\**\*.*" SubFolder="Extensions\" />
<FileToCopy Include="$(SourcePath)bin\DataCollectors\Microsoft.TestPlatform.Extensions.EventLogCollector\$(Configuration)\$(NetFrameworkMinimum)\**\*.*" SubFolder="Extensions\" />
<FileToCopy Include="$(SourcePath)bin\DataCollectors\DumpMinitool\$(Configuration)\$(NetFrameworkMinimum)\win7-x64\**\*.*" SubFolder="Extensions\blame\" />
<FileToCopy Include="$(SourcePath)bin\DataCollectors\DumpMinitool.x86\$(Configuration)\$(NetFrameworkMinimum)\win7-x86\**\*.*" SubFolder="Extensions\blame\" />
<FileToCopy Include="$(SourcePath)bin\DataCollectors\DumpMinitool.arm64\$(Configuration)\$(NetFrameworkMinimum)\win10-arm64\**\*.*" SubFolder="Extensions\blame\" />
<FileToCopy Include="$(SourcePath)bin\datacollector\$(Configuration)\net472\win7-x64\**\*.*" SubFolder="netfx\" />
<FileToCopy Include="$(SourcePath)bin\Microsoft.TestPlatform.Extensions.BlameDataCollector\$(Configuration)\net472\**\*.*" SubFolder="netfx\Extensions\" />
<FileToCopy Include="$(SourcePath)bin\DataCollectors\Microsoft.TestPlatform.Extensions.EventLogCollector\$(Configuration)\$(NetFrameworkMinimum)\**\*.*" SubFolder="netfx\Extensions\" />
<FileToCopy Include="$(SourcePath)bin\DataCollectors\DumpMinitool\$(Configuration)\$(NetFrameworkMinimum)\win7-x64\**\*.*" SubFolder="netfx\Extensions\blame\" />
<FileToCopy Include="$(SourcePath)bin\DataCollectors\DumpMinitool.x86\$(Configuration)\$(NetFrameworkMinimum)\win7-x86\**\*.*" SubFolder="netfx\Extensions\blame\" />
<FileToCopy Include="$(SourcePath)bin\DataCollectors\DumpMinitool.arm64\$(Configuration)\$(NetFrameworkMinimum)\win10-arm64\**\*.*" SubFolder="netfx\Extensions\blame\" />

<!-- copy loggers -->
<FileToCopy Include="$(SourcePath)bin\Microsoft.TestPlatform.Extensions.HtmlLogger\$(Configuration)\$(NetFrameworkMinimum)\Microsoft.VisualStudio.TestPlatform.Extensions.Html.TestLogger*" SubFolder="Extensions\" />
<FileToCopy Include="$(SourcePath)bin\Microsoft.TestPlatform.Extensions.HtmlLogger\$(Configuration)\$(NetFrameworkMinimum)\Microsoft.VisualStudio.TestPlatform.Extensions.Html.TestLogger*" SubFolder="netfx\Extensions\" />

<!-- .NET console -->
<FileToCopy Include="$(SourcePath)bin\vstest.console\$(Configuration)\$(NetCoreAppMinimum)\**\*.*" SubFolder="net" />
<FileToCopy Include="$(SourcePath)bin\Microsoft.TestPlatform.TestHostProvider\$(Configuration)\netstandard2.0\**\*.*" SubFolder="net\Extensions\" />

<!-- copy testhost -->
<FileToCopy Include="$(SourcePath)bin\testhost\$(Configuration)\$(NetCoreAppMinimum)\**\*.*" SubFolder="net" />

<!-- copy datacollectors --><!--
<FileToCopy Include="$(SourcePath)bin\datacollector\$(Configuration)\net472\**\*.*" SubFolder="net\" />
<FileToCopy Include="$(SourcePath)bin\Microsoft.TestPlatform.Extensions.BlameDataCollector\$(Configuration)\net472\**\*.*" SubFolder="net\Extensions\" />
<FileToCopy Include="$(SourcePath)bin\DataCollectors\Microsoft.TestPlatform.Extensions.EventLogCollector\$(Configuration)\$(NetCoreAppMinimum)\**\*.*" SubFolder="net\Extensions\" />
<FileToCopy Include="$(SourcePath)bin\DataCollectors\DumpMinitool\$(Configuration)\$(NetCoreAppMinimum)\**\*.*" SubFolder="net\Extensions\blame\" />
<FileToCopy Include="$(SourcePath)bin\DataCollectors\DumpMinitool.x86\$(Configuration)\$(NetCoreAppMinimum)\win7-x86\**\*.*" SubFolder="net\Extensions\blame\" />
<FileToCopy Include="$(SourcePath)bin\DataCollectors\DumpMinitool.arm64\$(Configuration)\$(NetCoreAppMinimum)\win10-arm64\**\*.*" SubFolder="net\Extensions\blame\" />-->

<!-- copy loggers --><!--
<FileToCopy Include="$(SourcePath)bin\Microsoft.TestPlatform.Extensions.HtmlLogger\$(Configuration)\$(NetCoreAppMinimum)\Microsoft.VisualStudio.TestPlatform.Extensions.Html.TestLogger*" SubFolder="net\Extensions\" />-->

<!-- copy test target -->
<FileToCopy Include="$(SourcePath)bin\Microsoft.TestPlatform.Build\$(Configuration)\netstandard2.0\*" SubFolder="net\" />
</ItemGroup>

<Copy SourceFiles="@(FileToCopy)" DestinationFiles="@(FileToCopy -> '$(DestinationPath)\%(SubFolder)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="True" OverwriteReadOnlyFiles="True" Retries="3" RetryDelayMilliseconds="500" UseHardlinksIfPossible="False" UseSymboliclinksIfPossible="False" ErrorIfLinkFails="False" Condition="@(FileToCopy-&gt;Count()) &gt; 0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildFrameworkPackageVersion)" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildUtilitiesCorePackageVersion)" />
<PackageReference Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildFrameworkPackageVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildUtilitiesCorePackageVersion)" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Label="NuGet">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ Copyright (c) .NET Foundation. All rights reserved.
<CallTarget Targets="_VSTestMSBuild" Condition="$(VsTestUseMSBuildOutput)" />
</Target>

<!-- Used when called from dotnet msbuild command line: uses MSBuild logs but does not allow for console colorization -->
<!--
Used when called from dotnet msbuild command line: uses MSBuild logs but does not allow for console colorization.
We call to empty target _TestRunStart to mark start of the actual test running, in case we need to do build before
the test running. This is used in MSBuild Terminal Logger to detect that the current project will run some tests.
-->
<Target Name="_VSTestMSBuild" Condition="'$(IsTestProject)' == 'true'">
<CallTarget Condition="!$(VSTestNoBuild)" Targets="BuildProject" />
<CallTarget Targets="_TestRunStart" />

<VSTestTask2
TestFileFullPath="$(TargetPath)"
Expand Down Expand Up @@ -67,6 +72,8 @@ Copyright (c) .NET Foundation. All rights reserved.
/>
</Target>

<Target Name="_TestRunStart" />

<!-- Used when called from dotnet test command line: does not use MSBuild logs to allow for console colorization -->
<Target Name="_VSTestConsole">
<CallTarget Condition="'$(VSTestNoBuild)' != 'true' AND '$(IsTestProject)' == 'true'" Targets="BuildProject" />
Expand Down
Loading

0 comments on commit 8013ffe

Please sign in to comment.