Skip to content

Commit

Permalink
add utilities to test whether DefineConstants overlaps with target fr…
Browse files Browse the repository at this point in the history
…amework symbols or not
  • Loading branch information
smdn committed Mar 30, 2022
1 parent 16f2743 commit 607aaae
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,26 @@ SPDX-License-Identifier: MIT
/>
</ItemGroup>
</Target>

<!-- returns value that represents whether the $(Set) overlaps with $(OtherSet) or not -->
<Target Name="TestSetOverlapsWith" Returns="$(OtherSetHasElementWhichIncludedInSet)">
<ItemGroup>
<OtherSetElement Remove="@(OtherSetElement)" />
<OtherSetElement Include="$(OtherSet)" />
<OtherSetElement Update="@(OtherSetElement)">
<IsIncludedInSet>$([System.Text.RegularExpressions.Regex]::IsMatch('$(Set)', '\b%(Identity)\b'))</IsIncludedInSet>
</OtherSetElement>
</ItemGroup>

<Message Text="'$(Set)' contains element '%(OtherSetElement.Identity)' = %(OtherSetElement.IsIncludedInSet)" Importance="low" />

<PropertyGroup>
<OtherSetElementsInclusivities>@(OtherSetElement->Metadata('IsIncludedInSet'), ';')</OtherSetElementsInclusivities>
<OtherSetHasElementWhichIncludedInSet>false</OtherSetHasElementWhichIncludedInSet>
<OtherSetHasElementWhichIncludedInSet Condition="$([System.String]::new('$(OtherSetElementsInclusivities)').Contains('True'))">true</OtherSetHasElementWhichIncludedInSet>
</PropertyGroup>

<Message Text="inclusivities of other set elements: $(OtherSetElementsInclusivities)" Importance="low" />
<Message Text="'$(Set)' overlaps with '$(OtherSet)' = $(OtherSetHasElementWhichIncludedInSet)" Importance="normal" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ SPDX-FileCopyrightText: 2022 smdn <smdn@smdn.jp>
SPDX-License-Identifier: MIT
-->
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(MSBuildThisFileDirectory)\..\..\src\Smdn.MSBuild.DefineConstants.NETSdkApi\build\Smdn.MSBuild.DefineConstants.NETSdkApi.targets" />
<PropertyGroup>
<PackageBuildTargetsFile>$(MSBuildThisFileDirectory)\..\..\src\Smdn.MSBuild.DefineConstants.NETSdkApi\build\Smdn.MSBuild.DefineConstants.NETSdkApi.targets</PackageBuildTargetsFile>
</PropertyGroup>

<Import Project="$(PackageBuildTargetsFile)" />

<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1;netstandard2.1;netstandard2.0;netstandard1.6;net48;net472;net461;net46;net45</TargetFrameworks>
Expand All @@ -12,4 +16,8 @@ SPDX-License-Identifier: MIT
<ItemGroup>
<PackageReference Remove="Smdn.MSBuild.DefineConstants.NETSdkApi" />
</ItemGroup>

<Target Name="RunTests_PackageBuildTargets" BeforeTargets="DispatchToInnerBuilds">
<MSBuild Projects="tests\PackageBuildTargetsTests.proj" Properties="PackageBuildTargetsFile=$(PackageBuildTargetsFile)" Targets="RunTests" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!--
SPDX-FileCopyrightText: 2022 smdn <smdn@smdn.jp>
SPDX-License-Identifier: MIT
-->
<Project>
<Target Name="RunTests">
<CallTarget Targets="RunTestCases_TestSetOverlapsWith" />
<Message Text="$(MSBuildThisFile): all tests passed" Importance="high" />
</Target>

<Target Name="RunTestCases_TestSetOverlapsWith">
<PropertyGroup><Set>A;B;C</Set><OtherSet></OtherSet><ExpectedResult>false</ExpectedResult></PropertyGroup>
<MSBuild Properties="Set=$(Set);OtherSet=$(OtherSet);ExpectedResult=$(ExpectedResult)" Projects="$(MSBuildThisFileFullPath)" Targets="RunTestCase_TestSetOverlapsWith" />

<PropertyGroup><Set>A;B;C</Set><OtherSet>A</OtherSet><ExpectedResult>true</ExpectedResult></PropertyGroup>
<MSBuild Properties="Set=$(Set);OtherSet=$(OtherSet);ExpectedResult=$(ExpectedResult)" Projects="$(MSBuildThisFileFullPath)" Targets="RunTestCase_TestSetOverlapsWith" />

<PropertyGroup><Set>A;B;C</Set><OtherSet>B</OtherSet><ExpectedResult>true</ExpectedResult></PropertyGroup>
<MSBuild Properties="Set=$(Set);OtherSet=$(OtherSet);ExpectedResult=$(ExpectedResult)" Projects="$(MSBuildThisFileFullPath)" Targets="RunTestCase_TestSetOverlapsWith" />

<PropertyGroup><Set>A;B;C</Set><OtherSet>X</OtherSet><ExpectedResult>false</ExpectedResult></PropertyGroup>
<MSBuild Properties="Set=$(Set);OtherSet=$(OtherSet);ExpectedResult=$(ExpectedResult)" Projects="$(MSBuildThisFileFullPath)" Targets="RunTestCase_TestSetOverlapsWith" />

<PropertyGroup><Set>A;B;C</Set><OtherSet>A;B;C</OtherSet><ExpectedResult>true</ExpectedResult></PropertyGroup>
<MSBuild Properties="Set=$(Set);OtherSet=$(OtherSet);ExpectedResult=$(ExpectedResult)" Projects="$(MSBuildThisFileFullPath)" Targets="RunTestCase_TestSetOverlapsWith" />

<PropertyGroup><Set>A;B;C</Set><OtherSet>B;C;A</OtherSet><ExpectedResult>true</ExpectedResult></PropertyGroup>
<MSBuild Properties="Set=$(Set);OtherSet=$(OtherSet);ExpectedResult=$(ExpectedResult)" Projects="$(MSBuildThisFileFullPath)" Targets="RunTestCase_TestSetOverlapsWith" />

<PropertyGroup><Set>A;B;C</Set><OtherSet>A;B;X</OtherSet><ExpectedResult>true</ExpectedResult></PropertyGroup>
<MSBuild Properties="Set=$(Set);OtherSet=$(OtherSet);ExpectedResult=$(ExpectedResult)" Projects="$(MSBuildThisFileFullPath)" Targets="RunTestCase_TestSetOverlapsWith" />

<PropertyGroup><Set>A;B;C</Set><OtherSet>A;X;Y</OtherSet><ExpectedResult>true</ExpectedResult></PropertyGroup>
<MSBuild Properties="Set=$(Set);OtherSet=$(OtherSet);ExpectedResult=$(ExpectedResult)" Projects="$(MSBuildThisFileFullPath)" Targets="RunTestCase_TestSetOverlapsWith" />

<PropertyGroup><Set>A;B;C</Set><OtherSet>A;B;C;D</OtherSet><ExpectedResult>true</ExpectedResult></PropertyGroup>
<MSBuild Properties="Set=$(Set);OtherSet=$(OtherSet);ExpectedResult=$(ExpectedResult)" Projects="$(MSBuildThisFileFullPath)" Targets="RunTestCase_TestSetOverlapsWith" />

<PropertyGroup><Set>A;B;C</Set><OtherSet>X;Y;Z</OtherSet><ExpectedResult>false</ExpectedResult></PropertyGroup>
<MSBuild Properties="Set=$(Set);OtherSet=$(OtherSet);ExpectedResult=$(ExpectedResult)" Projects="$(MSBuildThisFileFullPath)" Targets="RunTestCase_TestSetOverlapsWith" />
</Target>

<Target Name="RunTestCase_TestSetOverlapsWith">
<MSBuild Properties="Set=$(Set);OtherSet=$(OtherSet)" Projects="$(PackageBuildTargetsFile)" Targets="TestSetOverlapsWith" >
<Output TaskParameter="TargetOutputs" PropertyName="ResultTestSetOverlapsWith" />
</MSBuild>
<Error
Text="test failed: Set='$(Set)', OtherSet='$(OtherSet)', Result='$(ResultTestSetOverlapsWith)', Expected='$(ExpectedResult)'"
Condition="'$(ResultTestSetOverlapsWith)' != '$(ExpectedResult)'"
/>
</Target>
</Project>

0 comments on commit 607aaae

Please sign in to comment.