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

Add BindReturn to Property CE #364

Merged
merged 3 commits into from
Nov 26, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.403
dotnet-version: 5.0.403
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.403
dotnet-version: 5.0.403
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Version ?

- Rename `Property.failOnFalse` to `Property.falseToFailure` ([#384][384], [@TysonMN][TysonMN])
- Add `BindReturn` to the `property` CE ([#364][364], [@TysonMN][TysonMN])
- A breaking change. Previously, returning a `bool` from a `property` CE (after using `let!`) caused the CE to have return type `Property<unit>`. Now this results in a return type of `Property<bool>`. The previous behavior can now be expressed by piping the `Property<bool>` instance into `Property.falseToFailure`.

## Version 0.11.1 (2021-11-19)

Expand Down Expand Up @@ -188,6 +190,8 @@
https://github.com/hedgehogqa/fsharp-hedgehog/pull/381
[380]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/380
[364]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/364
[363]:
https://github.com/hedgehogqa/fsharp-hedgehog/pull/363
[362]:
Expand Down
6 changes: 6 additions & 0 deletions src/Hedgehog/Property.fs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,12 @@ module PropertyBuilder =
member __.Return(b : bool) : Property<unit> =
Property.ofBool b

member __.BindReturn(m : Gen<'a>, f: 'a -> 'b) =
m
|> Gen.map (fun a -> (Journal.empty, Success a))
|> Property.ofGen
|> Property.map f

member __.ReturnFrom(m : Property<'a>) : Property<'a> =
m

Expand Down
2 changes: 1 addition & 1 deletion tests/Hedgehog.Benchmarks/Hedgehog.Benchmarks.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions tests/Hedgehog.Benchmarks/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Benchmarks () =
let! i = Gen.int32 (Range.constant 0 10000)
return i >= 0
}
|> Property.falseToFailure
|> Property.check

[<Benchmark>]
Expand All @@ -23,6 +24,7 @@ type Benchmarks () =
let! i = Gen.string (Range.constant 0 100) Gen.ascii
return i.Length >= 0
}
|> Property.falseToFailure
|> Property.check

[<Benchmark>]
Expand Down
2 changes: 1 addition & 1 deletion tests/Hedgehog.Linq.Tests/Hedgehog.Linq.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net5.0</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<ApplicationIcon />
<OutputType>Library</OutputType>
Expand Down
2 changes: 2 additions & 0 deletions tests/Hedgehog.Tests/GenTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ let genTests = testList "Gen tests" [
let! _ = Gen.int64 (Range.exponentialBounded ())
return true
}
|> Property.falseToFailure
|> Property.check

fableIgnore "uint64 can create exponentially bounded integer" <| fun _ ->
property {
let! _ = Gen.uint64 (Range.exponentialBounded ())
return true
}
|> Property.falseToFailure
|> Property.check

testCase "apply is chainable" <| fun _ ->
Expand Down
2 changes: 1 addition & 1 deletion tests/Hedgehog.Tests/Hedgehog.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<OutputType>Exe</OutputType>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
Expand Down
2 changes: 2 additions & 0 deletions tests/Hedgehog.Tests/PropertyTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let propertyTests = testList "Property tests" [
let! xs = Range.singleton 0 |> Gen.int32 |> Gen.list (Range.singleton 5) |> Gen.map ResizeArray
return false
}
|> Property.falseToFailure
|> Property.renderWith (PropertyConfig.withShrinks 0<shrinks> PropertyConfig.defaultConfig)
Expect.isNotMatch report "\.\.\." "Abbreviation (...) found"

Expand Down Expand Up @@ -57,6 +58,7 @@ let propertyTests = testList "Property tests" [
let! opt = Gen.constant () |> Gen.option
return opt |> Option.isSome
}
|> Property.falseToFailure
|> Property.report
|> Report.render
|> ignore
Expand Down
1 change: 1 addition & 0 deletions tests/Hedgehog.Tests/ShrinkTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ let shrinkTests = testList "Shrink tests" [
let! actual = Range.linear 1 1_000_000 |> Gen.int32
return actual < 500_000
}
|> Property.falseToFailure
|> Property.reportWith propConfig
match report.Status with
| Failed failureData ->
Expand Down