% $Id: Testing.oz,v 1.5 2007/08/19 18:19:10 leavens Exp leavens $ % % Assertion and testing procedures for Oz. % % AUTHOR: Gary T. Leavens functor $ import System(showInfo) export assert: Assert assume: Assume start: StartTesting test: Test define %% Assert that the argument is true. proc {Assert B} if {Not B} then {Exception.raiseError assertionFailed} end end %% Mark an assumption that the argument is true. proc {Assume B} if {Not B} then {Exception.raiseError assumptionFailed} end end %% Print a newline and a message that testing is beginning. proc {StartTesting Name} {System.showInfo ""} {System.showInfo 'Testing ' # Name # '...'} end %% Test if Actual == Expected. %% If so, print a message, otherwise throw an exception. proc {Test Actual Connective Expected} if Actual == Expected then {System.showInfo {Value.toVirtualString Actual 5 10} # ' ' # Connective # ' ' # {Value.toVirtualString Expected 5 10}} else {Exception.raiseError testFailed(actual:Actual connective:Connective expected:Expected debug:unit) } end end end