Skip to content

Commit 33dd010

Browse files
committed
Completed Dotty modules generation.
1 parent dd981a9 commit 33dd010

File tree

12 files changed

+740
-121
lines changed

12 files changed

+740
-121
lines changed

build.sbt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,16 @@ lazy val scalatestMatchersCoreNative = ScalatestBuild.scalatestMatchersCoreNativ
8585
lazy val scalatestShouldMatchersNative = ScalatestBuild.scalatestShouldMatchersNative
8686
lazy val scalatestMustMatchersNative = ScalatestBuild.scalatestMustMatchersNative
8787
lazy val scalatestModulesNative = ScalatestBuild.scalatestModulesNative
88-
lazy val scalatestCoreDotty = ScalatestBuild.scalatestCoreDotty
88+
lazy val scalatestCoreDotty = ScalatestBuild.scalatestCoreDotty
89+
lazy val scalatestFeatureSpecDotty = ScalatestBuild.scalatestFeatureSpecDotty
90+
lazy val scalatestFlatSpecDotty = ScalatestBuild.scalatestFlatSpecDotty
91+
lazy val scalatestFreeSpecDotty = ScalatestBuild.scalatestFreeSpecDotty
92+
lazy val scalatestFunSuiteDotty = ScalatestBuild.scalatestFunSuiteDotty
93+
lazy val scalatestPropSpecDotty = ScalatestBuild.scalatestPropSpecDotty
94+
lazy val scalatestRefSpecDotty = ScalatestBuild.scalatestRefSpecDotty
95+
lazy val scalatestWordSpecDotty = ScalatestBuild.scalatestWordSpecDotty
96+
lazy val scalatestDiagramsDotty = ScalatestBuild.scalatestDiagramsDotty
97+
lazy val scalatestMatchersCoreDotty = ScalatestBuild.scalatestMatchersCoreDotty
98+
lazy val scalatestShouldMatchersDotty = ScalatestBuild.scalatestShouldMatchersDotty
99+
lazy val scalatestMustMatchersDotty = ScalatestBuild.scalatestMustMatchersDotty
100+
lazy val scalatestModulesDotty = ScalatestBuild.scalatestModulesDotty

project/DottyBuild.scala

Lines changed: 360 additions & 5 deletions
Large diffs are not rendered by default.

project/GenModulesDotty.scala

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ object GenModulesDotty {
7474
}.toList ++
7575
copyDir("scalatest.dotty/src/main/scala/org/scalatest", "org/scalatest", targetDir,
7676
List(
77-
"package.scala"/*,
78-
"CompileMacro.scala"*/
77+
"package.scala"
7978
)
8079
) ++
8180
copyDir("scalatest.dotty/src/main/scala/org/scalatest/diagrams", "org/scalatest/diagrams", targetDir,List.empty)
@@ -86,4 +85,101 @@ object GenModulesDotty {
8685
copyDir("scalatest/src/main/java/org/scalatest/tags", "org/scalatest/tags", targetDir,List.empty)
8786
}
8887

