ALPSCore reference
gtest_par_xml_output.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
7 #include <string>
8 #include <cstring>
9 
12 
13 namespace alps {
14 
15  void gtest_par_xml_output::operator()(unsigned int irank, int argc, char** argv)
16  {
17  if (argc<2) return;
18 
19  const std::string option_prefix="--gtest_output=xml";
20  const size_t prefix_len=option_prefix.size();
21  const std::string srank=std::to_string(irank);
22 
23  for (int i=1; i<argc; ++i) {
24  std::string arg(argv[i]);
25  if (arg.compare(0,prefix_len,option_prefix)!=0) continue; // starts with prefix?
26  arg.replace(0,prefix_len, "",0); // remove the prefix; arg is "argument" after "=xml"
27  std::string arg_new;
28  if (arg.empty()) { // "=xml"
29  arg_new=":test_details"+srank+".xml";
30  } else {
31  if (arg[0]!=':') continue;
32  if (arg[arg.size()-1]=='/') {
33  arg_new=arg.substr(0,arg.size()-1)+srank+"/";
34  } else {
35  std::string ext=alps::fs::get_extension(arg.substr(1,arg.size()-1));
36  arg_new=arg.substr(0,arg.size()-ext.size())
37  +srank+ext;
38  }
39  }
40  std::string new_argv_i=option_prefix+arg_new;
41  argv[i]=new char[new_argv_i.size()+1];
42  // std::cerr << "DEBUG: gtest_par_xml_output() allocate ptr=" << (void*)argv[i] << "\n";
43  keeper_.push_back(argv[i]);
44  strcpy(argv[i],new_argv_i.c_str());
45  }
46  }
47 
49  {
50  for(char* p : keeper_) {
51  // std::cerr << "DEBUG: gtest_par_xml_output() deallocate ptr=" << (void*)p << "\n";
52  delete[] p;
53  }
54  }
55 }
void operator()(unsigned int irank, int argc, char **argv)
Tweaks (argc,argv) to redirect GTest XML output to different files.
std::string get_extension(const std::string &filename)
Returns the file name extension.