All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scala.tools.partest.StubErrorMessageTest.scala Maven / Gradle / Ivy

There is a newer version: 2.13.15
Show newest version
/*
 * Scala (https://www.scala-lang.org)
 *
 * Copyright EPFL and Lightbend, Inc.
 *
 * Licensed under Apache License 2.0
 * (http://www.apache.org/licenses/LICENSE-2.0).
 *
 * See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.
 */

package scala.tools.partest

trait StubErrorMessageTest extends StoreReporterDirectTest {
  // Stub to feed to partest, unused
  def code = throw new Error("Use `userCode` instead of `code`.")

  val classpath = List(sys.props("partest.lib"), testOutput.path)
    .mkString(sys.props("path.separator"))

  def compileCode(codes: String*) = {
    val global = newCompiler("-cp", classpath, "-d", testOutput.path)
    val sourceFiles = newSources(codes: _*)
    withRun(global)(_ compileSources sourceFiles)
  }

  def removeClasses(inPackage: String, classNames: Seq[String]): Unit = {
    val pkg = new File(testOutput.path, inPackage)
    classNames.foreach { className =>
      val classFile = new File(pkg, s"$className.class")
      assert(classFile.exists)
      assert(classFile.delete())
    }
  }

  def removeFromClasspath(): Unit
  def codeA: String
  def codeB: String
  def userCode: String
  def extraUserCode: String = ""

  def show(): Unit = {
    compileCode(codeA)
    assert(filteredInfos.isEmpty, filteredInfos)

    compileCode(codeB)
    assert(filteredInfos.isEmpty, filteredInfos)
    removeFromClasspath()

    if (extraUserCode == "") compileCode(userCode)
    else compileCode(userCode, extraUserCode)
    import scala.reflect.internal.util.Position
    filteredInfos.sortBy(_.pos.point).foreach { report =>
      print(if (report.severity == storeReporter.ERROR) "error: " else "")
      println(Position.formatMessage(report.pos, report.msg, true))
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy