Skip to content

Commit eef6a01

Browse files
committed
Dotty - pass expectation specs
only 6 tests skipped, which is not supported in Dotty - 3 about checking parsing errors - 3 about checking type error messages
1 parent 4ff1c0b commit eef6a01

File tree

5 files changed

+39
-20
lines changed

5 files changed

+39
-20
lines changed

project/GenScalaTestDotty.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ object GenScalaTestDotty {
179179
copyFiles("scalatest-test/src/test/scala/org/scalatest", "org/scalatest", targetDir,
180180
List(
181181
"AssertionsSpec.scala",
182+
"ExpectationsSpec.scala",
182183
"ShouldCompileSpec.scala",
183184
"ShouldNotCompileSpec.scala",
184185
"ShouldNotTypeCheckSpec.scala"

scalatest-test/src/test/scala/org/scalatest/ExpectationsSpec.scala

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ExpectationsSpec extends FunSpec with Expectations {
2525

2626
describe("The expectResult method") {
2727
it("should give a correct Fact result when the expectation fails") {
28-
val fact = expectResult(3) { 2 }
28+
val fact = expectResult(3) { 2 }
2929
assert(fact.isNo)
3030
assert(fact.factMessage == "Expected 3, but got 2")
3131
assert(fact.simplifiedFactMessage == "3 did not equal 2")
@@ -43,7 +43,7 @@ class ExpectationsSpec extends FunSpec with Expectations {
4343
assert(!fact.isVacuousYes)
4444
}
4545
it("should give a correct Fact result when the expectation succeeds") {
46-
val fact = expectResult(3) { 3 }
46+
val fact = expectResult(3) { 3 }
4747
assert(fact.isYes)
4848
assert(fact.factMessage == "Expected 3, and got 3")
4949
assert(fact.simplifiedFactMessage == "3 equaled 3")
@@ -118,11 +118,11 @@ class ExpectationsSpec extends FunSpec with Expectations {
118118
assert(fact2.isNo)
119119
assert(fact2.factMessage == "3 equaled 3, but 4 equaled 4")
120120
assert(fact2.toString ==
121-
"No(" + NEWLINE +
122-
" Yes(expected 3, and got 3) &&" + NEWLINE +
123-
" No(" + NEWLINE +
124-
" !Yes(expected 4, and got 4)" + NEWLINE +
125-
" )" + NEWLINE +
121+
"No(" + NEWLINE +
122+
" Yes(expected 3, and got 3) &&" + NEWLINE +
123+
" No(" + NEWLINE +
124+
" !Yes(expected 4, and got 4)" + NEWLINE +
125+
" )" + NEWLINE +
126126
")"
127127
)
128128
assert(!fact2.isVacuousYes)
@@ -206,7 +206,7 @@ class ExpectationsSpec extends FunSpec with Expectations {
206206
" !Yes(expected 4, and got 4)" + NEWLINE +
207207
" )" + NEWLINE +
208208
" ) ||" + NEWLINE +
209-
" No(expected 5, but got 6)" + NEWLINE +
209+
" No(expected 5, but got 6)" + NEWLINE +
210210
")"
211211
)
212212
assert(fact.toString ==
@@ -324,6 +324,7 @@ class ExpectationsSpec extends FunSpec with Expectations {
324324
}
325325
}
326326

327+
// SKIP-DOTTY-START
327328
describe("The expectThrows method") {
328329
it("should catch subtypes") {
329330
class MyException extends RuntimeException
@@ -368,6 +369,7 @@ class ExpectationsSpec extends FunSpec with Expectations {
368369
}
369370
}
370371
}
372+
// SKIP-DOTTY-END
371373

372374
describe("The expect method") {
373375

@@ -525,6 +527,7 @@ class ExpectationsSpec extends FunSpec with Expectations {
525527
assert(!fact.isVacuousYes)
526528
}
527529

530+
// SKIP-DOTTY-START
528531
it("should return No with correct fact message when type check failed") {
529532
val fact = expectCompiles("val a: String = 2")
530533
assert(fact.isInstanceOf[Fact.Leaf])
@@ -545,6 +548,7 @@ class ExpectationsSpec extends FunSpec with Expectations {
545548

546549
assert(!fact.isVacuousYes)
547550
}
551+
// SKIP-DOTTY-END
548552

549553
it("should return Yes with correct fact message when the code compiles with implicit view in scope") {
550554
import scala.collection.JavaConverters._
@@ -581,6 +585,7 @@ class ExpectationsSpec extends FunSpec with Expectations {
581585
assert(!fact.isVacuousYes)
582586
}
583587

588+
// SKIP-DOTTY-START
584589
it("should return No with correct fact message when type check failed") {
585590
val fact =
586591
expectCompiles(
@@ -620,6 +625,7 @@ class ExpectationsSpec extends FunSpec with Expectations {
620625
))
621626
assert(!fact.isVacuousYes)
622627
}
628+
// SKIP-DOTTY-END
623629

624630
it("should return Yes with correct fact message when the code compiles with implicit view in scope") {
625631
import scala.collection.JavaConverters._
@@ -663,6 +669,7 @@ class ExpectationsSpec extends FunSpec with Expectations {
663669
assert(!fact.isVacuousYes)
664670
}
665671

672+
// SKIP-DOTTY-START
666673
it("should return No with correct fact message when parse failed ") {
667674
val fact = expectTypeError("println(\"test)")
668675
assert(fact.isInstanceOf[Fact.Leaf])
@@ -673,6 +680,7 @@ class ExpectationsSpec extends FunSpec with Expectations {
673680
assert(fact.factMessage == Resources.expectedTypeErrorButGotParseError("unclosed string literal", "println(\"test)"))
674681
assert(!fact.isVacuousYes)
675682
}
683+
// SKIP-DOTTY-END
676684

677685
it("should return Yes with correct fact message when used with 'val i: Int = null'") {
678686
val fact = expectTypeError("val i: Int = null")
@@ -735,6 +743,7 @@ class ExpectationsSpec extends FunSpec with Expectations {
735743
assert(!fact.isVacuousYes)
736744
}
737745

746+
// SKIP-DOTTY-START
738747
it("should return No with correct fact message when parse failed ") {
739748
val fact =
740749
expectTypeError(
@@ -756,6 +765,7 @@ class ExpectationsSpec extends FunSpec with Expectations {
756765
))
757766
assert(!fact.isVacuousYes)
758767
}
768+
// SKIP-DOTTY-END
759769

760770
it("should return Yes with correct fact message when used with 'val i: Int = null'") {
761771
val fact =

scalatest.dotty/src/main/scala/org/scalatest/CompileMacro.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ object CompileMacro {
2727
// parse and type check a code snippet, generate code to throw TestFailedException when type check passes or parse error
2828
def assertTypeErrorImpl(code: String, pos: Expr[source.Position])(implicit refl: Reflection): Expr[Assertion] = {
2929
import refl._
30-
30+
3131
if (!typing.typeChecks(code)) '{ Succeeded }
3232
else '{
3333
val messageExpr = Resources.expectedCompileErrorButGotNone(${ code.toExpr })
@@ -54,7 +54,7 @@ object CompileMacro {
5454
}
5555
else
5656
'{
57-
val messageExpr = Resources.expectedTypeErrorButGotNone(${ code.toExpr })
57+
val messageExpr = Resources.gotTypeErrorAsExpected(${ code.toExpr })
5858

5959
Fact.Yes(
6060
messageExpr,
@@ -86,7 +86,7 @@ object CompileMacro {
8686

8787
if (typing.typeChecks(code))
8888
'{
89-
val messageExpr = Resources.expectedTypeErrorButGotNone(${ code.toExpr })
89+
val messageExpr = Resources.expectedCompileErrorButGotNone(${ code.toExpr })
9090
Fact.No(
9191
messageExpr,
9292
messageExpr,
@@ -100,7 +100,7 @@ object CompileMacro {
100100
}
101101
else
102102
'{
103-
val messageExpr = Resources.expectedTypeErrorButGotNone(${ code.toExpr })
103+
val messageExpr = Resources.didNotCompile(${ code.toExpr })
104104

105105
Fact.Yes(
106106
messageExpr,
@@ -131,7 +131,7 @@ object CompileMacro {
131131

132132
if (typing.typeChecks(code))
133133
'{
134-
val messageExpr = Resources.expectedTypeErrorButGotNone(${ code.toExpr })
134+
val messageExpr = Resources.compiledSuccessfully(${ code.toExpr })
135135
Fact.Yes(
136136
messageExpr,
137137
messageExpr,
@@ -145,7 +145,7 @@ object CompileMacro {
145145
}
146146
else
147147
'{
148-
val messageExpr = Resources.expectedTypeErrorButGotNone(${ code.toExpr })
148+
val messageExpr = Resources.expectedNoErrorButGotTypeError("", ${ code.toExpr })
149149

150150
Fact.No(
151151
messageExpr,
@@ -174,7 +174,7 @@ object CompileMacro {
174174
}
175175

176176
self.unseal.underlyingArgument match {
177-
177+
178178
case Apply(
179179
Apply(
180180
Select(_, shouldOrMustTerconvertToStringShouldOrMustWrapperTermName),
@@ -196,7 +196,7 @@ object CompileMacro {
196196
),
197197
_
198198
) if shouldOrMustTerconvertToStringShouldOrMustWrapperTermName == "convertToString" + shouldOrMust.capitalize + "Wrapper" =>
199-
checkNotCompile(code.toString)
199+
checkNotCompile(code.toString)
200200

201201
case other =>
202202
throw QuoteError("The '" + shouldOrMust + " compile' syntax only works with String literals.")
@@ -209,7 +209,7 @@ object CompileMacro {
209209

210210
// used by mustNot compile syntax, delegate to assertNotCompileImpl to generate code
211211
def mustNotCompileImpl(self: Expr[MustMatchers#AnyMustWrapper[_]], compileWord: Expr[CompileWord])(pos: Expr[source.Position])(implicit refl: Reflection): Expr[Assertion] =
212-
assertNotCompileImpl(self, compileWord, pos)("must")
212+
assertNotCompileImpl(self, compileWord, pos)("must")
213213

214214
// check that a code snippet does not compile
215215
def assertNotTypeCheckImpl(self: Expr[Matchers#AnyShouldWrapper[_]], typeCheckWord: Expr[TypeCheckWord], pos: Expr[source.Position])(shouldOrMust: String)(implicit refl: Reflection): Expr[Assertion] = {
@@ -249,7 +249,7 @@ object CompileMacro {
249249
_
250250
) if shouldOrMustTerconvertToStringShouldOrMustWrapperTermName == "convertToString" + shouldOrMust.capitalize + "Wrapper" =>
251251
// LHS is a normal string literal, call checkNotTypeCheck with the extracted code string to generate code
252-
checkNotTypeCheck(code.toString)
252+
checkNotTypeCheck(code.toString)
253253

254254
case _ =>
255255
throw QuoteError("The '" + shouldOrMust + "Not typeCheck' syntax only works with String literals.")
@@ -301,7 +301,7 @@ object CompileMacro {
301301
_
302302
) if shouldOrMustTerconvertToStringShouldOrMustWrapperTermName == "convertToString" + shouldOrMust.capitalize + "Wrapper" =>
303303
// LHS is a normal string literal, call checkCompile with the extracted code string to generate code
304-
checkCompile(code.toString)
304+
checkCompile(code.toString)
305305

306306
case other =>
307307
println("###other: " + other)

scalatest.dotty/src/main/scala/org/scalatest/Expectations.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@ import scala.concurrent.ExecutionContext
2121
import scala.concurrent.Future
2222
import scala.reflect.ClassTag
2323

24+
import scala.tasty._
25+
import scala.quoted._
26+
2427
private[scalatest] trait Expectations {
2528

29+
inline def (inline x: String) stripMargin <: String =
30+
${ Expectations.stripMarginImpl(x) }
31+
2632
// TODO: Need to make this and assertResult use custom equality I think.
2733
def expectResult(expected: Any)(actual: Any)(implicit prettifier: Prettifier, pos: source.Position): Fact = {
2834
if (!DefaultEquality.areEqualComparingArraysStructurally(actual, expected)) {
@@ -130,6 +136,8 @@ private[scalatest] trait Expectations {
130136
}
131137

132138
object Expectations extends Expectations {
139+
def stripMarginImpl(x: String)(implicit refl: Reflection): Expr[String] =
140+
new scala.collection.immutable.StringOps(x).stripMargin.toExpr
133141

134142
class ExpectationsHelper {
135143

scalatest.dotty/src/main/scala/org/scalatest/ExpectationsMacro.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import scala.tasty._
2222
/**
2323
* Macro implementation that provides rich error message for boolean expression assertion.
2424
*/
25-
private[scalatest] object ExpectationsMacro {
25+
object ExpectationsMacro {
2626

2727
def expect(condition: Expr[Boolean])(prettifier: Expr[Prettifier], pos: Expr[source.Position])(implicit refl: Reflection): Expr[Fact] = {
2828
import refl._

0 commit comments

Comments
 (0)