Skip to content

Commit c7c2325

Browse files
committed
Merged dotty supports from #12, ready for 3.2.0.0 release.
1 parent be12bca commit c7c2325

15 files changed

+146
-83
lines changed

build.sbt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,22 @@ developers := List(
2323
)
2424
)
2525

26-
crossScalaVersions := List("2.10.7", "2.11.12", "2.12.11", "2.13.2")
26+
crossScalaVersions := List(
27+
"2.10.7",
28+
"2.11.12",
29+
"2.12.11",
30+
"2.13.2",
31+
"0.24.0"
32+
)
33+
34+
/** Add src/main/scala-{2|3} to Compile / unmanagedSourceDirectories */
35+
Compile / unmanagedSourceDirectories ++= {
36+
val sourceDir = (Compile / sourceDirectory).value
37+
CrossVersion.partialVersion(scalaVersion.value).map {
38+
case (0 | 3, _) => sourceDir / "scala-3"
39+
case (n, _) => sourceDir / s"scala-$n"
40+
}
41+
}
2742

2843
libraryDependencies ++= Seq(
2944
"org.scalatest" %% "scalatest-core" % "3.2.0",
@@ -33,6 +48,7 @@ libraryDependencies ++= Seq(
3348
"org.scalatest" %% "scalatest-funsuite" % "3.2.0" % "test",
3449
"org.scalatest" %% "scalatest-shouldmatchers" % "3.2.0" % "test"
3550
)
51+
Test / scalacOptions ++= (if (isDotty.value) Seq("-language:implicitConversions") else Nil)
3652

3753
import scala.xml.{Node => XmlNode, NodeSeq => XmlNodeSeq, _}
3854
import scala.xml.transform.{RewriteRule, RuleTransformer}

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.2.8
1+
sbt.version=1.3.12

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1")
33
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.2.2")
44

55
addSbtPlugin("com.typesafe.sbt" % "sbt-osgi" % "0.9.4")
6+
7+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.4.1")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.scalatestplus.junit
2+
3+
import org.scalactic.{Prettifier, source}
4+
import org.scalatest.{Assertion, Assertions}
5+
6+
trait VersionSpecificAssertionsForJUnit extends Assertions {
7+
import scala.language.experimental.macros
8+
9+
override def assert(condition: Boolean)(implicit prettifier: Prettifier, pos: source.Position): Assertion = macro AssertionsForJUnitMacro.assert
10+
11+
override def assert(condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: source.Position): Assertion = macro AssertionsForJUnitMacro.assertWithClue
12+
13+
override def assume(condition: Boolean)(implicit prettifier: Prettifier, pos: source.Position): Assertion = macro AssertionsForJUnitMacro.assume
14+
15+
override def assume(condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: source.Position): Assertion = macro AssertionsForJUnitMacro.assumeWithClue
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.scalatestplus.junit
2+
3+
import org.scalactic.{Prettifier, source}
4+
import org.scalatest.Assertions
5+
import org.scalatest.AssertionsMacro.transform
6+
import org.scalatest.compatible.Assertion
7+
8+
import scala.quoted.{Expr, QuoteContext}
9+
10+
object AssertionsForJUnitMacro {
11+
def assert(condition: Expr[Boolean], prettifier: Expr[Prettifier], pos: Expr[source.Position], clue: Expr[Any])(implicit qctx: QuoteContext): Expr[Assertion] =
12+
transform('{AssertionsForJUnit.assertionsHelper.macroAssert}, condition, prettifier, pos, clue)
13+
14+
def assume(condition: Expr[Boolean], prettifier: Expr[Prettifier], pos: Expr[source.Position], clue: Expr[Any])(implicit qctx: QuoteContext): Expr[Assertion] =
15+
transform('{AssertionsForJUnit.assertionsHelper.macroAssume}, condition, prettifier, pos, clue)
16+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.scalatestplus.junit
2+
3+
import org.scalactic.{Prettifier, source}
4+
import org.scalatest.{Assertions, AssertionsMacro}
5+
import org.scalatest.compatible.Assertion
6+
7+
trait VersionSpecificAssertionsForJUnit extends Assertions {
8+
// https://github.com/lampepfl/dotty/pull/8601#pullrequestreview-380646858
9+
implicit object UseJUnitAssertions
10+
11+
inline def assert(inline condition: Boolean)(implicit prettifier: Prettifier, pos: source.Position, use: UseJUnitAssertions.type): Assertion =
12+
${ AssertionsForJUnitMacro.assert('{condition}, '{prettifier}, '{pos}, '{""}) }
13+
14+
inline def assert(inline condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: source.Position, use: UseJUnitAssertions.type): Assertion =
15+
${ AssertionsForJUnitMacro.assert('{condition}, '{prettifier}, '{pos}, '{clue}) }
16+
17+
inline def assume(inline condition: Boolean)(implicit prettifier: Prettifier, pos: source.Position, use: UseJUnitAssertions.type): Assertion =
18+
${ AssertionsForJUnitMacro.assume('{condition}, '{prettifier}, '{pos}, '{""}) }
19+
20+
inline def assume(inline condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: source.Position, use: UseJUnitAssertions.type): Assertion =
21+
${ AssertionsForJUnitMacro.assume('{condition}, '{prettifier}, '{pos}, '{clue}) }
22+
23+
}

src/main/scala/org/scalatestplus/junit/AssertionsForJUnit.scala

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ import org.scalatest.exceptions.{StackDepthException, TestCanceledException}
9595
*
9696
* @author Bill Venners
9797
*/
98-
trait AssertionsForJUnit extends Assertions {
98+
trait AssertionsForJUnit extends VersionSpecificAssertionsForJUnit {
9999

100100
private[org] override def newAssertionFailedException(optionalMessage: Option[String], optionalCause: Option[Throwable], pos: source.Position, differences: scala.collection.immutable.IndexedSeq[String]): Throwable = {
101101
new JUnitTestFailedError(optionalMessage, optionalCause, pos, None)
@@ -116,16 +116,6 @@ trait AssertionsForJUnit extends Assertions {
116116
}
117117
}
118118

119-
import scala.language.experimental.macros
120-
121-
override def assert(condition: Boolean)(implicit prettifier: Prettifier, pos: source.Position): Assertion = macro AssertionsForJUnitMacro.assert
122-
123-
override def assert(condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: source.Position): Assertion = macro AssertionsForJUnitMacro.assertWithClue
124-
125-
override def assume(condition: Boolean)(implicit prettifier: Prettifier, pos: source.Position): Assertion = macro AssertionsForJUnitMacro.assume
126-
127-
override def assume(condition: Boolean, clue: Any)(implicit prettifier: Prettifier, pos: source.Position): Assertion = macro AssertionsForJUnitMacro.assumeWithClue
128-
129119
/*
130120
private[scalatest] override def newAssertionFailedException(optionalMessage: Option[Any], optionalCause: Option[Throwable], stackDepth: Int): Throwable = {
131121
@@ -222,6 +212,9 @@ object AssertionsForJUnit extends AssertionsForJUnit {
222212
Succeeded
223213
}
224214

215+
def macroAssert(bool: Bool, clue: Any, pos: source.Position): Assertion =
216+
macroAssert(bool, clue, bool.prettifier, pos)
217+
225218
/**
226219
* Assume that the passed in <code>Bool</code> is <code>true</code>, else throw <code>TestCanceledException</code>.
227220
*
@@ -236,6 +229,9 @@ object AssertionsForJUnit extends AssertionsForJUnit {
236229
}
237230
Succeeded
238231
}
232+
233+
def macroAssume(bool: Bool, clue: Any, pos: source.Position): Assertion =
234+
macroAssume(bool, clue, bool.prettifier, pos)
239235
}
240236

241237
/**

src/main/scala/org/scalatestplus/junit/JUnitHelper.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import org.scalatest.{Suite, TagAnnotation}
2323
private[junit] object JUnitHelper {
2424

2525
def mergeMap[A, B](ms: List[Map[A, B]])(f: (B, B) => B): Map[A, B] =
26-
(Map[A, B]() /: (for (m <- ms; kv <- m) yield kv)) { (a, kv) =>
26+
(for (m <- ms; kv <- m) yield kv).foldLeft(Map[A, B]()) { (a, kv) =>
2727
a + (if (a.contains(kv._1)) kv._1 -> f(a(kv._1), kv._2) else kv)
2828
}
2929

@@ -47,7 +47,7 @@ private[junit] object JUnitHelper {
4747
val decodedTestText = scala.reflect.NameTransformer.decode(testText)
4848
val formattedText =
4949
if (includeIcon) {
50-
val testSucceededIcon = Resources.testSucceededIconChar
50+
val testSucceededIcon = Resources.testSucceededIconChar()
5151
(" " * (if (level == 0) 0 else (level - 1))) + Resources.iconPlusShortName(testSucceededIcon, decodedTestText)
5252
}
5353
else {
@@ -59,7 +59,7 @@ private[junit] object JUnitHelper {
5959
def checkForPublicNoArgConstructor(clazz: java.lang.Class[_]) = {
6060

6161
try {
62-
val constructor = clazz.getConstructor(new Array[java.lang.Class[T] forSome { type T }](0): _*)
62+
val constructor = clazz.getConstructor(new Array[java.lang.Class[_]](0): _*)
6363

6464
Modifier.isPublic(constructor.getModifiers)
6565
}

src/main/scala/org/scalatestplus/junit/JUnitWrapperSuite.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class JUnitWrapperSuite(junitClassName: String, loader: ClassLoader) extends Sui
8585
* @return number of expected test count
8686
*/
8787
override def expectedTestCount(filter: Filter): Int = {
88-
getRequest.getRunner.getDescription.testCount
88+
getRequest().getRunner.getDescription.testCount
8989
}
9090

9191
/**

src/main/scala/org/scalatestplus/junit/MyRunListener.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import exceptions._
5252
if (throwableOrNull != null)
5353
throwableOrNull.toString
5454
else
55-
Resources.jUnitTestFailed
55+
Resources.jUnitTestFailed()
5656

5757
val formatter = getIndentedTextForTest(testName, 1, true)
5858
val payload =

src/main/scala/org/scalatestplus/junit/RunNotifierReporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private[junit] class RunNotifierReporter(runNotifier: RunNotifier) extends Repor
9898
case None => null // Yuck. Not sure if the exception passed to new Failure can be null, but it could be given this code. Usually throwable would be defined.
9999
}
100100
val possiblyEmptyMessage = messageOrThrowablesDetailMessage(message, throwable)
101-
val description = Description.createSuiteDescription(Resources.runAborted + " " + possiblyEmptyMessage)
101+
val description = Description.createSuiteDescription(Resources.runAborted() + " " + possiblyEmptyMessage)
102102
runNotifier.fireTestFailure(new Failure(description, throwableOrNull)) // Best we can do in JUnit, as far as I know
103103
runNotifier.fireTestFinished(description)
104104

src/test/scala/org/scalatestplus/junit/JUnitRunnerSuite.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ package org.scalatestplus.junit {
105105
test("a test failure is reported due to an exception thrown from " +
106106
"beforeAll when JUnitRunner.run is called directly")
107107
{
108-
val runNotifier =
109-
new RunNotifier {
110-
var methodInvocationCount = 0
111-
var passed: Option[Failure] = None
112-
override def fireTestFailure(failure: Failure): Unit = {
113-
methodInvocationCount += 1
114-
passed = Some(failure)
115-
}
108+
class MyRunNotifier extends RunNotifier {
109+
var methodInvocationCount = 0
110+
var passed: Option[Failure] = None
111+
override def fireTestFailure(failure: Failure): Unit = {
112+
methodInvocationCount += 1
113+
passed = Some(failure)
116114
}
115+
}
116+
val runNotifier = new MyRunNotifier
117117

118118
(new JUnitRunner(classOf[KerblooeySuite])).run(runNotifier)
119119

src/test/scala/org/scalatestplus/junit/JUnitSuiteSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
*/
1616
package org.scalatestplus.junit {
1717

18-
import org.scalatest._
18+
import org.scalatest._
1919
import org.scalatest.events._
2020

2121
// Put fixture suites in a subpackage, so they won't be discovered by
2222
// -m org.scalatest.junit when running the test target for this project.
2323
package helpers {
2424

2525
import _root_.org.junit.Ignore
26-
import _root_.org.junit.Test
26+
import _root_.org.junit.Test
2727

2828
class HappySuite extends JUnitSuite {
2929

src/test/scala/org/scalatestplus/junit/RunNotifierSuite.scala

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,15 @@ class RunNotifierSuite extends funsuite.AnyFunSuite {
3333
val ordinal = new Ordinal(99)
3434

3535
test("report(TestStarting) generates a fireTestStarted invocation") {
36-
37-
val runNotifier =
38-
new RunNotifier {
39-
var fireTestStartedInvocationCount = 0
40-
var passedDesc: Option[Description] = None
41-
override def fireTestStarted(description: Description): Unit = {
42-
fireTestStartedInvocationCount += 1
43-
passedDesc = Some(description)
44-
}
36+
class MyRunNotifier extends RunNotifier {
37+
var fireTestStartedInvocationCount = 0
38+
var passedDesc: Option[Description] = None
39+
override def fireTestStarted(description: Description): Unit = {
40+
fireTestStartedInvocationCount += 1
41+
passedDesc = Some(description)
4542
}
43+
}
44+
val runNotifier = new MyRunNotifier
4645

4746
import scala.language.reflectiveCalls
4847

@@ -60,16 +59,15 @@ class RunNotifierSuite extends funsuite.AnyFunSuite {
6059
}
6160

6261
test("report(TestFailed) generates a fireTestFailure invocation") {
63-
64-
val runNotifier =
65-
new RunNotifier {
66-
var methodInvocationCount = 0
67-
var passed: Option[Failure] = None
68-
override def fireTestFailure(failure: Failure): Unit = {
69-
methodInvocationCount += 1
70-
passed = Some(failure)
71-
}
62+
class MyRunNotifier extends RunNotifier {
63+
var methodInvocationCount = 0
64+
var passed: Option[Failure] = None
65+
override def fireTestFailure(failure: Failure): Unit = {
66+
methodInvocationCount += 1
67+
passed = Some(failure)
7268
}
69+
}
70+
val runNotifier = new MyRunNotifier
7371

7472
val reporter = new RunNotifierReporter(runNotifier)
7573
val exception = new IllegalArgumentException
@@ -83,16 +81,15 @@ class RunNotifierSuite extends funsuite.AnyFunSuite {
8381
}
8482

8583
test("report(TestSucceeded) generates a fireTestFinished invocation") {
86-
87-
val runNotifier =
88-
new RunNotifier {
89-
var methodInvocationCount = 0
90-
var passed: Option[Description] = None
91-
override def fireTestFinished(description: Description): Unit = {
92-
methodInvocationCount += 1
93-
passed = Some(description)
94-
}
84+
class MyRunNotifier extends RunNotifier {
85+
var methodInvocationCount = 0
86+
var passed: Option[Description] = None
87+
override def fireTestFinished(description: Description): Unit = {
88+
methodInvocationCount += 1
89+
passed = Some(description)
9590
}
91+
}
92+
val runNotifier = new MyRunNotifier
9693

9794
import scala.language.reflectiveCalls
9895

@@ -104,16 +101,15 @@ class RunNotifierSuite extends funsuite.AnyFunSuite {
104101
}
105102

106103
test("report(TestIgnored) generates a fireTestIgnored invocation") {
107-
108-
val runNotifier =
109-
new RunNotifier {
110-
var methodInvocationCount = 0
111-
var passed: Option[Description] = None
112-
override def fireTestIgnored(description: Description): Unit = {
113-
methodInvocationCount += 1
114-
passed = Some(description)
115-
}
104+
class MyRunNotifier extends RunNotifier {
105+
var methodInvocationCount = 0
106+
var passed: Option[Description] = None
107+
override def fireTestIgnored(description: Description): Unit = {
108+
methodInvocationCount += 1
109+
passed = Some(description)
116110
}
111+
}
112+
val runNotifier = new MyRunNotifier
117113

118114
import scala.language.reflectiveCalls
119115

@@ -134,16 +130,15 @@ class RunNotifierSuite extends funsuite.AnyFunSuite {
134130

135131
// fireTestFailure is the best we could do given the RunNotifier interface
136132
test("report(SuiteAborted) generates a fireTestFailure invocation") {
137-
138-
val runNotifier =
139-
new RunNotifier {
140-
var methodInvocationCount = 0
141-
var passed: Option[Failure] = None
142-
override def fireTestFailure(failure: Failure): Unit = {
143-
methodInvocationCount += 1
144-
passed = Some(failure)
145-
}
133+
class MyRunNotifier extends RunNotifier {
134+
var methodInvocationCount = 0
135+
var passed: Option[Failure] = None
136+
override def fireTestFailure(failure: Failure): Unit = {
137+
methodInvocationCount += 1
138+
passed = Some(failure)
146139
}
140+
}
141+
val runNotifier = new MyRunNotifier
147142

148143
import scala.language.reflectiveCalls
149144

@@ -169,16 +164,15 @@ class RunNotifierSuite extends funsuite.AnyFunSuite {
169164

170165
// fireTestFailure is the best we could do given the RunNotifier interface
171166
test("report(RunAborted) generates a fireTestFailure invocation") {
172-
173-
val runNotifier =
174-
new RunNotifier {
175-
var methodInvocationCount = 0
176-
var passed: Option[Failure] = None
177-
override def fireTestFailure(failure: Failure): Unit = {
178-
methodInvocationCount += 1
179-
passed = Some(failure)
180-
}
167+
class MyRunNotifier extends RunNotifier {
168+
var methodInvocationCount = 0
169+
var passed: Option[Failure] = None
170+
override def fireTestFailure(failure: Failure): Unit = {
171+
methodInvocationCount += 1
172+
passed = Some(failure)
181173
}
174+
}
175+
val runNotifier = new MyRunNotifier
182176

183177
val reporter = new RunNotifierReporter(runNotifier)
184178
val exception = new IllegalArgumentException

0 commit comments

Comments
 (0)