Skip to content

Commit 227562f

Browse files
committed
Add integration test suite for group conditions
1 parent 3ac6f2e commit 227562f

30 files changed

+1650
-502
lines changed

.paket/Paket.Restore.targets

Lines changed: 497 additions & 500 deletions
Large diffs are not rendered by default.
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
module Paket.IntegrationTests.ConditionSpecs
2+
3+
open System.Text.RegularExpressions
4+
open Fake
5+
open System
6+
open NUnit.Framework
7+
open FsUnit
8+
open System
9+
open System.IO
10+
open System.Diagnostics
11+
open Paket
12+
open Paket.Domain
13+
14+
let preparePackages workingDir =
15+
let packagesDir = workingDir @@ "Packages"
16+
17+
[1..5]
18+
|> List.filter (fun v -> fileExists (workingDir @@ "Packages" @@ $"PaketTest2394.PackageA.%d{v}.0.0.nupkg") |> not)
19+
|> List.map (fun v -> directDotnet false $"pack -o . -p:Version=%d{v}.0" packagesDir)
20+
|> ignore
21+
22+
let private shouldIncludeVersionedString (pattern: string) (version: int) (inputs: string seq) =
23+
let expected = pattern.Replace("XX", version.ToString())
24+
let regex = $"""^%s{Regex.Escape(pattern).Replace("XX", "(\d)")}$"""
25+
26+
inputs
27+
|> Seq.filter (fun input -> Regex.IsMatch(input, regex))
28+
|> Seq.iter (fun input -> Assert.That(input, Is.EqualTo expected))
29+
30+
let private shouldIncludePackageA v i = shouldIncludeVersionedString "PackageA XX.0" v i
31+
let private shouldIncludePackageB v i = shouldIncludeVersionedString "PackageB XX.0 (references PackageB.Transient XX.0)" v i
32+
let private shouldIncludePackageBTransient v i = shouldIncludeVersionedString "PackageB.Transient XX.0" v i
33+
let private shouldIncludeConstant v i = shouldIncludeVersionedString "Constant PACKAGEA_XX set" v i
34+
35+
[<Test>]
36+
let ``#2394 default group with no condition`` () =
37+
let scenario = "i002394-group-conditions"
38+
preparePackages (originalScenarioPath scenario)
39+
40+
use __ = prepare scenario
41+
let root = scenarioTempPath scenario
42+
let projectDir = root @@ "TestProjects"
43+
44+
directPaketInPath "install" projectDir |> ignore
45+
let output = directDotnet false "run --project MainGroup.fsproj" projectDir |> Seq.map (_.Message)
46+
directDotnet false "pack MainGroup.fsproj -o ." projectDir |> ignore
47+
48+
output |> shouldIncludePackageA 1
49+
output |> shouldIncludePackageB 1
50+
output |> shouldIncludePackageBTransient 1
51+
output |> shouldIncludeConstant 1
52+
53+
let nupkgPath = projectDir @@ "MainGroup.1.0.0.nupkg"
54+
55+
if File.Exists nupkgPath |> not then Assert.Fail $"Expected '%s{nupkgPath}' to exist"
56+
let nuspec = NuGetCache.getNuSpecFromNupkg nupkgPath
57+
let dependencies = nuspec.Dependencies.Value
58+
|> List.map (fun (n, v, _) -> n.Name, v.Range.ToString())
59+
60+
let expected = [("PaketTest2394.PackageA", ">= 1.0 < 2.0"); ("PaketTest2394.PackageB", ">= 1.0 < 2.0")]
61+
Assert.That(dependencies, Is.SupersetOf expected)
62+
63+
[<Test>]
64+
let ``#2394 alternate group with no condition`` () =
65+
let scenario = "i002394-group-conditions"
66+
preparePackages (originalScenarioPath scenario)
67+
68+
use __ = prepare scenario
69+
let root = scenarioTempPath scenario
70+
let projectDir = root @@ "TestProjects"
71+
72+
directPaketInPath "install" projectDir |> ignore
73+
let output = directDotnet false "run --project NonConditionalGroup.fsproj" projectDir |> Seq.map (_.Message)
74+
directDotnet false "pack NonConditionalGroup.fsproj -o ." projectDir |> ignore
75+
76+
output |> shouldIncludePackageA 2
77+
output |> shouldIncludePackageB 2
78+
output |> shouldIncludePackageBTransient 2
79+
output |> shouldIncludeConstant 2
80+
81+
let nupkgPath = projectDir @@ "NonConditionalGroup.1.0.0.nupkg"
82+
83+
if File.Exists nupkgPath |> not then Assert.Fail $"Expected '%s{nupkgPath}' to exist"
84+
let nuspec = NuGetCache.getNuSpecFromNupkg nupkgPath
85+
let dependencies = nuspec.Dependencies.Value
86+
|> List.map (fun (n, v, _) -> n.Name, v.Range.ToString())
87+
88+
let expected = [("PaketTest2394.PackageA", ">= 2.0 < 3.0"); ("PaketTest2394.PackageB", ">= 2.0 < 3.0")]
89+
Assert.That(dependencies, Is.SupersetOf expected)
90+
91+
[<Test>]
92+
let ``#2394 group with fixed property condition`` () =
93+
let scenario = "i002394-group-conditions"
94+
preparePackages (originalScenarioPath scenario)
95+
96+
use __ = prepare scenario
97+
let root = scenarioTempPath scenario
98+
let projectDir = root @@ "TestProjects"
99+
100+
directPaketInPath "install" projectDir |> ignore
101+
let output = directDotnet false "run --project FixedProperty.fsproj" projectDir |> Seq.map (_.Message)
102+
directDotnet false "pack FixedProperty.fsproj -o ." projectDir |> ignore
103+
104+
output |> shouldIncludePackageA 3
105+
output |> shouldIncludePackageB 3
106+
output |> shouldIncludePackageBTransient 3
107+
output |> shouldIncludeConstant 3
108+
109+
let nupkgPath = projectDir @@ "FixedProperty.1.0.0.nupkg"
110+
111+
if File.Exists nupkgPath |> not then Assert.Fail $"Expected '%s{nupkgPath}' to exist"
112+
let nuspec = NuGetCache.getNuSpecFromNupkg nupkgPath
113+
let dependencies = nuspec.Dependencies.Value
114+
|> List.map (fun (n, v, _) -> n.Name, v.Range.ToString())
115+
116+
let expected = [("PaketTest2394.PackageA", ">= 3.0 < 4.0"); ("PaketTest2394.PackageB", ">= 3.0 < 4.0")]
117+
Assert.That(dependencies, Is.SupersetOf expected)
118+
119+
[<Test>]
120+
let ``#2394 mix dependencies from multiple groups with conditions`` () =
121+
let scenario = "i002394-group-conditions"
122+
preparePackages (originalScenarioPath scenario)
123+
124+
use __ = prepare scenario
125+
let root = scenarioTempPath scenario
126+
let projectDir = root @@ "TestProjects"
127+
128+
directPaketInPath "install" projectDir |> ignore
129+
let output = directDotnet false "run --project MixedProperties.fsproj" projectDir |> Seq.map (_.Message)
130+
directDotnet false "pack MixedProperties.fsproj -o ." projectDir |> ignore
131+
132+
output |> shouldIncludePackageA 4
133+
output |> shouldIncludePackageB 5
134+
output |> shouldIncludePackageBTransient 5
135+
output |> shouldIncludeConstant 4
136+
137+
let expected = ["PackageA 4.0"; "PackageB 5.0 (references PackageB.Transient 5.0)"; "PackageB.Transient 5.0"; "Constant PACKAGEA_4 set"]
138+
let rejected = ["PackageA 1.0"; "PackageB.Transient 1.0"; "Constant PACKAGEA_1 set"
139+
"PackageA 2.0"; "PackageB.Transient 2.0"; "Constant PACKAGEA_2 set"
140+
"PackageA 3.0"; "PackageB.Transient 3.0"; "Constant PACKAGEA_3 set"
141+
"PackageA 5.0"; "PackageB.Transient 4.0"; "Constant PACKAGEA_5 set"]
142+
Assert.That(output, Is.SupersetOf expected)
143+
Assert.That(output, Is.Not.SubsetOf rejected)
144+
145+
let nupkgPath = projectDir @@ "MixedProperties.1.0.0.nupkg"
146+
147+
if File.Exists nupkgPath |> not then Assert.Fail $"Expected '%s{nupkgPath}' to exist"
148+
let nuspec = NuGetCache.getNuSpecFromNupkg nupkgPath
149+
let dependencies = nuspec.Dependencies.Value
150+
|> List.map (fun (n, v, _) -> n.Name, v.Range.ToString())
151+
152+
let expected = [("PaketTest2394.PackageA", ">= 4.0 < 5.0"); ("PaketTest2394.PackageB", ">= 5.0 < 6.0")]
153+
Assert.That(dependencies, Is.SupersetOf expected)
154+
155+
[<Test>]
156+
let ``#2394 project with dynamic condition based on configuration 1`` () =
157+
let scenario = "i002394-group-conditions"
158+
preparePackages (originalScenarioPath scenario)
159+
160+
use __ = prepare scenario
161+
let root = scenarioTempPath scenario
162+
let projectDir = root @@ "TestProjects"
163+
164+
directPaketInPath "install" projectDir |> ignore
165+
let output = directDotnet false "run --project ConfigurationDependent.fsproj" projectDir |> Seq.map (_.Message)
166+
directDotnet false "pack ConfigurationDependent.fsproj -o ." projectDir |> ignore
167+
168+
output |> shouldIncludePackageA 3
169+
output |> shouldIncludePackageB 3
170+
output |> shouldIncludePackageBTransient 3
171+
output |> shouldIncludeConstant 3
172+
173+
let nupkgPath = projectDir @@ "ConfigurationDependent.1.0.0.nupkg"
174+
175+
if File.Exists nupkgPath |> not then Assert.Fail $"Expected '%s{nupkgPath}' to exist"
176+
let nuspec = NuGetCache.getNuSpecFromNupkg nupkgPath
177+
let dependencies = nuspec.Dependencies.Value
178+
|> List.map (fun (n, v, _) -> n.Name, v.Range.ToString())
179+
180+
let expected = [("PaketTest2394.PackageA", ">= 3.0 < 4.0"); ("PaketTest2394.PackageB", ">= 3.0 < 4.0")]
181+
Assert.That(dependencies, Is.SupersetOf expected)
182+
183+
[<Test>]
184+
let ``#2394 project with dynamic condition based on configuration 2`` () =
185+
let scenario = "i002394-group-conditions"
186+
preparePackages (originalScenarioPath scenario)
187+
188+
use __ = prepare scenario
189+
let root = scenarioTempPath scenario
190+
let projectDir = root @@ "TestProjects"
191+
192+
directPaketInPath "install" projectDir |> ignore
193+
let output = directDotnet false "run --project ConfigurationDependent.fsproj --configuration Alternate" projectDir |> Seq.map (_.Message)
194+
directDotnet false "pack ConfigurationDependent.fsproj --configuration Alternate -o ." projectDir |> ignore
195+
196+
output |> shouldIncludePackageA 4
197+
output |> shouldIncludePackageB 4
198+
output |> shouldIncludePackageBTransient 4
199+
output |> shouldIncludeConstant 4
200+
201+
let nupkgPath = projectDir @@ "ConfigurationDependent.1.0.0.nupkg"
202+
203+
if File.Exists nupkgPath |> not then Assert.Fail $"Expected '%s{nupkgPath}' to exist"
204+
let nuspec = NuGetCache.getNuSpecFromNupkg nupkgPath
205+
let dependencies = nuspec.Dependencies.Value
206+
|> List.map (fun (n, v, _) -> n.Name, v.Range.ToString())
207+
208+
let expected = [("PaketTest2394.PackageA", ">= 4.0 < 5.0"); ("PaketTest2394.PackageB", ">= 4.0 < 5.0")]
209+
Assert.That(dependencies, Is.SupersetOf expected)

