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  // Re-check the next argument, since rostest will *add* a
40  // --gtest_output argument on each retry.
41  // https://github.com/ros/ros_comm/blob/d9059f49d14b7baf4a58c7759deab1f019681f5b/tools/rostest/src/rostest/runner.py#L137
42  i -= 1;
43  }
44  }
45 
46  if(!test_output.empty())
47  {
48  session.configData().reporterName = "ros_junit";
49  session.configData().outputFilename = test_output;
50  }
51 
52  int returnCode = session.applyCommandLine( argc, argv );
53  if( returnCode != 0 ) // Indicates a command line error
54  return returnCode;
55 
56  std::string nodeName = ros::this_node::getName();
57  std::replace(nodeName.begin(), nodeName.end(), '/', '_');
58  session.configData().name = session.configData().processName + nodeName;
59 
60  // The catkin scripts calling tests do not create the output directory for
61  // us :-(
62  if(!session.configData().outputFilename.empty())
63  {
64  fs::path outputPath = session.configData().outputFilename;
65 
66  fs::path outputDir = outputPath.parent_path();
67  if(!fs::exists(outputDir))
68  {
69  fs::create_directories(outputDir);
70  }
71  }
72 
73  return session.run();
74 }
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 Thu Jan 14 2021 03:32:26