Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit d123f34

Browse files
author
Nate McMaster
committed
Port xunit-test target to MSBuild
1 parent c4e40ee commit d123f34

File tree

4 files changed

+100
-125
lines changed

4 files changed

+100
-125
lines changed

build/makefile.proj

+8-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
<!-- TFM used only for the purpose of restoring build tools. It does not affect the TFM of projects -->
66
<TargetFramework>netcoreapp1.0</TargetFramework>
77
<SakeVersion>0.2.2</SakeVersion>
8+
9+
<!--
10+
We want to ensure these properties do not flow into sub-builds.
11+
This group of properties should be specified in RemoveProperties when an MSBuild task is used.
12+
These properties include those that could interfere with inner builds
13+
or could result in an unnecessary build cache miss.
14+
-->
15+
<_BuildPropertiesToRemove>$(_BuildPropertiesToRemove);TargetFramework;TargetFrameworks;LifecycleType;RestoreGraphProjectInput;_InvalidConfigurationWarn;_InvalidConfigurationError</_BuildPropertiesToRemove>
816
</PropertyGroup>
917

1018
<ItemGroup>
@@ -32,11 +40,6 @@
3240

3341
<Import Project="$(RepositoryRoot)build\repo.props" Condition="Exists('$(RepositoryRoot)build\repo.props')" />
3442

35-
<ItemGroup>
36-
<Solutions Condition="'$(Solutions)'==''"
37-
Include="$(RepositoryRoot)\*.sln" />
38-
</ItemGroup>
39-
4043
<Import Project="$(MSBuildThisFileDirectory)\targets\legacy-lifecycle.targets" Condition="'$(LifecycleType)'=='Legacy'" />
4144
<Import Project="$(MSBuildThisFileDirectory)\targets\standard-lifecycle.targets" Condition="'$(LifecycleType)'=='Standard'" />
4245

build/shade/_dotnet-test.shade

-45
This file was deleted.

build/shade/_k-standard-goals.shade

+2-66
Original file line numberDiff line numberDiff line change
@@ -178,69 +178,11 @@ functions
178178
nuget-resilient-publish sourcePackagesDir='${BUILD_DIR}' nugetFeed='${E("NUGET_PUBLISH_FEED")}' if='!string.IsNullOrEmpty(E("NUGET_PUBLISH_FEED"))'
179179
-}
180180

181-
#xunit-test target='test' if='Directory.Exists("test")'
181+
#xunit-test target='test'
182182
@{
183-
var projectFiles = Files.Include(TEST_PROJECT_GLOB);
184-
foreach (var projectFile in projectFiles)
185-
{
186-
var dir = Path.GetDirectoryName(projectFile);
187-
if (File.Exists(Path.Combine(dir, ".notest")))
188-
{
189-
continue;
190-
}
191-
192-
var options = E("KOREBUILD_DOTNET_TEST_OPTIONS");
193-
if (IsTeamCity)
194-
{
195-
// TODO put all trx files in same folder. See https://github.com/Microsoft/vstest/issues/243
196-
// TODO or use TC logger https://github.com/Microsoft/vstest/issues/254
197-
options += " --logger:trx ";
198-
}
199-
// workaround for https://github.com/Microsoft/vstest/issues/283
200-
var txt = File.ReadAllText(projectFile);
201-
var multiTfm = Regex.Match(txt, @"\<TargetFrameworks\>(.+)\<\/TargetFrameworks\>");
202-
var singleTfm = Regex.Match(txt, @"\<TargetFramework\>(.+)\<\/TargetFramework\>");
203-
if (multiTfm != null && multiTfm.Success)
204-
{
205-
var frameworks = multiTfm.Groups[1]
206-
.Value
207-
.Split(new string[] {";"}, StringSplitOptions.RemoveEmptyEntries)
208-
.Select(s => s.Trim())
209-
.ToArray();
210-
211-
foreach (var framework in frameworks)
212-
{
213-
if (IsLinux && framework != null && framework.StartsWith("net4"))
214-
{
215-
Log.Info("Skipping tests for TFM " + framework + " on this platform");
216-
continue;
217-
}
218-
219-
DotnetTest(projectFile, Configuration, options, framework);
220-
}
221-
// end workaround
222-
}
223-
else if(singleTfm != null && singleTfm.Success)
224-
{
225-
var framework = singleTfm.Groups[1].Value;
226-
if (IsLinux && framework != null && framework.StartsWith("net4"))
227-
{
228-
Log.Info("Skipping tests for TFM " + framework + " on this platform");
229-
}
230-
else
231-
{
232-
DotnetTest(projectFile, Configuration, options, framework);
233-
}
234-
}
235-
else
236-
{
237-
// default invocation
238-
DotnetTest(projectFile, Configuration, options);
239-
}
240-
}
183+
MSBuild("/t:Test");
241184
}
242185

