summaryrefslogtreecommitdiff
path: root/.packages/microsoft.dotnet.arcade.sdk/1.0.0-beta.20113.5/tools/XUnit/XUnit.targets
blob: e25da54ae4958342083cfa2ae678af5c1dd72744 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?xml version="1.0" encoding="utf-8"?>
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
<Project>
  <ItemGroup>
    <PackageReference Include="xunit" Version="$(XUnitVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true"/>
    <PackageReference Include="xunit.runner.visualstudio" Version="$(XUnitRunnerVisualStudioVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true"/>
    <PackageReference Include="xunit.runner.console" Version="$(XUnitRunnerConsoleVersion)" IsImplicitlyDefined="true" PrivateAssets="all" Publish="true"/>
  </ItemGroup>

  <!--
    Include settings file (xunit.runner.json) if specified.
  -->
  <ItemGroup>
    <None Include="$(XUnitDesktopSettingsFile)"
          CopyToOutputDirectory="PreserveNewest"
          Visible="false"
          Condition="'$(XUnitDesktopSettingsFile)' != '' and '$(TargetFrameworkIdentifier)' == '.NETFramework'" />

    <None Include="$(XUnitCoreSettingsFile)"
          CopyToOutputDirectory="PreserveNewest"
          Visible="false"
          Condition="'$(XUnitCoreSettingsFile)' != '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
  </ItemGroup>

  <!-- 
    Include '*' target to force running tests even if the input assemblies haven't changed and the outputs are present.
    This matches the common expectations that test command always runs all tests in scope.
  -->
  <Target Name="RunTests"
          Inputs="@(TestToRun);*"
          Outputs="%(TestToRun.ResultsStdOutPath);%(TestToRun.ResultsXmlPath);%(TestToRun.ResultsHtmlPath)">
    <Telemetry EventName="NETCORE_ENGINEERING_TELEMETRY" EventData="Category=Test" />
    <PropertyGroup>
      <_TestEnvironment>%(TestToRun.EnvironmentDisplay)</_TestEnvironment>
      <_TestAssembly>%(TestToRun.Identity)</_TestAssembly>
      <_TestRuntime>%(TestToRun.TestRuntime)</_TestRuntime>
      <_TestRunnerAdditionalArguments>%(TestToRun.TestRunnerAdditionalArguments)</_TestRunnerAdditionalArguments>

      <!-- Always use net472 for desktop to enable displaying source location from Portable PDBs in stack traces -->
      <_TestRunnerTargetFramework>net472</_TestRunnerTargetFramework>
      <_TestRunnerTargetFramework Condition="'$(_TestRuntime)' == 'Core'">netcoreapp2.0</_TestRunnerTargetFramework>
      <_TestRunnerTargetFramework Condition="%(TestToRun.TargetFramework) == 'netcoreapp1.1' or %(TestToRun.TargetFramework) == 'netcoreapp1.0'">netcoreapp1.0</_TestRunnerTargetFramework>
    </PropertyGroup>

    <PropertyGroup Condition="'$(_TestRuntime)' == 'Core'">
      <_TargetFileNameNoExt>$([System.IO.Path]::GetFileNameWithoutExtension('$(_TestAssembly)'))</_TargetFileNameNoExt>
      <_TargetDir>$([System.IO.Path]::GetDirectoryName('$(_TestAssembly)'))\</_TargetDir>
      <_CoreRuntimeConfigPath>$(_TargetDir)$(_TargetFileNameNoExt).runtimeconfig.json</_CoreRuntimeConfigPath>
      <_CoreDepsPath>$(_TargetDir)$(_TargetFileNameNoExt).deps.json</_CoreDepsPath>
      
      <_TestRunner Condition="'%(TestToRun.Architecture)'=='x86' And Exists('$(DotNetRoot)x86\dotnet.exe')">$(DotNetRoot)x86\dotnet.exe</_TestRunner>
      <_TestRunner Condition="'$(_TestRunner)'==''">$(DotNetTool)</_TestRunner>
      
      <_TestRunnerArgs>exec --depsfile "$(_CoreDepsPath)" --runtimeconfig "$(_CoreRuntimeConfigPath)" $(TestRuntimeAdditionalArguments) "$(NuGetPackageRoot)xunit.runner.console/$(XUnitVersion)/tools/$(_TestRunnerTargetFramework)/xunit.console.dll" "$(_TestAssembly)" -noautoreporters -xml "%(TestToRun.ResultsXmlPath)" -html "%(TestToRun.ResultsHtmlPath)" $(_TestRunnerAdditionalArguments)</_TestRunnerArgs>
    </PropertyGroup>

    <PropertyGroup Condition="'$(_TestRuntime)' != 'Core'">
      <_XUnitConsoleExe>xunit.console.exe</_XUnitConsoleExe>
      <_XUnitConsoleExe Condition="'%(TestToRun.Architecture)' == 'x86'">xunit.console.x86.exe</_XUnitConsoleExe>
      <_XUnitConsoleExePath>$(NuGetPackageRoot)xunit.runner.console\$(XUnitVersion)\tools\$(_TestRunnerTargetFramework)\$(_XUnitConsoleExe)</_XUnitConsoleExePath>

      <_TestRunnerArgs>"$(_TestAssembly)" -noshadow -xml "%(TestToRun.ResultsXmlPath)" -html "%(TestToRun.ResultsHtmlPath)" $(_TestRunnerAdditionalArguments)</_TestRunnerArgs>
      <_TestRunnerArgs Condition="'$(_TestRuntime)' == 'Mono'">$(TestRuntimeAdditionalArguments) "$(_XUnitConsoleExePath)" $(_TestRunnerArgs)</_TestRunnerArgs>

      <_TestRunner Condition="'$(_TestRuntime)' == 'Mono'">$(MonoTool)</_TestRunner>
      <_TestRunner Condition="'$(_TestRuntime)' != 'Mono'">$(_XUnitConsoleExePath)</_TestRunner>
    </PropertyGroup>

    <PropertyGroup>
      <_TestRunnerCommand>"$(_TestRunner)" $(_TestRunnerArgs)</_TestRunnerCommand>

      <!-- 
        Redirect std output of the runner.
        Note that xUnit outputs failure info to both STDOUT (stack trace, message) and STDERR (failed test name) 
      -->
      <_TestRunnerCommand Condition="'$(TestCaptureOutput)' != 'false'">$(_TestRunnerCommand) > "%(TestToRun.ResultsStdOutPath)" 2>&amp;1</_TestRunnerCommand>
    </PropertyGroup>

    <ItemGroup>
      <_OutputFiles Include="%(TestToRun.ResultsXmlPath)" />
      <_OutputFiles Include="%(TestToRun.ResultsHtmlPath)" />
      <_OutputFiles Include="%(TestToRun.ResultsStdOutPath)" />
    </ItemGroup>

    <MakeDir Directories="@(_OutputFiles->'%(RootDir)%(Directory)')"/>
    <Delete Files="@(_OutputFiles)" />

    <Message Text="Running tests: $(_TestAssembly) [$(_TestEnvironment)]" Importance="high"/>
    <Exec Command='$(_TestRunnerCommand)' LogStandardErrorAsError="false" WorkingDirectory="$(_TargetDir)" IgnoreExitCode="true">
      <Output TaskParameter="ExitCode" PropertyName="_TestErrorCode" />
    </Exec>

    <!--
      Add command line to the log.
    -->
    <WriteLinesToFile File="%(TestToRun.ResultsStdOutPath)" 
                      Overwrite="false" 
                      Lines=";=== COMMAND LINE ===;$(_TestRunnerCommand)"
                      Condition="'$(TestCaptureOutput)' != 'false'" />

    <!--
      Report test status.
    -->
    <Message Text="Tests succeeded: $(_TestAssembly) [$(_TestEnvironment)]" Condition="'$(_TestErrorCode)' == '0'" Importance="high" />

    <PropertyGroup>
      <_ResultsFileToDisplay>%(TestToRun.ResultsHtmlPath)</_ResultsFileToDisplay>
      <_ResultsFileToDisplay Condition="!Exists('$(_ResultsFileToDisplay)')">%(TestToRun.ResultsStdOutPath)</_ResultsFileToDisplay>
    </PropertyGroup>

    <!-- 
      Ideally we would set ContinueOnError="ErrorAndContinue" so that when a test fails in multi-targeted test project
      we'll still run tests for all target frameworks. ErrorAndContinue doesn't work well on Linux though: https://github.com/Microsoft/msbuild/issues/3961.
    -->
    <Error Text="Tests failed: $(_ResultsFileToDisplay) [$(_TestEnvironment)]" Condition="'$(_TestErrorCode)' != '0'" File="XUnit" />

    <ItemGroup>
      <FileWrites Include="@(_OutputFiles)"/>
    </ItemGroup>
  </Target>

  <!-- Workaround for https://github.com/xunit/xunit/issues/1651 -->
  <ItemGroup>
    <None Remove="$(NuGetPackageRoot)xunit.runner.visualstudio\$(XUnitRunnerVisualStudioVersion)\build\net20\..\_common\xunit.abstractions.dll" />
  </ItemGroup>

</Project>