From c9f29e25333e734dc3bfdc4bc27d0901be566d4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=CC=A7ois=20Monniot?= Date: Sat, 9 Dec 2023 08:16:49 -0800 Subject: [PATCH] fix ScalaMocks#withExpectations and use the new trait in our tests --- .../scala/eu/monniot/scala3mock/ScalaMocks.scala | 9 ++++++++- .../eu/monniot/scala3mock/mock/MockSuite.scala | 15 +++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/core/src/main/scala/eu/monniot/scala3mock/ScalaMocks.scala b/core/src/main/scala/eu/monniot/scala3mock/ScalaMocks.scala index 7ba77f7..6b104bb 100644 --- a/core/src/main/scala/eu/monniot/scala3mock/ScalaMocks.scala +++ b/core/src/main/scala/eu/monniot/scala3mock/ScalaMocks.scala @@ -1,5 +1,7 @@ package eu.monniot.scala3mock +import eu.monniot.scala3mock.context.MockContext + object ScalaMocks extends ScalaMocks /** Helper trait that provide access to all components (mandatory or optional) @@ -10,4 +12,9 @@ trait ScalaMocks with macros.Mocks with matchers.Matchers: - export main.withExpectations + // apparently using export in 3.2.2 lose the default value of the + // parameter. That might have been fixed in 3.3+, but we can't use + // that version so for now we will duplicate the definition. + def withExpectations[A](verifyAfterRun: Boolean = true)( + f: MockContext ?=> A + ): A = main.withExpectations(verifyAfterRun)(f) diff --git a/core/src/test/scala/eu/monniot/scala3mock/mock/MockSuite.scala b/core/src/test/scala/eu/monniot/scala3mock/mock/MockSuite.scala index 08d4c93..6aa1606 100644 --- a/core/src/test/scala/eu/monniot/scala3mock/mock/MockSuite.scala +++ b/core/src/test/scala/eu/monniot/scala3mock/mock/MockSuite.scala @@ -1,19 +1,10 @@ package mock -import eu.monniot.scala3mock.main.withExpectations -import eu.monniot.scala3mock.functions.MockFunctions -import eu.monniot.scala3mock.main.TestExpectationEx -import eu.monniot.scala3mock.matchers.MatchAny -import eu.monniot.scala3mock.macros.* -import fixtures.* -import eu.monniot.scala3mock.handlers.CallHandler1 -import eu.monniot.scala3mock.functions.MockFunction1 -import eu.monniot.scala3mock.context.MockContext +import eu.monniot.scala3mock.ScalaMocks import eu.monniot.scala3mock.main.Default +import fixtures.* -class MockSuite extends munit.FunSuite with MockFunctions { - - def * = new MatchAny +class MockSuite extends munit.FunSuite with ScalaMocks { case class TestException() extends RuntimeException case class AnotherTestException() extends RuntimeException