This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
/
tests.targets
253 lines (215 loc) · 14.4 KB
/
tests.targets
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- This is the target that copies the test assets to the test output -->
<Import Project="$(MSBuildThisFileDirectory)publishtest.targets" />
<UsingTask TaskName="GetTargetMachineInfo" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll"/>
<UsingTask TaskName="GenerateTestExecutionScripts" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll"/>
<!-- Which categories of tests to run by default -->
<PropertyGroup>
<TestDisabled>false</TestDisabled>
<TestDisabled Condition="'$(IsTestProject)'!='true' Or '$(SkipTests)'=='true' Or '$(RunTestsForProject)'=='false'">true</TestDisabled>
<TestsSuccessfulSemaphore>tests.passed</TestsSuccessfulSemaphore>
</PropertyGroup>
<ItemGroup>
<!-- Split semicolon separated lists -->
<WithCategoriesItems Include="$(WithCategories)" />
<WithoutCategoriesItems Include="$(WithoutCategories)" />
<DefaultNoCategories Include="$(DefaultNoCategories)" />
<UnsupportedPlatformsItems Include="$(UnsupportedPlatforms)"/>
</ItemGroup>
<PropertyGroup>
<TestWithCore Condition="'$(TestWithCore)' == '' And '$(TargetGroup)' == 'net45'">false</TestWithCore>
<TestWithCore Condition="'$(TestWithCore)' == '' And '$(TargetGroup)' == 'net46'">false</TestWithCore>
<TestWithCore Condition="'$(TestWithCore)' == '' And '$(TargetGroup)' == 'net461'">false</TestWithCore>
<TestWithCore Condition="'$(TestWithCore)' == '' And '$(TargetGroup)' == 'net462'">false</TestWithCore>
<TestWithCore Condition="'$(TestWithCore)' == ''">true</TestWithCore>
</PropertyGroup>
<PropertyGroup Condition="'$(TestWithCore)' == 'true'">
<TestHostExecutable>CoreRun.exe</TestHostExecutable>
<TestHostDirectory>$(TestPath)netcoreapp1.0/</TestHostDirectory>
<XunitExecutable Condition="'$(XunitExecutable)' == ''">xunit.console.netcore.exe</XunitExecutable>
<DebugTestFrameworkFolder>netcoreapp1.0</DebugTestFrameworkFolder>
<DebugEngines>{2E36F1D4-B23C-435D-AB41-18E608940038}</DebugEngines>
</PropertyGroup>
<PropertyGroup Condition="'$(TestWithCore)' != 'true'">
<XunitExecutable Condition="'$(XunitExecutable)' == ''">xunit.console.exe</XunitExecutable>
<DebugTestFrameworkFolder>net45</DebugTestFrameworkFolder>
</PropertyGroup>
<ItemGroup Condition="'$(TestWithCore)' == 'true'">
<TestTargetFramework Include=".NETCoreApp,Version=v1.0">
<Folder>netcoreapp1.0</Folder>
</TestTargetFramework>
</ItemGroup>
<ItemGroup Condition="'$(TestWithCore)' != 'true'">
<TestTargetFramework Include=".NETFramework,Version=v4.6.2" Condition="'$(TargetGroup)' == 'net462'">
<Folder>net462</Folder>
</TestTargetFramework>
<TestTargetFramework Include=".NETFramework,Version=v4.6.1" Condition="'$(TargetGroup)' == 'net461'">
<Folder>net461</Folder>
</TestTargetFramework>
<TestTargetFramework Include=".NETFramework,Version=v4.6" Condition="'$(TargetGroup)' == 'net46'">
<Folder>net46</Folder>
</TestTargetFramework>
<TestTargetFramework Include=".NETFramework,Version=v4.5" Condition="'$(TargetGroup)' == 'net45'">
<Folder>net45</Folder>
</TestTargetFramework>
</ItemGroup>
<!-- General xunit options -->
<PropertyGroup>
<XunitResultsFileName>testResults.xml</XunitResultsFileName>
<XunitOptions Condition="'$(TestWithCore)' != 'true'">$(XunitOptions) -noshadow </XunitOptions>
<XunitOptions>$(XunitOptions) -xml $(XunitResultsFileName)</XunitOptions>
<XunitOptions Condition="'$(Performance)'!='true'">$(XunitOptions) -notrait Benchmark=true</XunitOptions>
<XunitOptions Condition="'$(XunitMaxThreads)'!=''">$(XunitOptions) -maxthreads $(XunitMaxThreads)</XunitOptions>
<XunitTestAssembly Condition="'$(XunitTestAssembly)' == ''">$(TargetFileName)</XunitTestAssembly>
<XunitArguments>$(XunitTestAssembly) $(XunitOptions)</XunitArguments>
<TestProgram Condition="'$(TestHostExecutable)'!=''">$(TestHostExecutable)</TestProgram>
<TestArguments Condition="'$(TestHostExecutable)'!=''">$(XunitExecutable) $(XunitArguments)</TestArguments>
<TestProgram Condition="'$(TestHostExecutable)'==''">$(XunitExecutable)</TestProgram>
<TestArguments Condition="'$(TestHostExecutable)'==''">$(XunitArguments)</TestArguments>
<TestCommandLine>$(TestProgram) $(TestArguments) {XunitTraitOptions}</TestCommandLine>
</PropertyGroup>
<!-- The Code Coverage targets will override TestHost and TestCommandLine if coverage is enabled -->
<Import Project="$(MSBuildThisFileDirectory)CodeCoverage.targets" />
<!-- import settings for perf testing -->
<Import Project="$(MSBuildThisFileDirectory)PerfTesting.targets" Condition="'$(Performance)'=='true'"/>
<!-- In VS (2015 Preview or later currently required): Debug to run unit tests on CoreCLR. -->
<PropertyGroup Condition="'$(IsTestProject)'=='true'">
<StartWorkingDirectory Condition="'$(StartWorkingDirectory)'==''">$(TestPath)$(DebugTestFrameworkFolder)</StartWorkingDirectory>
<StartAction Condition="'$(StartAction)'==''">Program</StartAction>
<StartProgram Condition="'$(StartProgram)'==''">$(TestProgram)</StartProgram>
<StartArguments Condition="'$(StartArguments)'==''">$(TestArguments) -wait -parallel none</StartArguments>
</PropertyGroup>
<Target Name="DiscoverTestInputs" DependsOnTargets="ResolveProjectReferences;ResolveAssemblyReferences;GetCopyToOutputDirectoryItems">
<ItemGroup>
<RunTestsForProjectInputs Include="@(ReferenceCopyLocalPaths)" />
<RunTestsForProjectInputs Include="@(Content)" />
<RunTestsForProjectInputs Include="@(IntermediateAssembly)" />
<RunTestsForProjectInputs Include="@(_DebugSymbolsIntermediatePath)" />
<RunTestsForProjectInputs Include="@(AllItemsFullPathWithTargetPath)" />
</ItemGroup>
</Target>
<!--
On command line run unit tests on CoreCLR after the Test target.
Set ForceRunTests to true to run tests even if there have been no changes since the last successful run.
-->
<Target Name="RunTestsForProject"
DependsOnTargets="DiscoverTestInputs;CheckTestCategories"
AfterTargets="CheckTestCategories"
Inputs="@(RunTestsForProjectInputs)"
Outputs="$(TestsSuccessfulSemaphore);$(TestPath)%(TestTargetFramework.Folder)/$(XunitResultsFileName);$(CoverageOutputFilePath)"
>
<ItemGroup>
<RunWithoutTraits Condition="'$(TargetOS)'=='Windows_NT'" Include="nonwindowstests" />
<RunWithoutTraits Condition="'$(TargetOS)'=='Linux'" Include="nonlinuxtests" />
<RunWithoutTraits Condition="'$(TargetOS)'=='OSX'" Include="nonosxtests"/>
<RunWithoutTraits Condition="'$(TargetOS)'=='FreeBSD'" Include="nonfreebsdtests"/>
<RunWithoutTraits Condition="'$(TargetOS)'=='NetBSD'" Include="nonnetbsdtests"/>
</ItemGroup>
<PropertyGroup>
<RunnerScriptName Condition="'$(TargetOS)'=='Windows_NT'" >RunTests.cmd</RunnerScriptName>
<RunnerTemplateName Condition="'$(TargetOS)'=='Windows_NT'" >RunnerTemplate.Windows.txt</RunnerTemplateName>
<RunnerScriptName Condition="'$(TargetOS)'!='Windows_NT'" >RunTests.sh</RunnerScriptName>
<RunnerTemplateName Condition="'$(TargetOS)'!='Windows_NT'" >RunnerTemplate.Unix.txt</RunnerTemplateName>
</PropertyGroup>
<PropertyGroup>
<XunitTraitOptions Condition="'@(RunWithTraits)'!=''">$(XunitTraitOptions) -trait category=@(RunWithTraits, ' -trait category=') </XunitTraitOptions>
<XunitTraitOptions Condition="'@(RunWithoutTraits)'!=''">$(XunitTraitOptions) -notrait category=@(RunWithoutTraits, ' -notrait category=') </XunitTraitOptions>
</PropertyGroup>
<!-- Replace the {XunitTraitOptions} place holder with the actual traits. We use the place holder
because code coverage needs to have a bit of the test command line after the traits (it adds ending quotes
to one of its options). Simply appending the traits would break code coverage.
Additionally, replace CoreRun.exe with ./corerun on Non-Windows OSes (this is the only difference in the command)
Future refactoring will allow us to construct this correctly initially, but we don't always know the TargetOS
when the properties are set currently.
-->
<PropertyGroup>
<TestCommandLine Condition="'$(TargetOS)'!='Windows_NT'" >$(TestCommandLine.Replace('$(TestHostExecutable)', './corerun'))</TestCommandLine>
<TestCommandLine>$(TestCommandLine.Replace('{XunitTraitOptions}', '$(XunitTraitOptions)'))</TestCommandLine>
<OutputFolderForScriptGenerator>$(TestPath)%(TestTargetFramework.Folder)</OutputFolderForScriptGenerator>
<OutputPathForScriptGenerator>$(OutputFolderForScriptGenerator)/$(RunnerScriptName)</OutputPathForScriptGenerator>
<OutputFolderForTestDependencies>$(BinDir)/TestDependencies</OutputFolderForTestDependencies>
</PropertyGroup>
<MakeDir Condition="'$(CoverageEnabledForProject)'=='true'" Directories="$(CoverageReportDir)" />
<ItemGroup>
<!-- Not all platforms can use the .ni.dlls that come from packages. If TestWithoutNativeImages is specified, we'll exclude them from copy generation.
If we end up needing this for any other sorts of filtering, we'll want to add a list of filtered extensions to be matched on EndsWith. -->
<IncludedFileForRunnerScript Include="@(_TestCopyLocalByFileNameWithoutDuplicates)"
Condition="'$(TestWithoutNativeImages)' != 'true' Or !$([System.String]::Copy('%(_TestCopyLocalByFileNameWithoutDuplicates.SourcePath)').EndsWith('.ni.dll'))" >
<PackageRelativePath Condition="'%(_TestCopyLocalByFileNameWithoutDuplicates.NugetPackageId)' != ''">$([System.String]::Copy('%(_TestCopyLocalByFileNameWithoutDuplicates.SourcePath)').Replace('$(PackagesDir)',''))</PackageRelativePath>
<UseAbsolutePath Condition="'$(TestWithLocalLibraries)'=='true'">$([System.String]::Copy('%(_TestCopyLocalByFileNameWithoutDuplicates.SourcePath)').StartsWith('$(BinDir)'))</UseAbsolutePath>
</IncludedFileForRunnerScript>
</ItemGroup>
<MakeDir Directories="$(OutputFolderForTestDependencies)" />
<PropertyGroup>
<_TestDependencyListRoot>$(AssemblyName)-$(OSGroup).$(Platform).$(ConfigurationGroup)</_TestDependencyListRoot>
<_TestDependencyListRoot Condition="'$(TargetGroup)' != ''">$(_TestDependencyListRoot).$(TargetGroup)</_TestDependencyListRoot>
<_TestDependencyListFileName>$(_TestDependencyListRoot).dependencylist.txt</_TestDependencyListFileName>
<TestDependencyListFilePath>$(OutputFolderForTestDependencies)/$(_TestDependencyListFileName)</TestDependencyListFilePath>
</PropertyGroup>
<Message Text="Generating $(TestDependencyListFilePath)" />
<WriteLinesToFile
File="$(TestDependencyListFilePath)"
Lines="@(IncludedFileForRunnerScript -> '%(PackageRelativePath)')"
Overwrite="true"
Encoding="Ascii" />
<Message Text="Generating JSON-Processed $(OutDir)assemblylist.txt for legacy execution" />
<GenerateAssemblyList
InputListLocation="$(TestDependencyListFilePath)"
OutputListLocation="$(OutDir)assemblylist.txt"
/>
<!-- Add commands for before / after test execution here. -->
<ItemGroup>
<TestCommandLines Include="$(TestCommandLine)"/>
</ItemGroup>
<GenerateTestExecutionScripts
TestCommands="@(TestCommandLines)"
TestDependencies="@(IncludedFileForRunnerScript)"
RunnerScriptTemplate="$(MSBuildThisFileDirectory)/$(RunnerTemplateName)"
ScriptOutputPath ="$(OutputPathForScriptGenerator)"
/>
<Exec Condition="'$(TestDisabled)'!='true'"
Command="$(TestPath)%(TestTargetFramework.Folder)/$(RunnerScriptName) $(PackagesDir)"
WorkingDirectory="$(TestPath)%(TestTargetFramework.Folder)"
CustomErrorRegularExpression="Failed: [^0]"
ContinueOnError="true">
<Output PropertyName="TestRunExitCode" TaskParameter="ExitCode" />
</Exec>
<Delete Condition="'$(DeletePerfDataFile)' == 'true'" Files="$(TestPath)%(TestTargetFramework.Folder)/$(EventTracerDataFile)" />
<Error Condition="'$(TestDisabled)'!='true' And '$(TestRunExitCode)' != '0'" Text="One or more tests failed while running tests from '$(MSBuildProjectName)' please check log for details!" />
<Touch Condition="'$(TestRunExitCode)' == '0'" Files="$(TestsSuccessfulSemaphore)" AlwaysCreate="true" />
</Target>
<!-- Needs to run before RunTestsForProject target as it computes categories and set TestDisabled -->
<Target Name="CheckTestCategories"
AfterTargets="CheckTestPlatforms">
<!-- Default behavior is to disable OuterLoop and failing tests if not specified in WithCategories. -->
<ItemGroup>
<DefaultNoCategories Condition="'$(Outerloop)'!='true'" Include="OuterLoop" />
<DefaultNoCategories Include="failing" />
<WithoutCategoriesItems Include="@(DefaultNoCategories)" Exclude="@(WithCategoriesItems)" />
<WithoutCategoriesItemsDistinct Include="@(WithoutCategoriesItems->Distinct())" />
</ItemGroup>
<ItemGroup>
<RunWithTraits Condition="'@(WithCategoriesItems)'!=''" Include="@(WithCategoriesItems)" />
<RunWithoutTraits Condition="'@(WithoutCategoriesItemsDistinct)'!=''" Include="@(WithoutCategoriesItemsDistinct)" />
</ItemGroup>
<PropertyGroup>
<TestsSuccessfulSemaphore Condition="'@(RunWithTraits)' != ''">$(TestsSuccessfulSemaphore).with.@(RunWithTraits, '.')</TestsSuccessfulSemaphore>
<TestsSuccessfulSemaphore Condition="'@(RunWithoutTraits)' != ''">$(TestsSuccessfulSemaphore).without.@(RunWithoutTraits, '.')</TestsSuccessfulSemaphore>
<TestsSuccessfulSemaphore>$(TestPath)%(TestTargetFramework.Folder)/$(TestsSuccessfulSemaphore)</TestsSuccessfulSemaphore>
</PropertyGroup>
<Delete Condition="'$(ForceRunTests)'=='true' And Exists($(TestsSuccessfulSemaphore))"
Files="$(TestsSuccessfulSemaphore)" />
</Target>
<Target Name="CheckTestPlatforms"
AfterTargets="Test">
<GetTargetMachineInfo Condition="'$(TargetOS)' == ''">
<Output TaskParameter="TargetOS" PropertyName="TargetOS" />
</GetTargetMachineInfo>
<PropertyGroup>
<TestDisabled Condition="'%(UnsupportedPlatformsItems.Identity)' == '$(TargetOS)'">true</TestDisabled>
</PropertyGroup>
<Message Condition="'%(UnsupportedPlatformsItems.Identity)' == '$(TargetOS)'"
Text="Skipping tests in $(AssemblyName) because it is not supported on $(TargetOS)" />
</Target>
</Project>