Skip to content

Commit

Permalink
Create a ToolTask based VSTestTask that integrates nicely in the MSBu…
Browse files Browse the repository at this point in the history
…ild infrastructure (microsoft#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.
  • Loading branch information
mcartoixa committed Aug 1, 2022
1 parent 648f1f5 commit f182de1
Show file tree
Hide file tree
Showing 8 changed files with 542 additions and 262 deletions.
43 changes: 43 additions & 0 deletions src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.targets
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ Copyright (c) .NET Foundation. All rights reserved.
<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>
<VSTestUseConsole Condition="'$(VSTestUseConsole)' == ''">False</VSTestUseConsole>
</PropertyGroup>
<UsingTask TaskName="Microsoft.TestPlatform.Build.Tasks.VSTestForwardingTask" AssemblyFile="$(VSTestTaskAssemblyFile)" />
<UsingTask TaskName="Microsoft.TestPlatform.Build.Tasks.VSTestLogsTask" AssemblyFile="$(VSTestTaskAssemblyFile)" />
<UsingTask TaskName="Microsoft.TestPlatform.Build.Tasks.VSTestTask" AssemblyFile="$(VSTestTaskAssemblyFile)" />

<!--
============================================================
Expand All @@ -26,6 +28,47 @@ 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="$(VSTestUseConsole)" />
<!-- Proper MSBuild integration, but no custom colorization -->
<CallTarget Targets="_VSTestMSBuild" Condition="!$(VSTestUseConsole)" />
</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" />

<VSTestTask
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" />
Expand Down
55 changes: 55 additions & 0 deletions src/Microsoft.TestPlatform.Build/PublicAPI/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,63 @@ Microsoft.TestPlatform.Build.Tasks.VSTestForwardingTask.VSTestTraceDataCollector
Microsoft.TestPlatform.Build.Tasks.VSTestForwardingTask.VSTestTraceDataCollectorDirectoryPath.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestForwardingTask.VSTestVerbosity.get -> string?
Microsoft.TestPlatform.Build.Tasks.VSTestForwardingTask.VSTestVerbosity.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask
Microsoft.TestPlatform.Build.Tasks.VSTestTask.TestFileFullPath.get -> Microsoft.Build.Framework.ITaskItem?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.TestFileFullPath.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlame.get -> bool
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlame.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlameCrash.get -> bool
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlameCrash.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlameCrashCollectAlways.get -> bool
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlameCrashCollectAlways.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlameCrashDumpType.get -> string?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlameCrashDumpType.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlameHang.get -> bool
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlameHang.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlameHangDumpType.get -> string?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlameHangDumpType.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlameHangTimeout.get -> string?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestBlameHangTimeout.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestCLIRunSettings.get -> string![]?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestCLIRunSettings.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestCollect.get -> string![]?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestCollect.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestConsolePath.get -> Microsoft.Build.Framework.ITaskItem?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestConsolePath.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestDiag.get -> string?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestDiag.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestFramework.get -> string?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestFramework.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestListTests.get -> bool
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestListTests.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestLogger.get -> string![]?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestLogger.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestNoLogo.get -> bool
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestNoLogo.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestArtifactsProcessingMode.get -> string?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestArtifactsProcessingMode.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestSessionCorrelationId.get -> string?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestSessionCorrelationId.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestPlatform.get -> string?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestPlatform.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestResultsDirectory.get -> Microsoft.Build.Framework.ITaskItem?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestResultsDirectory.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestSetting.get -> string?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestSetting.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestTask() -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestTestAdapterPath.get -> Microsoft.Build.Framework.ITaskItem![]?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestTestAdapterPath.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestTestCaseFilter.get -> string?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestTestCaseFilter.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestTraceDataCollectorDirectoryPath.get -> Microsoft.Build.Framework.ITaskItem?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestTraceDataCollectorDirectoryPath.set -> void
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestVerbosity.get -> string?
Microsoft.TestPlatform.Build.Tasks.VSTestTask.VSTestVerbosity.set -> void
Microsoft.TestPlatform.Build.Trace.Tracing
override Microsoft.TestPlatform.Build.Tasks.VSTestLogsTask.Execute() -> bool
override Microsoft.TestPlatform.Build.Tasks.VSTestForwardingTask.Execute() -> bool
override Microsoft.TestPlatform.Build.Tasks.VSTestTask.GenerateCommandLineCommands() -> string?
override Microsoft.TestPlatform.Build.Tasks.VSTestTask.GenerateFullPathToTool() -> string?
override Microsoft.TestPlatform.Build.Tasks.VSTestTask.ToolName.get -> string?
static Microsoft.TestPlatform.Build.Trace.Tracing.Trace(string! message) -> void
static Microsoft.TestPlatform.Build.Trace.Tracing.traceEnabled -> bool
39 changes: 39 additions & 0 deletions src/Microsoft.TestPlatform.Build/Tasks/ITestTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Microsoft.TestPlatform.Build.Tasks;

internal interface ITestTask : ITask, ICancelableTask
{

ITaskItem? TestFileFullPath { get; set; }
string? VSTestSetting { get; set; }
ITaskItem[]? VSTestTestAdapterPath { get; set; }
string? VSTestFramework { get; set; }
string? VSTestPlatform { get; set; }
string? VSTestTestCaseFilter { get; set; }
string[]? VSTestLogger { get; set; }
bool VSTestListTests { get; set; }
string? VSTestDiag { get; set; }
string[]? VSTestCLIRunSettings { get; set; }
ITaskItem? VSTestConsolePath { get; set; }
ITaskItem? VSTestResultsDirectory { get; set; }
string? VSTestVerbosity { get; set; }
string[]? VSTestCollect { get; set; }
bool VSTestBlame { get; set; }
bool VSTestBlameCrash { get; set; }
string? VSTestBlameCrashDumpType { get; set; }
bool VSTestBlameCrashCollectAlways { get; set; }
bool VSTestBlameHang { get; set; }
string? VSTestBlameHangDumpType { get; set; }
string? VSTestBlameHangTimeout { get; set; }
ITaskItem? VSTestTraceDataCollectorDirectoryPath { get; set; }
bool VSTestNoLogo { get; set; }
string? VSTestArtifactsProcessingMode { get; set; }
string? VSTestSessionCorrelationId { get; set; }

TaskLoggingHelper Log { get; }
}
Loading

0 comments on commit f182de1

Please sign in to comment.