% $Id: TestingNoStop.oz,v 1.4 2010/02/16 03:17:23 leavens Exp leavens $ % % Assertion and testing procedures for Oz that do not stop % (you have to check the output) % % AUTHOR: Gary T. Leavens, using ideas from Jeff Balogh declare %% Assert that the argument is true. proc {Assert B} if {Not B} then {System.showInfo 'ASSERTION FAILED!'} end end %% Assert that the second argument is true. proc {AssertTrue Message B} if {Not B} then {System.showInfo 'ASSERTION FAILED: ' # Message} end end %% Assert that the second argument is false. proc {AssertFalse Message B} {AssertTrue Message {Not B}} end %% Mark an assumption that the argument is true. proc {Assume B} if {Not B} then {System.showInfo 'ASSUMPTION FAILED!'} end end %% Mark an assumption that the second argument is true. proc {AssumeTrue Message B} if {Not B} then {System.showInfo 'ASSUMPTION FAILED: ' # Message} end end %% Mark an assumption that the second argument is false. proc {AssumeFalse Message B} {AssumeTrue Message {Not B}} 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 output a failure message. proc {Test Actual Connective Expected} if Actual == Expected then {System.showInfo {Value.toVirtualString Actual 5 20} # ' ' # Connective # ' ' # {Value.toVirtualString Expected 5 20}} else {System.showInfo 'TEST FAILURE: ' # {Value.toVirtualString Actual 5 20} # ' ' # Connective # ' ' # {Value.toVirtualString Expected 5 20} } end end %% Test if Actual == Expected. %% If so, print a message, otherwise output a failure message. %% This assumes that Expected is a String. proc {TestString Actual Connective Expected} if Actual == Expected then %% they are equal, so Actual is also a String {System.showInfo Actual # ' ' # Connective # ' ' # Expected} else if {IsString Actual} then {System.showInfo 'TEST FAILURE: ' # Actual # ' ' # Connective # ' ' # Expected} else {System.showInfo 'TEST FAILURE: ' # {Value.toVirtualString Actual 5 20} # ' ' # Connective # ' ' # Expected} end end end %% Test if Actual == Expected. %% If so, print a message, otherwise output a failure message. %% This assumes that Expected is a . proc {TestLOS Actual Connective Expected} fun {Virtualize LOS} if LOS == nil then "n"#"il" else "[" # {FoldR LOS fun {$ X Res} '"'#X#'" '#Res end ""} # "]" end end in if Actual == Expected then %% they are equal, so Actual is also a {System.showInfo {Virtualize Actual} # ' ' # Connective # ' ' # {Virtualize Expected}} else if {IsList Actual} andthen {All Actual IsString} then {System.showInfo 'TEST FAILURE: ' # {Virtualize Actual} # ' ' # Connective # ' ' # {Virtualize Expected}} else {System.showInfo 'TEST FAILURE: ' # {Value.toVirtualString Actual 5 20} # ' ' # Connective # ' ' # {Virtualize Expected}} end end end