Skip to content

Commit dd981a9

Browse files
committed
Generated ScalaTest Core for Dotty.
1 parent 0ac347d commit dd981a9

File tree

10 files changed

+479
-162
lines changed

10 files changed

+479
-162
lines changed

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,5 @@ lazy val scalatestDiagramsNative = ScalatestBuild.scalatestDiagramsNative
8484
lazy val scalatestMatchersCoreNative = ScalatestBuild.scalatestMatchersCoreNative
8585
lazy val scalatestShouldMatchersNative = ScalatestBuild.scalatestShouldMatchersNative
8686
lazy val scalatestMustMatchersNative = ScalatestBuild.scalatestMustMatchersNative
87-
lazy val scalatestModulesNative = ScalatestBuild.scalatestModulesNative
87+
lazy val scalatestModulesNative = ScalatestBuild.scalatestModulesNative
88+
lazy val scalatestCoreDotty = ScalatestBuild.scalatestCoreDotty
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2001-2018 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
17+
18+
/**
19+
* Classes and traits supporting ScalaTest's "fixture" style traits, which
20+
* allow you to pass fixture objects into tests.
21+
*
22+
* This package is released as part of the `scalatest-core` module.
23+
*/
24+
package object fixture
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright 2001-2013 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
17+
18+
/**
19+
* ScalaTest's main traits, classes, and other members, including members supporting ScalaTest's DSL for the Scala interpreter.
20+
*/
21+
package object scalatest {
22+
23+
// SKIP-SCALATESTJS,NATIVE-START
24+
private val defaultShell = ShellImpl()
25+
26+
/**
27+
* Returns a copy of this <code>Shell</code> with <code>colorPassed</code> configuration parameter set to <code>true</code>.
28+
*/
29+
lazy val color: Shell = defaultShell.color
30+
31+
/**
32+
* Returns a copy of this <code>Shell</code> with <code>durationsPassed</code> configuration parameter set to <code>true</code>.
33+
*/
34+
lazy val durations: Shell = defaultShell.durations
35+
36+
/**
37+
* Returns a copy of this <code>Shell</code> with <code>shortStacksPassed</code> configuration parameter set to <code>true</code>.
38+
*/
39+
lazy val shortstacks: Shell = defaultShell.shortstacks
40+
41+
/**
42+
* Returns a copy of this <code>Shell</code> with <code>fullStacksPassed</code> configuration parameter set to <code>true</code>.
43+
*/
44+
lazy val fullstacks: Shell = defaultShell.fullstacks
45+
46+
/**
47+
* Returns a copy of this <code>Shell</code> with <code>statsPassed</code> configuration parameter set to <code>true</code>.
48+
*/
49+
lazy val stats: Shell = defaultShell.stats
50+
51+
/**
52+
* Returns a copy of this <code>Shell</code> with <code>colorPassed</code> configuration parameter set to <code>false</code>.
53+
*/
54+
lazy val nocolor: Shell = defaultShell.nocolor
55+
56+
/**
57+
* Returns a copy of this <code>Shell</code> with <code>durationsPassed</code> configuration parameter set to <code>false</code>.
58+
*/
59+
lazy val nodurations: Shell = defaultShell.nodurations
60+
61+
/**
62+
* Returns a copy of this <code>Shell</code> with <code>shortStacksPassed</code> configuration parameter set to <code>false</code>.
63+
*/
64+
lazy val nostacks: Shell = defaultShell.nostacks
65+
66+
/**
67+
* Returns a copy of this <code>Shell</code> with <code>statsPassed</code> configuration parameter set to <code>false</code>.
68+
*/
69+
lazy val nostats: Shell = defaultShell.nostats
70+
// SKIP-SCALATESTJS,NATIVE-END
71+
72+
/**
73+
* The version number of ScalaTest.
74+
*
75+
* @return the ScalaTest version number.
76+
*/
77+
val ScalaTestVersion: String = ScalaTestVersions.ScalaTestVersion
78+
79+
private[scalatest] type Expectation = Fact
80+
81+
/**
82+
* Marker trait that serves as the result type of <code>assert</code>, <code>assume</code>, and <code>pending</code> methods of
83+
* trait <code>Assertions</code>, which return its only instance, the <code>Succeeded</code> singleton, or throw
84+
* an exception that indicates a failed, canceled, or pending test.
85+
*/
86+
type Assertion = compatible.Assertion
87+
}

