Skip to content

Commit 1e56ca0

Browse files
committed
Port tasty inspector test from scala2-library-tasty-tests
Part of #19379 The new test is run on all available configurations. Now it also runs on Windows.
1 parent 21cfb15 commit 1e56ca0

File tree

2 files changed

+53
-32
lines changed

2 files changed

+53
-32
lines changed

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ class BootstrappedStdLibTASYyTest:
1717

1818
import BootstrappedStdLibTASYyTest._
1919

20-
/** Test that we can load trees from TASTy */
21-
@Test def testTastyInspector: Unit =
22-
loadWithTastyInspector(loadBlacklisted)
23-
2420
/** Test that we can load and compile trees from TASTy in a Jar */
2521
@Test def testFromTastyInJar: Unit =
2622
compileFromTastyInJar(loadBlacklisted.union(compileBlacklisted))
@@ -52,23 +48,6 @@ class BootstrappedStdLibTASYyTest:
5248
compileBlacklisted.diff(scalaLibTastyPathsSet).mkString(
5349
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n"))
5450

55-
@Ignore
56-
@Test def testLoadBacklistIsMinimal =
57-
var shouldBeWhitelisted = List.empty[String]
58-
val size = loadBlacklisted.size
59-
for (notBlacklisted, i) <- loadBlacklist.zipWithIndex do
60-
val blacklist = loadBlacklisted - notBlacklisted
61-
println(s"Trying without $notBlacklisted in the blacklist (${i+1}/$size)")
62-
try {
63-
loadWithTastyInspector(blacklist)
64-
shouldBeWhitelisted = notBlacklisted :: shouldBeWhitelisted
65-
}
66-
catch {
67-
case ex: Throwable => // ok
68-
}
69-
assert(shouldBeWhitelisted.isEmpty,
70-
shouldBeWhitelisted.mkString("Some classes do not need to be blacklisted in `loadBlacklisted`\n ", "\n ", "\n\n"))
71-
7251
@Ignore
7352
@Test def testCompileBlacklistIsMinimal =
7453
var shouldBeWhitelisted = List.empty[String]
@@ -101,17 +80,6 @@ object BootstrappedStdLibTASYyTest:
10180
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + "/"))
10281
.toList
10382

104-
def loadWithTastyInspector(blacklisted: Set[String]): Unit =
105-
val inspector = new scala.tasty.inspector.Inspector {
106-
def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
107-
for tasty <- tastys do
108-
tasty.ast.show(using quotes.reflect.Printer.TreeStructure) // Check that we can traverse the full tree
109-
()
110-
}
111-
val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted)
112-
val isSuccess = TastyInspector.inspectTastyFiles(tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString))(inspector)
113-
assert(isSuccess, "Errors reported while loading from TASTy")
114-
11583
def compileFromTastyInJar(blacklisted: Set[String]): Unit = {
11684
val driver = new dotty.tools.dotc.Driver
11785
val yFromTastyBlacklist =
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import scala.quoted._
2+
import scala.tasty.inspector._
3+
4+
import dotty.tools.io.Directory
5+
6+
import java.io.File.pathSeparator
7+
import java.io.File.separator
8+
9+
@main def Test: Unit =
10+
blacklistsOnlyContainsClassesThatExist()
11+
testTastyInspector()
12+
13+
/** Test that we can load trees from TASTy */
14+
def testTastyInspector(): Unit =
15+
loadWithTastyInspector(loadBlacklisted)
16+
17+
def blacklistsOnlyContainsClassesThatExist() =
18+
val scalaLibTastyPathsSet = scalaLibTastyPaths.toSet
19+
assert(loadBlacklisted.diff(scalaLibTastyPathsSet).isEmpty,
20+
loadBlacklisted.diff(scalaLibTastyPathsSet).mkString(
21+
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n"))
22+
23+
def dottyVersion =
24+
System.getProperty("java.class.path").nn.split(pathSeparator).collectFirst {
25+
case path if path.endsWith(".jar") && path.contains("scala3-library_3-") =>
26+
path.split("scala3-library_3-").last.stripSuffix(".jar")
27+
}.get
28+
29+
def scalaLibClassesPath =
30+
java.nio.file.Paths.get(
31+
s"out/bootstrap/scala2-library-bootstrapped/scala-$dottyVersion-nonbootstrapped/classes".replace("/", separator))
32+
33+
lazy val scalaLibTastyPaths =
34+
new Directory(scalaLibClassesPath).deepFiles
35+
.filter(_.`extension` == "tasty")
36+
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + separator))
37+
.toList
38+
39+
def loadWithTastyInspector(blacklisted: Set[String]): Unit =
40+
val inspector = new scala.tasty.inspector.Inspector {
41+
def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
42+
for tasty <- tastys do
43+
tasty.ast.show(using quotes.reflect.Printer.TreeStructure) // Check that we can traverse the full tree
44+
()
45+
}
46+
val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted)
47+
val isSuccess = TastyInspector.inspectTastyFiles(tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString))(inspector)
48+
assert(isSuccess, "Errors reported while loading from TASTy")
49+
50+
/** Set of tasty files that cannot be loaded from TASTy */
51+
def loadBlacklisted = Set[String](
52+
// No issues :)
53+
)

0 commit comments

Comments
 (0)