|
| 1 | +package dotty.tools.dotc.core.tasty |
| 2 | + |
| 3 | +import java.io.{File => JFile, ByteArrayOutputStream, IOException} |
| 4 | +import java.nio.file.{Files, NoSuchFileException, Path, Paths} |
| 5 | + |
| 6 | +import scala.sys.process._ |
| 7 | + |
| 8 | +import org.junit.Test |
| 9 | +import org.junit.Assert.{assertEquals, assertTrue, assertFalse, fail} |
| 10 | + |
| 11 | +import dotty.tools.dotc.ast.tpd |
| 12 | +import dotty.tools.dotc.ast.tpd.TreeOps |
| 13 | +import dotty.tools.dotc.{Driver, Main} |
| 14 | +import dotty.tools.dotc.decompiler |
| 15 | +import dotty.tools.dotc.core.Comments.CommentsContext |
| 16 | +import dotty.tools.dotc.core.Contexts.Context |
| 17 | +import dotty.tools.dotc.core.Decorators.{toTermName, toTypeName} |
| 18 | +import dotty.tools.dotc.core.Mode |
| 19 | +import dotty.tools.dotc.core.Names.Name |
| 20 | +import dotty.tools.dotc.interfaces.Diagnostic.ERROR |
| 21 | +import dotty.tools.dotc.reporting.TestReporter |
| 22 | +import dotty.tools.io.{Directory, File, Path} |
| 23 | + |
| 24 | +import dotty.tools.vulpix.TestConfiguration |
| 25 | + |
| 26 | +class PathPicklingTest { |
| 27 | + |
| 28 | + @Test def test(): Unit = { |
| 29 | + val out = JFile("out/testPathPickling") |
| 30 | + val cwd = JFile("").getAbsolutePath() |
| 31 | + delete(out) |
| 32 | + out.mkdir() |
| 33 | + |
| 34 | + locally { |
| 35 | + val ignorantProcessLogger = ProcessLogger(_ => ()) |
| 36 | + val options = TestConfiguration.defaultOptions |
| 37 | + .and("-d", s"$out/out.jar") |
| 38 | + .and("-sourceroot", "tests/pos") |
| 39 | + .and(s"$cwd/tests/pos/i10430/lib.scala", s"$cwd/tests/pos/i10430/app.scala") |
| 40 | + val reporter = TestReporter.reporter(System.out, logLevel = ERROR) |
| 41 | + val rep = Main.process(options.all, reporter) |
| 42 | + assertFalse("Compilation failed.", rep.hasErrors) |
| 43 | + } |
| 44 | + |
| 45 | + val decompiled = |
| 46 | + val outstream = new ByteArrayOutputStream() |
| 47 | + val options = TestConfiguration.defaultOptions |
| 48 | + .and("-print-tasty") |
| 49 | + .and("-color:never") |
| 50 | + .and(s"$out/out.jar") |
| 51 | + val reporter = TestReporter.reporter(System.out, logLevel = ERROR) |
| 52 | + val rep = Console.withOut(outstream) { |
| 53 | + decompiler.Main.process(options.all, reporter) |
| 54 | + } |
| 55 | + assertFalse("Decompilation failed.", rep.hasErrors) |
| 56 | + new String(outstream.toByteArray(), "UTF-8") |
| 57 | + |
| 58 | + assertTrue(decompiled.contains(": i10430/lib.scala")) |
| 59 | + assertTrue(decompiled.contains(": i10430/app.scala")) |
| 60 | + assertTrue(decompiled.contains("[i10430/lib.scala]")) |
| 61 | + assertTrue(decompiled.contains("[i10430/app.scala]")) |
| 62 | + |
| 63 | + assertFalse(decompiled.contains(": i10430\\lib.scala")) |
| 64 | + assertFalse(decompiled.contains(": i10430\\app.scala")) |
| 65 | + assertFalse(decompiled.contains("[i10430\\lib.scala]")) |
| 66 | + assertFalse(decompiled.contains("[i10430\\app.scala]")) |
| 67 | + } |
| 68 | + |
| 69 | + private def delete(file: JFile): Unit = { |
| 70 | + if (file.isDirectory) file.listFiles.foreach(delete) |
| 71 | + try Files.delete(file.toPath) |
| 72 | + catch { |
| 73 | + case _: NoSuchFileException => // already deleted, everything's fine |
| 74 | + } |
| 75 | + } |
| 76 | +} |
0 commit comments