コード例 #1
0
  /**
   * If you have extra command line parameters, you may use this method to start CPUnit
   * after you have done your own. You should use {@link #get_cmd_line_parser()} to obtain
   * a parser which is already set up to accept the CPUnit specific command line parameters,
   * and then use CmdLineParser.add_legal to specify the arguments you expect in addition.
   * 
   * @param parser A parser contaiing the command line arguments, excluding the program name.
   *               I.e. from main(int& argc,char** args), the parser would be called as
   *               {@link CmdLineParser#parse(const int, const char**) parser.parse(arcg-1,args+1)}.
   * @return 0 if all tests succeed, and >0 elsewise.
  */
  int main(const CmdLineParser &parser) {

    AutoDisposer ad;
    try {
      CPUNIT_ITRACE("EntryPoint - Actual arguments:"<<parser.to_string());

      std::vector<std::string> patterns = parser.program_input();
      if (patterns.size() == 0) { 
	patterns.push_back("*");
      }
      
      if(parser.has_one_of("-h --help")) {
	usage();
	return 0;
      }
      if(parser.has_one_of("-L --list")) {
	list_tests(patterns);
	return 0;
      }
      if(parser.has_one_of("-V --version")) {
	print_version_info();
	return 0;
      }
      
      const bool verbose    = parser.has("-v") || parser.has("--verbose");
      const bool robust     = parser.has("-a") || parser.has("--all");
      const bool conformity = parser.has("--conformity");
      
      CPUNIT_ITRACE("EntryPoint - verbose="<<verbose<<" robust="<<robust<<" conformity="<<conformity);
      
      bool conform = true;
      if (conformity) {
	std::vector<std::string> conf_patterns = get_conformity_format(parser);
	const int num_conformity_breaches = conformity_report(patterns, conf_patterns[0], conf_patterns[1], conf_patterns[2], verbose, std::cout);
	std::cout<<"There where "<<num_conformity_breaches<<" conformity breaches."<<std::endl;
	conform = num_conformity_breaches == 0;
      }

      const std::string report_format = parser.value_of<std::string>(error_format_token);
      const double max_time = parser.value_of<double>(max_time_token);
      const std::vector<cpunit::ExecutionReport> result = cpunit::TestExecutionFacade().execute(patterns, max_time, verbose, robust);
      bool all_well = report_result(result, report_format, std::cout);
      
      int exit_value = 0;
      if (!all_well) {
	exit_value |= 0x1;
      }
      if(!conform) {
	exit_value |= 0x2;
      }
      return exit_value;
    } catch (AssertionException &e) {
      std::cout<<"Terminated due to AssertionException: "<<std::endl<<e.what()<<std::endl;
      return 1;
    }
  }
コード例 #2
0
 /**
  * Creates a command line parser initialized with default values.
  * @return a command line parser initialized with default values.
  */
 CmdLineParser get_cmd_line_parser() {
   CmdLineParser parser;
   parser.add_legal("-h --help -L --list -v --verbose -V --version -a --all -f --conformity --conformity-format --max-time");
   const int argc = 3;
   const char *defaults[argc] = {
     "--conformity-format=*Test|test_*|*",
     "-f=%p::%n - %m (%ts)%N(Registered at %f:%l)",
     "--max-time=1e+10",
   };
   parser.parse(argc, defaults);
   CPUNIT_ITRACE("EntryPoint - Default arguments:"<<parser.to_string());
   return parser;
 }