Skip to content

Commit b425f90

Browse files
committed
Merge branch 'cheeseng-feature-js-modules' into 3.1.x
2 parents 55cce77 + 4abf65e commit b425f90

File tree

19 files changed

+674
-72
lines changed

19 files changed

+674
-72
lines changed

build.sbt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,16 @@ lazy val scalatestWordSpec = ScalatestBuild.scalatestWordSpec
5959
lazy val scalatestDiagrams = ScalatestBuild.scalatestDiagrams
6060
lazy val scalatestMatchersCore = ScalatestBuild.scalatestMatchersCore
6161
lazy val scalatestShouldMatchers = ScalatestBuild.scalatestShouldMatchers
62-
lazy val scalatestMustMatchers = ScalatestBuild.scalatestMustMatchers
62+
lazy val scalatestMustMatchers = ScalatestBuild.scalatestMustMatchers
63+
lazy val scalatestCoreJS = ScalatestBuild.scalatestCoreJS
64+
lazy val scalatestFeatureSpecJS = ScalatestBuild.scalatestFeatureSpecJS
65+
lazy val scalatestFlatSpecJS = ScalatestBuild.scalatestFlatSpecJS
66+
lazy val scalatestFreeSpecJS = ScalatestBuild.scalatestFreeSpecJS
67+
lazy val scalatestFunSuiteJS = ScalatestBuild.scalatestFunSuiteJS
68+
lazy val scalatestPropSpecJS = ScalatestBuild.scalatestPropSpecJS
69+
lazy val scalatestWordSpecJS = ScalatestBuild.scalatestWordSpecJS
70+
lazy val scalatestDiagramsJS = ScalatestBuild.scalatestDiagramsJS
71+
lazy val scalatestMatchersCoreJS = ScalatestBuild.scalatestMatchersCoreJS
72+
lazy val scalatestShouldMatchersJS = ScalatestBuild.scalatestShouldMatchersJS
73+
lazy val scalatestMustMatchersJS = ScalatestBuild.scalatestMustMatchersJS
74+
lazy val scalatestModulesJS = ScalatestBuild.scalatestModulesJS
File renamed without changes.
File renamed without changes.

