Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Property tests for dependencies file parsing #807

Merged
merged 10 commits into from
May 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
source https://nuget.org/api/v2

nuget FsCheck
nuget FsCheck.NUnit
nuget Newtonsoft.Json
nuget UnionArgParser
nuget NUnit.Runners
Expand All @@ -12,4 +14,4 @@ nuget ILRepack
github forki/FsUnit FsUnit.fs
github fsharp/FAKE modules/Octokit/Octokit.fsx
github fsharp/FAKE src/app/FakeLib/Globbing/Globbing.fs
github fsprojects/Chessie src/Chessie/ErrorHandling.fs
github fsprojects/Chessie src/Chessie/ErrorHandling.fs
5 changes: 5 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ NUGET
remote: https://nuget.org/api/v2
specs:
FAKE (3.30.3)
FsCheck (1.0.4)
FsCheck.Nunit (1.0.4)
FsCheck (>= 1.0.4)
NUnit (>= 2.6.3)
NUnit.Runners (>= 2.6.3)
FSharp.Compiler.Service (0.0.89)
FSharp.Core (3.1.2.1)
FSharp.Formatting (2.9.4)
Expand Down
19 changes: 19 additions & 0 deletions tests/Paket.Tests/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.4.14350" newVersion="2.6.4.14350" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="nunit.core" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.4.14350" newVersion="2.6.4.14350" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="nunit.core.interfaces" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.4.14350" newVersion="2.6.4.14350" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
154 changes: 154 additions & 0 deletions tests/Paket.Tests/DependenciesFile/PropertyTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
module Paket.DependenciesFile.PropertyTests

open System
open FsCheck
open FsCheck.NUnit
open Paket
open TestHelpers

let nl = Environment.NewLine
let linesToString s = String.concat nl s

let alphaNumString =
Arb.generate<char>
|> Gen.suchThat Char.IsLetterOrDigit
|> Gen.nonEmptyListOf
|> Gen.map (fun xs -> String(xs |> Array.ofList))

let smallAlphaNum size = alphaNumString |> Gen.resize (size |> float |> sqrt |> int)

let remoteSource = Gen.sized (fun size -> gen {
let builder = UriBuilder()
let! host = smallAlphaNum size
builder.Host <- host
let! scheme = Gen.elements ["http"; "https"]
builder.Scheme <- scheme
let! path =
smallAlphaNum size
|> Gen.nonEmptyListOf
|> Gen.map (String.concat "/")
builder.Path <- path
let! creds =
Gen.frequency [
70, Gen.constant ""
15, smallAlphaNum size
|> Gen.two
|> Gen.map (fun (x,y) -> sprintf " username: \"%s\" password: \"%s\"" x y)
15, smallAlphaNum size
|> Gen.two
|> Gen.map (fun (x,y) -> sprintf " username: \"%%%s%%\" password: \"%%%s%%\"" x y)
]
return "source " + builder.ToString() + creds
})

let pathSource = Gen.constant "source C:"

let source = Gen.oneof [remoteSource; pathSource]

let semVer = gen {
let! major = Arb.generate<PositiveInt>
let! minor = Arb.generate<PositiveInt>
let! patch = Arb.generate<PositiveInt>
return {
Major = major.Get
Minor = minor.Get
Patch = patch.Get
PreRelease = None
Build = ""
PreReleaseBuild = ""
Original = None }
}

let nuget =
let packageId =
Gen.sized (fun size ->
smallAlphaNum size
|> Gen.nonEmptyListOf
|> Gen.map (String.concat "."))

let g = Gen.elements [">"; ">="]
let l = Gen.elements ["<"; "<="]
let gOrL = Gen.oneof [g; l]

let _constraint =
Gen.oneof [
Gen.constant ""
semVer |> Gen.map (sprintf " ~> %O")
semVer |> Gen.map (sprintf " == %O")
(gOrL, semVer) ||> Gen.map2 (sprintf " %s %O")
Gen.map2 (sprintf " %s %O") gOrL semVer
Gen.map4 (sprintf " %s %O %s %O") g semVer l semVer
]

(packageId, _constraint)
||> Gen.map2 (fun p c -> sprintf "nuget %s%s" p c)

let github = Gen.constant "github forki/FsUnit FsUnit.fs"

let gist = Gen.constant "gist Thorium/1972349 timestamp.fs"

let http = Gen.constant "http http://www.fssnip.net/1n decrypt.fs"

let empty = Gen.constant ""

let line = Gen.oneof [source; nuget; github; gist; http; empty]

let slashComment = Gen.constant "//comment"
let lineWComment =
let line = Gen.oneof [source; nuget; empty]
(line, slashComment)
||> Gen.map2 (fun l c -> l + " " + c)

let hashComment = Gen.constant "#comment"
let comment = Gen.oneof [slashComment; hashComment]

let depLine = Gen.frequency [80, line; 10, lineWComment; 10, comment]

let framework =
Arb.generate<FrameworkVersion>
|> Gen.nonEmptyListOf
|> Gen.map (Seq.distinct
>> Array.ofSeq
>> Array.map (DotNetFramework >> string)
>> String.concat ", "
>> (fun x -> "framework: ", x))

let globalOpts =
Gen.oneof
[ Gen.constant ("references: ", "strict")
framework
Gen.constant ("content: ", "none")
Gen.constant ("import_targets: ", "false")
Gen.constant ("copy_local: ", "false") ]
|> Gen.arrayOf
|> Gen.map (Seq.distinctBy fst >> Seq.map (fun (a,b) -> a+b) >> Array.ofSeq)

