Skip to content

Commit

Permalink
Create a proper MSBuild ToolTask based VSTestTask (#2702)
Browse files Browse the repository at this point in the history
* Rename VSTestTask to VSTestForwardingTask (#680)

VSTestForwardingTask redirects the console output instead of using MSBuild logs. Renaming it will allow to create a new VSTestTask that uses the MSBuild log infrastructure.

* Refactor the VSTestForwardingTask to use the MSBuild infrastructure (#680)

* Create a ToolTask based VSTestTask that integrates nicely in the MSBuild infrastructure (#680)

This new task will be used by default during the build. If the $(VSTestUseConsole) property is set to True, the old console forwarding VSTestForwardTask will be used instead.

* Initialize the VsTestUseConsole property during acceptance tests

The `$(VSTestUseConsole)` should be set to `True` when running the `dotnet test` command to keep the legacy behavior. Adding it during the tests for now: it should be set in the command itself eventually.

* Fix various issues raised by the latest review

* Simplify the handling of null values

* Log messages to MSBuild instead of to the console

* Integrate changes from the latest code review

* Patch dotnet with newest build task

* wip

* rnm

* revert tests

* tests

* Try adding msbuild specialized logger to output errors on tests

* Use simpler logger

* wip

* fix no-source

* fix no-source

* add message for full error

* Revert playground

* Revert console logger

* Revert integration tests

* Revert change in integration tests

* Fix test

* Revert test unignore

---------

Co-authored-by: Jakub Jareš <me@jakubjares.com>
  • Loading branch information
mcartoixa and nohwnd committed Nov 16, 2023
1 parent a561f75 commit b99e5fa
Show file tree
Hide file tree
Showing 31 changed files with 1,794 additions and 1,355 deletions.
100 changes: 0 additions & 100 deletions src/Microsoft.TestPlatform.Build/ArgumentEscaper.cs

This file was deleted.

102 changes: 73 additions & 29 deletions src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.targets
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ Copyright (c) .NET Foundation. All rights reserved.
<PropertyGroup>
<VSTestTaskAssemblyFile Condition="$(VSTestTaskAssemblyFile) == ''">Microsoft.TestPlatform.Build.dll</VSTestTaskAssemblyFile>
<VSTestConsolePath Condition="$(VSTestConsolePath) == ''">$([System.IO.Path]::Combine($(MSBuildThisFileDirectory),"vstest.console.dll"))</VSTestConsolePath>
<VSTestNoBuild Condition="'$(VSTestNoBuild)' == ''">False</VSTestNoBuild>
<VsTestUseMSBuildOutput Condition="'$(VsTestUseMSBuildOutput)' == ''">False</VsTestUseMSBuildOutput>
</PropertyGroup>
<UsingTask TaskName="Microsoft.TestPlatform.Build.Tasks.VSTestTask" AssemblyFile="$(VSTestTaskAssemblyFile)" />
<UsingTask TaskName="Microsoft.TestPlatform.Build.Tasks.VSTestLogsTask" AssemblyFile="$(VSTestTaskAssemblyFile)" />
<UsingTask TaskName="Microsoft.TestPlatform.Build.Tasks.VSTestTask2" AssemblyFile="$(VSTestTaskAssemblyFile)" />

<!--
============================================================
Expand All @@ -25,11 +28,52 @@ Copyright (c) .NET Foundation. All rights reserved.
============================================================
-->
<Target Name="VSTest" DependsOnTargets="ShowInfoMessageIfProjectHasNoIsTestProjectProperty">
<!-- Unloggable colorized output (cf. https://github.com/microsoft/vstest/issues/680) -->
<CallTarget Targets="_VSTestConsole" Condition="!$(VsTestUseMSBuildOutput)" />
<!-- Proper MSBuild integration, but no custom colorization -->
<CallTarget Targets="_VSTestMSBuild" Condition="$(VsTestUseMSBuildOutput)" />
</Target>

<!-- Used when called from dotnet msbuild command line: uses MSBuild logs but does not allow for console colorization -->
<Target Name="_VSTestMSBuild" Condition="'$(IsTestProject)' == 'true'">
<CallTarget Condition="!$(VSTestNoBuild)" Targets="BuildProject" />

<VSTestTask2
TestFileFullPath="$(TargetPath)"
VSTestSetting="$([MSBuild]::ValueOrDefault($(VSTestSetting), '$(RunSettingsFilePath)'))"
VSTestTestAdapterPath="$(VSTestTestAdapterPath)"
VSTestFramework="$(TargetFrameworkMoniker)"
VSTestPlatform="$(PlatformTarget)"
VSTestTestCaseFilter="$(VSTestTestCaseFilter)"
VSTestLogger="$(VSTestLogger)"
VSTestListTests="$(VSTestListTests)"
VSTestDiag="$(VSTestDiag)"
VSTestCLIRunSettings="$(VSTestCLIRunSettings)"
VSTestConsolePath="$(VSTestConsolePath)"
VSTestResultsDirectory="$(VSTestResultsDirectory)"
VSTestVerbosity="$(VSTestVerbosity)"
VSTestCollect="$(VSTestCollect)"
VSTestBlame="$(VSTestBlame)"
VSTestBlameCrash="$(VSTestBlameCrash)"
VSTestBlameCrashDumpType="$(VSTestBlameCrashDumpType)"
VSTestBlameCrashCollectAlways="$(VSTestBlameCrashCollectAlways)"
VSTestBlameHang="$(VSTestBlameHang)"
VSTestBlameHangDumpType="$(VSTestBlameHangDumpType)"
VSTestBlameHangTimeout="$(VSTestBlameHangTimeout)"
VSTestTraceDataCollectorDirectoryPath="$(TraceDataCollectorDirectoryPath)"
VSTestArtifactsProcessingMode="$(VSTestArtifactsProcessingMode)"
VSTestSessionCorrelationId="$(VSTestSessionCorrelationId)"
VSTestNoLogo="$(VSTestNoLogo)"
/>
</Target>

<!-- 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" />

<CallTarget Targets="ShowCallOfVSTestTaskWithParameter" />

<Microsoft.TestPlatform.Build.Tasks.VSTestTask
<VSTestTask
TestFileFullPath="$(TargetPath)"
VSTestSetting="$([MSBuild]::ValueOrDefault($(VSTestSetting), '$(RunSettingsFilePath)'))"
VSTestTestAdapterPath="$(VSTestTestAdapterPath)"
Expand Down Expand Up @@ -60,47 +104,47 @@ Copyright (c) .NET Foundation. All rights reserved.
</Target>

<Target Name="ShowInfoMessageIfProjectHasNoIsTestProjectProperty" Condition="'$(IsTestProject)' == ''">
<Microsoft.TestPlatform.Build.Tasks.VSTestLogsTask LogType="NoIsTestProjectProperty" ProjectFilePath="$(MSBuildProjectFullPath)" />
<VSTestLogsTask LogType="NoIsTestProjectProperty" ProjectFilePath="$(MSBuildProjectFullPath)" />
</Target>

<Target Name="BuildProject">
<CallTarget Targets="ShowMsbuildWithParameter" />

<Microsoft.TestPlatform.Build.Tasks.VSTestLogsTask LogType="BuildStarted" />
<VSTestLogsTask LogType="BuildStarted" />
<MSBuild Projects ="$(MSBuildProjectFullPath)" />
<Microsoft.TestPlatform.Build.Tasks.VSTestLogsTask LogType="BuildCompleted" />
<VSTestLogsTask LogType="BuildCompleted" />

<Message Text="Done Building project $(MSBuildProjectFullPath) for TargetFramework=$(TargetFramework)" Importance="low" />
<Message Importance="Low" Text="Done Building project $(MSBuildProjectFullPath) for TargetFramework=$(TargetFramework)" />
</Target>

<Target Name="ShowMsbuildWithParameter">
<Message Text="Building project $(MSBuildProjectFullPath) for TargetFramework=$(TargetFramework)" Importance="low"/>
<Message Text="Value passed to msbuild are..." Importance="low" />
<Message Text="Configuration = $(Configuration)" Importance="low" />
<Message Text="TargetFramework = $(TargetFramework)" Importance="low" />
<Message Text="Platform = $(PlatformTarget)" Importance="low" />
<Message Text="OutputPath = $(OutputPath)" Importance="low" />
<Message Importance="Low" Text="Building project $(MSBuildProjectFullPath) for TargetFramework=$(TargetFramework)" />
<Message Importance="Low" Text="Value passed to msbuild are..." />
<Message Importance="Low" Text="Configuration = $(Configuration)" />
<Message Importance="Low" Text="TargetFramework = $(TargetFramework)" />
<Message Importance="Low" Text="Platform = $(PlatformTarget)" />
<Message Importance="Low" Text="OutputPath = $(OutputPath)" />
</Target>

<Target Name="ShowCallOfVSTestTaskWithParameter">
<Message Text="Calling task Microsoft.TestPlatform.Build.Tasks.VSTestTask with following parameter..." Importance="low" />
<Message Text="TestFileFullPath = $(TargetPath)" Importance="low" />
<Message Text="VSTestSetting = $(VSTestSetting)" Importance="low" />
<Message Text="VSTestTestAdapterPath = $(VSTestTestAdapterPath)" Importance="low" />
<Message Text="VSTestFramework = $(TargetFrameworkMoniker)" Importance="low" />
<Message Text="VSTestPlatform = $(PlatformTarget)" Importance="low" />
<Message Text="VSTestTestCaseFilter = $(VSTestTestCaseFilter)" Importance="low" />
<Message Text="VSTestLogger = $(VSTestLogger)" Importance="low" />
<Message Text="VSTestListTests = $(VSTestListTests)" Importance="low" />
<Message Text="VSTestDiag = $(VSTestDiag)" Importance="low" />
<Message Text="VSTestCLIRunSettings = $(VSTestCLIRunSettings)" Importance="low" />
<Message Text="VSTestResultsDirectory = $(VSTestResultsDirectory)" Importance="low" />
<Message Text="VSTestConsolePath = $(VSTestConsolePath)" Importance="low" />
<Message Text="VSTestVerbosity = $(VSTestVerbosity)" Importance="low" />
<Message Text="VSTestCollect = $(VSTestCollect)" Importance="low" />
<Message Text="VSTestBlame = $(VSTestBlame)" Importance="low" />
<Message Text="VSTestTraceDataCollectorDirectoryPath = $(TraceDataCollectorDirectoryPath)" Importance="low" />
<Message Text="VSTestNoLogo = $(VSTestNoLogo)" Importance="low" />
<Message Importance="Low" Text="Calling task Microsoft.TestPlatform.Build.Tasks.VSTestTask with following parameter..." />
<Message Importance="Low" Text="TestFileFullPath = $(TargetPath)" />
<Message Importance="Low" Text="VSTestSetting = $(VSTestSetting)" />
<Message Importance="Low" Text="VSTestTestAdapterPath = $(VSTestTestAdapterPath)" />
<Message Importance="Low" Text="VSTestFramework = $(TargetFrameworkMoniker)" />
<Message Importance="Low" Text="VSTestPlatform = $(PlatformTarget)" />
<Message Importance="Low" Text="VSTestTestCaseFilter = $(VSTestTestCaseFilter)" />
<Message Importance="Low" Text="VSTestLogger = $(VSTestLogger)" />
<Message Importance="Low" Text="VSTestListTests = $(VSTestListTests)" />
<Message Importance="Low" Text="VSTestDiag = $(VSTestDiag)" />
<Message Importance="Low" Text="VSTestCLIRunSettings = $(VSTestCLIRunSettings)" />
<Message Importance="Low" Text="VSTestResultsDirectory = $(VSTestResultsDirectory)" />
<Message Importance="Low" Text="VSTestConsolePath = $(VSTestConsolePath)" />
<Message Importance="Low" Text="VSTestVerbosity = $(VSTestVerbosity)" />
<Message Importance="Low" Text="VSTestCollect = $(VSTestCollect)" />
<Message Importance="Low" Text="VSTestBlame = $(VSTestBlame)" />
<Message Importance="Low" Text="VSTestTraceDataCollectorDirectoryPath = $(TraceDataCollectorDirectoryPath)" />
<Message Importance="Low" Text="VSTestNoLogo = $(VSTestNoLogo)" />
</Target>

</Project>

0 comments on commit b99e5fa

Please sign in to comment.