Skip to content

Port tasty inspector test from scala2-library-tasty-tests #19901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions scala2-library-tasty-tests/test/BootstrappedStdLibTASYyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ class BootstrappedStdLibTASYyTest:

import BootstrappedStdLibTASYyTest._

/** Test that we can load trees from TASTy */
@Test def testTastyInspector: Unit =
loadWithTastyInspector(loadBlacklisted)

/** Test that we can load and compile trees from TASTy in a Jar */
@Test def testFromTastyInJar: Unit =
compileFromTastyInJar(loadBlacklisted.union(compileBlacklisted))
Expand Down Expand Up @@ -52,23 +48,6 @@ class BootstrappedStdLibTASYyTest:
compileBlacklisted.diff(scalaLibTastyPathsSet).mkString(
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n"))

@Ignore
@Test def testLoadBacklistIsMinimal =
var shouldBeWhitelisted = List.empty[String]
val size = loadBlacklisted.size
for (notBlacklisted, i) <- loadBlacklist.zipWithIndex do
val blacklist = loadBlacklisted - notBlacklisted
println(s"Trying without $notBlacklisted in the blacklist (${i+1}/$size)")
try {
loadWithTastyInspector(blacklist)
shouldBeWhitelisted = notBlacklisted :: shouldBeWhitelisted
}
catch {
case ex: Throwable => // ok
}
assert(shouldBeWhitelisted.isEmpty,
shouldBeWhitelisted.mkString("Some classes do not need to be blacklisted in `loadBlacklisted`\n ", "\n ", "\n\n"))

@Ignore
@Test def testCompileBlacklistIsMinimal =
var shouldBeWhitelisted = List.empty[String]
Expand Down Expand Up @@ -101,17 +80,6 @@ object BootstrappedStdLibTASYyTest:
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + "/"))
.toList

def loadWithTastyInspector(blacklisted: Set[String]): Unit =
val inspector = new scala.tasty.inspector.Inspector {
def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
for tasty <- tastys do
tasty.ast.show(using quotes.reflect.Printer.TreeStructure) // Check that we can traverse the full tree
()
}
val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted)
val isSuccess = TastyInspector.inspectTastyFiles(tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString))(inspector)
assert(isSuccess, "Errors reported while loading from TASTy")

def compileFromTastyInJar(blacklisted: Set[String]): Unit = {
val driver = new dotty.tools.dotc.Driver
val yFromTastyBlacklist =
Expand Down
53 changes: 53 additions & 0 deletions tests/run-tasty-inspector/scala2-library-test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import scala.quoted._
import scala.tasty.inspector._

import dotty.tools.io.Directory

import java.io.File.pathSeparator
import java.io.File.separator

@main def Test: Unit =
blacklistsOnlyContainsClassesThatExist()
testTastyInspector()

/** Test that we can load trees from TASTy */
def testTastyInspector(): Unit =
loadWithTastyInspector(loadBlacklisted)

def blacklistsOnlyContainsClassesThatExist() =
val scalaLibTastyPathsSet = scalaLibTastyPaths.toSet
assert(loadBlacklisted.diff(scalaLibTastyPathsSet).isEmpty,
loadBlacklisted.diff(scalaLibTastyPathsSet).mkString(
"`loadBlacklisted` contains names that are not in `scalaLibTastyPaths`: \n ", "\n ", "\n\n"))

def dottyVersion =
System.getProperty("java.class.path").nn.split(pathSeparator).collectFirst {
case path if path.endsWith(".jar") && path.contains("scala3-library_3-") =>
path.split("scala3-library_3-").last.stripSuffix(".jar")
}.get

def scalaLibClassesPath =
java.nio.file.Paths.get(
s"out/bootstrap/scala2-library-bootstrapped/scala-$dottyVersion-nonbootstrapped/classes".replace("/", separator))

lazy val scalaLibTastyPaths =
new Directory(scalaLibClassesPath).deepFiles
.filter(_.`extension` == "tasty")
.map(_.normalize.path.stripPrefix(scalaLibClassesPath.toString + separator))
.toList

def loadWithTastyInspector(blacklisted: Set[String]): Unit =
val inspector = new scala.tasty.inspector.Inspector {
def inspect(using Quotes)(tastys: List[Tasty[quotes.type]]): Unit =
for tasty <- tastys do
tasty.ast.show(using quotes.reflect.Printer.TreeStructure) // Check that we can traverse the full tree
()
}
val tastyFiles = scalaLibTastyPaths.filterNot(blacklisted)
val isSuccess = TastyInspector.inspectTastyFiles(tastyFiles.map(x => scalaLibClassesPath.resolve(x).toString))(inspector)
assert(isSuccess, "Errors reported while loading from TASTy")

/** Set of tasty files that cannot be loaded from TASTy */
def loadBlacklisted = Set[String](
// No issues :)
)