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