// @(#)$Id: ExpectException.scala,v 1.1 2005/10/28 09:04:50 leavens Exp leavens $
package testing;

import scala.testing.SUnit;
import SUnit._; 

/** Test cases for simple expected results.
 * @author Gary T. Leavens
 */
class ExpectException[T](val code : String, value : => T) extends TestCase(code) {
  /** The message about the result. */   
  val threw = "       throws exception (as expected)";
  
  /** Method to run the code to produce the value,
   *  and to announce the result. */
  def evalAnnounce(code: String, value: => T): Unit = {
    Console.println(code);
    Console.flush;
    try {
      value;
      Console.println("Error!");
      fail(code);
    } catch {
      case _ => Console.println(threw);
    }
  }

  // doc comment inherited    
  override def runTest(): Unit = {
    evalAnnounce(code, value);
  }
}
