-
Notifications
You must be signed in to change notification settings - Fork 59
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 support for Scala 3 #364
Comments
This replaces #330 |
Scala 3 first official version got released yesterday: https://github.com/lampepfl/dotty/releases/tag/3.0.0 |
Yeah, my main blocker is the tooling, I really need good debugging tools to reverse engineer what mockito and/or the scala compiler does and I found that almost impossible at the moment. |
Hi @bbonanno! We at Twitter are actively trying to cross-build our Util library (https://github.com/twitter/util) with Scala 3. We use In the meantime, I'm looking at potentially using 2.13-specific versions for mockito-scala and mockito-scala-scalatest for the Scala 3 crossbuild, but I'm still not sure how that will pan out. I will comment when I know more. |
Hi @dotordogh, If you, and anybody else that's looking to migrate, can outline the features that are deemed the most important, I can try to focus on those first and hopefully release a "lite" version whilst the bulk of the features are still being developed. I'd also be very interested to see how did it go using the 2.13 version for the cross-build :) Cheers! |
@bbonanno Got it! Thank you for responding! I did see you mention that the IDE support for Scala 3 was subpar, but I was mainly wondering if things had improved since then. I did try it with the 2.13 version and it seems to work fine for the cross-build, so we'll stick with that until we can upgrade. @NataliaMGonzalez or I can provide you with a list of features that we use in the coming week to help inform a "lite" release. Thank you again! We really appreciate it! |
Hi @bbonanno we have identified that this are the features we depend on:
Thanks again for all your help! |
Yeah, pretty much anything that uses macros :( |
Hi @bbonanno, do you have any news about this? |
@jveldhuizen I'm afraid not, I've been pretty busy at work and had 0 time. |
Any update? |
I'm afraid I'm not actively developing the lib anymore, just basic maintenance atm, so no clear path to get a Scala 3 version any time soon... |
Since `mockito-scala` seems to be non-active, lets try another mockito wrapper. Source: mockito/mockito-scala#364 (comment)
Since `mockito-scala` seems to be non-active, lets try another mockito wrapper. Source: mockito/mockito-scala#364 (comment)
* Scala 3 Upgrade Upgraded Joern and as minimal dependencies as possible to their compatible Scala 3 variant. Note: [Mockito has no Scala 3 compatibility](https://index.scala-lang.org/mockito/mockito-scala) (yet) so we will have to disable it or find an alternative. The bad news is that this project has no clear path to [Scala 3](mockito/mockito-scala#364 (comment)) * Removing Mockito * Updated Scala format to Scala 3 * Removed Scala 2.13 spec from code quality workflow * Fixed Scala 3 compilation issues * removed snakeyaml dependency --------- Co-authored-by: “Hitesh <[email protected]>
@ultrasecreth has anything change since last update? there are still no plans to support Scala 3, right? |
I understand that mockito-scala depends heavily on macros, migrating the code to scala3 isn't likely trivial. https://github.com/fmonniot/scala3mock is an alternative which you could consider, in our case, we ended up using java mockito. |
Would love to read a 'how to convert' style blog post if you find yourself so motivated! Is it ugly? |
We also moved to pure Mockito and/or ScalatestPlus-Mockito. Relatively easy but I guess we were not strongly relying on Mockito scala's specific feature. |
EDITED: To add a I've actually just done this, it really was quite easy, but we weren't using mockito-scala matchers. So most of our matchers were already java friendly, and it was mostly just changing I found that I had to implement a special matcher for import org.mockito.ArgumentMatchers.argThat
import org.mockito.Mockito
import org.mockito.stubbing.{Answer, Stubber}
import scala.reflect.ClassTag
/** Minimal helper functions to make Java Mockito slightly more scala
*/
object CustomMockito {
// This method might struggle to mock complex generic types due to type erasure. If experiencing issues
// Try using Mockito.mock directly with mock[MyClass]
def mock[T: ClassTag]: T = Mockito.mock(implicitly[ClassTag[T]].runtimeClass.asInstanceOf[Class[T]])
def mock[T: ClassTag](defaultAnswer: Answer[Object]): T =
Mockito.mock(implicitly[ClassTag[T]].runtimeClass.asInstanceOf[Class[T]], defaultAnswer)
object Stubber {
def doNothing: Stubber = Mockito.doNothing()
}
object Matchers {
def someMatcher[T]: Option[T] = argThat((arg: Option[T]) =>
arg match {
case null => false // Java interop
case None => false
case Some(_) => true
}
)
def noneMatcher[T]: Option[T] = argThat((arg: Option[T]) =>
arg match {
case null => true // Java interop
case None => true
case _ => false
}
)
}
} Usage like:
|
Scala 3 has a ton of changes on the internals and more importantly, the macros.
mockito-scala makes heavy use of macros, reflection and it also relies on knowing how certain features are compiled/implemented so they can run in the JVM.
This means that pretty much a new lib has to be written for dotty.
My current line of thinking is that we need to:
The text was updated successfully, but these errors were encountered: