From 3dc8bc0e12ae9ff23caa9c9ec861f741a8e490f9 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Wed, 8 Oct 2014 09:48:16 +0200 Subject: [PATCH] Can understand Fantomas --- .../InstallModelSpecs.fs | 102 +++++++++++++++--- .../{ => InstallModel}/NuspecSpecs.fs | 1 + tests/Paket.Tests/Paket.Tests.fsproj | 22 ++-- 3 files changed, 98 insertions(+), 27 deletions(-) rename tests/Paket.Tests/{ProjectFile => InstallModel}/InstallModelSpecs.fs (83%) rename tests/Paket.Tests/{ => InstallModel}/NuspecSpecs.fs (96%) diff --git a/tests/Paket.Tests/ProjectFile/InstallModelSpecs.fs b/tests/Paket.Tests/InstallModel/InstallModelSpecs.fs similarity index 83% rename from tests/Paket.Tests/ProjectFile/InstallModelSpecs.fs rename to tests/Paket.Tests/InstallModel/InstallModelSpecs.fs index f4fbb1a0ec..4f23ac7ca8 100644 --- a/tests/Paket.Tests/ProjectFile/InstallModelSpecs.fs +++ b/tests/Paket.Tests/InstallModel/InstallModelSpecs.fs @@ -1,4 +1,4 @@ -module Paket.ProjectFile.InstallationModelpecs +module Paket.InstallModelSpecs open Paket open NUnit.Framework @@ -24,20 +24,30 @@ type InstallModell = Frameworks = List.fold (fun map f -> Map.add f Set.empty map) Map.empty frameworks } member this.GetFrameworks() = this.Frameworks |> Seq.map (fun kv -> kv.Key) - member this.GetFiles(framework) = this.Frameworks.[framework] - - member this.Add(framework,lib) : InstallModell = + member this.GetFiles(framework) = + match this.Frameworks.TryFind framework with + | Some libs -> libs + | None -> Set.empty + + member this.Add(framework,lib:string,references) : InstallModell = + let install = + match references with + | Nuspec.References.All -> true + | Nuspec.References.Explicit list -> list |> List.exists lib.EndsWith + + if not install then this else { this with Frameworks = match Map.tryFind framework this.Frameworks with | Some files -> Map.add framework (Set.add lib files) this.Frameworks | None -> Map.add framework (Set.singleton lib) this.Frameworks } - member this.Add (libs) : InstallModell = + member this.Add (libs,references) : InstallModell = libs |> List.fold (fun model lib -> match FrameworkIdentifier.DetectFromPathNew lib with - | Some framework -> model.Add(framework,lib) + | Some framework -> model.Add(framework,lib,references) | _ -> model) this + member this.Add libs = this.Add(libs, Nuspec.References.All) member this.FilterBlackList() = { this with Frameworks = @@ -46,6 +56,20 @@ type InstallModell = (fun frameworks f -> Map.map (fun _ files -> files |> Set.filter (f >> not)) frameworks) this.Frameworks } + member this.UseGenericFrameworkVersionIfEmpty() = + let genericFramework = DotNetFramework(All, Full) + let newFiles = this.GetFiles genericFramework + + let model = + if Set.isEmpty newFiles then this else + + let target = DotNetFramework(Framework "v1.0",Full) + match Map.tryFind target this.Frameworks with + | Some files when Set.isEmpty files |> not -> this + | _ -> { this with Frameworks = Map.add target newFiles this.Frameworks } + + { model with Frameworks = model.Frameworks |> Map.remove genericFramework } + member this.UseLowerVersionLibIfEmpty() = KnownDotNetFrameworks |> List.rev @@ -68,6 +92,8 @@ type InstallModell = (fun (model : InstallModell) kv -> let newFiles = kv.Value + if Set.isEmpty newFiles then model else + let otherProfiles = match kv.Key with | PortableFramework(_, f) -> @@ -75,16 +101,17 @@ type InstallModell = |> Array.map (FrameworkIdentifier.Extract false) |> Array.choose id | _ -> [||] - if Set.isEmpty newFiles || Array.isEmpty otherProfiles then model - else - otherProfiles - |> Array.fold (fun (model : InstallModell) framework -> - match Map.tryFind framework model.Frameworks with - | Some files when Set.isEmpty files |> not -> model - | _ -> { model with Frameworks = Map.add framework newFiles model.Frameworks }) model) this + + if Array.isEmpty otherProfiles then model else + otherProfiles + |> Array.fold (fun (model : InstallModell) framework -> + match Map.tryFind framework model.Frameworks with + | Some files when Set.isEmpty files |> not -> model + | _ -> { model with Frameworks = Map.add framework newFiles model.Frameworks }) model) this member this.Process() = this + .UseGenericFrameworkVersionIfEmpty() .UsePortableVersionLibIfEmpty() .UseLowerVersionLibIfEmpty() .FilterBlackList() @@ -411,13 +438,58 @@ let ``should handle lib install of Microsoft.Bcl 1.1.9``() = model.GetFiles(Silverlight("v5.0")) |> shouldContain @"..\Microsoft.Bcl\lib\sl5\System.Threading.Tasks.dll" +[] +let ``should handle lib install of Fantomas 1.5``() = + let model = + emptymodel.Add( + [ @"..\Fantomas\lib\FantomasLib.dll" + @"..\Fantomas\lib\FSharp.Core.dll" + @"..\Fantomas\lib\Fantomas.exe" ]) + .UseGenericFrameworkVersionIfEmpty() + .UseLowerVersionLibIfEmpty() + + model.GetFiles(DotNetFramework(All, Full)) |> shouldBeEmpty + model.GetFiles(DotNetFramework(Framework "v2.0", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll" + model.GetFiles(DotNetFramework(Framework "v2.0", Full)) |> shouldContain @"..\Fantomas\lib\FSharp.Core.dll" + + model.GetFiles(DotNetFramework(Framework "v3.5", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll" + model.GetFiles(DotNetFramework(Framework "v3.5", Full)) |> shouldContain @"..\Fantomas\lib\FSharp.Core.dll" + + model.GetFiles(DotNetFramework(Framework "v4.0", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll" + model.GetFiles(DotNetFramework(Framework "v4.0", Full)) |> shouldContain @"..\Fantomas\lib\FSharp.Core.dll" + + model.GetFiles(DotNetFramework(Framework "v4.5", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll" + model.GetFiles(DotNetFramework(Framework "v4.5", Full)) |> shouldContain @"..\Fantomas\lib\FSharp.Core.dll" + +[] +let ``should handle lib install of Fantomas 1.5.0 with explicit references``() = + let model = + emptymodel.Add( + [ @"..\Fantomas\lib\FantomasLib.dll" + @"..\Fantomas\lib\FSharp.Core.dll" + @"..\Fantomas\lib\Fantomas.exe" ], Nuspec.Explicit ["FantomasLib.dll"]) + .Process() + + model.GetFiles(DotNetFramework(All, Full)) |> shouldBeEmpty + model.GetFiles(DotNetFramework(Framework "v2.0", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll" + model.GetFiles(DotNetFramework(Framework "v2.0", Full)) |> shouldNotContain @"..\Fantomas\lib\FSharp.Core.dll" + + model.GetFiles(DotNetFramework(Framework "v3.5", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll" + model.GetFiles(DotNetFramework(Framework "v3.5", Full)) |> shouldNotContain @"..\Fantomas\lib\FSharp.Core.dll" + + model.GetFiles(DotNetFramework(Framework "v4.0", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll" + model.GetFiles(DotNetFramework(Framework "v4.0", Full)) |> shouldNotContain @"..\Fantomas\lib\FSharp.Core.dll" + + model.GetFiles(DotNetFramework(Framework "v4.5", Full)) |> shouldContain @"..\Fantomas\lib\FantomasLib.dll" + model.GetFiles(DotNetFramework(Framework "v4.5", Full)) |> shouldNotContain @"..\Fantomas\lib\FSharp.Core.dll" + [] let ``should not install tools``() = let model = emptymodel.Add( [ @"..\FAKE\tools\FAKE.exe" - @"..\FAKE\tools\FakeLib.exe" - @"..\FAKE\tools\Fake.SQL.exe" ]) + @"..\FAKE\tools\FakeLib.dll" + @"..\FAKE\tools\Fake.SQL.dll" ]) .Process() model.Frameworks diff --git a/tests/Paket.Tests/NuspecSpecs.fs b/tests/Paket.Tests/InstallModel/NuspecSpecs.fs similarity index 96% rename from tests/Paket.Tests/NuspecSpecs.fs rename to tests/Paket.Tests/InstallModel/NuspecSpecs.fs index b199182dc8..87e7341d38 100644 --- a/tests/Paket.Tests/NuspecSpecs.fs +++ b/tests/Paket.Tests/InstallModel/NuspecSpecs.fs @@ -4,6 +4,7 @@ open Paket open NUnit.Framework open FsUnit open Nuspec +open Paket.InstallModelSpecs [] let ``can detect explicit references``() = diff --git a/tests/Paket.Tests/Paket.Tests.fsproj b/tests/Paket.Tests/Paket.Tests.fsproj index b231c55c73..839d4dca01 100644 --- a/tests/Paket.Tests/Paket.Tests.fsproj +++ b/tests/Paket.Tests/Paket.Tests.fsproj @@ -56,6 +56,14 @@ + + True @@ -75,7 +83,6 @@ Always - @@ -103,8 +110,9 @@ PreserveNewest - + + @@ -115,22 +123,12 @@ - - Paket {09b32f18-0c20-4489-8c83-5106d5c04c93} True - -