1 /** 2 Run-time options. 3 */ 4 module unit_threaded.runner.options; 5 6 7 /// 8 struct Options { 9 bool multiThreaded; 10 string[] testsToRun; 11 bool debugOutput; 12 bool list; 13 bool exit; 14 bool forceEscCodes; 15 bool random; 16 uint seed; 17 bool stackTraces; 18 bool showChrono; 19 bool quiet; 20 } 21 22 /** 23 * Parses the command-line args and returns Options 24 */ 25 auto getOptions(string[] args) { 26 27 import std.stdio: writeln; 28 import std.random: unpredictableSeed; 29 import std.getopt: getopt, defaultGetoptPrinter; 30 31 bool single; 32 bool debugOutput; 33 bool help; 34 bool list; 35 bool forceEscCodes; 36 bool random; 37 uint seed = unpredictableSeed; 38 bool stackTraces; 39 bool showChrono; 40 bool quiet; 41 42 auto helpInfo = 43 getopt(args, 44 "single|s", "Run in one thread", &single, 45 "debug|d", "Print debug output", &debugOutput, 46 "esccodes|e", "force ANSI escape codes even for !isatty", &forceEscCodes, 47 "list|l", "List available tests", &list, 48 "random|r", "Run tests in random order (in one thread)", &random, 49 "seed", "Set the seed for the random order execution", &seed, 50 "trace|t", "enable stack traces", &stackTraces, 51 "chrono|c", "Print execution time per test", &showChrono, 52 "q|quiet", "Only print information about failing tests", &quiet, 53 ); 54 55 if(helpInfo.helpWanted) { 56 help = true; 57 defaultGetoptPrinter("Usage: <progname> <options> <tests>...", helpInfo.options); 58 } 59 60 if(random) { 61 if(!single) writeln("-r implies -s, running in a single thread\n"); 62 single = true; 63 } 64 65 version(unitUnthreaded) 66 single = true; 67 68 immutable exit = help || list; 69 return Options(!single, args[1..$], debugOutput, list, exit, forceEscCodes, 70 random, seed, stackTraces, showChrono, quiet); 71 }