243-
244186
#make-roslyn-fast
245187
ngen-roslyn
246188

@@ -404,12 +346,6 @@ macro name="DotnetPack" projectFile='string' dotnetPackOutputDir='string' config
404346
macro name="DotnetPublish" projectFile='string' outputFolder='string' framework='string' configuration='string'
405347
dotnet-publish
406348

407-
macro name="DotnetTest" projectFile='string' configuration='string' test_options='string'
408-
dotnet-test
409-
410-
macro name="DotnetTest" projectFile='string' configuration='string' test_options='string' framework='string'
411-
dotnet-test
412-
413349
macro name='Npm' npmCommand='string' npmDir='string'
414350
npm
415351

build/targets/standard-lifecycle.targets

+90-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ When extending the solution build, chain off one of these
1616

1717
<Target Name="Package" DependsOnTargets="PackageProjects;PackSharedSources" />
1818

19-
<Target Name="Test" />
19+
<Target Name="Test" DependsOnTargets="TestProjects" />
2020

2121
<Target Name="Verify" DependsOnTargets="VerifyPackages" />
2222

@@ -54,32 +54,58 @@ as they are subject to change.
5454
Targets: {Target}Solutions
5555
5656
Items: Solutions
57+
Properties: ExcludeSolutions
5758
5859
Executes /t:{Target} on all solutions
5960
###################################################################
6061
-->
61-
<Target Name="CleanSolutions">
62+
<PropertyGroup>
63+
<_SolutionWasBuilt>false</_SolutionWasBuilt>
64+
<!-- ensure its value doesn't invalidate MSBuild build cache -->
65+
<_BuildPropertiesToRemove>$(_BuildPropertiesToRemove);_SolutionWasBuilt</_BuildPropertiesToRemove>
66+
67+
<BuildInParallel>true</BuildInParallel>
68+
</PropertyGroup>
69+
70+
<Target Name="_GetSolutions" Condition="'$(Solutions)'==''">
71+
<ItemGroup>
72+
<Solutions Include="$(RepositoryRoot)\*.sln" Exclude="$(ExcludeSolutions)" />
73+
</ItemGroup>
74+
</Target>
75+
76+
<Target Name="CleanSolutions" DependsOnTargets="_GetSolutions">
6277
<MSBuild Targets="Clean"
6378
Projects="@(Solutions)"
6479
Properties="Configuration=$(Configuration)" />
6580
</Target>
6681

67-
<Target Name="RestoreSolutions">
82+
<Target Name="RestoreSolutions" DependsOnTargets="_GetSolutions">
6883
<MSBuild Targets="Restore"
6984
Projects="@(Solutions)"
7085
Properties="Configuration=$(Configuration)" />
7186
</Target>
7287

73-
<Target Name="BuildSolutions">
88+
<Target Name="BuildSolutions" DependsOnTargets="_GetSolutions">
7489
<MSBuild Targets="Build"
7590
Projects="@(Solutions)"
76-
Properties="Configuration=$(Configuration)" />
91+
Properties="Configuration=$(Configuration)"
92+
BuildInParallel="$(BuildInParallel)"
93+
RemoveProperties="$(_BuildPropertiesToRemove)" />
94+
95+
<PropertyGroup>
96+
<_SolutionWasBuilt>true</_SolutionWasBuilt>
97+
</PropertyGroup>
7798
</Target>
7899

79-
<Target Name="RebuildSolutions">
100+
<Target Name="RebuildSolutions" DependsOnTargets="_GetSolutions">
80101
<MSBuild Targets="Rebuild"
81102
Projects="@(Solutions)"
82-
Properties="Configuration=$(Configuration)" />
103+
Properties="Configuration=$(Configuration)"
104+
RemoveProperties="$(_BuildPropertiesToRemove)" />
105+
106+
<PropertyGroup>
107+
<_SolutionWasBuilt>true</_SolutionWasBuilt>
108+
</PropertyGroup>
83109
</Target>
84110