88+
def genScalaTestFeatureSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
89+
GenScalaTestDotty.genScalaPackages.filter { case (packagePath, skipList) =>
90+
List(
91+
"org/scalatest/featurespec"
92+
).contains(packagePath)
93+
}.flatMap { case (packagePath, skipList) =>
94+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
95+
}.toList
96+
97+
def genScalaTestFlatSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
98+
GenScalaTestDotty.genScalaPackages.filter { case (packagePath, skipList) =>
99+
List(
100+
"org/scalatest/flatspec"
101+
).contains(packagePath)
102+
}.flatMap { case (packagePath, skipList) =>
103+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
104+
}.toList
105+
106+
def genScalaTestFreeSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
107+
GenScalaTestDotty.genScalaPackages.filter { case (packagePath, skipList) =>
108+
List(
109+
"org/scalatest/freespec"
110+
).contains(packagePath)
111+
}.flatMap { case (packagePath, skipList) =>
112+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
113+
}.toList
114+
115+
def genScalaTestFunSuite(targetDir: File, version: String, scalaVersion: String): Seq[File] =
116+
GenScalaTestDotty.genScalaPackages.filter { case (packagePath, skipList) =>
117+
List(
118+
"org/scalatest/funsuite"
119+
).contains(packagePath)
120+
}.flatMap { case (packagePath, skipList) =>
121+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
122+
}.toList
123+
124+
def genScalaTestPropSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
125+
GenScalaTestDotty.genScalaPackages.filter { case (packagePath, skipList) =>
126+
List(
127+
"org/scalatest/propspec"
128+
).contains(packagePath)
129+
}.flatMap { case (packagePath, skipList) =>
130+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
131+
}.toList
132+
133+
def genScalaTestRefSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
134+
GenScalaTestDotty.genScalaPackages.filter { case (packagePath, skipList) =>
135+
List(
136+
"org/scalatest/refspec"
137+
).contains(packagePath)
138+
}.flatMap { case (packagePath, skipList) =>
139+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
140+
}.toList
141+
142+
def genScalaTestWordSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
143+
GenScalaTestDotty.genScalaPackages.filter { case (packagePath, skipList) =>
144+
List(
145+
"org/scalatest/wordspec"
146+
).contains(packagePath)
147+
}.flatMap { case (packagePath, skipList) =>
148+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
149+
}.toList
150+
151+
def genScalaTestDiagrams(targetDir: File, version: String, scalaVersion: String): Seq[File] =
152+
GenScalaTestDotty.genScalaPackages.filter { case (packagePath, skipList) =>
153+
List(
154+
"org/scalatest/diagrams"
155+
).contains(packagePath)
156+
}.flatMap { case (packagePath, skipList) =>
157+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
158+
}.toList
159+
160+
def genScalaTestMatchersCore(targetDir: File, version: String, scalaVersion: String): Seq[File] =
161+
GenScalaTestDotty.genScalaPackages.filter { case (packagePath, skipList) =>
162+
List(
163+
"org/scalatest/matchers",
164+
"org/scalatest/matchers/dsl"
165+
).contains(packagePath)
166+
}.flatMap { case (packagePath, skipList) =>
167+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
168+
}.toList ++
169+
copyDir("scalatest.dotty/src/main/scala/org/scalatest/matchers", "org/scalatest/matchers", targetDir,List.empty) ++
170+
copyDir("scalatest.dotty/src/main/scala/org/scalatest/matchers/dsl", "org/scalatest/matchers/dsl", targetDir,List.empty)
171+
172+
def genScalaTestShouldMatchers(targetDir: File, version: String, scalaVersion: String): Seq[File] =
173+
GenScalaTestDotty.genScalaPackages.filter { case (packagePath, skipList) =>
174+
List(
175+
"org/scalatest/matchers/should"
176+
).contains(packagePath)
177+
}.flatMap { case (packagePath, skipList) =>
178+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
179+
}.toList ++
180+
copyDir("scalatest.dotty/src/main/scala/org/scalatest/matchers/should", "org/scalatest/matchers/should", targetDir,List.empty)
181+
182+
def genScalaTestMustMatchers(targetDir: File, version: String, scalaVersion: String): Seq[File] =
183+
copyDir("scalatest.dotty/src/main/scala/org/scalatest/matchers/must", "org/scalatest/matchers/must", targetDir,List.empty)
184+
89185
}

project/GenScalaTestDotty.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ object GenScalaTestDotty {
117117
"DoNotDiscover.java",
118118
"Ignore.java"
119119
)) ++
120-
copyDir("scalatest/src/main/java/org/scalatest/compatible", "org/scalatest/compatible", targetDir, List.empty)
120+
copyDir("scalatest/src/main/java/org/scalatest/compatible", "org/scalatest/compatible", targetDir, List.empty) ++
121+
copyDir("scalatest/src/main/java/org/scalatest/tags", "org/scalatest/tags", targetDir, List.empty)
121122
}
122123

