diff options
author | Tarek Mahmoud Sayed <tarekms@microsoft.com> | 2016-07-01 19:44:44 +0300 |
---|---|---|
committer | Tarek Mahmoud Sayed <tarekms@microsoft.com> | 2016-07-01 19:44:44 +0300 |
commit | 3e714b8b1efe68c693469b6cab7883ff8a1b51d8 (patch) | |
tree | 735c711f52be324ea6f7b9115f0f7f20223f64be /dir.traversal.targets | |
parent | 9e253430aea9b8d2420266183d479201af8ec505 (diff) |
Support filtering to TestTFM
This change is to support filtering according to the TestTFM. e.g. can do
“build.cmd /p:FilterToTestTFM=net46”
The change here is splitting the Build phase from the Test phase in dir.traversal.targets
so we don’t have to rebuild the test assemblies when passing TestTFM property to run the test.
Now if FilterToTestTFM is not specified, we default running the tests as netcoreapp1.0
so when issuing “build.cmd/sh” Command without passing FilterToTestTFM, it will
filter the tests to netcoreapp1.0 and run those tests.
I have enabled one of the test projects System.AppContext.Tests to support net46
as example, next step will be Enabling the rest of all projects to run against all
platforms (net46, net461, net462, netcore50 and netcore50aot)
Diffstat (limited to 'dir.traversal.targets')
-rw-r--r-- | dir.traversal.targets | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/dir.traversal.targets b/dir.traversal.targets index 4632cab829..1047fc87eb 100644 --- a/dir.traversal.targets +++ b/dir.traversal.targets @@ -39,7 +39,7 @@ <UndefineProperties Condition="'%(Project.OSGroup)'==''">%(Project.UndefineProperties);OSGroup</UndefineProperties> </Project> <Project> - <UndefineProperties Condition="'%(Project.Extension)'!='.builds' and '%(Project.Extension)'!='.proj'">%(Project.UndefineProperties);FilterToOSGroup;DefaultBuildAllTarget;SerializeProjects;BuildAllOSGroups</UndefineProperties> + <UndefineProperties Condition="'%(Project.Extension)'!='.builds' and '%(Project.Extension)'!='.proj'">%(Project.UndefineProperties);FilterToOSGroup;FilterToTestTFM;DefaultBuildAllTarget;SerializeProjects;BuildAllOSGroups</UndefineProperties> </Project> </ItemGroup> @@ -110,6 +110,71 @@ <Error Condition="'$(MSBuildLastTaskResult)'=='false'" /> </Target> + <!-- FilterProjectsToTest will filter the project list according to the FilterToTestTFM value --> + <Target Name="FilterProjectsToTest" + BeforeTargets="TestAllProjects" + Condition="$(MSBuildProjectName.EndsWith('.Tests'))"> + + <PropertyGroup> + <!-- we default FilterToTestTFM to netcoreapp1.0 if it is not explicity defined --> + <FilterToTestTFM Condition="'$(FilterToTestTFM)'==''">netcoreapp1.0</FilterToTestTFM> + </PropertyGroup> + + <ItemGroup> + <Project> + <!-- make sure every defined TestTFM value are surrounded by semicolons for easier search, e.g. ";net46;"" --> + <TestTFMs Condition="'%(Project.TestTFMs)' != ''">;%(Project.TestTFMs);</TestTFMs> + </Project> + + <!-- for projects not defining TestTFM in .builds files, we assume the TestTFM is the default which is netcoreapp1.0 --> + <ProjectsToTest Include="@(Project)" Condition="'%(Project.Extension)'=='.csproj' And '$(FilterToTestTFM)' == 'netcoreapp1.0' And '%(Project.TestTFMs)' == ''" /> + + <!-- include the projects have TestTFM value match FilterToTestTFM --> + <ProjectsToTest Include="@(Project)" Condition="'%(Project.Extension)'=='.csproj' And $([System.String]::new('%(Project.TestTFMs)').Contains(';$(FilterToTestTFM);'))" /> + + <!-- For net46 we include projects with TestTFM values net461 and net462 --> + <ProjectsToTest Include="@(Project)" Condition="'%(Project.Extension)'=='.csproj' And '$(FilterToTestTFM)' == 'net46' And $([System.String]::new('%(Project.TestTFMs)').Contains(';net461;'))" /> + <ProjectsToTest Include="@(Project)" Condition="'%(Project.Extension)'=='.csproj' And '$(FilterToTestTFM)' == 'net46' And $([System.String]::new('%(Project.TestTFMs)').Contains(';net462;'))" /> + <!-- For net461 we include projects with TestTFM values net462 --> + <ProjectsToTest Include="@(Project)" Condition="'%(Project.Extension)'=='.csproj' And '$(FilterToTestTFM)' == 'net461' And $([System.String]::new('%(Project.TestTFMs)').Contains(';net462;'))" /> + + <ProjectsToTest> + <AdditionalProperties Condition="'%(ProjectsToTest.TestTFMs)'!=''">TestTFMs=%(ProjectsToTest.TestTFMs);%(ProjectsToTest.AdditionalProperties)</AdditionalProperties> + <AdditionalProperties>TestTFM=$(FilterToTestTFM);%(ProjectsToTest.AdditionalProperties)</AdditionalProperties> + </ProjectsToTest> + <ProjectsToTest> + <FilterToTestTFM>$(FilterToTestTFM)</FilterToTestTFM> + </ProjectsToTest> + <ProjectsToTest> + <AdditionalProperties Condition="'%(ProjectsToTest.FilterToTestTFM)'!=''">FilterToTestTFM=%(ProjectsToTest.FilterToTestTFM);%(ProjectsToTest.AdditionalProperties)</AdditionalProperties> + </ProjectsToTest> + </ItemGroup> + </Target> + + <!-- TestAllProjects will run all tests according to TestTFM value we are filtering with --> + <Target Name="TestAllProjects" + AfterTargets="BuildAllProjects" + Condition="$(MSBuildProjectName.EndsWith('.Tests'))"> + <!-- To Serialize we use msbuild's batching functionality '%' to force it to batch all similar projects with the same identity + however since the project names are unique it will essentially force each to run in its own batch --> + + <MSBuild Targets="PrepareForRun;Test" + Projects="@(ProjectsToTest)" + Condition="'$(SerializeProjects)'=='true' AND '%(Identity)' != ''" + Properties="DefaultBuildAllTarget=$(DefaultBuildAllTarget);BuildAllProjects=true" + ContinueOnError="ErrorAndContinue" /> + + <MSBuild Targets="PrepareForRun;Test" + Projects="@(ProjectsToTest)" + Condition="'$(SerializeProjects)'!='true'" + Properties="DefaultBuildAllTarget=$(DefaultBuildAllTarget);BuildAllProjects=true" + BuildInParallel="true" + ContinueOnError="ErrorAndContinue" /> + + <!-- Given we ErrorAndContinue we need to propagate the error if the overall task failed --> + <Error Condition="'$(MSBuildLastTaskResult)'=='false'" /> + </Target> + <Target Name="GetFilesToPackage" DependsOnTargets="FilterProjects" Returns="@(FilesToPackage)"> <MSBuild Targets="GetFilesToPackage" |