Exit before second main with -funittest

Ali Çehreli acehreli at yahoo.com
Fri Jul 30 03:45:21 UTC 2021


Almost all of my programs are in the following pattern:

import std.stdio;

void main(string[] args) {
   version (unittest) {
     // Don't execute the main program when unit testing
     return;
   }

   try {
     // Dispatch to the actual "main" function
     doIt(args);

   } catch (Exception exc) {
     // Note .msg because we don't want to print stack trace
     stderr.writefln!"ERROR: %s"(exc.msg);

   } catch (Error err) {
     // Note NO .msg because we DO want to print stack trace
     stderr.writefln!"ERROR: %s"(err);
   }
}

// This is the actual "main"
void doIt(string[] args) {
   // ...
}

Ali



More information about the Digitalmars-d-learn mailing list