-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add Meta Subtype to Cause #1706
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
da65739
implement Cause.Meta
adamgfraser 0dec587
fix access levels
adamgfraser 9a0abd0
make case class final
adamgfraser 70edd5c
address review comments
adamgfraser 2bcbbf5
migrate tests to ZIO Test
adamgfraser b8c1437
address review comments
adamgfraser af973a4
fix type
adamgfraser f2f5bc2
fix another typo
adamgfraser 51712ec
pass `Data` in from above
adamgfraser 9f2926d
implement flatMap
adamgfraser 6c2e741
merge upstream changes
adamgfraser d17b505
implement flatten
adamgfraser cbdf7bb
implement unsandbox via flatten
adamgfraser 1a76255
merge upstream changes
adamgfraser 14ea0b4
apply nonFlaky only on JVM
adamgfraser 5b5a2d0
use jvm test aspect more
adamgfraser 3f39707
remove test
adamgfraser 686a5df
try ignoring tests
adamgfraser d0468bb
start reenabling tests
adamgfraser 3572eb4
remove unused import
adamgfraser 51373fb
merge upstream changes
adamgfraser 2e743b6
reenable more tests
adamgfraser d264395
Add ZSchedule.elapsed example to docs (#1871)
reibitto 472bc18
ignore flaky supervision test (#1874)
adamgfraser ad007b2
CircleCI improvements (#1859)
sideeffffect 0e13088
Implement ZIO#timeoutFork (#1856)
adamgfraser 0f04654
revert change to ZStream#flatMap
adamgfraser 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 hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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,59 +1,127 @@ | ||
| package zio | ||
|
|
||
| import org.specs2.{ ScalaCheck, Specification } | ||
|
|
||
| class CauseSpec extends Specification with ScalaCheck { | ||
| import Cause._ | ||
| import ArbitraryCause._ | ||
|
|
||
| def is = "CauseSpec".title ^ s2""" | ||
| Cause | ||
| `Cause#died` and `Cause#stripFailures` are consistent $e1 | ||
| `Cause.equals` is symmetric $e2 | ||
| `Cause.equals` and `Cause.hashCode` satisfy the contract $e3 | ||
| `Cause#untraced` removes all traces $e8 | ||
| Then | ||
| `Then.equals` satisfies associativity $e4 | ||
| `Then.equals` satisfies distributivity $e5 | ||
| Both | ||
| `Both.equals` satisfies associativity $e6 | ||
| `Both.equals` satisfies commutativity $e7 | ||
| """ | ||
|
|
||
| private def e1 = prop { c: Cause[String] => | ||
| if (c.died) c.stripFailures must beSome | ||
| else c.stripFailures must beNone | ||
| } | ||
|
|
||
| private def e2 = prop { (a: Cause[String], b: Cause[String]) => | ||
| (a == b) must_== (b == a) | ||
| } | ||
|
|
||
| private def e3 = | ||
| prop { (a: Cause[String], b: Cause[String]) => | ||
| (a == b) ==> (a.hashCode must_== (b.hashCode)) | ||
| }.set(minTestsOk = 10, maxDiscardRatio = 99.0f) | ||
|
|
||
| private def e4 = prop { (a: Cause[String], b: Cause[String], c: Cause[String]) => | ||
| Then(Then(a, b), c) must_== Then(a, Then(b, c)) | ||
| Then(a, Then(b, c)) must_== Then(Then(a, b), c) | ||
| } | ||
|
|
||
| private def e5 = prop { (a: Cause[String], b: Cause[String], c: Cause[String]) => | ||
| Then(a, Both(b, c)) must_== Both(Then(a, b), Then(a, c)) | ||
| Then(Both(a, b), c) must_== Both(Then(a, c), Then(b, c)) | ||
| } | ||
|
|
||
| private def e6 = prop { (a: Cause[String], b: Cause[String], c: Cause[String]) => | ||
| Both(Both(a, b), c) must_== Both(a, Both(b, c)) | ||
| Both(Both(a, b), c) must_== Both(a, Both(b, c)) | ||
| } | ||
|
|
||
| private def e7 = prop { (a: Cause[String], b: Cause[String]) => | ||
| Both(a, b) must_== Both(b, a) | ||
| } | ||
|
|
||
| private def e8 = prop { (c: Cause[String]) => | ||
| c.untraced.traces.headOption must beNone | ||
| } | ||
| import zio.Cause.{ Both, Then } | ||
| import zio.random.Random | ||
| import zio.test._ | ||
| import zio.test.Assertion._ | ||
|
|
||
| import zio.CauseSpecUtil._ | ||
|
|
||
| object CauseSpec | ||
| extends ZIOBaseSpec( | ||
| suite("CauseSpec")( | ||
| suite("Cause")( | ||
| testM("`Cause#died` and `Cause#stripFailures` are consistent") { | ||
| check(causes) { c => | ||
| assert(c.stripFailures, if (c.died) isSome(anything) else isNone) | ||
| } | ||
| }, | ||
| testM("`Cause.equals` is symmetric") { | ||
| check(causes, causes) { (a, b) => | ||
| assert(a == b, equalTo(b == a)) | ||
| } | ||
| }, | ||
| testM("`Cause.equals` and `Cause.hashCode` satisfy the contract") { | ||
| check(equalCauses) { | ||
| case (a, b) => | ||
| assert(a.hashCode, equalTo(b.hashCode)) | ||
| } | ||
| }, | ||
| testM("`Cause#untraced` removes all traces") { | ||
| check(causes) { c => | ||
| assert(c.untraced.traces.headOption, isNone) | ||
| } | ||
| } | ||
| ), | ||
| suite("Then")( | ||
| testM("`Then.equals` satisfies associativity") { | ||
| check(causes, causes, causes) { (a, b, c) => | ||
| assert(Then(Then(a, b), c), equalTo(Then(a, Then(b, c)))) && | ||
| assert(Then(a, Then(b, c)), equalTo(Then(Then(a, b), c))) | ||
| } | ||
| }, | ||
| testM("`Then.equals` satisfies distributivity") { | ||
| check(causes, causes, causes) { (a, b, c) => | ||
| assert(Then(a, Both(b, c)), equalTo(Both(Then(a, b), Then(a, c)))) && | ||
| assert(Then(Both(a, b), c), equalTo(Both(Then(a, c), Then(b, c)))) | ||
| } | ||
| } | ||
| ), | ||
| suite("Both")( | ||
| testM("`Both.equals` satisfies associativity") { | ||
| check(causes, causes, causes) { (a, b, c) => | ||
| assert(Both(Both(a, b), c), equalTo(Both(a, Both(b, c)))) && | ||
| assert(Both(a, Both(b, c)), equalTo(Both(Both(a, b), c))) | ||
| } | ||
| }, | ||
| testM("`Both.equals` satisfies distributivity") { | ||
| check(causes, causes, causes) { (a, b, c) => | ||
| assert(Both(Then(a, b), Then(a, c)), equalTo(Then(a, Both(b, c)))) && | ||
| assert(Both(Then(a, c), Then(b, c)), equalTo(Then(Both(a, b), c))) | ||
| } | ||
| }, | ||
| testM("`Both.equals` satisfies commutativity") { | ||
| check(causes, causes) { (a, b) => | ||
| assert(Both(a, b), equalTo(Both(b, a))) | ||
| } | ||
| } | ||
| ), | ||
| suite("Meta")( | ||
| testM("`Meta` is excluded from equals") { | ||
| check(causes) { c => | ||
| assert(Cause.stackless(c), equalTo(c)) && | ||
| assert(c, equalTo(Cause.stackless(c))) | ||
| } | ||
| }, | ||
| testM("`Meta` is excluded from hashCode") { | ||
| check(causes) { c => | ||
| assert(Cause.stackless(c).hashCode, equalTo(c.hashCode)) | ||
| } | ||
| } | ||
| ), | ||
| suite("Monad Laws:")( | ||
| testM("Left identity") { | ||
| check(causes) { c => | ||
| assert(c.flatMap(Cause.fail), equalTo(c)) | ||
| } | ||
| }, | ||
| testM("Right identity") { | ||
| check(errors, errorCauseFunctions) { (e, f) => | ||
| assert(Cause.fail(e).flatMap(f), equalTo(f(e))) | ||
| } | ||
| }, | ||
| testM("Associativity") { | ||
| check(causes, errorCauseFunctions, errorCauseFunctions) { (c, f, g) => | ||
| assert(c.flatMap(f).flatMap(g), equalTo(c.flatMap(e => f(e).flatMap(g)))) | ||
| } | ||
| } | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| object CauseSpecUtil { | ||
|
|
||
| val causes: Gen[Random with Sized, Cause[String]] = | ||
| Gen.causes(Gen.anyString, Gen.anyString.map(s => new RuntimeException(s))) | ||
|
|
||
| val equalCauses: Gen[Random with Sized, (Cause[String], Cause[String])] = | ||
| (causes <*> causes <*> causes).flatMap { | ||
| case ((a, b), c) => | ||
| Gen.elements( | ||
| (a, a), | ||
| (a, Cause.traced(a, ZTrace(0, Nil, Nil, None))), | ||
| (Then(Then(a, b), c), Then(a, Then(b, c))), | ||
| (Then(a, Both(b, c)), Both(Then(a, b), Then(a, c))), | ||
| (Both(Both(a, b), c), Both(a, Both(b, c))), | ||
| (Both(Then(a, c), Then(b, c)), Then(Both(a, b), c)), | ||
| (Both(a, b), Both(b, a)), | ||
| (a, Cause.stackless(a)) | ||
| ) | ||
| } | ||
|
|
||
| val errorCauseFunctions: Gen[Random with Sized, String => Cause[String]] = | ||
| Gen.function(causes) | ||
|
|
||
| val errors: Gen[Random with Sized, String] = | ||
| Gen.anyString | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
💪