-
Notifications
You must be signed in to change notification settings - Fork 100
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
Scala 3 #490
Scala 3 #490
Changes from all commits
fecf1eb
4257c04
8847328
db8e040
a7d15bd
1fef344
c32eedd
b40375e
19dc384
8aa4f87
a65fd22
c7dc49e
f41f74d
8365357
81de4e2
abd8ead
e7ebb7e
d53474a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,26 +1,20 @@ | ||||||
import sbtcrossproject.CrossPlugin.autoImport.crossProject | ||||||
|
||||||
ThisBuild / scalaVersion := "2.11.12" | ||||||
ThisBuild / crossScalaVersions := Seq("2.11.12", "2.12.18", "2.13.12") | ||||||
//ThisBuild / scalaJSUseRhino := true | ||||||
|
||||||
lazy val scalatest = Def.setting("org.scalatest" %%% "scalatest" % "3.2.17") | ||||||
lazy val specs2 = Def.setting("org.specs2" %%% "specs2-core" % "4.10.6") | ||||||
lazy val specs2 = Def.setting("org.specs2" %%% "specs2-core" % "4.20.2") | ||||||
|
||||||
val commonSettings = Defaults.coreDefaultSettings ++ Seq( | ||||||
Compile / unmanagedSourceDirectories ++= { | ||||||
CrossVersion.partialVersion(scalaVersion.value) match { | ||||||
case Some((2L, minor)) => | ||||||
Some(baseDirectory.value.getParentFile / s"shared/src/main/scala-2.$minor") | ||||||
case _ => | ||||||
None | ||||||
} | ||||||
}, | ||||||
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-Xcheckinit", "-target:jvm-1.8") | ||||||
/** | ||||||
* Symbol.newClass is marked experimental, so we should use @experimental annotation in every test suite. | ||||||
* 3.3.0 has a bug so we can omit this annotation | ||||||
*/ | ||||||
scalaVersion := "3.3.0", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a bug in 3.3.0 which allows us not to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth a comment, then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-release:8") | ||||||
) | ||||||
|
||||||
lazy val scalamock = crossProject(JSPlatform, JVMPlatform) in file(".") settings( | ||||||
commonSettings, | ||||||
crossScalaSettings, | ||||||
name := "scalamock", | ||||||
Compile / packageBin / publishArtifact := true, | ||||||
Compile / packageDoc / publishArtifact := true, | ||||||
|
@@ -29,21 +23,43 @@ lazy val scalamock = crossProject(JSPlatform, JVMPlatform) in file(".") settings | |||||
Compile / doc / scalacOptions ++= Opts.doc.title("ScalaMock") ++ | ||||||
Opts.doc.version(version.value) ++ Seq("-doc-root-content", "rootdoc.txt", "-version"), | ||||||
libraryDependencies ++= Seq( | ||||||
"org.scala-lang" % "scala-reflect" % scalaVersion.value, | ||||||
scalatest.value % Optional, | ||||||
specs2.value % Optional | ||||||
) | ||||||
) | ||||||
|
||||||
lazy val `scalamock-js` = scalamock.js | ||||||
lazy val `scalamock-jvm` = scalamock.jvm | ||||||
|
||||||
lazy val examples = project in file("examples") settings( | ||||||
commonSettings, | ||||||
crossScalaSettings, | ||||||
name := "ScalaMock Examples", | ||||||
publish / skip := true, | ||||||
libraryDependencies ++= Seq( | ||||||
scalatest.value % Test, | ||||||
specs2.value % Test | ||||||
) | ||||||
) dependsOn scalamock.jvm | ||||||
|
||||||
def crossScalaSettings = { | ||||||
def addDirsByScalaVersion(path: String): Def.Initialize[Seq[sbt.File]] = | ||||||
scalaVersion.zip(baseDirectory) { case (v, base) => | ||||||
CrossVersion.partialVersion(v) match { | ||||||
case Some((v, _)) if Set(2L, 3L).contains(v) => | ||||||
Seq(base / path / s"scala-$v") | ||||||
case _ => | ||||||
Seq.empty | ||||||
} | ||||||
} | ||||||
Seq( | ||||||
crossScalaVersions := Seq("2.12.18", "2.13.12", scalaVersion.value), | ||||||
Compile / unmanagedSourceDirectories ++= addDirsByScalaVersion("src/main").value, | ||||||
Test / unmanagedSourceDirectories ++= addDirsByScalaVersion("src/test").value, | ||||||
libraryDependencies ++= { | ||||||
CrossVersion.partialVersion(scalaVersion.value) match { | ||||||
case Some((2, _)) => | ||||||
Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value) | ||||||
case _ => | ||||||
Seq.empty | ||||||
} | ||||||
} | ||||||
) | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.paulbutcher.test.mock | ||
|
||
import com.paulbutcher.test.TestTrait | ||
import org.scalamock.function.FunctionAdapter1 | ||
import org.scalatest.matchers.should.Matchers | ||
import org.scalamock.scalatest.MockFactory | ||
import org.scalatest.freespec.AnyFreeSpec | ||
|
||
class ByNameParametersTest extends AnyFreeSpec with MockFactory with Matchers { | ||
|
||
autoVerify = false | ||
|
||
"cope with methods with by name parameters" in { | ||
withExpectations { | ||
val m = mock[TestTrait] | ||
(m.byNameParam _).expects(*).returning("it worked") | ||
assertResult("it worked") { m.byNameParam(42) } | ||
} | ||
} | ||
|
||
//! TODO - find a way to make this less ugly | ||
"match methods with by name parameters" in { | ||
withExpectations { | ||
val m = mock[TestTrait] | ||
val f: (=> Int) => Boolean = { x => x == 1 && x == 2 } | ||
((m.byNameParam _): (=> Int) => String).expects(new FunctionAdapter1(f)).returning("it works") | ||
var y = 0 | ||
assertResult("it works") { m.byNameParam { y += 1; y } } | ||
} | ||
} | ||
} |
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.
is JDK 11 still the best runtime?
17/21 are available as LTS versions now but the class-version may be too high for Scala?
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.
No, we can user latter version
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.
Play framework still supports JDK 11 and I use ScalaMock in a library released for Play, it would be awesome supporting JDK 11 for a while
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.
left 11