|
| 1 | +package dotty.tools.dotc.core.tasty |
| 2 | + |
| 3 | +import java.io.{File => JFile, 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.core.Comments.CommentsContext |
| 15 | +import dotty.tools.dotc.core.Contexts.Context |
| 16 | +import dotty.tools.dotc.core.Decorators.{toTermName, toTypeName} |
| 17 | +import dotty.tools.dotc.core.Mode |
| 18 | +import dotty.tools.dotc.core.Names.Name |
| 19 | +import dotty.tools.dotc.interfaces.Diagnostic.ERROR |
| 20 | +import dotty.tools.dotc.reporting.TestReporter |
| 21 | +import dotty.tools.io.{Directory, File, Path} |
| 22 | + |
| 23 | +import dotty.tools.vulpix.TestConfiguration |
| 24 | + |
| 25 | +class PathPicklingTest { |
| 26 | + |
| 27 | + @Test def test(): Unit = { |
| 28 | + val out = JFile("out/testPathPickling") |
| 29 | + val cwd = JFile("").getAbsolutePath() |
| 30 | + delete(out) |
| 31 | + out.mkdir() |
| 32 | + |
| 33 | + // let's try to avoid potentially catastrophic things, shall we? |
| 34 | + require(!out.toString.contains(" ")) |
| 35 | + require(!cwd.toString.contains(" ")) |
| 36 | + |
| 37 | + val exitcode = |
| 38 | + val ignorantProcessLogger = ProcessLogger(_ => ()) |
| 39 | + Seq("sbt", s"scalac -d $out/out.jar -sourceroot tests/pos $cwd/tests/pos/i10430/lib.scala $cwd/tests/pos/i10430/app.scala").!(ignorantProcessLogger) |
| 40 | + |
| 41 | + assertTrue("Compilation failed.", exitcode == 0) |
| 42 | + |
| 43 | + val decompiled = |
| 44 | + Seq("sbt", s"scalac -decompile -print-tasty -color:never $out/out.jar").!! |
| 45 | + |
| 46 | + assertTrue(decompiled.contains(": i10430/lib.scala")) |
| 47 | + assertTrue(decompiled.contains(": i10430/app.scala")) |
| 48 | + assertTrue(decompiled.contains("[i10430/lib.scala]")) |
| 49 | + assertTrue(decompiled.contains("[i10430/app.scala]")) |
| 50 | + |
| 51 | + assertFalse(decompiled.contains(": i10430\\lib.scala")) |
| 52 | + assertFalse(decompiled.contains(": i10430\\app.scala")) |
| 53 | + assertFalse(decompiled.contains("[i10430\\lib.scala]")) |
| 54 | + assertFalse(decompiled.contains("[i10430\\app.scala]")) |
| 55 | + } |
| 56 | + |
| 57 | + private def delete(file: JFile): Unit = { |
| 58 | + if (file.isDirectory) file.listFiles.foreach(delete) |
| 59 | + try Files.delete(file.toPath) |
| 60 | + catch { |
| 61 | + case _: NoSuchFileException => // already deleted, everything's fine |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments