1 module unit_threaded.options; 2 3 import std.getopt; 4 import std.stdio; 5 import std.random; 6 import std.exception; 7 8 9 struct Options { 10 bool multiThreaded; 11 string[] testsToRun; 12 bool debugOutput; 13 bool list; 14 bool exit; 15 bool forceEscCodes; 16 bool random; 17 uint seed; 18 bool stackTraces; 19 bool showChrono; 20 } 21 22 /** 23 * Parses the command-line args and returns Options 24 */ 25 auto getOptions(string[] args) { 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 }