project/GenModulesJS.scala

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import java.io.{File, BufferedWriter, FileWriter}
2+
import scala.io.Source
3+
4+
object GenModulesJS {
5+
6+
private def uncommentJsExport(line: String): String =
7+
if (line.trim.startsWith("//SCALATESTJS,NATIVE-ONLY "))
8+
line.substring(line.indexOf("//SCALATESTJS,NATIVE-ONLY ") + 26)
9+
else if (line.trim.startsWith("//SCALATESTJS-ONLY "))
10+
line.substring(line.indexOf("//SCALATESTJS-ONLY ") + 19)
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-SCALATESTJS,NATIVE-START" || line.trim == "// SKIP-SCALATESTJS-START")
24+
skipMode = true
25+
else if (line.trim == "// SKIP-SCALATESTJS,NATIVE-END" || line.trim == "// SKIP-SCALATESTJS-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+
private 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"))).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 genScalaTestCompatible(targetDir: File, version: String, scalaVersion: String): Seq[File] = {
55+
copyDir("scalatest/src/main/java/org/scalatest/compatible", "org/scalatest/compatible", targetDir,List.empty)
56+
}*/
57+
58+
def genScalaTestCore(targetDir: File, version: String, scalaVersion: String): Seq[File] = {
59+
GenScalaTestJS.genScalaPackages.filter { case (packagePath, skipList) =>
60+
List(
61+
"org/scalatest",
62+
"org/scalatest/concurrent",
63+
"org/scalatest/enablers",
64+
"org/scalatest/exceptions",
65+
"org/scalatest/events",
66+
"org/scalatest/fixture",
67+
"org/scalatest/prop",
68+
"org/scalatest/tagobjects",
69+
"org/scalatest/time",
70+
"org/scalatest/tools",
71+
"org/scalatest/verbs",
72+
).contains(packagePath)
73+
}.flatMap { case (packagePath, skipList) =>
74+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir,
75+
if (packagePath == "org/scalatest" || packagePath == "org/scalatest/fixture") skipList ++ List("package.scala") else skipList)
76+
}.toList ++
77+
copyDir("scalatest.js/src/main/scala/org/scalatest", "org/scalatest", targetDir, List.empty) ++
78+
copyDir("scalatest.js/src/main/scala/org/scalatest/compatible", "org/scalatest/compatible", targetDir, List.empty) ++
79+
copyDir("scalatest.js/src/main/scala/org/scalatest/concurrent", "org/scalatest/concurrent", targetDir, List.empty) ++
80+
copyDir("scalatest.js/src/main/scala/org/scalatest/exceptions", "org/scalatest/exceptions", targetDir, List.empty) ++
81+
copyDir("scalatest.js/src/main/scala/org/scalatest/tools", "org/scalatest/tools", targetDir, List.empty) ++
82+
copyDir("modules/jvm/scalatest-core/src/main/scala/org/scalatest", "org/scalatest", targetDir, List.empty) ++
83+
copyDir("modules/jvm/scalatest-core/src/main/scala/org/scalatest/fixture", "org/scalatest/fixture", targetDir, List.empty)
84+
}
85+
86+
def genScalaTestFeatureSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
87+
GenScalaTestJS.genScalaPackages.filter { case (packagePath, skipList) =>
88+
List(
89+
"org/scalatest/featurespec"
90+
).contains(packagePath)
91+
}.flatMap { case (packagePath, skipList) =>
92+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
93+
}.toList
94+
95+
def genScalaTestFlatSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
96+
GenScalaTestJS.genScalaPackages.filter { case (packagePath, skipList) =>
97+
List(
98+
"org/scalatest/flatspec"
99+
).contains(packagePath)
100+
}.flatMap { case (packagePath, skipList) =>
101+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
102+
}.toList
103+
104+
def genScalaTestFreeSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
105+
GenScalaTestJS.genScalaPackages.filter { case (packagePath, skipList) =>
106+
List(
107+
"org/scalatest/freespec"
108+
).contains(packagePath)
109+
}.flatMap { case (packagePath, skipList) =>
110+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
111+
}.toList
112+
113+
def genScalaTestFunSuite(targetDir: File, version: String, scalaVersion: String): Seq[File] =
114+
GenScalaTestJS.genScalaPackages.filter { case (packagePath, skipList) =>
115+
List(
116+
"org/scalatest/funsuite"
117+
).contains(packagePath)
118+
}.flatMap { case (packagePath, skipList) =>
119+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
120+
}.toList
121+
122+
def genScalaTestPropSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
123+
GenScalaTestJS.genScalaPackages.filter { case (packagePath, skipList) =>
124+
List(
125+
"org/scalatest/propspec"
126+
).contains(packagePath)
127+
}.flatMap { case (packagePath, skipList) =>
128+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
129+
}.toList
130+
131+
def genScalaTestWordSpec(targetDir: File, version: String, scalaVersion: String): Seq[File] =
132+
GenScalaTestJS.genScalaPackages.filter { case (packagePath, skipList) =>
133+
List(
134+
"org/scalatest/wordspec"
135+
).contains(packagePath)
136+
}.flatMap { case (packagePath, skipList) =>
137+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
138+
}.toList
139+
140+
def genScalaTestDiagrams(targetDir: File, version: String, scalaVersion: String): Seq[File] =
141+
GenScalaTestJS.genScalaPackages.filter { case (packagePath, skipList) =>
142+
List(
143+
"org/scalatest/diagrams"
144+
).contains(packagePath)
145+
}.flatMap { case (packagePath, skipList) =>
146+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
147+
}.toList
148+
149+
def genScalaTestMatchersCore(targetDir: File, version: String, scalaVersion: String): Seq[File] =
150+
GenScalaTestJS.genScalaPackages.filter { case (packagePath, skipList) =>
151+
List(
152+
"org/scalatest/matchers",
153+
"org/scalatest/matchers/dsl"
154+
).contains(packagePath)
155+
}.flatMap { case (packagePath, skipList) =>
156+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
157+
}.toList
158+
159+
def genScalaTestShouldMatchers(targetDir: File, version: String, scalaVersion: String): Seq[File] =
160+
GenScalaTestJS.genScalaPackages.filter { case (packagePath, skipList) =>
161+
List(
162+
"org/scalatest/matchers/should"
163+
).contains(packagePath)
164+
}.flatMap { case (packagePath, skipList) =>
165+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
166+
}.toList
167+
}

project/GenScalaTestJS.scala

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ object GenScalaTestJS {
123123
copyResourceDir("scalatest/src/main/html", "html", targetDir, List.empty)
124124
}
125125

126-
def genScala(targetDir: File, version: String, scalaVersion: String): Seq[File] = {
127-
copyDir("scalatest/src/main/scala/org/scalatest", "org/scalatest", targetDir,
128-
List(
126+
val genScalaPackages: Map[String, List[String]] =
127+
Map(
128+
"org/scalatest" -> List(
129129
"DispatchReporter.scala",
130130
"Doc.scala",
131131
"DocSpec.scala",
@@ -140,27 +140,21 @@ object GenScalaTestJS {
140140
"SuiteRerunner.scala",
141141
"run.scala",
142142
"SeveredStackTraces.scala" // skipped because stack trace isn't really helpful after linked in different js env like node.
143-
)
144-
) ++
145-
copyDir("scalatest/src/main/scala/org/scalatest/fixture", "org/scalatest/fixture", targetDir,
146-
List(
143+
),
144+
"org/scalatest/fixture" -> List(
147145
"Spec.scala",
148146
"SpecLike.scala"
149-
)
150-
) ++
151-
copyDir("scalatest/src/main/scala/org/scalatest/diagrams", "org/scalatest/diagrams", targetDir, List.empty) ++
152-
copyDir("scalatest/src/main/scala/org/scalatest/events", "org/scalatest/events", targetDir, List.empty) ++
153-
copyDir("scalatest/src/main/scala/org/scalatest/expectations", "org/scalatest/expectations", targetDir, List.empty) ++
154-
copyDir("scalatest/src/main/scala/org/scalatest/matchers", "org/scalatest/matchers", targetDir, List.empty) ++
155-
copyDir("scalatest/src/main/scala/org/scalatest/matchers/dsl", "org/scalatest/matchers/dsl", targetDir,
156-
List(
147+
),
148+
"org/scalatest/diagrams" -> List.empty,
149+
"org/scalatest/events" -> List.empty,
150+
"org/scalatest/expectations" -> List.empty,
151+
"org/scalatest/matchers" -> List.empty,
152+
"org/scalatest/matchers/dsl" -> List(
157153
"JavaCollectionWrapper.scala",
158154
"JavaMapWrapper.scala"
159-
)
160-
) ++
161-
copyDir("scalatest/src/main/scala/org/scalatest/matchers/should", "org/scalatest/matchers/should", targetDir, List.empty) ++
162-
copyDir("scalatest/src/main/scala/org/scalatest/tools", "org/scalatest/tools", targetDir,
163-
List(
155+
),
156+
"org/scalatest/matchers/should" -> List.empty,
157+
"org/scalatest/tools" -> List(
164158
"AboutJDialog.scala",
165159
//"AnsiColor.scala",
166160
"AnsiReset.scala",
@@ -209,27 +203,23 @@ object GenScalaTestJS {
209203
"TestSpec.scala",
210204
"XmlReporter.scala",
211205
"XmlSocketReporter.scala"
212-
)
213-
) ++
214-
copyDir("scalatest/src/main/scala/org/scalatest/exceptions", "org/scalatest/exceptions", targetDir,
215-
List(
206+
),
207+
"org/scalatest/exceptions" -> List(
216208
"StackDepthExceptionHelper.scala"
217-
)
218-
) ++
219-
copyDir("scalatest/src/main/scala/org/scalatest/time", "org/scalatest/time", targetDir, List.empty) ++
220-
copyDir("scalatest/src/main/scala/org/scalatest/verbs", "org/scalatest/verbs", targetDir, List.empty) ++
221-
copyDir("scalatest/src/main/scala/org/scalatest/words", "org/scalatest/words", targetDir, List.empty) ++
222-
copyDir("scalatest/src/main/scala/org/scalatest/enablers", "org/scalatest/enablers", targetDir, List.empty) ++
223-
copyDir("scalatest/src/main/scala/org/scalatest/funsuite", "org/scalatest/funsuite", targetDir, List.empty) ++
224-
copyDir("scalatest/src/main/scala/org/scalatest/featurespec", "org/scalatest/featurespec", targetDir, List.empty) ++
225-
copyDir("scalatest/src/main/scala/org/scalatest/funspec", "org/scalatest/funspec", targetDir, List.empty) ++
226-
copyDir("scalatest/src/main/scala/org/scalatest/freespec", "org/scalatest/freespec", targetDir, List.empty) ++
227-
copyDir("scalatest/src/main/scala/org/scalatest/flatspec", "org/scalatest/flatspec", targetDir, List.empty) ++
228-
copyDir("scalatest/src/main/scala/org/scalatest/prop", "org/scalatest/prop", targetDir, List.empty) ++
229-
copyDir("scalatest/src/main/scala/org/scalatest/propspec", "org/scalatest/propspec", targetDir, List.empty) ++
230-
copyDir("scalatest/src/main/scala/org/scalatest/wordspec", "org/scalatest/wordspec", targetDir, List.empty) ++
231-
copyDir("scalatest/src/main/scala/org/scalatest/concurrent", "org/scalatest/concurrent", targetDir,
232-
List(
209+
),
210+
"org/scalatest/time" -> List.empty,
211+
"org/scalatest/verbs" -> List.empty,
212+
"org/scalatest/words" -> List.empty,
213+
"org/scalatest/enablers" -> List.empty,
214+
"org/scalatest/funsuite" -> List.empty,
215+
"org/scalatest/featurespec" -> List.empty,
216+
"org/scalatest/funspec" -> List.empty,
217+
"org/scalatest/freespec" -> List.empty,
218+
"org/scalatest/flatspec" -> List.empty,
219+
"org/scalatest/prop" -> List.empty,
220+
"org/scalatest/propspec" -> List.empty,
221+
"org/scalatest/wordspec" -> List.empty,
222+
"org/scalatest/concurrent" -> List(
233223
"Waiters.scala", // skipeed because doesn't really make sense on js's single-thread environment.
234224
"Conductors.scala", // skipped because depends on PimpedReadWriteLock
235225
"ConductorFixture.scala", // skipped because depends on Conductors
@@ -249,19 +239,21 @@ object GenScalaTestJS {
249239
"Timeouts.scala", // skipped because js is single-threaded and does not share memory, there's no practical way to interrupt in js.
250240
"TimeoutTask.scala", // skipped because timeout is not supported.,
251241
"Ultimately.scala" // skipped because js is single thread and does not share memory.
252-
)
253-
) ++
254-
copyDir("scalatest/src/main/scala/org/scalatest/path", "org/scalatest/path", targetDir, List.empty) ++
255-
copyDir("scalatest/src/main/scala/org/scalatest/tagobjects", "org/scalatest/tagobjects", targetDir,
256-
List(
242+
),
243+
"org/scalatest/path" -> List.empty,
244+
"org/scalatest/tagobjects" -> List(
257245
"ChromeBrowser.scala", // skipped because selenium not supported.
258246
"FirefoxBrowser.scala", // skipped because selenium not supported.
259247
"HtmlUnitBrowser.scala", // skipped because selenium not supported.
260248
"InternetExplorerBrowser.scala", // skipped because selenium not supported.
261249
"SafariBrowser.scala" // skipped because selenium not supported.
262250
)
263251
)
264-
}
252+
253+
def genScala(targetDir: File, version: String, scalaVersion: String): Seq[File] =
254+
genScalaPackages.flatMap { case (packagePath, skipList) =>
255+
copyDir("scalatest/src/main/scala/" + packagePath, packagePath, targetDir, skipList)
256+
}.toList
265257

266258
def genTest(targetDir: File, version: String, scalaVersion: String): Seq[File] = {
267259
//copyStartsWithFiles("scalatest-test/src/test/scala/org/scalatest", "org/scalatest", "Async", targetDir) ++

0 commit comments

Comments
 (0)