Add validation target to avoid losing test coverage with merged test wrappers (#66951)
authorJeremy Koritzinsky <jekoritz@microsoft.com>
Tue, 22 Mar 2022 00:12:23 +0000 (17:12 -0700)
committerGitHub <noreply@github.com>
Tue, 22 Mar 2022 00:12:23 +0000 (17:12 -0700)
Co-authored-by: Bruce Forstall <brucefo@microsoft.com>
src/tests/Common/mergedrunner.targets [new file with mode: 0644]
src/tests/Directory.Build.targets

diff --git a/src/tests/Common/mergedrunner.targets b/src/tests/Common/mergedrunner.targets
new file mode 100644 (file)
index 0000000..8d67c62
--- /dev/null
@@ -0,0 +1,16 @@
+<Project>
+  <Target Name="_ValidateNoTestProjectsDroppedByConflictResolution" AfterTargets="ResolveReferences">
+    <ItemGroup>
+      <_ProjectReferencesUsedByReferencePaths Include="@(ReferencePath->Metadata('ProjectReferenceOriginalItemSpec'))" />
+      <_ProjectAssemblyReferences Include="@(ProjectReference)" Condition="'%(ProjectReference.OutputItemType)' == ''" />
+      <_ProjectReferencesRemovedDueToConflictResolution Include="@(_ProjectAssemblyReferences)" Exclude="@(_ProjectReferencesUsedByReferencePaths)" />
+    </ItemGroup>
+    <!--
+      Produce an error if any project references were removed due to conflict resolution.
+      If a ProjectReference is removed due to conflict resolution, then we're likely losing test coverage as it's probably a test that has the same assembly name and version as another test.
+    -->
+    <Error Text="@(_ProjectReferencesRemovedDueToConflictResolution->'This project has an assembly name identical to another project: %(FullPath)', '&#010;')" Condition="'@(_ProjectReferencesRemovedDueToConflictResolution)' != ''"  />
+  </Target>
+  
+  <Import Project="$(RepoRoot)/src/tests/Common/mergedrunnermobile.targets" Condition="'$(TargetsMobile)' == 'true'" />
+</Project>
\ No newline at end of file
index 83fc083..bc9091d 100644 (file)
   <Import Project="$(RepoRoot)/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.props" />
   <Import Project="$(RepoRoot)eng/liveBuilds.targets" />
   <Import Project="$(MSBuildProjectFullPath).targets" Condition="Exists('$(MSBuildProjectFullPath).targets')"/>
-  <Import Project="$(RepoRoot)/src/tests/Common/mergedrunnermobile.targets" Condition="'$(IsMergedTestRunnerAssembly)' == 'true' and '$(TargetsMobile)' == 'true'" />
+  <Import Project="$(RepoRoot)/src/tests/Common/mergedrunner.targets" Condition="'$(IsMergedTestRunnerAssembly)' == 'true'" />
 
   <Target Name="GetBinPlaceTargetFramework" />