|
| 1 | +<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. --> |
| 2 | +<Project> |
| 3 | + |
| 4 | + <Target Name="RunTests" |
| 5 | + Outputs="%(TestToRun.ResultsStdOutPath)" |
| 6 | + Condition="'@(TestToRun)' != ''"> |
| 7 | + <Telemetry EventName="NETCORE_ENGINEERING_TELEMETRY" EventData="Category=Test" /> |
| 8 | + |
| 9 | + <PropertyGroup> |
| 10 | + <_TestResultDirectory>$([System.IO.Path]::GetDirectoryName('%(TestToRun.ResultsTrxPath)'))</_TestResultDirectory> |
| 11 | + <_TestResultTrxFileName>$([System.IO.Path]::GetFileName('%(TestToRun.ResultsTrxPath)'))</_TestResultTrxFileName> |
| 12 | + <_TestResultXmlFileName>$([System.IO.Path]::GetFileName('%(TestToRun.ResultsXmlFileName)'))</_TestResultXmlFileName> |
| 13 | + <_TestResultHtmlFileName>$([System.IO.Path]::GetFileName('%(TestToRun.ResultsHtmlFileName)'))</_TestResultHtmlFileName> |
| 14 | + </PropertyGroup> |
| 15 | + |
| 16 | + <PropertyGroup> |
| 17 | + <_TestEnvironment>%(TestToRun.EnvironmentDisplay)</_TestEnvironment> |
| 18 | + <_TestAssembly>%(TestToRun.Identity)</_TestAssembly> |
| 19 | + <_TestAssembly>$([System.IO.Path]::ChangeExtension($(_TestAssembly), '.exe'))</_TestAssembly> |
| 20 | + <_TestRuntime>%(TestToRun.TestRuntime)</_TestRuntime> |
| 21 | + <_TestTimeout>%(TestToRun.TestTimeout)</_TestTimeout> |
| 22 | + <_TestRunnerAdditionalArguments>%(TestToRun.TestRunnerAdditionalArguments)</_TestRunnerAdditionalArguments> |
| 23 | + |
| 24 | + <_TestRunner>$(_TestAssembly)</_TestRunner> |
| 25 | + <_TestRunnerArgs>$(_TestRunnerAdditionalArguments) --results-directory "$(_TestResultDirectory)" --report-xunit --report-xunit-filename "$(_TestResultXmlFileName)" --report-xunit-html --report-xunit-html-filename "$(_TestResultHtmlFileName)"</_TestRunnerArgs> |
| 26 | + </PropertyGroup> |
| 27 | + |
| 28 | + <PropertyGroup Condition="'$(_TestRuntime)' == 'Core'"> |
| 29 | + <_TestRunnerArgs>$(_TestRunnerArgs) --auto-reporters off</_TestRunnerArgs> |
| 30 | + </PropertyGroup> |
| 31 | + |
| 32 | + <PropertyGroup> |
| 33 | + <_TestRunnerCommand>"$(_TestRunner)" $(_TestRunnerArgs)</_TestRunnerCommand> |
| 34 | + |
| 35 | + <!-- |
| 36 | + Redirect std output of the runner. |
| 37 | + Note that xUnit outputs failure info to both STDOUT (stack trace, message) and STDERR (failed test name) |
| 38 | + --> |
| 39 | + <_TestRunnerCommand Condition="'$(TestCaptureOutput)' != 'false'">$(_TestRunnerCommand) > "%(TestToRun.ResultsStdOutPath)" 2>&1</_TestRunnerCommand> |
| 40 | + </PropertyGroup> |
| 41 | + |
| 42 | + <ItemGroup> |
| 43 | + <_OutputFiles Include="%(TestToRun.ResultsXmlPath)" /> |
| 44 | + <_OutputFiles Include="%(TestToRun.ResultsHtmlPath)" /> |
| 45 | + <_OutputFiles Include="%(TestToRun.ResultsStdOutPath)" /> |
| 46 | + </ItemGroup> |
| 47 | + |
| 48 | + <MakeDir Directories="@(_OutputFiles->'%(RootDir)%(Directory)')"/> |
| 49 | + <Delete Files="@(_OutputFiles)" /> |
| 50 | + |
| 51 | + <Message Text="Running tests: $(_TestAssembly) [$(_TestEnvironment)]" Importance="high"/> |
| 52 | + <Exec Command='$(_TestRunnerCommand)' |
| 53 | + LogStandardErrorAsError="false" |
| 54 | + WorkingDirectory="$(_TargetDir)" |
| 55 | + IgnoreExitCode="true" |
| 56 | + Timeout="$(_TestTimeout)" |
| 57 | + EnvironmentVariables="DOTNET_ROOT=$(DotNetRoot);DOTNET_ROOT_X86=$(DotNetRoot)x86" |
| 58 | + ContinueOnError="WarnAndContinue"> |
| 59 | + <Output TaskParameter="ExitCode" PropertyName="_TestErrorCode" /> |
| 60 | + </Exec> |
| 61 | + |
| 62 | + <!-- |
| 63 | + Add command line to the log. |
| 64 | + --> |
| 65 | + <WriteLinesToFile File="%(TestToRun.ResultsStdOutPath)" |
| 66 | + Overwrite="false" |
| 67 | + Lines=";=== COMMAND LINE ===;$(_TestRunnerCommand)" |
| 68 | + Condition="'$(TestCaptureOutput)' != 'false'" /> |
| 69 | + |
| 70 | + <!-- |
| 71 | + Report test status. |
| 72 | + --> |
| 73 | + <Message Text="Tests succeeded: $(_TestAssembly) [$(_TestEnvironment)]" Condition="'$(_TestErrorCode)' == '0'" Importance="high" /> |
| 74 | + |
| 75 | + <PropertyGroup> |
| 76 | + <_ResultsFileToDisplay>%(TestToRun.ResultsHtmlPath)</_ResultsFileToDisplay> |
| 77 | + <_ResultsFileToDisplay Condition="!Exists('$(_ResultsFileToDisplay)')">%(TestToRun.ResultsStdOutPath)</_ResultsFileToDisplay> |
| 78 | + </PropertyGroup> |
| 79 | + |
| 80 | + <!-- |
| 81 | + Ideally we would set ContinueOnError="ErrorAndContinue" so that when a test fails in multi-targeted test project |
| 82 | + we'll still run tests for all target frameworks. ErrorAndContinue doesn't work well on Linux though: https://github.com/Microsoft/msbuild/issues/3961. |
| 83 | + --> |
| 84 | + <Error Text="Tests failed: $(_ResultsFileToDisplay) [$(_TestEnvironment)]" Condition="'$(_TestErrorCode)' != '0' and '$(_ErrorOnTestFailure)' != 'false'" File="XUnit" /> |
| 85 | + |
| 86 | + <ItemGroup> |
| 87 | + <FileWrites Include="@(_OutputFiles)"/> |
| 88 | + </ItemGroup> |
| 89 | + </Target> |
| 90 | + |
| 91 | +</Project> |
0 commit comments