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

Skip to content

Conversation

@leszekgruchala
Copy link
Contributor

This is a more complex test example using layers and TestClock. I had to spend some time to have it working, hopefully this will help other people too πŸ‘

Unfortunately, I cannot make it compilable under mdoc even though it compiles in scastie.

error: /Users/lgr/projects/opensource/zio/docs/howto/test_effects.md:342:63: type mismatch;
 found   : repl.MdocSession.App1.ZIO[Any,Exception,Unit]
 required: zio.ZIO[?,?,Any]
        (ZIO.sleep(10.seconds) *> promise.succeed(1).tap(b => logger.log(b.toString)))
                                                              ^^^^^^^^^^^^^^^^^^^^^^
error: /Users/lgr/projects/opensource/zio/docs/howto/test_effects.md:349:64: type mismatch;
 found   : zio.IO[Exception,Nothing]
    (which expands to)  zio.ZIO[Any,Exception,Nothing]
 required: repl.MdocSession.App1.ZIO[Any,Exception,Unit]
    override def log(msg: String): ZIO[Any, Exception, Unit] = ZIO.fail(new Exception("BOOM"))
                                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: /Users/lgr/projects/opensource/zio/docs/howto/test_effects.md:357:57: type mismatch;
 found   : repl.MdocSession.App1.ZIO[Any,Exception,Boolean]
 required: zio.ZIO[?,?,?]
      result  <- ZIO.service[SchedulingService].flatMap(_.schedule(promise)).run.fork
                                                        ^^^^^^^^^^^^^^^^^^^
error: /Users/lgr/projects/opensource/zio/docs/howto/test_effects.md:362:45: This operation assumes that your effect requires an environment. However, your effect has Any for the environment type, which means it has no requirement, so there is no need to provide the environment.
  testCase.provideSomeLayer[TestEnvironment](partialLayer)
                                            ^

Any idea how to solve it?

@leszekgruchala
Copy link
Contributor Author

I decided to remove mdoc from my example, I am unable to make it work. It works well in scastie.

@adamgfraser
Copy link
Contributor

Will take a look. Thanks for working on this!

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.

@leszekgruchala You're getting the error because the definition of ZIO is being shadowed by the definition on line 199. You can use the reset command in mdoc to get a fresh scope. With this change your code compiles correctly when I run mdoc so then we should be good to go.

@leszekgruchala
Copy link
Contributor Author

@adamgfraser awesome, thank you, fixed!

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.

Thank you for adding this! πŸ™

@adamgfraser adamgfraser merged commit 095ffe0 into zio:master Sep 24, 2020
@leszekgruchala leszekgruchala deleted the leszek/test-effect-with-clock-layer branch September 24, 2020 19:10
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