integrationtests/Paket.IntegrationTests/Paket.IntegrationTests.fsproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<None Include="paket.references" />
4141
<Content Include="App.config" />
4242
<Compile Include="AddGithubSpecs.fs" />
43+
<Compile Include="ConditionSpecs.fs" />
4344
</ItemGroup>
4445
<ItemGroup>
4546
<ProjectReference Include="..\..\src\Paket.Core\Paket.Core.fsproj" />
@@ -51,4 +52,4 @@
5152
</Reference>
5253
</ItemGroup>
5354
<Import Project="..\..\.paket\Paket.Restore.targets" />
54-
</Project>
55+
</Project>

integrationtests/Paket.IntegrationTests/TestHelper.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ open System
1010
open System.IO
1111
open Paket.Logging
1212

13-
let disableScenarioCleanup = false // change to true to debug a single test temporarily.
13+
let disableScenarioCleanup = true // change to true to debug a single test temporarily.
1414

1515
let isLiveUnitTesting = AppDomain.CurrentDomain.GetAssemblies() |> Seq.exists (fun a -> a.GetName().Name = "Microsoft.CodeAnalysis.LiveUnitTesting.Runtime")
1616

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.nupkg
2+
bin/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project>
2+
<!-- Based on https://github.com/NuGet/Home/issues/5525#issuecomment-1179525536 -->
3+
<Target Name="UseExplicitPackageVersions" BeforeTargets="GenerateNuspec">
4+
<ItemGroup>
5+
<_ProjectReferenceWithExplicitPackageVersion Include="@(ProjectReference->'%(FullPath)')" Condition="'%(ProjectReference.PackageVersion)' != ''" />
6+
<_ProjectReferenceWithExactPackageVersion Include="@(ProjectReference->'%(FullPath)')" />
7+
<_ProjectReferenceWithReassignedVersion Include="@(_ProjectReferencesWithVersions)" Condition="'%(Identity)' != '' And '@(_ProjectReferenceWithExplicitPackageVersion)' == '@(_ProjectReferencesWithVersions)'">
8+
<ProjectVersion>@(_ProjectReferenceWithExplicitPackageVersion->'%(PackageVersion)')</ProjectVersion>
9+
</_ProjectReferenceWithReassignedVersion>
10+
<_ProjectReferenceWithReassignedVersion Include="@(_ProjectReferencesWithVersions)" Condition="'%(Identity)' != '' And '@(_ProjectReferenceWithExactPackageVersion)' == '@(_ProjectReferencesWithVersions)'">
11+
<ProjectVersion>[@(_ProjectReferencesWithVersions->'%(ProjectVersion)')]</ProjectVersion>
12+
</_ProjectReferenceWithReassignedVersion>
13+
<_ProjectReferencesWithVersions Remove="@(_ProjectReferenceWithReassignedVersion)" />
14+
<_ProjectReferencesWithVersions Include="@(_ProjectReferenceWithReassignedVersion)" />
15+
</ItemGroup>
16+
</Target>
17+
</Project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaketTest2394.PackageA", "PaketTest2394.PackageA\PaketTest2394.PackageA.csproj", "{A0449AB0-A1EA-4BE6-8D03-701BC5A2FD46}"
4+
EndProject
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaketTest2394.PackageB", "PaketTest2394.PackageB\PaketTest2394.PackageB.csproj", "{59B3FFCE-AA5A-4AAA-B73D-108A6A15E524}"
6+
EndProject
7+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaketTest2394.PackageB.Transient", "PaketTest2394.PackageB.Transient\PaketTest2394.PackageB.Transient.csproj", "{C763B8F6-18BF-4018-B852-CA8EE39C94F5}"
8+
EndProject
9+
Global
10+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
11+
Debug|Any CPU = Debug|Any CPU
12+
Release|Any CPU = Release|Any CPU
13+
EndGlobalSection
14+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
15+
{A0449AB0-A1EA-4BE6-8D03-701BC5A2FD46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
16+
{A0449AB0-A1EA-4BE6-8D03-701BC5A2FD46}.Debug|Any CPU.Build.0 = Debug|Any CPU
17+
{A0449AB0-A1EA-4BE6-8D03-701BC5A2FD46}.Release|Any CPU.ActiveCfg = Release|Any CPU
18+
{A0449AB0-A1EA-4BE6-8D03-701BC5A2FD46}.Release|Any CPU.Build.0 = Release|Any CPU
19+
{59B3FFCE-AA5A-4AAA-B73D-108A6A15E524}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{59B3FFCE-AA5A-4AAA-B73D-108A6A15E524}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{59B3FFCE-AA5A-4AAA-B73D-108A6A15E524}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{59B3FFCE-AA5A-4AAA-B73D-108A6A15E524}.Release|Any CPU.Build.0 = Release|Any CPU
23+
{C763B8F6-18BF-4018-B852-CA8EE39C94F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{C763B8F6-18BF-4018-B852-CA8EE39C94F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{C763B8F6-18BF-4018-B852-CA8EE39C94F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{C763B8F6-18BF-4018-B852-CA8EE39C94F5}.Release|Any CPU.Build.0 = Release|Any CPU
27+
EndGlobalSection
28+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace PaketTest2394.PackageA;
2+
3+
public static class PackageDescription
4+
{
5+
public static string GetDescription()
6+
{
7+
var assemblyName = typeof(PackageDescription).Assembly.GetName();
8+
return $"PackageA {assemblyName.Version!.ToString(2)}";
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<None Include="build/PaketTest2394.PackageA.targets" Pack="true" PackagePath="build\PaketTest2394.PackageA.targets" />
10+
</ItemGroup>
11+
<Target Name="UpdateTargetsFile" BeforeTargets="Build">
12+
<PropertyGroup>
13+
<NewDefineConstants>%24(DefineConstants)%3BPACKAGEA_$(Version.Split('.')[0])</NewDefineConstants>
14+
</PropertyGroup>
15+
<XmlPoke XmlInputPath="build/PaketTest2394.PackageA.targets" Query="//DefineConstants" Value="$(NewDefineConstants)"/>
16+
</Target>
17+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<PropertyGroup>
3+
<DefineConstants>$(DefineConstants);PACKAGEA_5</DefineConstants>
4+
</PropertyGroup>
5+
</Project>

0 commit comments

Comments
 (0)