Skip to content

Commit

Permalink
create regression test and fix for #1305
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Dec 12, 2015
1 parent 1260972 commit 3886207
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 11 deletions.
19 changes: 14 additions & 5 deletions src/Paket.Core/DependencyChangeDetection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/PackageResolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<StartArguments>update group Build</StartArguments>
<StartArguments>pack output D:\code\paketbug\output</StartArguments>
<StartArguments>install</StartArguments>
<StartArguments>pack buildconfig Debug output . symbols</StartArguments>
<StartArguments>restore</StartArguments>
<StartAction>Project</StartAction>
<StartProgram>paket.exe</StartProgram>
<StartWorkingDirectory>c:\code\Paketkopie</StartWorkingDirectory>
Expand All @@ -46,7 +46,7 @@
<StartWorkingDirectory>d:\code\paketbug</StartWorkingDirectory>
<StartWorkingDirectory>d:\code\paketrepro</StartWorkingDirectory>
<StartWorkingDirectory>D:\code\Paket\integrationtests\scenarios\i001270-net461\temp</StartWorkingDirectory>
<StartWorkingDirectory>D:\code\FsLab\</StartWorkingDirectory>
<StartWorkingDirectory>C:\code\restore</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down
26 changes: 26 additions & 0 deletions tests/Paket.Tests/DependenciesFile/DependencyChangesSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@ open FsUnit
open TestHelpers
open Paket.Domain


[<Test>]
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

[<Test>]
let ``should detect remove of single nuget package``() =
let before = """source http://nuget.org/api/v2
Expand Down
46 changes: 45 additions & 1 deletion tests/Paket.Tests/Lockfile/GenerateWithOptionsSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open NUnit.Framework
open FsUnit
open TestHelpers
open Paket.Domain
open Paket.Requirements

let config1 = """
references strict
Expand Down Expand Up @@ -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)
|> shouldEqual (normalizeLineEndings expected)



[<Test>]
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)

2 changes: 1 addition & 1 deletion tests/Paket.Tests/PackageProcessSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion tests/Paket.Tests/RestrictionFilterSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ let ``should filter net45 and >= net40``() =
[<Test>]
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


[<Test>]
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

Expand Down

0 comments on commit 3886207

Please sign in to comment.