85111
<!--
@@ -96,9 +122,15 @@ Executes /t:Pack on all projects matching src/*/*.csproj.
96122
<ProjectsToPack Condition="'$(ProjectsToPack)' == ''" Include="$(RepositoryRoot)src\*\*.csproj" />
97123
</ItemGroup>
98124

125+
<PropertyGroup>
126+
<PackageNoBuild Condition="'$(PackageNoBuild)' == ''">$(_SolutionWasBuilt)</PackageNoBuild>
127+
</PropertyGroup>
128+
99129
<MSBuild Targets="Pack"
100130
Projects="@(ProjectsToPack)"
101-
Properties="Configuration=$(Configuration);PackageOutputPath=$(BuildDir);NoBuild=true" />
131+
Properties="Configuration=$(Configuration);PackageOutputPath=$(BuildDir);NoBuild=$(PackageNoBuild)"
132+
BuildInParallel="$(BuildInParallel)"
133+
RemoveProperties="$(_BuildPropertiesToRemove);PackageNoBuild" />
102134
</Target>
103135

104136
<!--
@@ -125,9 +157,58 @@ that matches "$(RepositoryRoot)/shared/*.Sources".
125157
<MSBuild Targets="Pack"
126158
Projects="$(MSBuildThisFileDirectory)..\shared\sharedsources.csproj"
127159
Properties="PackageOutputPath=$(BuildDir);RepositoryRoot=$(RepositoryRoot);NuspecBasePath=%(SharedSourceDirectories.Identity);PackageId=%(FileName)%(Extension)"
128-
Condition="'@(SharedSourceDirectories)'!=''" />
160+
Condition="'@(SharedSourceDirectories)'!=''"
161+
BuildInParallel="$(BuildInParallel)" />
162+
</Target>
163+
164+
<!--
165+
###################################################################
166+
Target: TestProjects
167+
168+
Items: TestProjects. Defaults to test/*/*.csproj
169+
Properties: ExcludeFromTest. ItemSpec for projects to avoid testing.
170+
171+
Runs the VSTest on all projects in the TestProjects itemgroup.
172+
###################################################################
173+
-->
174+
175+
<PropertyGroup>
176+
<!-- TODO if VS Test doesn't make minimal output the default log setting, we can set that here. cref https://github.com/Microsoft/vstest/issues/301 -->
177+
<VSTestLogger Condition=" '$(VSTestLogger)'=='' AND '$(TEAMCITY_VERSION)' != '' ">trx</VSTestLogger>
178+
<IgnoreFailingTestProjects>false</IgnoreFailingTestProjects>
179+
<ContinueOnTestError Condition="'$(KOREBUILD_IGNORE_DOTNET_TEST_EXIT_CODE)' == '1'">true</ContinueOnTestError>
180+
181+
<!-- experimental flag to see if running test projects in parallel works -->
182+
<TestInParallel Condition="'$(TestInParallel)' == ''">false</TestInParallel>
183+
</PropertyGroup>
184+
185+
<Target Name="TestProjects">
186+
187+
<ItemGroup Condition="'@(TestProjects)'==''">
188+
<!-- put unit test projects ahead of functional tests -->
189+
<TestProjects Include="$(RepositoryRoot)test\*\*.Tests.csproj" Exclude="$(ExcludeFromTest)" />
190+
<TestProjects Include="$(RepositoryRoot)test\*\*.Test.csproj" Exclude="$(ExcludeFromTest)" />
191+
<TestProjects Include="$(RepositoryRoot)test\*\*.csproj" Exclude="@(TestProjects);$(ExcludeFromTest)" />
192+
</ItemGroup>
193+
194+
<PropertyGroup>
195+
<VSTestNoBuild Condition="'$(VSTestNoBuild)' == ''">$(_SolutionWasBuilt)</VSTestNoBuild>
196+
<_TestContinueOnError Condition="'$(IgnoreFailingTestProjects)' == 'true'">ErrorAndContinue</_TestContinueOnError>
197+
<_TestContinueOnError Condition="'$(IgnoreFailingTestProjects)' != 'true'">ErrorAndStop</_TestContinueOnError>
198+
</PropertyGroup>
199+
200+
<!-- Intentional use of batching ('%') instead of passing items ('@') so that tests fail sooner -->
201+
<MSBuild Projects="%(TestProjects.Identity)"
202+
Targets="VSTest"
203+
Properties="Configurationf=$(Configuration);VSTestLogger=$(VSTestLogger);VSTestNoBuild=$(VSTestNoBuild)"
204+
Condition="'@(TestProjects)'!=''"
205+
ContinueOnError="$(_TestContinueOnError)"
206+
BuildInParallel="$(TestInParallel)"
207+
RemoveProperties="$(_BuildPropertiesToRemove);_TestContinueOnError" />
208+
129209
</Target>
130210

211+
131212
<!--
132213
###################################################################
133214
Target: VerifyPackages

0 commit comments

Comments
 (0)