Repository navigation
Expand file tree
/
Copy pathConditionalTests.targets
More file actions
53 lines (47 loc) · 3.57 KB
/
Copy pathConditionalTests.targets
File metadata and controls
53 lines (47 loc) · 3.57 KB
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
<!-- Targets for removing test projects based on SkippedTestScopes.
Imported by UnitTests.proj (production) and test assets (testing).
Prerequisites:
- $(RepoRoot) must be set (used for glob expansion and to locate ConditionalTests.props)
- SDKCustomTestProject items must exist
- $(SkippedTestScopes) controls which scopes are filtered
How SkippedTestScopes is set:
- scripts/EvaluateConditionalTestScopes.cs runs in CI and outputs scope names to skip
- "__all__" means all conditional projects are removed
- Empty (local dev, script failure, or global trigger match) means all tests run -->
<Project>
<Import Project="$(RepoRoot)test\ConditionalTests.props" />
<!-- _CollectSkippedTestProjects uses target batching (Outputs="%(...)") to iterate over
ConditionalTestScope items. For each scope that matches SkippedTestScopes, it prepends
$(RepoRoot) to the relative TestProjects paths and includes them as glob patterns.
Target batching is needed because MSBuild cannot resolve metadata references inside
property functions in ItemGroup conditions. -->
<Target Name="_CollectSkippedTestProjects" Outputs="%(ConditionalTestScope.Identity)" Condition="'$(SkippedTestScopes)' != ''">
<PropertyGroup>
<!-- The pipeline passes a '|'-separated list (see EvaluateConditionalTestScopes.cs); normalize
it to ';' here. This must be in the target, not a static <PropertyGroup>, because
SkippedTestScopes is a global /p: property that a project-level assignment can't override. -->
<_NormalizedSkippedScopes>$(SkippedTestScopes.Replace('|',';'))</_NormalizedSkippedScopes>
<_CurrentScope>%(ConditionalTestScope.Identity)</_CurrentScope>
<_CurrentTestProjects>%(ConditionalTestScope.TestProjects)</_CurrentTestProjects>
<_CurrentMechanism>%(ConditionalTestScope.Mechanism)</_CurrentMechanism>
<_ShouldSkip Condition="'$(_CurrentMechanism)' == 'project' and ('$(_NormalizedSkippedScopes)' == '__all__' or $([System.String]::Concat(';','$(_NormalizedSkippedScopes)',';').Contains(';$(_CurrentScope);')))">true</_ShouldSkip>
<_ShouldSkip Condition="'$(_ShouldSkip)' != 'true'">false</_ShouldSkip>
<!-- Prepend $(RepoRoot) to each semicolon-separated relative path for glob resolution.
Replace() escapes semicolons internally, so Unescape restores them for item splitting. -->
<_AbsoluteTestProjects Condition="'$(_ShouldSkip)' == 'true'">$(RepoRoot)$(_CurrentTestProjects.Replace(';',';$(RepoRoot)'))</_AbsoluteTestProjects>
<_AbsoluteTestProjects Condition="'$(_ShouldSkip)' == 'true'">$([MSBuild]::Unescape('$(_AbsoluteTestProjects)'))</_AbsoluteTestProjects>
</PropertyGroup>
<ItemGroup Condition="'$(_ShouldSkip)' == 'true'">
<SkippedTestProject Include="$(_AbsoluteTestProjects)" />
</ItemGroup>
</Target>
<Target Name="RemoveSkippedConditionalTestProjects" BeforeTargets="CreateSDKCustomTestWorkItems" DependsOnTargets="_CollectSkippedTestProjects" Condition="'$(SkippedTestScopes)' != ''">
<ItemGroup>
<!-- MatchOnMetadata="FullPath" with PathLike ensures removal works regardless of whether
the SDKCustomTestProject identity is a relative or absolute path, using OS-appropriate
path comparison (case-insensitive on Windows). -->
<SDKCustomTestProject Remove="@(SkippedTestProject)" MatchOnMetadata="FullPath" MatchOnMetadataOptions="PathLike" />
</ItemGroup>
<Message Importance="normal" Text="Conditional test filtering applied (SkippedTestScopes: $(SkippedTestScopes))" />
</Target>
</Project>