summaryrefslogtreecommitdiff
path: root/src/partest-alternative/scala/tools/partest/Categories.scala
blob: 172cca74b46c0f9bbc80bbcdfb5cdc5f3b045c8d (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
/*                     __                                               *\
**     ________ ___   / /  ___     Scala Parallel Testing               **
**    / __/ __// _ | / /  / _ |    (c) 2007-2010, LAMP/EPFL             **
**  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **
** /____/\___/_/ |_/____/_/ | |                                         **
**                          |/                                          **
\*                                                                      */

package scala.tools
package partest

import nsc.Settings
import nsc.io._
import nsc.util.{ ClassPath }

trait Categories {
  self: Universe =>

  trait TestCategory extends AbsTestCategory {
    def kind: String
    def startMessage: String = "Executing test group"
    def testSequence: TestSequence

    class TestSettings(entity: TestEntity, error: String => Unit) extends Settings(error) {
      def this(entity: TestEntity) = this(entity, Console println _)

      deprecation.value   = false
      encoding.value      = "ISO-8859-1"
      classpath.value     = entity.testClasspath
      outdir.value        = entity.outDir.path
    }

    def createSettings(entity: TestEntity): TestSettings = new TestSettings(entity)
    def createTest(location: Path): TestEntity =
      if (location.isFile) TestFile(this, location.toFile)
      else if (location.isDirectory) TestDirectory(this, location.toDirectory)
      else error("Failed to create test at '%s'" format location)

    /** Category test identification.
     */
    def denotesTestFile(p: Path)  = p.isFile && (p hasExtension "scala")
    def denotesTestDir(p: Path)   = p.isDirectory && !ignorePath(p)
    def denotesTest(p: Path)      = denotesTestDir(p) || denotesTestFile(p)

    /** This should verify that all necessary files are present.
     *  By default it delegates to denotesTest.
     */
    def denotesValidTest(p: Path) = denotesTest(p)
  }

  abstract class DirBasedCategory(val kind: String) extends TestCategory with CategoryContribution {
    lazy val root = Directory(src / kind).normalize
    def enumerate = root.list filter denotesTest map createTest toList

    /** Standard actions.  These can be overridden either on the
     *  Category level or by individual tests.
     */
    def compile: TestStep         = (_: TestEntity).compile()
    def checkFileRequired: TestStep  = (_: TestEntity).checkFileRequired
    def diff: TestStep            = (_: TestEntity).diff()
    def run: TestStep             = (_: TestEntity).run()
    def exec: TestStep            = (_: TestEntity).exec()

    /** Combinators.
     */
    def not(f: TestStep): TestStep = !f(_: TestEntity)

    override def toString = kind
  }
}