let generator =
(Gen.arrayOf depLine, globalOpts)
||> Gen.map2 (fun lines globalOpts -> Array.append globalOpts lines)
|> Gen.map linesToString

let shrinker s =
let lines = s |> toLines
seq {
for i in [0 .. lines.Length - 1] do
yield seq {
for j in [0 .. lines.Length - 1] do
if i <> j then yield lines.[j] }
|> linesToString}

type DFFileGenerator =
static member StringArray() =
{new Arbitrary<string>() with
override x.Generator = generator
override x.Shrinker t = shrinker t }

let _ = PropertyAttribute(Verbose = true)

[<Property(
Arbitrary = [|typeof<DFFileGenerator>|],
Verbose = true)>]
let ``round trip`` (contents : string) =
let lines = toLines contents
let df = DependenciesFile(DependenciesFileParser.parseDependenciesFile "dummy" lines)
df.ToString() = String.concat Environment.NewLine lines
14 changes: 14 additions & 0 deletions tests/Paket.Tests/FsCheckAddin.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace FsCheck.NUnit.Examples

open NUnit.Core.Extensibility

open FsCheck.NUnit
open FsCheck.NUnit.Addin

[<NUnitAddin(Description = "FsCheck addin")>]
type FsCheckAddin() =
interface IAddin with
override x.Install host =
let tcBuilder = new FsCheckTestCaseBuider()
host.GetExtensionPoint("TestCaseBuilders").Install(tcBuilder)
true
46 changes: 42 additions & 4 deletions tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand Down Expand Up @@ -65,6 +65,9 @@
-->
<Import Project="$(SolutionDir)\.paket\paket.targets" />
<ItemGroup>
<Compile Include="FsCheckAddin.fs">
<Paket>True</Paket>
</Compile>
<Compile Include="..\..\paket-files\forki\FsUnit\FsUnit.fs">
<Paket>True</Paket>
<Link>FsUnit.fs</Link>
Expand Down Expand Up @@ -123,7 +126,7 @@
</Content>
<Content Include="Nuspec\WindowsAzure.Storage.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</Content>
<Content Include="Nuspec\LiteGuard.Source.nuspec">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -178,6 +181,7 @@
<Compile Include="DependenciesFile\AddPackageSpecs.fs" />
<Compile Include="DependenciesFile\RemovePackageSpecs.fs" />
<Compile Include="DependenciesFile\DependencyChangesSpecs.fs" />
<Compile Include="DependenciesFile\PropertyTests.fs" />
<Compile Include="Resolver\DependencyGraphSpecs.fs" />
<Compile Include="Resolver\SimpleDependenciesSpecs.fs" />
<Compile Include="Resolver\CyclicGraphSpecs.fs" />
Expand Down Expand Up @@ -224,10 +228,10 @@
</None>
<None Include="ProjectFile\TestData\MaintainsOrdering.fsprojtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</None>
<None Include="ProjectFile\TestData\NewSilverlightClassLibrary.csprojtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</None>
<None Include="ProjectFile\TestData\FSharp.Core.Fluent-3.1.fsprojtest">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -261,9 +265,16 @@
<Compile Include="InstallModel\Penalty\FrameworkConditionsSpecs.fs" />
<Compile Include="DependencyModel\ProjectDependencySpecs.fs" />
<None Include="paket.references" />
<Content Include="App.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="nunit.core">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had to add those manually - FsCheck.Nunit package does that through powershell

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @kurtschelfthout why is this in the powershell script?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On mobile now so don't have a good overview, but think that's wrong, should be reference/content or whatever the canonical way of doing it is. Would you mind opening an issue?

<HintPath>..\..\packages\NUnit.Runners\tools\lib\nunit.core.dll</HintPath>
</Reference>
<Reference Include="nunit.core.interfaces">
<HintPath>..\..\packages\NUnit.Runners\tools\lib\nunit.core.interfaces.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Numerics" />
<Reference Include="System.Security" />
Expand All @@ -276,6 +287,33 @@
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<Import Project="Paket.Tests.paket.targets" Condition="Exists('Paket.Tests.paket.targets')" />
<Choose>
<When Condition="($(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6')) Or ($(TargetFrameworkIdentifier) == 'MonoAndroid') Or ($(TargetFrameworkIdentifier) == 'MonoTouch')">
<ItemGroup>
<Reference Include="FsCheck">
<HintPath>..\..\packages\FsCheck\lib\net45\FsCheck.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="($(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6')) Or ($(TargetFrameworkIdentifier) == 'MonoAndroid') Or ($(TargetFrameworkIdentifier) == 'MonoTouch')">
<ItemGroup>
<Reference Include="FsCheck.NUnit.Addin">
<HintPath>..\..\packages\FsCheck.Nunit\lib\net45\FsCheck.NUnit.Addin.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
<Reference Include="FsCheck.NUnit">
<HintPath>..\..\packages\FsCheck.Nunit\lib\net45\FsCheck.NUnit.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.0' Or $(TargetFrameworkVersion) == 'v4.5' Or $(TargetFrameworkVersion) == 'v4.5.1' Or $(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.5.3' Or $(TargetFrameworkVersion) == 'v4.6')">
<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions tests/Paket.Tests/paket.references
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
NUnit
NUnit.Runners
File:FsUnit.fs .
FSharp.Core
FSharp.Core
FsCheck
FsCheck.NUnit
File:FsUnit.fs .