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

Remove TFM parsing from xunit test target #160

Merged
merged 2 commits into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions build/makefile.proj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
<!-- TFM used only for the purpose of restoring build tools. It does not affect the TFM of projects -->
<TargetFramework>netcoreapp1.0</TargetFramework>
<SakeVersion>0.2.2</SakeVersion>

<!--
We want to ensure these properties do not flow into sub-builds.
This group of properties should be specified in RemoveProperties when an MSBuild task is used.
These properties include those that could interfere with inner builds
or could result in an unnecessary build cache miss.
-->
<_BuildPropertiesToRemove>$(_BuildPropertiesToRemove);TargetFramework;TargetFrameworks;LifecycleType;RestoreGraphProjectInput;_InvalidConfigurationWarn;_InvalidConfigurationError</_BuildPropertiesToRemove>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -32,11 +40,6 @@

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

<ItemGroup>
<Solutions Condition="'$(Solutions)'==''"
Include="$(RepositoryRoot)\*.sln" />
</ItemGroup>

<Import Project="$(MSBuildThisFileDirectory)\targets\legacy-lifecycle.targets" Condition="'$(LifecycleType)'=='Legacy'" />
<Import Project="$(MSBuildThisFileDirectory)\targets\standard-lifecycle.targets" Condition="'$(LifecycleType)'=='Standard'" />

Expand Down
45 changes: 0 additions & 45 deletions build/shade/_dotnet-test.shade

This file was deleted.

68 changes: 2 additions & 66 deletions build/shade/_k-standard-goals.shade
Original file line number Diff line number Diff line change
Expand Up @@ -178,69 +178,11 @@ functions
nuget-resilient-publish sourcePackagesDir='${BUILD_DIR}' nugetFeed='${E("NUGET_PUBLISH_FEED")}' if='!string.IsNullOrEmpty(E("NUGET_PUBLISH_FEED"))'
-}

#xunit-test target='test' if='Directory.Exists("test")'
#xunit-test target='test'
@{
var projectFiles = Files.Include(TEST_PROJECT_GLOB);
foreach (var projectFile in projectFiles)
{
var dir = Path.GetDirectoryName(projectFile);
if (File.Exists(Path.Combine(dir, ".notest")))
{
continue;
}

var options = E("KOREBUILD_DOTNET_TEST_OPTIONS");
if (IsTeamCity)
{
// TODO put all trx files in same folder. See https://github.com/Microsoft/vstest/issues/243
// TODO or use TC logger https://github.com/Microsoft/vstest/issues/254
options += " --logger:trx ";
}
// workaround for https://github.com/Microsoft/vstest/issues/283
var txt = File.ReadAllText(projectFile);
var multiTfm = Regex.Match(txt, @"\<TargetFrameworks\>(.+)\<\/TargetFrameworks\>");
var singleTfm = Regex.Match(txt, @"\<TargetFramework\>(.+)\<\/TargetFramework\>");
if (multiTfm != null && multiTfm.Success)
{
var frameworks = multiTfm.Groups[1]
.Value
.Split(new string[] {";"}, StringSplitOptions.RemoveEmptyEntries)
.Select(s => s.Trim())
.ToArray();

foreach (var framework in frameworks)
{
if (IsLinux && framework != null && framework.StartsWith("net4"))
{
Log.Info("Skipping tests for TFM " + framework + " on this platform");
continue;
}

DotnetTest(projectFile, Configuration, options, framework);
}
// end workaround
}
else if(singleTfm != null && singleTfm.Success)
{
var framework = singleTfm.Groups[1].Value;
if (IsLinux && framework != null && framework.StartsWith("net4"))
{
Log.Info("Skipping tests for TFM " + framework + " on this platform");
}
else
{
DotnetTest(projectFile, Configuration, options, framework);
}
}
else
{
// default invocation
DotnetTest(projectFile, Configuration, options);
}
}
MSBuild("/t:Test");
}


#make-roslyn-fast
ngen-roslyn

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

macro name="DotnetTest" projectFile='string' configuration='string' test_options='string'
dotnet-test

macro name="DotnetTest" projectFile='string' configuration='string' test_options='string' framework='string'
dotnet-test

macro name='Npm' npmCommand='string' npmDir='string'
npm

Expand Down
24 changes: 24 additions & 0 deletions build/targets/DefaultItems.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project>
<PropertyGroup>
<SharedSourcesFolder>$(RepositoryRoot)shared/</SharedSourcesFolder>
</PropertyGroup>

<!-- DisableDefaultItems only when you really want to control what is built and tested. Otherwise, use the Exclude* item groups -->
<ItemGroup Condition="'$(DisableDefaultItems)' != 'true'">
<Solutions Include="$(RepositoryRoot)\*.sln" />
<Solutions Remove="@(ExcludeSolutions)" />

<ProjectsToPack Include="$(RepositoryRoot)src\*\*.csproj" />
<ProjectsToPack Remove="@(ExcludeFromPack)" />

