1 //: A simple test harness. To create new tests define functions starting with 2 //: 'test_'. To run all tests so defined, run: 3 //: $ ./mu test 4 //: 5 //: Every layer should include tests, and can reach into previous layers. 6 //: However, it seems like a good idea never to reach into tests from previous 7 //: layers. Every test should be a contract that always passes as originally 8 //: written, regardless of any later layers. Avoid writing 'temporary' tests 9 //: that are only meant to work until some layer. 10 11 :(before "End Types") 12 typedef void (*test_fn)(void); 13 :(before "Globals") 14 // move a global ahead into types that we can't generate an extern declaration for 15 const test_fn Tests[] = { 16 #include "test_list" // auto-generated; see 'build' script 17 }; 18 19 :(before "End Globals") 20 bool Run_tests = false; 21 bool Passed = true; // set this to false inside any test to indicate failure 22 long Num_failures = 0; 23 24 :(before "End Includes") 25 #define CHECK(X) \ 26 if (Passed && !(X)) { \ 27 cerr << "\nF - " << __FUNCTION__ << "("discard """ output: ''' a char: true a char: false an int: 5 an int: 6 a string: abc a string: I'm root! CMP false CMP true CMP true CMP false CMP true CMP true a: a b: b x: 5 y: 6 z: abc thaRootMan: I'm root! myDisc: enC c: Z enC Z ''' """ type SomeRootObj = object of RootObj thaRootMan: string TMyObj = object of SomeRootObj a, b: char x, y: int z: string TEnum = enum enA, enB, enC TMyCaseObj = object case myDisc: TEnum of enA: a: int of enB: b: string of enC: c: char proc p(x: char) = echo "a char: ", x <= 'a' proc p(x: int) = echo "an int: ", x proc p(x: string) = echo "a string: ", x proc myobj(a, b: char, x, y: int, z: string): TMyObj = result.a = a; result.b = b; result.x = x; result.y = y; result.z = z result.thaRootMan = "I'm root!" var x = myobj('a', 'b', 5, 6, "abc") var y = myobj('A', 'b', 5, 9, "abc") for f in fields(x): p f for a, b in fields(x, y): echo "CMP ", a == b for key, val in fieldPairs(x): echo key, ": ", val var co: TMyCaseObj co.myDisc =