rostest_main.cpp
Go to the documentation of this file.
1 
2 #define CATCH_CONFIG_RUNNER
3 #include <catch_ros/catch.hpp>
4 
5 #include "ros_junit_reporter.h"
6 
7 #include <boost/filesystem.hpp>
8 
9 #include <ros/init.h>
10 #include <ros/node_handle.h>
11 #include <ros/this_node.h>
12 
13 namespace fs = boost::filesystem;
14 
15 int main( int argc, char** argv )
16 {
17  ros::init(argc, argv, "catch_test");
18  ros::NodeHandle nh("~");
19 
20  Catch::Session session;
21 
22  // writing to session.configData() here sets defaults
23  // this is the preferred way to set them
24 
25  // Parse gtest-style output options
26  std::string test_output;
27  for(int i = 1; i < argc; ++i)
28  {
29  if(strncmp(argv[i], "--gtest_output=xml:", 19) == 0)
30  {
31  test_output = argv[i] + 19;
32 
33  // Remove this option from argc, argv
34  int j;
35  for(j = i; j < argc-1; ++j)
36  argv[j] = argv[j+1];
37  argc -= 1;
38  }
39  }
40 
41  if(!test_output.empty())
42  {
43  session.configData().reporterName = "ros_junit";
44  session.configData().outputFilename = test_output;
45  }
46 
47  int returnCode = session.applyCommandLine( argc, argv );
48  if( returnCode != 0 ) // Indicates a command line error
49  return returnCode;
50 
51  std::string nodeName = ros::this_node::getName();
52  std::replace(nodeName.begin(), nodeName.end(), '/', '_');
53  session.configData().name = session.configData().processName + nodeName;
54 
55  // The catkin scripts calling tests do not create the output directory for
56  // us :-(
57  if(!session.configData().outputFilename.empty())
58  {
59  fs::path outputPath = session.configData().outputFilename;
60 
61  fs::path outputDir = outputPath.parent_path();
62  if(!fs::exists(outputDir))
63  {
64  fs::create_directories(outputDir);
65  }
66  }
67 
68  return session.run();
69 }
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL const std::string & getName()


catch_ros
Author(s): Max Schwarz
autogenerated on Sat Jun 8 2019 17:59:58