Ejemplo n.º 1
0
std::auto_ptr<cpunit::TestRunner>
cpunit::TestExecutionFacade::get_test_runner(const bool robust, const double max_time) const {
  std::auto_ptr<TestRunner> leaf(new BasicTestRunner);

  if (robust) {
    CPUNIT_ITRACE("TestExecutionFacade::get_test_runner - Returning robust TestRunner");

    // For handling of extra, custom exceptions, insert your handler here,
    // and remember to modify the next decorator insertion...
    // std::auto_ptr<TestRunnerDecorator> d1(new MyCustomHandler);
    // d1->set_inner(leaf.release());

    // Add a layer of exception handling over the executing test runner
    std::auto_ptr<TestRunnerDecorator> d2(new RunAllTestRunner);
    d2->set_inner(leaf.release());

    // Add a layer of time taking
    std::auto_ptr<TestRunnerDecorator> d3(new TimeGuardRunner(max_time));
    d3->set_inner(d2.release());

    // Add a new layer of exception handling in case the max-time is exceeded
    std::auto_ptr<TestRunnerDecorator> d4(new RunAllTestRunner);
    d4->set_inner(d3.release());

    return std::auto_ptr<TestRunner>(d4.release());
  } else {
    CPUNIT_ITRACE("TestExecutionFacade::get_test_runner - Returning BasicTestRunner");

    // Add a layer of time taking over the executing test runner
    std::auto_ptr<TestRunnerDecorator> d1(new TimeGuardRunner(max_time));
    d1->set_inner(leaf.release());

    return std::auto_ptr<TestRunner>(d1.release());
  }
}
  /**
   * 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;
    }
  }
Ejemplo n.º 3
0
std::vector<cpunit::ExecutionReport>
cpunit::TestExecutionFacade::execute(const std::vector<std::string> &patterns, const double max_time, const bool verbose, const bool robust) {
  CPUNIT_ITRACE("TestExecutionFacade::execute Running subtree matching '"<<patterns<<"' in "<<(robust ? "" : "non-")<<"robust mode.");
  std::vector<TestUnit> tests;
  for (std::size_t i=0; i<patterns.size(); ++i) {
    std::vector<TestUnit> part = TestStore::get_instance().get_test_units(patterns[i]);
    tests.insert(tests.end(), part.begin(), part.end());
  }
  TestRunnerFactory trf(robust, max_time);
  return execute(tests, verbose, trf);
}
 /**
  * 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;
 }
Ejemplo n.º 5
0
cpunit::RunAllTestRunner::~RunAllTestRunner() {
  CPUNIT_ITRACE("RunAllTestRunner - destroyed.");
}
Ejemplo n.º 6
0
cpunit::RunAllTestRunner::RunAllTestRunner() :
  TestRunnerDecorator() {
  CPUNIT_ITRACE("RunAllTestRunner - instantiated.");
}