project/BuildCommons.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ trait BuildCommons {
1313

1414
def rootProject: Project
1515

16+
def scalatestCompatible: Project
17+
1618
def scalaXmlDependency(theScalaVersion: String): Seq[ModuleID]
1719

1820
def scalatestLibraryDependencies: Seq[ModuleID]

project/DottyBuild.scala

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,89 @@ trait DottyBuild { this: BuildCommons =>
183183
)
184184
).dependsOn(scalacticDotty)
185185

186+
lazy val scalatestCoreDotty = Project("scalatestCoreDotty", file("modules/dotty/scalatest-core"))
187+
.enablePlugins(SbtOsgi)
188+
.settings(sharedSettings: _*)
189+
.settings(dottySettings: _*)
190+
.settings(
191+
projectTitle := "ScalaTest",
192+
organization := "org.scalatest",
193+
moduleName := "scalatest-core",
194+
initialCommands in console := """|import org.scalatest._
195+
|import org.scalactic._
196+
|import Matchers._""".stripMargin,
197+
libraryDependencies ++= scalaXmlDependency(scalaVersion.value),
198+
libraryDependencies ++= scalatestLibraryDependencies,
199+
sourceGenerators in Compile += {
200+
Def.task {
201+
GenModulesDotty.genScalaTestCore((sourceManaged in Compile).value, version.value, scalaVersion.value) ++
202+
GenVersions.genScalaTestVersions((sourceManaged in Compile).value / "org" / "scalatest", version.value, scalaVersion.value) ++
203+
ScalaTestGenResourcesJVM.genResources((sourceManaged in Compile).value / "org" / "scalatest", version.value, scalaVersion.value) ++
204+
ScalaTestGenResourcesJVM.genFailureMessages((sourceManaged in Compile).value / "org" / "scalatest", version.value, scalaVersion.value) ++
205+
GenConfigMap.genMain((sourceManaged in Compile).value / "org" / "scalatest", version.value, scalaVersion.value)
206+
}.taskValue
207+
},
208+
javaSourceManaged := target.value / "java",
209+
managedSourceDirectories in Compile += javaSourceManaged.value,
210+
sourceGenerators in Compile += {
211+
Def.task{
212+
GenScalaTestDotty.genJava((javaSourceManaged in Compile).value, version.value, scalaVersion.value)
213+
}.taskValue
214+
},
215+
resourceGenerators in Compile += {
216+
Def.task {
217+
GenScalaTestDotty.genHtml((resourceManaged in Compile).value, version.value, scalaVersion.value)
218+
}.taskValue
219+
},
220+
sourceGenerators in Compile += {
221+
Def.task{
222+
GenTable.genMain((sourceManaged in Compile).value / "org" / "scalatest", version.value, scalaVersion.value) ++
223+
GenCompatibleClasses.genMain((sourceManaged in Compile).value / "org" / "scalatest" / "tools", version.value, scalaVersion.value)
224+
//GenSafeStyles.genMain((sourceManaged in Compile).value / "org" / "scalatest", version.value, scalaVersion.value)
225+
}.taskValue
226+
},
227+
//scalatestJSDocTaskSetting,
228+
publishArtifact in (Compile, packageDoc) := false, // Temporary disable publishing of doc, can't get it to build.
229+
mimaPreviousArtifacts := Set(organization.value %% name.value % previousReleaseVersion),
230+
mimaCurrentClassfiles := (classDirectory in Compile).value.getParentFile / (name.value + "_" + scalaBinaryVersion.value + "-" + releaseVersion + ".jar"),
231+
mimaBinaryIssueFilters ++= {
232+
Seq(
233+
exclude[MissingClassProblem]("org.scalatest.tools.SbtCommandParser$"),
234+
exclude[MissingClassProblem]("org.scalatest.tools.SbtCommandParser")
235+
)
236+
}
237+
).settings(osgiSettings: _*).settings(
238+
OsgiKeys.exportPackage := Seq(
239+
"org.scalatest",
240+
"org.scalatest.concurrent",
241+
"org.scalatest.enablers",
242+
"org.scalatest.exceptions",
243+
"org.scalatest.events",
244+
"org.scalatest.fixture",
245+
"org.scalatest.prop",
246+
"org.scalatest.tags",
247+
"org.scalatest.tagobjects",
248+
"org.scalatest.time",
249+
"org.scalatest.tools",
250+
"org.scalatest.verbs"
251+
),
252+
OsgiKeys.importPackage := Seq(
253+
"org.scalatest.*",
254+
"org.scalactic.*",
255+
"scala.util.parsing.*;version=\"$<range;[==,=+);$<replace;1.0.4;-;.>>\"",
256+
"scala.xml.*;version=\"$<range;[==,=+);$<replace;1.0.4;-;.>>\"",
257+
"scala.*;version=\"$<range;[==,=+);$<replace;"+scalaBinaryVersion.value+";-;.>>\"",
258+
"*;resolution:=optional"
259+
),
260+
OsgiKeys.additionalHeaders:= Map(
261+
"Bundle-Name" -> "ScalaTest",
262+
"Bundle-Description" -> "ScalaTest.js is an open-source test framework for the Javascript Platform designed to increase your productivity by letting you write fewer lines of test code that more clearly reveal your intent.",
263+
"Bundle-DocURL" -> "http://www.scalatest.org/",
264+
"Bundle-Vendor" -> "Artima, Inc.",
265+
"Main-Class" -> "org.scalatest.tools.Runner"
266+
)
267+
).dependsOn(/*scalatestCompatible, */scalacticDotty)
268+
186269
lazy val commonTestDotty = Project("commonTestDotty", file("common-test.dotty"))
187270
.settings(sharedSettings: _*)
188271
.settings(dottySettings: _*)

