Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kitlangton
Copy link
Member

@kitlangton kitlangton commented May 2, 2021

@adamgfraser and I have put together a first pass at smart assertions.

Basically we use a macro to automatically construct the lens like assertions without the user having to do anything other than write an expression returning a Boolean, similar to how the the automatic layer construction functionality automatically wires together layers. — @adamgfraser

Basically a series of rewrites (I mean, all macros are rewrites I guess😜 ):

val result: Int = ???
assert(result == 1)
//becomes
assert(result)(equalTo(1))

val result: Option[Int] = ???
assert(result.get == 1)
//becomes
assert(result)(isSome(equalTo(1))

val result: List[Int] = ???
assert(result.contains(10))
//becomes
assert(result)(contains(10))

case class Person(nameOption: Option[String])
val result: Person = ???
assert(result.nameOption.get.contains("howdy"))
//becomes
assert(result)(hasField("nameOption", _.nameOption, isSome(containsString("howdy"))))

EDIT: The above is no longer true 😜 We now translate into a specialized arrow-based dsl.

@kitlangton kitlangton force-pushed the smart-assert branch 2 times, most recently from d8adb00 to 39f008e Compare May 2, 2021 09:17
@kitlangton kitlangton force-pushed the smart-assert branch 6 times, most recently from 621f18d to b74624e Compare May 7, 2021 09:21
@kitlangton
Copy link
Member Author

CleanShot 2021-05-27 at 01 38 26@2x

CleanShot 2021-05-27 at 01 38 21@2x

CleanShot 2021-05-27 at 01 38 14@2x

CleanShot 2021-05-27 at 01 38 08@2x

@kitlangton kitlangton force-pushed the smart-assert branch 10 times, most recently from 404dfd7 to ef0b2b6 Compare May 29, 2021 18:59
Copy link
Contributor

@adamgfraser adamgfraser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this merged!

@adamgfraser adamgfraser merged commit 1bbf9c6 into zio:master Jun 1, 2021
hmemcpy pushed a commit to hmemcpy/zio that referenced this pull request Jun 6, 2021
* first pass at smart assertions

* refactor smart assertions & add more matchers

* clean up and add notes

* improve rendering

* wip: composable smart assertions

* wow. much progress.

* wip: smart assert improvements

* add more smart errors to assertions

* add helpful error messages

* support exceptions in smart assert

* work more on errors

* clean up

* as instance of helpers

* implement cross version macro dsl

* initial work on Scala 3 support

* clean up smart assert for Scala 3

* add smart forall

* fix tests

* fix type issue

* Zoom WIP

* progress on Zoom execution

* improve encoding for Zoom

* clean up

* improved assertion dsl

* rendering error progress

* clean up

* much better assert encoding

* flattening and rendering trees

* improve annotations

* add code/span

* enable pruning of test trace

* clean up tests

* add error messages

* highlight parent span

* handle dies in assert correctly

* add Assert wrapper

* add more assertions

* integrate smart assertions with default test reporter

* add more assertions

* more assertions

* improve rendering/add assertions

* enable nested errors

* add isEven/isOdd assertions

* start scalafix rule

* unify test result types

unify test result types

* fix warnings

* fix macro method application

* fix compilation errors

* fix tests

* implement working assertTrue for dotty

* fix scalafix rule for assertTrue

* clean up

* lift GenFailureDetails to AssertResult

* prepare for diffing

* String diffing

* revert extra changes

* Remove stray println

* Remove stray change

Co-authored-by: Adam Fraser <[email protected]>
# Conflicts:
#	test-junit/jvm/src/main/scala/zio/test/junit/ZTestJUnitRunner.scala
#	test/shared/src/main/scala/zio/test/DefaultTestReporter.scala
#	test/shared/src/main/scala/zio/test/package.scala
hmemcpy pushed a commit to hmemcpy/zio that referenced this pull request Jun 12, 2021
* first pass at smart assertions

* refactor smart assertions & add more matchers

* clean up and add notes

* improve rendering

* wip: composable smart assertions

* wow. much progress.

* wip: smart assert improvements

* add more smart errors to assertions

* add helpful error messages

* support exceptions in smart assert

* work more on errors

* clean up

* as instance of helpers

* implement cross version macro dsl

* initial work on Scala 3 support

* clean up smart assert for Scala 3

* add smart forall

* fix tests

* fix type issue

* Zoom WIP

* progress on Zoom execution

* improve encoding for Zoom

* clean up

* improved assertion dsl

* rendering error progress

* clean up

* much better assert encoding

* flattening and rendering trees

* improve annotations

* add code/span

* enable pruning of test trace

* clean up tests

* add error messages

* highlight parent span

* handle dies in assert correctly

* add Assert wrapper

* add more assertions

* integrate smart assertions with default test reporter

* add more assertions

* more assertions

* improve rendering/add assertions

* enable nested errors

* add isEven/isOdd assertions

* start scalafix rule

* unify test result types

unify test result types

* fix warnings

* fix macro method application

* fix compilation errors

* fix tests

* implement working assertTrue for dotty

* fix scalafix rule for assertTrue

* clean up

* lift GenFailureDetails to AssertResult

* prepare for diffing

* String diffing

* revert extra changes

* Remove stray println

* Remove stray change

Co-authored-by: Adam Fraser <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants