Skip to content

Commit 316a096

Browse files
committed
Port tests form scala2-library-tasty-tests to normal tests
Split BootstrappedStdLibTASYyTest into the part that tests the TASTy inspector and the part that tests recompilation. We also remove `scala2-library-tasty-tests` as it is now empty and will not serve any purpose anymore.
1 parent 1e56ca0 commit 316a096

File tree

6 files changed

+138
-171
lines changed

6 files changed

+138
-171
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141

142142
- name: Cmd Tests
143143
run: |
144-
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*; scala2-library-tasty-tests/test; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
144+
./project/scripts/sbt ";dist/pack; scala3-bootstrapped/compile; scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
145145
./project/scripts/cmdTests
146146
./project/scripts/bootstrappedOnlyCmdTests
147147
@@ -585,7 +585,7 @@ jobs:
585585

586586
- name: Test
587587
run: |
588-
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*; scala2-library-tasty-tests/test"
588+
./project/scripts/sbt ";dist/pack ;scala3-bootstrapped/compile ;scala3-bootstrapped/test ;sbt-test/scripted scala2-compat/*"
589589
./project/scripts/cmdTests
590590
./project/scripts/bootstrappedOnlyCmdTests
591591

build.sbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ val `scala3-bench-bootstrapped` = Build.`scala3-bench-bootstrapped`
1616
val `scala3-bench-micro` = Build.`scala3-bench-micro`
1717
val `scala2-library-bootstrapped` = Build.`scala2-library-bootstrapped`
1818
val `scala2-library-tasty` = Build.`scala2-library-tasty`
19-
val `scala2-library-tasty-tests` = Build.`scala2-library-tasty-tests`
2019
val `scala2-library-cc` = Build.`scala2-library-cc`
2120
val `scala2-library-cc-tasty` = Build.`scala2-library-cc-tasty`
2221
val `tasty-core` = Build.`tasty-core`

project/Build.scala

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,32 +1249,6 @@ object Build {
12491249
},
12501250
)
12511251

1252-
/** Test the tasty generated by `scala2-library-bootstrapped`
1253-
*
1254-
* The sources in src are compiled using TASTy from scala2-library-tasty but then run
1255-
* with the scala-library compiled be Scala 2.
1256-
*
1257-
* The tests are run with the bootstrapped compiler and the tasty inspector on the classpath.
1258-
* The classpath has the default `scala-library` and not `scala2-library-bootstrapped`.
1259-
*
1260-
* The jar of `scala2-library-bootstrapped` is provided for to the tests.
1261-
* - inspector: test that we can load the contents of the jar using the tasty inspector
1262-
* - from-tasty: test that we can recompile the contents of the jar using `dotc -from-tasty`
1263-
*/
1264-
lazy val `scala2-library-tasty-tests` = project.in(file("scala2-library-tasty-tests")).
1265-
withCommonSettings(Bootstrapped).
1266-
dependsOn(dottyCompiler(Bootstrapped) % "compile->compile").
1267-
dependsOn(`scala3-tasty-inspector` % "test->test").
1268-
dependsOn(`scala2-library-tasty`).
1269-
settings(commonBootstrappedSettings).
1270-
settings(
1271-
javaOptions := (`scala3-compiler-bootstrapped` / javaOptions).value,
1272-
Test / javaOptions += "-Ddotty.scala.library=" + (`scala2-library-bootstrapped` / Compile / packageBin).value.getAbsolutePath,
1273-
Compile / compile / fullClasspath ~= {
1274-
_.filterNot(file => file.data.getName == s"scala-library-$stdlibBootstrappedVersion.jar")
1275-
},
1276-
)
1277-
12781252
lazy val `scala3-sbt-bridge` = project.in(file("sbt-bridge/src")).
12791253
// We cannot depend on any bootstrapped project to compile the bridge, since the
12801254
// bridge is needed to compile these projects.

scala2-library-tasty-tests/test/BootstrappedStdLibTASYyTest.scala

