-
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
326 additions
and
252 deletions.
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
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,114 +1,113 @@ | ||
namespace Expecto | ||
#nowarn "44" | ||
|
||
open System | ||
open System.Text.RegularExpressions | ||
open FSharpx | ||
|
||
module Seq = | ||
let (|Empty|Cons|) l = | ||
if Seq.isEmpty l | ||
then Empty | ||
else Cons(Seq.head l, Seq.skip 1 l) | ||
|
||
let (|One|_|) l = | ||
match Seq.toList l with | ||
| [x] -> Some x | ||
| _ -> None | ||
|
||
let (|Two|_|) l = | ||
match Seq.toList l with | ||
| [x;y] -> Some(x,y) | ||
| _ -> None | ||
|
||
module String = | ||
let internal nullBool2 f a b = | ||
if a = null && a = null then | ||
true | ||
elif a = null || b = null then | ||
false | ||
else | ||
f b a | ||
|
||
let internal nullOption2 f a b = | ||
nullBool2 f a b |> Option.ofBool | ||
|
||
let (|StartsWith|_|) = | ||
nullOption2 (fun (s: string) -> s.StartsWith) | ||
|
||
let (|Contains|_|) = | ||
nullOption2 (fun (s: string) -> s.Contains) | ||
|
||
[<AutoOpen>] | ||
module TestHelpers = | ||
open Expecto | ||
open Expecto.Impl | ||
|
||
let evalSilent = eval TestPrinters.Default Seq.map | ||
|
||
let inline assertTestFails test = | ||
let test = TestCase test | ||
match evalSilent test with | ||
| [{ TestRunResult.result = TestResult.Failed _ }] -> () | ||
| x -> failtestf "Should have failed, but was %A" x | ||
|
||
let inline assertTestFailsWithMsg (msg : string) test = | ||
let normalize str = Regex.Replace(msg, @"\s", "") | ||
|
||
let test = TestCase test | ||
match evalSilent test with | ||
| [{ TestRunResult.result = TestResult.Failed x }] when String.Equals(normalize x, normalize msg) -> () | ||
| [{ TestRunResult.result = TestResult.Failed x }] -> failtestf "Shold have failed with message: \"%s\" but failed with \"%s\"" msg x | ||
| x -> failtestf "Should have failed, but was %A" x | ||
|
||
|
||
open FsCheck | ||
|
||
let genLimitedTimeSpan = | ||
lazy ( | ||
Arb.generate<TimeSpan> | ||
|> Gen.suchThat (fun t -> t.Days = 0) | ||
) | ||
|
||
let genTestResultCounts = | ||
lazy ( | ||
gen { | ||
let! passed = Arb.generate<string list> | ||
let! ignored = Arb.generate<string list> | ||
let! failed = Arb.generate<string list> | ||
let! errored = Arb.generate<string list> | ||
let! duration = genLimitedTimeSpan.Value | ||
return | ||
{ TestResultSummary.passed = passed | ||
ignored = ignored | ||
failed = failed | ||
errored = errored | ||
duration = duration } | ||
} | ||
) | ||
|
||
let shrinkTestResultCounts (c: TestResultSummary) : TestResultSummary seq = | ||
seq { | ||
for passed in Arb.shrink c.passed do | ||
for ignored in Arb.shrink c.ignored do | ||
for failed in Arb.shrink c.failed do | ||
for errored in Arb.shrink c.errored do | ||
for duration in Arb.shrink c.duration -> | ||
{ | ||
TestResultSummary.passed = passed | ||
ignored = ignored | ||
failed = failed | ||
errored = errored | ||
duration = duration | ||
} | ||
} | ||
|
||
let arbTestResultCounts = | ||
lazy ( | ||
Arb.fromGenShrink(genTestResultCounts.Value, shrinkTestResultCounts) | ||
) | ||
|
||
let twoTestResultCounts = | ||
lazy ( | ||
Gen.two arbTestResultCounts.Value.Generator |> Arb.fromGen | ||
) | ||
namespace Expecto | ||
#nowarn "44" | ||
|
||
open System | ||
open System.Text.RegularExpressions | ||
open FSharpx | ||
|
||
module Seq = | ||
let (|Empty|Cons|) l = | ||
if Seq.isEmpty l | ||
then Empty | ||
else Cons(Seq.head l, Seq.skip 1 l) | ||
|
||
let (|One|_|) l = | ||
match Seq.toList l with | ||
| [x] -> Some x | ||
| _ -> None | ||
|
||
let (|Two|_|) l = | ||
match Seq.toList l with | ||
| [x;y] -> Some(x,y) | ||
| _ -> None | ||
|
||
module String = | ||
let internal nullBool2 f a b = | ||
if a = null && a = null then | ||
true | ||
elif a = null || b = null then | ||
false | ||
else | ||
f b a | ||
|
||
let internal nullOption2 f a b = | ||
nullBool2 f a b |> Option.ofBool | ||
|
||
let (|StartsWith|_|) = | ||
nullOption2 (fun (s: string) -> s.StartsWith) | ||
|
||
let (|Contains|_|) = | ||
nullOption2 (fun (s: string) -> s.Contains) | ||
|
||
[<AutoOpen>] | ||
module TestHelpers = | ||
open Expecto | ||
open Expecto.Impl | ||
|
||
let evalSilent = eval TestPrinters.silent Seq.map | ||
|
||
let inline assertTestFails test = | ||
let test = TestCase test | ||
match evalSilent test with | ||
| [{ TestRunResult.result = TestResult.Failed _ }] -> () | ||
| x -> failtestf "Should have failed, but was %A" x | ||
|
||
let inline assertTestFailsWithMsg (msg : string) test = | ||
let test = TestCase test | ||
match evalSilent test with | ||
| [{ TestRunResult.result = TestResult.Failed x }] -> | ||
let trimmed = x.Trim('\n') | ||
Expect.equal trimmed msg "Test failure strings should equal" | ||
| x -> | ||
failtestf "Should have failed, but was %A" x | ||
|
||
open FsCheck | ||
|
||
let genLimitedTimeSpan = | ||
lazy ( | ||
Arb.generate<TimeSpan> | ||
|> Gen.suchThat (fun t -> t.Days = 0) | ||
) | ||
|
||
let genTestResultCounts = | ||
lazy ( | ||
gen { | ||
let! passed = Arb.generate<string list> | ||
let! ignored = Arb.generate<string list> | ||
let! failed = Arb.generate<string list> | ||
let! errored = Arb.generate<string list> | ||
let! duration = genLimitedTimeSpan.Value | ||
return | ||
{ TestResultSummary.passed = passed | ||
ignored = ignored | ||
failed = failed | ||
errored = errored | ||
duration = duration } | ||
} | ||
) | ||
|
||
let shrinkTestResultCounts (c: TestResultSummary) : TestResultSummary seq = | ||
seq { | ||
for passed in Arb.shrink c.passed do | ||
for ignored in Arb.shrink c.ignored do | ||
for failed in Arb.shrink c.failed do | ||
for errored in Arb.shrink c.errored do | ||
for duration in Arb.shrink c.duration -> | ||
{ | ||
TestResultSummary.passed = passed | ||
ignored = ignored | ||
failed = failed | ||
errored = errored | ||
duration = duration | ||
} | ||
} | ||
|
||
let arbTestResultCounts = | ||
lazy ( | ||
Arb.fromGenShrink(genTestResultCounts.Value, shrinkTestResultCounts) | ||
) | ||
|
||
let twoTestResultCounts = | ||
lazy ( | ||
Gen.two arbTestResultCounts.Value.Generator |> Arb.fromGen | ||
) |
Oops, something went wrong.