|
| 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) |
0 commit comments