123124
def genHtml(targetDir: File, version: String, scalaVersion: String): Seq[File] = {
@@ -173,6 +174,7 @@ object GenScalaTestDotty {
173174
"org/scalatest/path" -> List.empty,
174175
"org/scalatest/prop" -> List.empty,
175176
"org/scalatest/propspec" -> List.empty,
177+
"org/scalatest/tagobjects" -> List.empty,
176178
"org/scalatest/time" -> List.empty,
177179
"org/scalatest/verbs" -> List.empty,
178180
"org/scalatest/tools" -> List.empty,

scalatest.dotty/src/main/scala/org/scalatest/matchers/Matcher.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package org.scalatest.matchers
1717

1818
import org.scalactic._
1919
import org.scalatest.enablers._
20-
import org.scalatest.words._
2120
import org.scalatest.matchers.dsl._
2221
import org.scalatest.FailureMessages
2322
import org.scalatest.matchers.MatchersHelper.andMatchersAndApply

scalatest.dotty/src/main/scala/org/scalatest/matchers/MatchersCompileMacro.scala

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package org.scalatest.matchers
1717

1818
import org.scalactic._
19-
import org.scalatest.words.{TypeCheckWord, CompileWord}
19+
import org.scalatest.verbs.{TypeCheckWord, CompileWord}
2020
import org.scalatest.exceptions._
2121
import org.scalatest._
2222

@@ -67,67 +67,6 @@ object MatchersCompileMacro {
6767
}
6868
}
6969

70-
// used by shouldNot compile syntax, delegate to assertNotCompileImpl to generate code
71-
def shouldNotCompileImpl(self: Expr[Matchers#AnyShouldWrapper[_]], compileWord: Expr[CompileWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
72-
assertNotCompileImpl(self, compileWord, pos)("should")
73-
74-
// used by mustNot compile syntax, delegate to assertNotCompileImpl to generate code
75-
def mustNotCompileImpl(self: Expr[MustMatchers#AnyMustWrapper[_]], compileWord: Expr[CompileWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
76-
assertNotCompileImpl(self, compileWord, pos)("must")
77-
78-
// check that a code snippet does not compile
79-
def assertNotTypeCheckImpl(self: Expr[Matchers#AnyShouldWrapper[_]], typeCheckWord: Expr[TypeCheckWord], pos: Expr[source.Position])(shouldOrMust: String)(implicit qctx: QuoteContext): Expr[Assertion] = {
80-
import qctx.tasty._
81-
82-
// parse and type check a code snippet, generate code to throw TestFailedException if both parse and type check succeeded
83-
def checkNotTypeCheck(code: String): Expr[Assertion] =
84-
if (!typing.typeChecks(code)) '{ Succeeded }
85-
else '{
86-
val messageExpr = Resources.expectedTypeErrorButGotNone(${ code.toExpr })
87-
throw new TestFailedException((_: StackDepthException) => Some(messageExpr), None, $pos)
88-
}
89-
90-
val methodName = shouldOrMust + "Not"
91-
92-
self.unseal.underlyingArgument match {
93-
case Apply(
94-
Apply(
95-
Select(_, shouldOrMustTerconvertToStringShouldOrMustWrapperTermName),
96-
List(
97-
Literal(code)
98-
)
99-
),
100-
_
101-
) if shouldOrMustTerconvertToStringShouldOrMustWrapperTermName == "convertToString" + shouldOrMust.capitalize + "Wrapper" =>
102-
// LHS is a normal string literal, call checkNotTypeCheck with the extracted code string to generate code
103-
checkNotTypeCheck(code.toString)
104-
105-
case Apply(
106-
Apply(
107-
Ident(shouldOrMustTerconvertToStringShouldOrMustWrapperTermName),
108-
List(
109-
Literal(Constant(code: String))
110-
)
111-
),
112-
_
113-
) if shouldOrMustTerconvertToStringShouldOrMustWrapperTermName == "convertToString" + shouldOrMust.capitalize + "Wrapper" =>
114-
// LHS is a normal string literal, call checkNotTypeCheck with the extracted code string to generate code
115-
checkNotTypeCheck(code.toString)
116-
117-
case _ =>
118-
qctx.error("The '" + shouldOrMust + "Not typeCheck' syntax only works with String literals.")
119-
'{???}
120-
}
121-
}
122-
123-
// used by shouldNot typeCheck syntax, delegate to assertNotTypeCheckImpl to generate code
124-
def shouldNotTypeCheckImpl(self: Expr[Matchers#AnyShouldWrapper[_]], typeCheckWord: Expr[TypeCheckWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
125-
assertNotTypeCheckImpl(self, typeCheckWord, pos)("should")
126-
127-
// used by mustNot typeCheck syntax, delegate to assertNotTypeCheckImpl to generate code
128-
def mustNotTypeCheckImpl(self: Expr[Matchers#AnyShouldWrapper[_]], typeCheckWord: Expr[TypeCheckWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
129-
assertNotTypeCheckImpl(self, typeCheckWord, pos)("must")
130-
13170
// check that a code snippet compiles
13271
def assertCompileImpl[T](self: Expr[T], compileWord: Expr[CompileWord], pos: Expr[source.Position])(shouldOrMust: String)(implicit qctx: QuoteContext): Expr[Assertion] = {
13372
import qctx.tasty._
@@ -172,12 +111,4 @@ object MatchersCompileMacro {
172111
'{???}
173112
}
174113
}
175-
176-
// used by should compile syntax, delegate to assertCompileImpl to generate code
177-
def shouldCompileImpl(self: Expr[Matchers#AnyShouldWrapper[_]], compileWord: Expr[CompileWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
178-
assertCompileImpl(self, compileWord, pos)("should")
179-
180-
// used by should compile syntax, delegate to assertCompileImpl to generate code
181-
def mustCompileImpl(self: Expr[MustMatchers#AnyMustWrapper[_]], compileWord: Expr[CompileWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
182-
assertCompileImpl(self, compileWord, pos)("must")
183114
}

scalatest.dotty/src/main/scala/org/scalatest/matchers/TypeMatcherMacro.scala

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -168,42 +168,6 @@ object TypeMatcherMacro {
168168
'{ ($self).owner.or($rhs) }
169169
}
170170

171-
// Do checking on type parameter and generate AST to call TypeMatcherHelper.checkAType, used by 'shouldBe a [type]' syntax
172-
def shouldBeATypeImpl(self: Expr[org.scalatest.matchers.should.Matchers#AnyShouldWrapper[_]], aType: Expr[ResultOfATypeInvocation[_]])(implicit qctx: QuoteContext): Expr[org.scalatest.Assertion] = {
173-
import qctx.tasty._
174-
checkTypeParameter(qctx)(aType.unseal, "a")
175-
'{
176-
TypeMatcherHelper.assertAType(($self).leftSideValue, $aType, ($self).prettifier, ($self).pos)
177-
}
178-
}
179-
180-
// Do checking on type parameter and generate AST to call TypeMatcherHelper.checkAType, used by 'mustBe a [type]' syntax
181-
def mustBeATypeImpl(self: Expr[org.scalatest.matchers.must.Matchers#AnyMustWrapper[_]], aType: Expr[ResultOfATypeInvocation[_]])(implicit qctx: QuoteContext): Expr[org.scalatest.Assertion] = {
182-
import qctx.tasty._
183-
checkTypeParameter(qctx)(aType.unseal, "a")
184-
'{
185-
TypeMatcherHelper.assertAType(($self).leftSideValue, $aType, ($self).prettifier, ($self).pos)
186-
}
187-
}
188-
189-
// Do checking on type parameter and generate AST to call TypeMatcherHelper.checkAType, used by 'shouldBe an [type]' syntax
190-
def shouldBeAnTypeImpl(self: Expr[org.scalatest.matchers.should.Matchers#AnyShouldWrapper[_]], anType: Expr[ResultOfAnTypeInvocation[_]])(implicit qctx: QuoteContext): Expr[org.scalatest.Assertion] = {
191-
import qctx.tasty._
192-
checkTypeParameter(qctx)(anType.unseal, "an")
193-
'{
194-
TypeMatcherHelper.assertAnType(($self).leftSideValue, $anType, ($self).prettifier, ($self).pos)
195-
}
196-
}
197-
198-
// Do checking on type parameter and generate AST to call TypeMatcherHelper.checkAnType, used by 'mustBe an [type]' syntax
199-
def mustBeAnTypeImpl(self: Expr[org.scalatest.matchers.must.Matchers#AnyMustWrapper[_]], anType: Expr[ResultOfAnTypeInvocation[_]])(implicit qctx: QuoteContext): Expr[org.scalatest.Assertion] = {
200-
import qctx.tasty._
201-
checkTypeParameter(qctx)(anType.unseal, "an")
202-
'{
203-
TypeMatcherHelper.assertAnType(($self).leftSideValue, $anType, ($self).prettifier, ($self).pos)
204-
}
205-
}
206-
207171
// /*def expectTypeImpl(context: Context)(tree: context.Tree, beMethodName: String, assertMethodName: String): context.Expr[org.scalatest.Fact] = {
208172
// import context.universe._
209173

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright 2001-2012 Artima, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.scalatest.matchers.must
17+
18+
import org.scalactic._
19+
import org.scalatest.verbs.{TypeCheckWord, CompileWord}
20+
import org.scalatest.exceptions._
21+
import org.scalatest._
22+
23+
import scala.quoted._
24+
25+
object MatchersCompileMacro {
26+
27+
// used by mustNot compile syntax, delegate to assertNotCompileImpl to generate code
28+
def mustNotCompileImpl(self: Expr[Matchers#AnyMustWrapper[_]], compileWord: Expr[CompileWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
29+
org.scalatest.matchers.MatchersCompileMacro.assertNotCompileImpl(self, compileWord, pos)("must")
30+
31+
// check that a code snippet does not compile
32+
def assertNotTypeCheckImpl(self: Expr[Matchers#AnyMustWrapper[_]], typeCheckWord: Expr[TypeCheckWord], pos: Expr[source.Position])(shouldOrMust: String)(implicit qctx: QuoteContext): Expr[Assertion] = {
33+
import qctx.tasty._
34+
35+
// parse and type check a code snippet, generate code to throw TestFailedException if both parse and type check succeeded
36+
def checkNotTypeCheck(code: String): Expr[Assertion] =
37+
if (!typing.typeChecks(code)) '{ Succeeded }
38+
else '{
39+
val messageExpr = Resources.expectedTypeErrorButGotNone(${ code.toExpr })
40+
throw new TestFailedException((_: StackDepthException) => Some(messageExpr), None, $pos)
41+
}
42+
43+
val methodName = shouldOrMust + "Not"
44+
45+
self.unseal.underlyingArgument match {
46+
case Apply(
47+
Apply(
48+
Select(_, shouldOrMustTerconvertToStringShouldOrMustWrapperTermName),
49+
List(
50+
Literal(code)
51+
)
52+
),
53+
_
54+
) if shouldOrMustTerconvertToStringShouldOrMustWrapperTermName == "convertToString" + shouldOrMust.capitalize + "Wrapper" =>
55+
// LHS is a normal string literal, call checkNotTypeCheck with the extracted code string to generate code
56+
checkNotTypeCheck(code.toString)
57+
58+
case Apply(
59+
Apply(
60+
Ident(shouldOrMustTerconvertToStringShouldOrMustWrapperTermName),
61+
List(
62+
Literal(Constant(code: String))
63+
)
64+
),
65+
_
66+
) if shouldOrMustTerconvertToStringShouldOrMustWrapperTermName == "convertToString" + shouldOrMust.capitalize + "Wrapper" =>
67+
// LHS is a normal string literal, call checkNotTypeCheck with the extracted code string to generate code
68+
checkNotTypeCheck(code.toString)
69+
70+
case _ =>
71+
qctx.error("The '" + shouldOrMust + "Not typeCheck' syntax only works with String literals.")
72+
'{???}
73+
}
74+
}
75+
76+
// used by mustNot typeCheck syntax, delegate to assertNotTypeCheckImpl to generate code
77+
def mustNotTypeCheckImpl(self: Expr[org.scalatest.matchers.must.Matchers#AnyMustWrapper[_]], typeCheckWord: Expr[TypeCheckWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
78+
assertNotTypeCheckImpl(self, typeCheckWord, pos)("must")
79+
80+
// used by should compile syntax, delegate to assertCompileImpl to generate code
81+
def mustCompileImpl(self: Expr[org.scalatest.matchers.must.Matchers#AnyMustWrapper[_]], compileWord: Expr[CompileWord])(pos: Expr[source.Position])(implicit qctx: QuoteContext): Expr[Assertion] =
82+
org.scalatest.matchers.MatchersCompileMacro.assertCompileImpl(self, compileWord, pos)("must")
83+
}

0 commit comments

Comments
 (0)