abstract_regression_test_generator.h
Go to the documentation of this file.
1 
8 #pragma once
14 
15 namespace illumina{ namespace interop { namespace unittest
16 {
21  template<class Model>
23  {
24  public:
27  public:
33  abstract_regression_test_generator(const std::string& test_dir, const int test_modifier=0) :
34  abstract_generator< Model >(test_modifier), m_test_dir(test_dir)
35  {
37  }
44  abstract_regression_test_generator(const std::string& run_folder,
45  const std::string& test_dir,
46  const int test_modifier=0) :
47  abstract_generator< Model >(test_modifier), m_run_folder(run_folder), m_test_dir(test_dir)
48  {
49  }
55  base_t operator()(const std::string& name)const
56  {
57  m_run_folder=name;
58  return clone(name);
59  }
65  virtual base_t clone(const std::string& name)const=0;
73  ::testing::AssertionResult generate(Model& expected, Model& actual, bool* skip_test)const
74  {
76  const std::string baseline_file = baseline();
77  if(!data.rebaseline())
78  {
79  const bool expected_found = read_expected(baseline_file, expected);
80  const bool actual_generated = generate_actual(m_run_folder, actual);
81  if(expected_found == actual_generated)
82  {
83  *skip_test = !expected_found;
84  return ::testing::AssertionSuccess();
85  }
86  if(!expected_found)
87  return ::testing::AssertionFailure() << "Failed to find baseline: " << baseline_file;
88  return ::testing::AssertionFailure() << "Failed to generate data for baseline: " << baseline_file;
89  }
90  else
91  {
92  try
93  {
94  if(generate_actual(m_run_folder, actual))
95  {
96  if(!write_actual(baseline_file, actual))
97  return ::testing::AssertionFailure() << "Failed to write baseline: " << baseline_file;
98  }
99  *skip_test = true;
100  }
101  catch(const std::exception& ex)
102  {
103  std::cerr << "Failed to generate baseline: " << baseline_file << " " << ex.what() << std::endl;
104  std::exit(1);
105  //return ::testing::AssertionFailure() << "Failed to generate baseline: " << baseline_file << " " << ex.what();
106  }
107  }
108  return ::testing::AssertionSuccess();
109  }
114  virtual std::string baseline()const
115  {
117  }
118 
119  protected:
126  virtual bool read_expected(const std::string& baseline_file, Model& expected)const=0;
133  virtual bool generate_actual(const std::string& run_folder, Model& actual)const=0;
139  virtual bool write_actual(const std::string& baseline_file, const Model& actual)const=0;
144  virtual base_t clone()const=0;
145 
146  protected:
148  mutable std::string m_run_folder;
150  std::string m_test_dir;
151  };
152 
158  inline void read_metrics_safe(model::metrics::run_metrics& metrics, const std::string& run_folder)
159  {
160  try{
161  metrics.read(run_folder);
162  }
164  }
165 
166 }}}
167 
Definition: enum_description.h:15
std::string basename(std::string const &source)
Definition: filesystem.cpp:95
Definition: generic_fixture.h:23
std::string combine(const std::string &path, const std::string &name)
Definition: filesystem.cpp:39
base_t operator()(const std::string &name) const
Definition: abstract_regression_test_generator.h:55
virtual bool read_expected(const std::string &baseline_file, Model &expected) const =0
abstract_regression_test_generator(const std::string &run_folder, const std::string &test_dir, const int test_modifier=0)
Definition: abstract_regression_test_generator.h:44
static regression_test_data & instance()
Definition: regression_test_data.h:33
void add_subdir(const std::string &path)
Definition: regression_test_data.h:100
virtual std::string baseline() const
Definition: abstract_regression_test_generator.h:114
::testing::AssertionResult generate(Model &expected, Model &actual, bool *skip_test) const
Definition: abstract_regression_test_generator.h:73
int test_modifier() const
Definition: generic_fixture.h:63
abstract_generator< Model >::parent_type base_t
Definition: abstract_regression_test_generator.h:26
void read_metrics_safe(model::metrics::run_metrics &metrics, const std::string &run_folder)
Definition: abstract_regression_test_generator.h:158
abstract_regression_test_generator(const std::string &test_dir, const int test_modifier=0)
Definition: abstract_regression_test_generator.h:33
std::string m_run_folder
Definition: abstract_regression_test_generator.h:148
Definition: abstract_regression_test_generator.h:22
virtual bool write_actual(const std::string &baseline_file, const Model &actual) const =0
std::string m_test_dir
Definition: abstract_regression_test_generator.h:150
virtual bool generate_actual(const std::string &run_folder, Model &actual) const =0
Definition: regression_test_data.h:18
void rebaseline(const bool rebase)
Definition: regression_test_data.h:82