Lines changed: 0 additions & 142 deletions
This file was deleted.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import dotty.tools.io.Directory
2+
import dotty.tools.dotc.util.ClasspathFromClassloader
3+
4+
import java.io.File.pathSeparator
5+
import java.io.File.separator
6+
7+
@main def Test: Unit =
8+
blacklistsOnlyContainsClassesThatExist()
9+
compileFromTastyInJar(compileBlacklisted)
10+
11+
def blacklistsOnlyContainsClassesThatExist() =
12+
val scalaLibTastyPathsSet = scalaLibTastyPaths.toSet
13+
assert(compileBlacklisted.diff(scalaLibTastyPathsSet).isEmpty,
14+
compileBlacklisted.diff(scalaLibTastyPathsSet).mkString(
15+
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n"))
16+
17+
def dottyVersion =
18+
System.getProperty("java.class.path").nn.split(pathSeparator).collectFirst {
19+
case path if path.endsWith(".jar") && path.contains("scala3-library_3-") =>
20+
path.split("scala3-library_3-").last.stripSuffix(".jar")
21+
}.get
22+
23+
def scalaLibJarPath =
24+
s"out/bootstrap/scala2-library-tasty/scala-$dottyVersion-nonbootstrapped/scala2-library-tasty-experimental_3-$dottyVersion.jar"
25+
26+
def scalaLibClassesPath =
27+
java.nio.file.Paths.get(
28+
s"out/bootstrap/scala2-library-bootstrapped/scala-$dottyVersion-nonbootstrapped/classes")
29+
30+
lazy val scalaLibTastyPaths =
31+
new Directory(scalaLibClassesPath).deepFiles
32+
.filter(_.`extension` == "tasty")
33+
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + "/"))
34+
.toList
35+
36+
def compileFromTastyInJar(blacklisted: Set[String]): Unit = {
37+
val driver = new dotty.tools.dotc.Driver
38+
val yFromTastyBlacklist =
39+
blacklisted.mkString("-Yfrom-tasty-ignore-list:", ",", "")
40+
val args = Array(
41+
"-classpath", ClasspathFromClassloader(getClass.getClassLoader),
42+
"-from-tasty",
43+
"-d", "out/scala2-library-from-tasty-jar-test-output.jar",
44+
"-nowarn",
45+
yFromTastyBlacklist,
46+
scalaLibJarPath,
47+
)
48+
val reporter = driver.process(args)
49+
assert(reporter.errorCount == 0, "Errors while re-compiling")
50+
}
51+
52+
/** Set of tasty files that cannot be recompiled from TASTy */
53+
def compileBlacklisted = Set[String](
54+
// See #10048
55+
// failed: java.lang.AssertionError: assertion failed: class Boolean
56+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.assertClassNotArrayNotPrimitive(BCodeHelpers.scala:247)
57+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass(BCodeHelpers.scala:265)
58+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass$(BCodeHelpers.scala:210)
59+
// at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.getClassBTypeAndRegisterInnerClass(BCodeSkelBuilder.scala:62)
60+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.internalName(BCodeHelpers.scala:237)
61+
"scala/Array.tasty",
62+
"scala/Boolean.tasty",
63+
"scala/Byte.tasty",
64+
"scala/Char.tasty",
65+
"scala/Double.tasty",
66+
"scala/Float.tasty",
67+
"scala/Int.tasty",
68+
"scala/Long.tasty",
69+
"scala/Short.tasty",
70+
"scala/Unit.tasty",
71+
).map(_.replace("/", separator))
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import dotty.tools.io.Directory
2+
import dotty.tools.dotc.util.ClasspathFromClassloader
3+
4+
import java.io.File.pathSeparator
5+
import java.io.File.separator
6+
7+
@main def Test: Unit =
8+
blacklistsOnlyContainsClassesThatExist()
9+
compileFromTasty(compileBlacklisted)
10+
11+
def blacklistsOnlyContainsClassesThatExist() =
12+
val scalaLibTastyPathsSet = scalaLibTastyPaths.toSet
13+
assert(compileBlacklisted.diff(scalaLibTastyPathsSet).isEmpty,
14+
compileBlacklisted.diff(scalaLibTastyPathsSet).mkString(
15+
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n"))
16+
17+
def dottyVersion =
18+
System.getProperty("java.class.path").nn.split(pathSeparator).collectFirst {
19+
case path if path.endsWith(".jar") && path.contains("scala3-library_3-") =>
20+
path.split("scala3-library_3-").last.stripSuffix(".jar")
21+
}.get
22+
23+
def scalaLibClassesPath =
24+
java.nio.file.Paths.get(
25+
s"out/bootstrap/scala2-library-bootstrapped/scala-$dottyVersion-nonbootstrapped/classes")
26+
27+
lazy val scalaLibTastyPaths =
28+
new Directory(scalaLibClassesPath).deepFiles
29+
.filter(_.`extension` == "tasty")
30+
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + "/"))
31+
.toList
32+
33+
def compileFromTasty(blacklisted: Set[String]): Unit = {
34+
val driver = new dotty.tools.dotc.Driver
35+
val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted)
36+
val args = Array(
37+
"-classpath", ClasspathFromClassloader(getClass.getClassLoader),
38+
"-from-tasty",
39+
"-d", "out/scala2-library-from-tasty-test-output.jar",
40+
"-nowarn",
41+
) ++ tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString)
42+
val reporter = driver.process(args)
43+
assert(reporter.errorCount == 0, "Errors while re-compiling")
44+
}
45+
46+
/** Set of tasty files that cannot be recompiled from TASTy */
47+
def compileBlacklisted = Set[String](
48+
// See #10048
49+
// failed: java.lang.AssertionError: assertion failed: class Boolean
50+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.assertClassNotArrayNotPrimitive(BCodeHelpers.scala:247)
51+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass(BCodeHelpers.scala:265)
52+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.getClassBTypeAndRegisterInnerClass$(BCodeHelpers.scala:210)
53+
// at dotty.tools.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.getClassBTypeAndRegisterInnerClass(BCodeSkelBuilder.scala:62)
54+
// at dotty.tools.backend.jvm.BCodeHelpers$BCInnerClassGen.internalName(BCodeHelpers.scala:237)
55+
"scala/Array.tasty",
56+
"scala/Boolean.tasty",
57+
"scala/Byte.tasty",
58+
"scala/Char.tasty",
59+
"scala/Double.tasty",
60+
"scala/Float.tasty",
61+
"scala/Int.tasty",
62+
"scala/Long.tasty",
63+
"scala/Short.tasty",
64+
"scala/Unit.tasty",
65+
).map(_.replace("/", separator))

0 commit comments

Comments
 (0)