project/GenModulesDotty.scala

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import java.io.{File, BufferedWriter, FileWriter}
2+
import scala.io.Source
3+
4+
object GenModulesDotty {
5+
6+
private def uncommentJsExport(line: String): String =
7+
if (line.trim.startsWith("//DOTTY-ONLY "))
8+
line.substring(line.indexOf("//DOTTY-ONLY ") + 13)
9+
else if (line.trim.startsWith("//DOTTY-ONLY "))
10+
line.substring(line.indexOf("//DOTTY-ONLY ") + 13)
11+
else
12+
line
13+
14+
private def transformLine(line: String): String =
15+
uncommentJsExport(line)
16+
17+
private def copyFile(sourceFile: File, destFile: File): File = {
18+
val destWriter = new BufferedWriter(new FileWriter(destFile))
19+
try {
20+
val lines = Source.fromFile(sourceFile).getLines.toList
21+
var skipMode = false
22+
for (line <- lines) {
23+
if (line.trim == "// SKIP-DOTTY-START" || line.trim == "// SKIP-DOTTY-START")
24+
skipMode = true
25+
else if (line.trim == "// SKIP-DOTTY-END" || line.trim == "// SKIP-DOTTY-END")
26+
skipMode = false
27+
else if (!skipMode) {
28+
destWriter.write(transformLine(line))
29+
destWriter.newLine()
30+
}
31+
}
32+
destFile
33+
}
34+
finally {
35+
destWriter.flush()
36+
destWriter.close()
37+
println("Copied " + destFile.getAbsolutePath)
38+
}
39+
}
40+
41+
def copyDir(sourceDirName: String, packageDirName: String, targetDir: File, skipList: List[String]): Seq[File] = {
42+
val packageDir = new File(targetDir, packageDirName)
43+
packageDir.mkdirs()
44+
val sourceDir = new File(sourceDirName)
45+
sourceDir.listFiles.toList.filter(f => f.isFile && !skipList.contains(f.getName) && (f.getName.endsWith(".scala") || f.getName.endsWith(".java"))).map { sourceFile =>
46+
val destFile = new File(packageDir, sourceFile.getName)
47+
if (!destFile.exists || sourceFile.lastModified > destFile.lastModified)
48+
copyFile(sourceFile, destFile)
49+
50+
destFile
51+
}
52+
}
53+
54+
def genScalaTestCore(targetDir: File, version: String, scalaVersion: String): Seq[File] = {
55+
GenScalaTestDotty.genScalaPackages.filter { case (packagePath, skipList) =>
56+
List(
57+
"org/scalatest",
58+
"org/scalatest/compatible",
59+
"org/scalatest/concurrent",
60+
"org/scalatest/enablers",
61+
"org/scalatest/exceptions",
62+
"org/scalatest/events",
63+
"org/scalatest/fixture",
64+
"org/scalatest/prop",
65+
"org/scalatest/tagobjects",
66+
"org/scalatest/tags",
67+
"org/scalatest/time",
68+
"org/scalatest/tools",
69+
"org/scalatest/verbs",
70+
).contains(packagePath)
71+
}.flatMap { case (packagePath, skipList) =>
72+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir,
73+
if (packagePath == "org/scalatest" || packagePath == "org/scalatest/fixture") skipList ++ List("package.scala") else skipList)
74+
}.toList ++
75+
copyDir("scalatest.dotty/src/main/scala/org/scalatest", "org/scalatest", targetDir,
76+
List(
77+
"package.scala"/*,
78+
"CompileMacro.scala"*/
79+
)
80+
) ++
81+
copyDir("scalatest.dotty/src/main/scala/org/scalatest/diagrams", "org/scalatest/diagrams", targetDir,List.empty)
82+
}
83+
84+
def genScalaTestCoreJava(targetDir: File, version: String, scalaVersion: String): Seq[File] = {
85+
copyDir("scalatest/src/main/java/org/scalatest", "org/scalatest", targetDir,List.empty) ++
86+
copyDir("scalatest/src/main/java/org/scalatest/tags", "org/scalatest/tags", targetDir,List.empty)
87+
}
88+
89+
}

project/scalatest.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,15 @@ object ScalatestBuild extends BuildCommons with DottyBuild with NativeBuild with
607607
GenModules.genScalaTestCoreJava((javaSourceManaged in Compile).value, version.value, scalaVersion.value)
608608
}.taskValue
609609
},
610+
resourceGenerators in Compile += {
611+
Def.task {
612+
GenScalaTestDotty.genHtml((resourceManaged in Compile).value, version.value, scalaVersion.value)
613+
}.taskValue
614+
},
610615
sourceGenerators in Compile += {
611616
Def.task{
612617
GenModules.genScalaTestCore((sourceManaged in Compile).value, version.value, scalaVersion.value) ++
618+
GenTable.genMain((sourceManaged in Compile).value / "org" / "scalatest", version.value, scalaVersion.value) ++
613619
GenConfigMap.genMain((sourceManaged in Compile).value, version.value, scalaVersion.value) ++
614620
ScalaTestGenResourcesJVM.genResources((sourceManaged in Compile).value / "org" / "scalatest", version.value, scalaVersion.value) ++
615621
ScalaTestGenResourcesJVM.genFailureMessages((sourceManaged in Compile).value / "org" / "scalatest", version.value, scalaVersion.value) ++

0 commit comments

Comments
 (0)