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