logo

abstract class

sys::Test

sys::Obj
  sys::Test
   1  //
   2  // Copyright (c) 2006, Brian Frank and Andy Frank
   3  // Licensed under the Academic Free License version 3.0
   4  //
   5  // History:
   6  //   4 Jan 06  Brian Frank  Creation
   7  //
   8  
   9  **
  10  ** Test is the base for Fan unit tests.
  11  **
  12  abstract class Test
  13  {
  14  
  15  //////////////////////////////////////////////////////////////////////////
  16  // Constructor
  17  //////////////////////////////////////////////////////////////////////////
  18  
  19    **
  20    ** Protected constructor.
  21    **
  22    protected new make()
  23  
  24  //////////////////////////////////////////////////////////////////////////
  25  // Lifecycle
  26  //////////////////////////////////////////////////////////////////////////
  27  
  28    **
  29    ** Get a unique id for this run of the test method.  This id is
  30    ** guaranteed to be unique for the life of the VM.
  31    **
  32    Str id()
  33  
  34    **
  35    ** Setup is called before running each test method.
  36    **
  37    virtual Void setup()
  38  
  39    **
  40    ** Teardown is called after running every test method.
  41    **
  42    virtual Void teardown()
  43  
  44  //////////////////////////////////////////////////////////////////////////
  45  // Verify
  46  //////////////////////////////////////////////////////////////////////////
  47  
  48    **
  49    ** Verify that cond is true, otherwise throw a test
  50    ** failure exception.  If msg is non-null, include it
  51    ** in a failure exception.
  52    **
  53    Void verify(Bool cond, Str msg := null)
  54  
  55    **
  56    ** Verify that cond is false, otherwise throw a test
  57    ** failure exception.  If msg is non-null, include it
  58    ** in a failure exception.
  59    **
  60    Void verifyFalse(Bool cond, Str msg := null)
  61  
  62    **
  63    ** Verify that a == b, otherwise throw a test failure exception.
  64    ** If both a and b are nonnull, then this method also ensures
  65    ** that a.hash == b.hash, because any two objects which return
  66    ** true for equals() must also return the same hash code.  If
  67    ** msg is non-null, include it in failure exception.
  68    **
  69    Void verifyEq(Obj a, Obj b, Str msg := null)
  70  
  71    **
  72    ** Verify that a != b, otherwise throw a test failure exception.
  73    ** If msg is non-null, include it in failure exception.
  74    **
  75    Void verifyNotEq(Obj a, Obj b, Str msg := null)
  76  
  77    **
  78    ** Verify that a === b, otherwise throw a test failure exception.
  79    ** If msg is non-null, include it in failure exception.
  80    **
  81    Void verifySame(Obj a, Obj b, Str msg := null)
  82  
  83    **
  84    ** Verify that a !== b, otherwise throw a test* failure exception.
  85    ** If msg is non-null, include it in failure exception.
  86    **
  87    Void verifyNotSame(Obj a, Obj b, Str msg := null)
  88  
  89    **
  90    ** Verify that the function throws an Err of the
  91    ** exact same type as err (compare using === operator).
  92    **
  93    ** Examples:
  94    **   verifyErr(ParseErr.type) |,| { Int.fromStr("@#!") }
  95    **
  96    Void verifyErr(Type errType, |->Void| c)
  97  
  98    **
  99    ** Throw a test failure exception.  If msg is non-null, include
 100    ** it in the failure exception.
 101    **
 102    Void fail(Str msg := null)
 103  
 104  //////////////////////////////////////////////////////////////////////////
 105  // Utils
 106  //////////////////////////////////////////////////////////////////////////
 107  
 108    **
 109    ** Return a temporary test directory which may used as a scratch
 110    ** directory.  This directory is guaranteed to be created and empty
 111    ** the first time this method is called for a given test run.  This
 112    ** directory is also the same as the `Sys.appDir`.
 113    **
 114    File tempDir()
 115  
 116  }