| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (InteractiveTestSettings.scala)

This example Scala source code file (InteractiveTestSettings.scala) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Scala source code examples by using tags.

All credit for the original source code belongs to; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Scala tags/keywords

commentstartdelimiter, compiler, interactivetestsettings, nsc, presentationcompilerinstance, reporter, settings, testoptionsfileextension, testsettings

The InteractiveTestSettings.scala Scala example source code

package interactive
package tests

import core.Reporter
import core.TestSettings

trait InteractiveTestSettings extends TestSettings with PresentationCompilerInstance {
  /** Character delimiter for comments in .opts file */
  private final val CommentStartDelimiter = "#"

  private final val TestOptionsFileExtension = "flags"

  /** Prepare the settings object. Load the .opts file and adjust all paths from the
   *  Unix-like syntax to the platform specific syntax. This is necessary so that a
   *  single .opts file can be used on all platforms.
   *  @note Bootclasspath is treated specially. If there is a -bootclasspath option in
   *        the file, the 'usejavacp' setting is set to false. This ensures that the
   *        bootclasspath takes precedence over the scala-library used to run the current
   *        test.
  override protected def prepareSettings(settings: Settings) {
    def adjustPaths(paths: settings.PathSetting*) {
      for (p <- paths if argsString.contains( p.value = {
        case '/' => separatorChar
        case ':' => pathSeparatorChar
        case c   => c

    // need this so that the classpath comes from what partest
    // instead of scala.home
    settings.usejavacp.value = !argsString.contains("-bootclasspath")

    // pass any options coming from outside
    settings.processArgumentString(argsString) match {
      case (false, rest) =>
        println("error processing arguments (unprocessed: %s)".format(rest))
      case _ => ()

    // Make the --sourcepath path provided in the .flags file (if any) relative to the test's base directory
      settings.sourcepath.value = (baseDir / Path(settings.sourcepath.value)).path

    adjustPaths(settings.bootclasspath, settings.classpath, settings.javabootclasspath, settings.sourcepath)

  /** If there's a file ending in .opts, read it and parse it for cmd line arguments. */
  protected val argsString = {
    val optsFile = outDir / "%s.%s".format(System.getProperty("partest.testname"), TestOptionsFileExtension)
    val str = try File(optsFile).slurp() catch {
      case e: => ""
    str.lines.filter(!_.startsWith(CommentStartDelimiter)).mkString(" ")

  override protected def printClassPath(implicit reporter: Reporter) {
    reporter.println("\toutDir: %s".format(outDir.path))
    reporter.println("\tbaseDir: %s".format(baseDir.path))
    reporter.println("\targsString: %s".format(argsString))

Other Scala source code examples

Here is a short list of links related to this Scala InteractiveTestSettings.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.