alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (Categories.scala)

This example Scala source code file (Categories.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

categorycontribution, dirbasedcategory, executing, failed, path, path, string, string, testcategory, testentity, testentity, testsettings, teststep, teststep

The Scala Categories.scala source code

/*                     __                                               *\
**     ________ ___   / /  ___     Scala Parallel Testing               **
**    / __/ __// _ | / /  / _ |    (c) 2007-2011, 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
  }
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala Categories.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, alvinalexander.com
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.