<SharedSourceDirectories Include="$([System.IO.Directory]::GetDirectories(&quot;$(SharedSourcesFolder)&quot;, '*.Sources'))" Condition="Exists('$(SharedSourcesFolder)')" />
<SharedSourceDirectories Remove="@(ExcludeSharedSourceDirectories)" />

<!-- put unit test projects ahead of functional tests -->
<_FunctionalTests Include="$(RepositoryRoot)test\*\*FunctionalTest*.csproj" />
<ProjectsToTest Include="$(RepositoryRoot)test\*\*.csproj" Exclude="@(_FunctionalTests)" />
<ProjectsToTest Include="@(_FunctionalTests)" />
<ProjectsToTest Remove="@(ExcludeFromTest)" />
</ItemGroup>

</Project>
131 changes: 104 additions & 27 deletions build/targets/standard-lifecycle.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<Project>

<Import Project="DefaultItems.targets" />

<!--
###################################################################
Standard lifecycle targets.
Expand All @@ -16,7 +18,7 @@ When extending the solution build, chain off one of these

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

<Target Name="Test" />
<Target Name="Test" DependsOnTargets="TestProjects" />

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

Expand Down Expand Up @@ -54,32 +56,60 @@ as they are subject to change.
Targets: {Target}Solutions

Items: Solutions
Properties: ExcludeSolutions

Executes /t:{Target} on all solutions
###################################################################
-->
<Target Name="CleanSolutions">
<PropertyGroup>
<_SolutionWasBuilt>false</_SolutionWasBuilt>
<!-- ensure its value doesn't invalidate MSBuild build cache -->
<_BuildPropertiesToRemove>$(_BuildPropertiesToRemove);_SolutionWasBuilt</_BuildPropertiesToRemove>

<BuildInParallel>true</BuildInParallel>
</PropertyGroup>

<Target Name="_ResolveSolutions">
<RemoveDuplicates Inputs="@(Solutions)">
<Output TaskParameter="Filtered" ItemName="_SolutionItems" />
</RemoveDuplicates>

<Error Text="No solutions found to build" Condition="'@(_SolutionItems)' == ''" />
</Target>

<Target Name="CleanSolutions" DependsOnTargets="_ResolveSolutions">
<MSBuild Targets="Clean"
Projects="@(Solutions)"
Projects="@(_SolutionItems)"
Properties="Configuration=$(Configuration)" />
</Target>

<Target Name="RestoreSolutions">
<Target Name="RestoreSolutions" DependsOnTargets="_ResolveSolutions">
<MSBuild Targets="Restore"
Projects="@(Solutions)"
Projects="@(_SolutionItems)"
Properties="Configuration=$(Configuration)" />
</Target>

<Target Name="BuildSolutions">
<Target Name="BuildSolutions" DependsOnTargets="_ResolveSolutions">
<MSBuild Targets="Build"
Projects="@(Solutions)"
Properties="Configuration=$(Configuration)" />
Projects="@(_SolutionItems)"
Properties="Configuration=$(Configuration)"
BuildInParallel="$(BuildInParallel)"
RemoveProperties="$(_BuildPropertiesToRemove)" />

<PropertyGroup>
<_SolutionWasBuilt>true</_SolutionWasBuilt>
</PropertyGroup>
</Target>

<Target Name="RebuildSolutions">
<Target Name="RebuildSolutions" DependsOnTargets="_ResolveSolutions">
<MSBuild Targets="Rebuild"
Projects="@(Solutions)"
Properties="Configuration=$(Configuration)" />
Projects="@(_SolutionItems)"
Properties="Configuration=$(Configuration)"
RemoveProperties="$(_BuildPropertiesToRemove)" />

<PropertyGroup>
<_SolutionWasBuilt>true</_SolutionWasBuilt>
</PropertyGroup>
</Target>

