ssu
main.cpp
Go to the documentation of this file.
1 
8 #include <QTextStream>
9 #include <QRegExp>
10 #include <getopt.h>
11 
12 void usage()
13 {
14  QTextStream out(stderr);
15  out << "Parse QTest output on STDIN and make it shiny" << endl
16  << endl
17  << "Usage: formatoutput [options]" << endl
18  << endl
19  << "\t--skip-pass <yes|no> \tSkip PASS lines [yes]" << endl
20  << "\t--skip-debug <yes|no> \tSkip QDEBUG lines [yes]" << endl
21  << "\t--skip-warn <yes|no> \tSkip QWARN lines [no]" << endl
22  << "\t--skip-config <yes|no> \tSkip Config: lines [yes]" << endl
23  << endl
24  << "\t--help \tThis help text" << endl
25  << endl;
26 }
27 
28 bool isTrue(char *argument)
29 {
30  if (!strcasecmp(argument, "yes") ||
31  !strcasecmp(argument, "true") ||
32  !strcmp(argument, "1"))
33  return true;
34  else return false;
35 }
36 
37 int main(int argc, char **argv)
38 {
39  QTextStream in(stdin);
40  QTextStream out(stdout);
41  int c, option_index;
42 
43  static struct option long_options[] = {
44  {"skip-pass", required_argument, 0, 0 },
45  {"skip-debug", required_argument, 0, 0 },
46  {"skip-warn", required_argument, 0, 0 },
47  {"skip-config", required_argument, 0, 0 },
48  {"help", no_argument, 0, 0 }
49  };
50 
51  struct {
52  bool skip_pass = true;
53  bool skip_debug = true;
54  bool skip_warn = false;
55  bool skip_config = true;
56  } options;
57 
58  while ((c = getopt_long_only(argc, argv, "",
59  long_options, &option_index)) != EOF) {
60  switch (c) {
61  case 0:
62  if (!strcmp(long_options[option_index].name, "help")) {
63  usage();
64  exit(0);
65  } else if (!strcmp(long_options[option_index].name, "skip-pass")) {
66  options.skip_pass = isTrue(optarg);
67  } else if (!strcmp(long_options[option_index].name, "skip-debug")) {
68  options.skip_debug = isTrue(optarg);
69  } else if (!strcmp(long_options[option_index].name, "skip-warn")) {
70  options.skip_warn = isTrue(optarg);
71  } else if (!strcmp(long_options[option_index].name, "skip-config")) {
72  options.skip_config = isTrue(optarg);
73  }
74  break;
75  default:
76  usage();
77  exit(-1);
78  }
79  }
80 
81  while (!in.atEnd()) {
82  QString line = in.readLine();
83 
84  if (line.startsWith("PASS") && options.skip_pass) continue;
85  if (line.startsWith("QDEBUG") && options.skip_debug) continue;
86  if (line.startsWith("QWARN") && options.skip_warn) continue;
87  if (line.startsWith("Config:") && options.skip_config) continue;
88 
89  line.replace(QRegExp("^(\\*{3}.*\\*{3})"), "\033[0;36m\\1\033[0;0m");
90  line.replace(QRegExp("^(QDEBUG .*)"), "\033[0;90m\\1\033[0;0m");
91  line.replace(QRegExp("^(QWARN .*)"), "\033[0;34m\\1\033[0;0m");
92  line.replace(QRegExp("^FAIL!"), "\033[0;31mFAIL!\033[0;0m");
93  line.replace(QRegExp("^PASS"), "\033[0;32mPASS\033[0;0m");
94  line.replace(QRegExp("^Totals: (\\d{1,} passed), (\\d{1,} failed), (\\d{1,} skipped)"),
95  "Totals: \033[0;32m\\1\033[0;0m, \033[0;31m\\2\033[0;0m, \033[0;33m\\3\033[0;0m");
96  out << line << endl;
97  }
98 
99 }