diff --git a/scala2-library-tasty-tests/test/BootstrappedStdLibTASYyTest.scala b/scala2-library-tasty-tests/test/BootstrappedStdLibTASYyTest.scala index db810cd87f26..f05accd8c2ba 100644 --- a/scala2-library-tasty-tests/test/BootstrappedStdLibTASYyTest.scala +++ b/scala2-library-tasty-tests/test/BootstrappedStdLibTASYyTest.scala @@ -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)) @@ -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] @@ -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 = diff --git a/tests/run-tasty-inspector/scala2-library-test.scala b/tests/run-tasty-inspector/scala2-library-test.scala new file mode 100644 index 000000000000..15a251427d70 --- /dev/null +++ b/tests/run-tasty-inspector/scala2-library-test.scala @@ -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 :) +)