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

Scala example source code file (ConsoleReporter.scala)

This example Scala source code file (ConsoleReporter.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

consolereporter, consolereporter, int, int, params, passed, passed, string, string, unit

The Scala ConsoleReporter.scala source code

/*-------------------------------------------------------------------------*\
**  ScalaCheck                                                             **
**  Copyright (c) 2007-2010 Rickard Nilsson. All rights reserved.          **
**  http://www.scalacheck.org                                              **
**                                                                         **
**  This software is released under the terms of the Revised BSD License.  **
**  There is NO WARRANTY. See the file LICENSE for the full text.          **
\*-------------------------------------------------------------------------*/

package org.scalacheck

import Pretty._
import util.FreqMap

class ConsoleReporter(val verbosity: Int) extends Test.TestCallback {

  private val prettyPrms = Params(verbosity)

  override def onPropEval(name: String, w: Int, s: Int, d: Int) = 
    if(verbosity > 0) {
      if(name == "") {
        if(d == 0) printf("\rPassed %s tests\r", s)
        else printf("\rPassed %s tests; %s discarded\r", s, d)
      } else {
        if(d == 0) printf("\r  %s: Passed %s tests\r", name, s)
        else printf("\r  %s: Passed %s tests; %s discarded\r", name, s, d)
      }
      Console.flush
    }

  override def onTestResult(name: String, res: Test.Result) = {
    if(name == "") {
      print(List.fill(78)(' ').mkString)
      val s = (if(res.passed) "+ " else "! ") + pretty(res, prettyPrms)
      printf("\r%s\n", format(s, "", "", 75))
    } else {
      print(List.fill(78)(' ').mkString)
      val s = (if(res.passed) "+ " else "! ") + name + ": " + 
        pretty(res, prettyPrms)
      printf("\r%s\n", format(s, "", "", 75))
    }
  }

}

object ConsoleReporter {

  /** Factory method, creates a ConsoleReporter with the
   *  the given verbosity */
  def apply(verbosity: Int = 0) = new ConsoleReporter(verbosity)

  @deprecated("(v1.8)")
  def propReport(s: Int, d: Int) = {
    if(d == 0) printf("\rPassed %s tests\r", s)
    else printf("\rPassed %s tests; %s discarded\r", s, d)
    Console.flush
  }

  @deprecated("(v1.8)")
  def propReport(pName: String, s: Int, d: Int) = {
    if(d == 0) printf("\r  %s: Passed %s tests\r", pName, s)
    else printf("\r  %s: Passed %s tests; %s discarded\r", pName, s, d)
    Console.flush
  }

  @deprecated("(v1.8)")
  def testReport(res: Test.Result) = {
    print(List.fill(78)(' ').mkString)
    val s = (if(res.passed) "+ " else "! ") + pretty(res, Params(0))
    printf("\r%s\n", format(s, "", "", 75))
    res
  }

  @deprecated("(v1.8)")
  def testStatsEx(res: Test.Result): Unit = testStatsEx("", res)

  def testStatsEx(msg: String, res: Test.Result) = {
    lazy val m = if(msg.length == 0) "" else msg + ": "
    res.status match {
      case Test.Proved(_) => {}
      case Test.Passed => {}
      case f @ Test.Failed(_, _) => sys.error(m + f)
      case Test.Exhausted => {}
      case f @ Test.GenException(_) => sys.error(m + f)
      case f @ Test.PropException(_, _, _) => sys.error(m + f)
    }
  }

}

Other Scala examples (source code examples)

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