summaryrefslogtreecommitdiff
path: root/src/partest-alternative/scala/tools/partest/Entities.scala
blob: bea505b5942737c57901ceb53b1d0cc5b340c03b (plain) (blame)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* NEST (New Scala Test)
 * Copyright 2007-2010 LAMP/EPFL
 * @author Philipp Haller
 */

package scala.tools
package partest

import nsc.io._

trait Entities {
  self: Universe =>

  abstract class TestEntity extends AbsTestEntity
                               with TestContribution
                               with TestHousekeeping
                               with TestAlarms
                               with EntityLogging
                               with CompilableTest
                               with ScriptableTest
                               with DiffableTest {
    def location: Path
    def category: TestCategory

    lazy val label          = location.stripExtension
    lazy val testClasspath  = returning(createClasspathString())(x => vtrace("testClasspath: " + x))

    /** Was this test successful? Calling this for the first time forces
     *  lazy val "process" which actually runs the test.
     */
    def isSuccess = process

    /** Some standard files, which may or may not be present.
     */
    def scalaOptsFile = withExtension("flags").toFile     // opts to scalac
    def javaOptsFile  = withExtension("javaopts").toFile  // opts to java (but not javac)
    def commandFile   = withExtension("cmds").toFile      // sequence of commands to execute
    def logFile       = withExtension("log").toFile       // collected output

    /** Some standard directories.
     */
    def outDir        = withExtension("obj").toDirectory  // output dir, e.g. files/pos/t14.obj
    def categoryDir   = location.parent.normalize         // category dir, e.g. files/pos/
    def sourcesDir    = location ifDirectory (_.normalize) getOrElse categoryDir

    /** Standard arguments for run, exec, diff.
     */
    def argumentsToRun  = List("Test", "jvm")
    def argumentsToExec = List(location.path)

    /** Using a .cmds file for a custom test sequence.
     */
    def commandList   = safeLines(commandFile)
    def testSequence  =
      if (commandFile.isFile && commandList.nonEmpty) commandList map customTestStep
      else category.testSequence

    def run()   = runScala(argumentsToRun)
    def exec()  = runExec(argumentsToExec)
    def diff()  = runDiff() // checkFile, logFile

    /** The memoized result of the test run.
     */
    private lazy val process = {
      val outcome   = runWrappers(testSequence.actions forall (f => f(this)))

      // an empty outcome means we've been interrupted and are shutting down.
      outcome getOrElse false
    }
  }

  case class TestDirectory(category: TestCategory, location: Directory) extends TestEntity { }
  case class TestFile(category: TestCategory, location: File) extends TestEntity { }
}