https://github.com/akkartik/mu/blob/master/002test.cc
  1 //: A simple test harness. To create new tests, define functions starting with
  2 //: 'test_'. To run all tests so defined, run:
  3 //:   $ ./bootstrap 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*' scripts
 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 
 23 :(before "End Includes")
 24 #define CHECK(X) \
 25   if (Passed && !(X)) { \
 26     cerr << "\nF - " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): " << #X << '\n'; \
 27     Passed = false; \
 28     return;  /* Currently we stop at the very first failure. */ \
 29   }
 30 
 31 #define CHECK_EQ(X, Y) \
 32   if (Passed && (X) != (Y)) { \
 33     cerr << "\nF - " << __FUNCTION__ << "(" << __FILE__ << ":" << __LINE__ << "): " << #X << " == " << #Y << '\n'; \
 34     cerr << "  got " << (X) << '\n';  /* BEWARE: multiple eval */ \
 35     Passed = false; \
 36     return;  /* Currently we stop at the very first failure. */ \
 37   }
 38 
 39 :(before "End Reset")
 40 Passed = true;
 41 
 42 :(before "End Commandline Parsing")
 43 if (argc > 1 && is_equal(argv[1], "test")) {
 44   Run_tests = true;  --argc;  ++argv;  // shift 'test' out of co
#
#
#           The Nim Compiler
#        (c) Copyright 2013 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## This module implements destructors.

# included from sem.nim

# special marker values that indicates that we are
# 1) AnalyzingDestructor: currently analyzing the type for destructor
# generation (needed for recursive types)
# 2) DestructorIsTrivial: completed the analysis before and determined
# that the type has a trivial destructor
var analyzingDestructor, destructorIsTrivial: PSym
new(analyzingDestructor)
new(destructorIsTrivial)

var
  destructorName = getIdent"destroy_"
  destructorParam = getIdent"this_"
  destructorPragma = newIdentNode(getIdent"destructor", unknownLineInfo())

proc instantiateDestructor(c: PContext, typ: PType): PType

proc doDestructorStuff(c: PContext, s: PSym, n: PNode) =
  var t = s.typ.sons[1].skipTypes({tyVar})
  if t.kind == tyGenericInvocation:
    for i in 1 .. <t.sonsLen:
      if t.sons[i].kind != tyGenericParam: