From 388620709b7e9014a3cd3a94d6e0e3a09677af7a Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sat, 12 Dec 2015 11:27:54 +0100 Subject: [PATCH] create regression test and fix for #1305 --- src/Paket.Core/DependencyChangeDetection.fs | 19 ++++++-- src/Paket.Core/PackageResolver.fs | 2 +- src/Paket/Paket.fsproj | 4 +- .../DependencyChangesSpecs.fs | 26 +++++++++++ .../Lockfile/GenerateWithOptionsSpecs.fs | 46 ++++++++++++++++++- tests/Paket.Tests/PackageProcessSpecs.fs | 2 +- tests/Paket.Tests/RestrictionFilterSpecs.fs | 10 +++- 7 files changed, 98 insertions(+), 11 deletions(-) diff --git a/src/Paket.Core/DependencyChangeDetection.fs b/src/Paket.Core/DependencyChangeDetection.fs index 4e71e316b4..d0f4b3f1b1 100644 --- a/src/Paket.Core/DependencyChangeDetection.fs +++ b/src/Paket.Core/DependencyChangeDetection.fs @@ -5,9 +5,18 @@ open Paket.Requirements open Paket.PackageResolver let findNuGetChangesInDependenciesFile(dependenciesFile:DependenciesFile,lockFile:LockFile) = - let inline hasChanged (newRequirement:PackageRequirement) (originalPackage:ResolvedPackage) = - newRequirement.VersionRequirement.IsInRange originalPackage.Version |> not || - newRequirement.Settings <> originalPackage.Settings + let allTransitives groupName = lockFile.GetTransitiveDependencies groupName + let inline hasChanged groupName (newRequirement:PackageRequirement) (originalPackage:ResolvedPackage) = + + let isTransitive (packageName) = allTransitives groupName |> Seq.contains packageName + let settingsChanged = + if newRequirement.Settings <> originalPackage.Settings then + if newRequirement.Settings.FrameworkRestrictions <> originalPackage.Settings.FrameworkRestrictions then + isTransitive originalPackage.Name |> not + else true + else false + + newRequirement.VersionRequirement.IsInRange originalPackage.Version |> not || settingsChanged let added groupName = match dependenciesFile.Groups |> Map.tryFind groupName with @@ -21,7 +30,7 @@ let findNuGetChangesInDependenciesFile(dependenciesFile:DependenciesFile,lockFil | None -> true | Some group -> match group.Resolution.TryFind name with - | Some p -> hasChanged pr p + | Some p -> hasChanged groupName pr p | _ -> true) |> Seq.map (fun (p,_) -> groupName,p) |> Set.ofSeq @@ -38,7 +47,7 @@ let findNuGetChangesInDependenciesFile(dependenciesFile:DependenciesFile,lockFil [for t in lockFile.GetTopLevelDependencies(groupName) do let name = t.Key match directMap.TryFind name with - | Some pr -> if hasChanged pr t.Value then yield groupName, name // Modified + | Some pr -> if hasChanged groupName pr t.Value then yield groupName, name // Modified | _ -> yield groupName, name // Removed ] |> List.map lockFile.GetAllNormalizedDependenciesOf diff --git a/src/Paket.Core/PackageResolver.fs b/src/Paket.Core/PackageResolver.fs index 1855caf2ae..51c1ccd6f6 100644 --- a/src/Paket.Core/PackageResolver.fs +++ b/src/Paket.Core/PackageResolver.fs @@ -237,7 +237,7 @@ let Resolve(groupName:GroupName, sources, getVersionsF, getPackageDetailsF, stra | _ -> tracefn " - %O %A" dependency.Name version let newRestrictions = filterRestrictions dependency.Settings.FrameworkRestrictions globalFrameworkRestrictions - + let packageDetails : PackageDetails = getPackageDetailsF sources dependency.Name version let filteredDependencies = DependencySetFilter.filterByRestrictions newRestrictions packageDetails.DirectDependencies diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj index 23dc2a29ce..d9fe6d939f 100644 --- a/src/Paket/Paket.fsproj +++ b/src/Paket/Paket.fsproj @@ -37,7 +37,7 @@ update group Build pack output D:\code\paketbug\output install - pack buildconfig Debug output . symbols + restore Project paket.exe c:\code\Paketkopie @@ -46,7 +46,7 @@ d:\code\paketbug d:\code\paketrepro D:\code\Paket\integrationtests\scenarios\i001270-net461\temp - D:\code\FsLab\ + C:\code\restore pdbonly diff --git a/tests/Paket.Tests/DependenciesFile/DependencyChangesSpecs.fs b/tests/Paket.Tests/DependenciesFile/DependencyChangesSpecs.fs index 6ccf4aa134..81f5c3acf6 100644 --- a/tests/Paket.Tests/DependenciesFile/DependencyChangesSpecs.fs +++ b/tests/Paket.Tests/DependenciesFile/DependencyChangesSpecs.fs @@ -6,6 +6,32 @@ open FsUnit open TestHelpers open Paket.Domain + +[] +let ``should detect no changes with global framework``() = + let before = """framework: >= net40 + +source https://nuget.org/api/v2 + +nuget NLog framework: net40 +nuget NLog.Contrib""" + + let lockFileData = """FRAMEWORK: >= NET40 +NUGET + remote: https://nuget.org/api/v2 + specs: + NLog (4.2.1) + NLog.Contrib (1.0.0.2) + NLog (>= 2.1.0) +""" + + let after = before + + let cfg = DependenciesFile.FromCode(after) + let lockFile = LockFile.Parse("",toLines lockFileData) + let changedDependencies = DependencyChangeDetection.findNuGetChangesInDependenciesFile(cfg,lockFile) + changedDependencies.IsEmpty |> shouldEqual true + [] let ``should detect remove of single nuget package``() = let before = """source http://nuget.org/api/v2 diff --git a/tests/Paket.Tests/Lockfile/GenerateWithOptionsSpecs.fs b/tests/Paket.Tests/Lockfile/GenerateWithOptionsSpecs.fs index b95f0065cc..94e7171ebb 100644 --- a/tests/Paket.Tests/Lockfile/GenerateWithOptionsSpecs.fs +++ b/tests/Paket.Tests/Lockfile/GenerateWithOptionsSpecs.fs @@ -5,6 +5,7 @@ open NUnit.Framework open FsUnit open TestHelpers open Paket.Domain +open Paket.Requirements let config1 = """ references strict @@ -123,4 +124,47 @@ NUGET let cfg = DependenciesFile.FromCode(config) ResolveWithGraph(cfg,noSha1,VersionsFromGraphAsSeq graph3, PackageDetailsFromGraph graph3).[Constants.MainDependencyGroup].ResolvedPackages.GetModelOrFail() |> LockFileSerializer.serializePackages cfg.Groups.[Constants.MainDependencyGroup].Options - |> shouldEqual (normalizeLineEndings expected) \ No newline at end of file + |> shouldEqual (normalizeLineEndings expected) + + + +[] +let ``should resolve config with global framework restrictions``() = + + let config = """framework: >= net40 + +source https://nuget.org/api/v2 + +nuget NLog framework: net40 +nuget NLog.Contrib +""" + + let graph = [ + "NLog","1.0.0",[] + "NLog","1.0.1",[] + "NLog.Contrib","1.0.0",["NLog",DependenciesFileParser.parseVersionRequirement ">= 1.0.1"] + ] + + + let expected = """FRAMEWORK: >= NET40 +NUGET + remote: https://nuget.org/api/v2 + specs: + NLog (1.0.1) + NLog.Contrib (1.0.0) + NLog (>= 1.0.1)""" + + let cfg = DependenciesFile.FromCode(config) + let group = cfg.Groups.[Constants.MainDependencyGroup] + group.Packages.Head.Settings.FrameworkRestrictions + |> shouldEqual [FrameworkRestriction.Exactly(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V4_Client)) ] + + let resolved = ResolveWithGraph(cfg,noSha1,VersionsFromGraphAsSeq graph, PackageDetailsFromGraph graph).[Constants.MainDependencyGroup].ResolvedPackages.GetModelOrFail() + getVersion resolved.[PackageName "NLog"] |> shouldEqual "1.0.1" + resolved.[PackageName "NLog"].Settings.FrameworkRestrictions + |> shouldEqual [FrameworkRestriction.AtLeast(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V4_Client)) ] + + resolved + |> LockFileSerializer.serializePackages cfg.Groups.[Constants.MainDependencyGroup].Options + |> shouldEqual (normalizeLineEndings expected) + diff --git a/tests/Paket.Tests/PackageProcessSpecs.fs b/tests/Paket.Tests/PackageProcessSpecs.fs index 38c10fb596..f8da491784 100644 --- a/tests/Paket.Tests/PackageProcessSpecs.fs +++ b/tests/Paket.Tests/PackageProcessSpecs.fs @@ -25,7 +25,7 @@ let ``Loading assembly metadata works``() = if workingDir.Contains "Debug" then "Debug" else "Release" - let assemblyReader,id,versionFromAssembly,fileName = PackageMetaData.readAssemblyFromProjFile config "" projFile + let assemblyReader,id,versionFromAssembly,fileName = PackageMetaData.readAssemblyFromProjFile config "" projFile id |> shouldEqual "Paket.Tests" let attribs = PackageMetaData.loadAssemblyAttributes assemblyReader diff --git a/tests/Paket.Tests/RestrictionFilterSpecs.fs b/tests/Paket.Tests/RestrictionFilterSpecs.fs index a3a9e057c8..63ed3ea72c 100644 --- a/tests/Paket.Tests/RestrictionFilterSpecs.fs +++ b/tests/Paket.Tests/RestrictionFilterSpecs.fs @@ -19,7 +19,15 @@ let ``should filter net45 and >= net40``() = [] let ``should filter >= net40 and net45``() = let l1 = [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_5))] - let l2 = [FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4))] + let l2 = [FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4))] + filterRestrictions l1 l2 + |> shouldEqual l1 + + +[] +let ``should filter >= net40 and net40``() = + let l1 = [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_Client))] + let l2 = [FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4_Client))] filterRestrictions l1 l2 |> shouldEqual l1