LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
catch_main.cc
Go to the documentation of this file.
1 // vim: set sw=2 expandtab :
2 #define CATCH_CONFIG_RUNNER
3 #include "catch/catch.hpp"
4 
5 #include "cetlib/filepath_maker.h"
9 
10 #include <cstdlib>
11 #include <cstring>
12 #include <iostream>
13 #include <string>
14 
15 using namespace std;
16 using namespace std::string_literals;
17 
18 [[noreturn]] void
19 usage(Catch::Session& session, string processName)
20 {
21  cout << "usage:\n " << processName << " [-h]\n";
22  cout << " " << processName << " <fhicl-config-file> [catch-options]+\n\n";
23  cout << "Catch usage:" << endl;
24  session.showHelp(processName + " <fhicl-config-file>");
25  exit(1);
26 }
27 
28 string
29 processOptions(Catch::Session& session, int& argc, char**& argv)
30 {
31  string processName(argv[0]);
32  auto slashPos = processName.find_last_of('/');
33  if (slashPos == string::npos) {
34  slashPos = 0ull;
35  }
36  if (slashPos > 0ull && slashPos < (processName.size() - 1)) {
37  processName = processName.substr(slashPos + 1);
38  }
39  string fhiclConfigFileName;
40  if (argc < 2) {
41  cout << "ERROR: expected at least one argument.\n\n";
42  usage(session, processName);
43  } else if ((strcmp("-h", argv[1]) == 0) ||
44  (strncmp("--h", argv[1], 3) == 0)) {
45  usage(session, processName);
46  } else {
47  fhiclConfigFileName = argv[1];
48  argv[1] = argv[0];
49  --argc;
50  ++argv;
51  }
52  return fhiclConfigFileName;
53 }
54 
55 int
56 main(int argc, char** argv)
57 {
58  Catch::Session catchSession;
59  auto const fhiclConfigFileName = processOptions(catchSession, argc, argv);
60  int result = catchSession.applyCommandLine(argc, argv);
61  if (result == 0) {
62  mf::SetIteration("JobSetup"s);
63  fhicl::ParameterSet msg_ps;
64  cet::filepath_maker fpm;
65  fhicl::make_ParameterSet(fhiclConfigFileName, fpm, msg_ps);
67  result = catchSession.run();
68  }
69  return (result < 0xff ? result : 0xff);
70 }
Float_t s
Definition: plot.C:23
void SetIteration(string const &val)
static G4UIterminal * session
string processOptions(Catch::Session &session, int &argc, char **&argv)
Definition: catch_main.cc:29
STL namespace.
void make_ParameterSet(intermediate_table const &tbl, ParameterSet &ps)
void StartMessageFacility(fhicl::ParameterSet const &pset, string const &applicationName)
void usage(Catch::Session &session, string processName)
Definition: catch_main.cc:19
int main(int argc, char **argv)
Definition: catch_main.cc:56