<!--
Expand All @@ -92,13 +122,22 @@ Executes /t:Pack on all projects matching src/*/*.csproj.
<Target Name="PackageProjects">
<!-- TODO consider using GeneratePackageOnBuild or calling Pack on the solution.
This would require setting IsPackable=false and samples and possible on tests (see https://github.com/NuGet/NuGet.Client/pull/1170) -->
<ItemGroup>
<ProjectsToPack Condition="'$(ProjectsToPack)' == ''" Include="$(RepositoryRoot)src\*\*.csproj" />
</ItemGroup>
<RemoveDuplicates Inputs="@(ProjectsToPack)">
<Output TaskParameter="Filtered" ItemName="_PackProjectItems" />
</RemoveDuplicates>

<PropertyGroup>
<!-- TODO remove when we stop using Sake. Because Sake invokes the project multiple times, so this value is always false -->
<!--<PackageNoBuild Condition="'$(PackageNoBuild)' == ''">$(_SolutionWasBuilt)</PackageNoBuild>-->
<PackageNoBuild>true</PackageNoBuild>
</PropertyGroup>

<MSBuild Targets="Pack"
Projects="@(ProjectsToPack)"
Properties="Configuration=$(Configuration);PackageOutputPath=$(BuildDir);NoBuild=true" />
Projects="@(_PackProjectItems)"
Condition="'@(_PackProjectItems)' != ''"
Properties="Configuration=$(Configuration);PackageOutputPath=$(BuildDir);NoBuild=$(PackageNoBuild)"
BuildInParallel="$(BuildInParallel)"
RemoveProperties="$(_BuildPropertiesToRemove);PackageNoBuild" />
</Target>

<!--
Expand All @@ -109,23 +148,61 @@ Creates a content files package for all each directory in
that matches "$(RepositoryRoot)/shared/*.Sources".
###################################################################
-->
<PropertyGroup>
<SharedSourcesFolder>$(RepositoryRoot)shared/</SharedSourcesFolder>
</PropertyGroup>

<Target Name="PackSharedSources" Condition="Exists('$(SharedSourcesFolder)') OR '@(SharedSourceDirectories)' != ''">
<ItemGroup Condition="'@(SharedSourceDirectories)' == '' AND Exists('$(SharedSourcesFolder)')">
<SharedSourceDirectories Include="$([System.IO.Directory]::GetDirectories(&quot;$(SharedSourcesFolder)&quot;, '*.Sources'))" />
</ItemGroup>
<RemoveDuplicates Inputs="@(SharedSourceDirectories)">
<Output TaskParameter="Filtered" ItemName="_SharedSourceItems" />
</RemoveDuplicates>

<Message Importance="normal"
Text="Producing shared source package for %(SharedSourceDirectories.Identity)"
Condition="'@(SharedSourceDirectories)'!=''" />
Text="Producing shared source package for %(_SharedSourceItems.Identity)"
Condition="'@(_SharedSourceItems)' != ''" />

<MSBuild Targets="Pack"
Projects="$(MSBuildThisFileDirectory)..\shared\sharedsources.csproj"
Properties="PackageOutputPath=$(BuildDir);RepositoryRoot=$(RepositoryRoot);NuspecBasePath=%(SharedSourceDirectories.Identity);PackageId=%(FileName)%(Extension)"
Condition="'@(SharedSourceDirectories)'!=''" />
Properties="PackageOutputPath=$(BuildDir);RepositoryRoot=$(RepositoryRoot);NuspecBasePath=%(_SharedSourceItems.Identity);PackageId=%(FileName)%(Extension)"
Condition="'@(_SharedSourceItems)' != ''"
BuildInParallel="$(BuildInParallel)" />
</Target>

<!--
###################################################################
Target: TestProjects

Items: ProjectsToTest. Defaults to test/*/*.csproj
Properties: ExcludeFromTest. ItemSpec for projects to avoid testing.

Runs the VSTest on all projects in the ProjectsToTest itemgroup.
###################################################################
-->

<PropertyGroup>
<!-- 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 -->
<VSTestLogger Condition=" '$(VSTestLogger)' == '' AND '$(TEAMCITY_VERSION)' != '' ">trx</VSTestLogger>
<IgnoreFailingTestProjects>false</IgnoreFailingTestProjects>
<IgnoreFailingTestProjects Condition="'$(KOREBUILD_IGNORE_DOTNET_TEST_EXIT_CODE)' == '1'">true</IgnoreFailingTestProjects>
</PropertyGroup>

<Target Name="TestProjects">
<RemoveDuplicates Inputs="@(ProjectsToTest)">
<Output TaskParameter="Filtered" ItemName="_TestProjectItems" />
</RemoveDuplicates>

<Message Text="Running tests for:%0A@(_TestProjectItems -> '%(FileName)','%0A')" Importance="High" />

<PropertyGroup>
<VSTestNoBuild Condition="'$(VSTestNoBuild)' == ''">$(_SolutionWasBuilt)</VSTestNoBuild>
<_TestContinueOnError Condition="'$(IgnoreFailingTestProjects)' == 'true'">ErrorAndContinue</_TestContinueOnError>
<_TestContinueOnError Condition="'$(IgnoreFailingTestProjects)' != 'true'">ErrorAndStop</_TestContinueOnError>
</PropertyGroup>

<!-- Intentional use of batching ('%') instead of passing items ('@') so that tests fail sooner -->
<MSBuild Projects="%(_TestProjectItems.Identity)"
Targets="VSTest"
Properties="Configurationf=$(Configuration);VSTestLogger=$(VSTestLogger);VSTestNoBuild=$(VSTestNoBuild)"
Condition="'@(_TestProjectItems)' != ''"
ContinueOnError="$(_TestContinueOnError)"
RemoveProperties="$(_BuildPropertiesToRemove);_TestContinueOnError" />

</Target>

<!--
Expand Down