Skip to content

Commit 7a2919e

Browse files
Merge from master.
2 parents 4406d82 + 5cbd257 commit 7a2919e

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

FsCheck Release Notes.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
* Add a few missing `Prop.ForAll` overloads.
88

9+
* Includes changes in 2.16.4.
10+
911

1012
### 3.0.0-beta1 - 5 September 2021
1113

@@ -67,6 +69,12 @@
6769

6870
* Simplify sampling data: Gen.sample et al.
6971

72+
### 2.16.4 - 8 January 2022
73+
74+
* Fixed display issue affecting custom F# exceptions.
75+
76+
* `Prop.throws` now fails the test if an unexpected exception is thrown.
77+
7078
### 2.16.3 - 4 September 2021
7179

7280
* Allow configuration in FsCheck.Xunit.PropertiesAttribute to affect properties on nested types or modules. PropertiesAttribute on the closest enclosing type takes precedence.

docs/QuickStart.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ with existing test frameworks like NUnit, xUnit.NET or MsTest.
1414
1515
First install FsCheck, open an fsx file and start with:*)
1616
17-
#r "FsCheck"
17+
#r "nuget:FsCheck"
1818
1919
open FsCheck
2020

src/FsCheck/FSharp.Prop.fs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,15 @@ module Prop =
2424
///and a failure otherwise.
2525
[<CompiledName("Throws")>]
2626
let throws<'Exception, 'Testable when 'Exception :> exn> (p : Lazy<'Testable>) =
27-
property <| try ignore p.Value; Res.failedFalse with :? 'Exception -> Res.passed
27+
try
28+
ignore p.Value
29+
Res.failedException (exn "Expected exception, none was thrown")
30+
with
31+
| :? 'Exception ->
32+
Res.passed
33+
| e ->
34+
Res.failedException e
35+
|> property
2836

2937
let private stamp str =
3038
let add res =

src/FsCheck/Runner.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ module Runner =
522522
name data.NumberOfTests (pluralize data.NumberOfTests) (data.Stamps |> stampsToString)
523523
| TestResult.Failed (data, originalArgs, args, Outcome.Failed exc, originalSeed, lastSeed, lastSize) ->
524524
onFailureToString name data originalArgs args originalSeed lastSeed lastSize
525-
+ sprintf "with exception:%s%O%s" newline exc newline
525+
+ sprintf "with exception:%s%A%s" newline exc newline
526526
| TestResult.Failed (data, originalArgs, args, _, originalSeed, lastSeed, lastSize) ->
527527
onFailureToString name data originalArgs args originalSeed lastSeed lastSize
528528
| TestResult.Exhausted data ->

tests/FsCheck.Test/Property.fs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,17 @@ module Property =
142142
override __.OnFinished(_,testResult) =
143143
result <- Some testResult
144144

145+
let private checkResult (prop:Property) =
146+
let resultRunner = GetResultRunner()
147+
let config = Config.Quick.WithRunner(resultRunner).WithMaxTest(2)
148+
Check.One(config, prop)
149+
resultRunner.Result
150+
145151
[<Property>]
146152
let DSL() =
147153
Prop.forAll (Arb.fromGen symPropGen) (fun symprop ->
148154
let expected = determineResult symprop
155+
let actual = checkResult (toProperty symprop)
149156
let resultRunner = GetResultRunner()
150157
let config = Config.Quick.WithRunner(resultRunner).WithMaxTest(2)
151158
Check.One(config,toProperty symprop)
@@ -196,3 +203,18 @@ module Property =
196203
| TestResult.Passed _ -> false
197204
| TestResult.Failed _ -> true
198205
| TestResult.Exhausted _ -> false @>
206+
207+
[<Fact>]
208+
let ``throws should fail on unexpected exception``() =
209+
let test() =
210+
(lazy invalidOp "boom")
211+
|> Prop.throws<ArgumentException, _>
212+
|> Prop.label "Expected ArgumentException"
213+
let actual = checkResult (Prop.ofTestable test)
214+
match actual with
215+
| TestResult.Failed (td,_,_,Outcome.Failed e,_,_,_) when (e :? InvalidOperationException) ->
216+
if not (td.Labels.Contains("Expected ArgumentException")) then
217+
failwith "Expected label to be applied"
218+
| t -> failwithf "Expected failing test with exception, got %A" t
219+
220+

0 commit comments

Comments
 (0)