-
Notifications
You must be signed in to change notification settings - Fork 525
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5eef5ad
Add FsCheck to test project
theimowski 57ea25d
install fscheck to test project
theimowski 5c52142
vanilla ice test
theimowski a173a1b
hardcoded lines test
theimowski 1ec98b9
comment not allowed after http, github or gist dependency
theimowski b60186c
reinstall FsCheck and FsCheck.NUnit
theimowski 6ed71bd
real framework constraints
theimowski 539739b
remote source
theimowski 3f59787
nuget packages
theimowski 9327d17
make generated string smaller
theimowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 . |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?