File: Test.scala

package info (click to toggle)
scala 2.11.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 62,924 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,135; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (35 lines) | stat: -rw-r--r-- 1,283 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import scala.reflect.io.Streamable
import scala.tools.asm.{ClassWriter, ClassReader}
import scala.tools.asm.tree.ClassNode
import scala.tools.partest._
import scala.tools.partest.BytecodeTest.modifyClassFile
import java.io.{FileOutputStream, FileInputStream, File}

object Test extends DirectTest {
  def code = ???

  def compileCode(code: String) = {
    val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator")
    compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(code)
  }

  def app = """
    object O {
      new test.Annotated
    }
  """

  def show(): Unit = {
    compileCode(app)
    modifyClassFile(new File(testOutput.toFile, "test/Annotated.class")) {
      (cn: ClassNode) =>
        // As investigated https://issues.scala-lang.org/browse/SI-2464?focusedCommentId=64521&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-64521
        // classfiles in the wild sometimes lack the required InnerClass attribute for nested enums that
        // are referenced in an annotation. I don't know what compiler or bytecode processor leaves things
        // that way, but this test makes sure we don't crash.
        cn.innerClasses.clear()
        cn
    }
    compileCode(app)
  }
}