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 } 20 21 /** 22 * Parses the command-line args and returns Options 23 */ 24 auto getOptions(string[] args) { 25 bool single; 26 bool debugOutput; 27 bool help; 28 bool list; 29 bool forceEscCodes; 30 bool random; 31 uint seed = unpredictableSeed; 32 bool stackTraces; 33 34 getopt(args, 35 "single|s", &single, //single-threaded 36 "debug|d", &debugOutput, //print debug output 37 "esccodes|e", &forceEscCodes, 38 "help|h", &help, 39 "list|l", &list, 40 "random|r", &random, 41 "seed", &seed, 42 "trace|t", &stackTraces, 43 ); 44 45 if(help) { 46 writeln("Usage: <progname> <options> <tests>...\n", 47 "Options: \n", 48 " -h/--help: help\n" 49 " -s/--single: single-threaded\n", 50 " -l/--list: list tests\n", 51 " -d/--debug: enable debug output\n", 52 " -e/--esccodes: force ANSI escape codes even for !isatty\n", 53 " -r/--random: run tests in random order\n", 54 " --seed: set the seed for the random order\n", 55 " -t/--trace: enable stack traces\n", 56 ); 57 } 58 59 if(debugOutput) { 60 if(!single) { 61 writeln("-d implies -s, running in a single thread\n"); 62 } 63 single = true; 64 } 65 66 if(random) { 67 if(!single) writeln("-r implies -s, running in a single thread\n"); 68 single = true; 69 } 70 71 immutable exit = help || list; 72 return Options(!single, args[1..$], debugOutput, list, exit, forceEscCodes, 73 random, seed, stackTraces); 74 }