Manak  2.0.0
manak.hpp
Go to the documentation of this file.
1 
7 #ifndef MANAK_HPP_INCLUDED
8 #define MANAK_HPP_INCLUDED
9 
10 #include <functional>
11 
12 #include <manak/util/manak_env.hpp>
13 #include <manak/util/set_env.hpp>
14 
18 
20 
22 
24 
25 #include <manak/util/cli.hpp>
26 
27 namespace manak
28 {
29 
30 #ifdef MANAK_INIT
31 
36 inline bool manak_init_module()
37 {
39  #ifdef MANAK_CONFIG_FILE
40  #include MANAK_CONFIG_FILE
41  #endif // MANAK_CONFIG_FILE
42 
46  #ifdef MANAK_MANUAL_INIT_FUNCTION
47  MANAK_MANUAL_INIT_FUNCTION();
48  #endif // MANAK_MANUAL_INIT_FUNCTION
49 
52 
53  return true;
54 }
55 
62 inline int manak_main(int argc, char* argv[] )
63 {
64  bool output_format_html = true;
65  bool compare = false;
66 
67  if(manak::utils::cli::CLI::cmdOptionExists(argv, argv + argc, "-h"))
68  {
69  std::cout << "-h : For help" << std::endl;
70  std::cout << "-r regex : Only the cases satisfying the given regex will run." << std::endl;
71  std::cout << " Check out guide for supported regex expressions." << std::endl;
72  std::cout << "-o filename : Save output to given file." << std::endl;
73  std::cout << "-s filename : Save the result for comparison." << std::endl;
74  std::cout << "-c filename : Load the given file for comparison." << std::endl;
75  std::cout << "-f HTML : Save the output as HTML(Default)" << std::endl;
76  std::cout << " TXT : Save the output as text document" << std::endl;
77  exit(0);
78  }
79 
80  if(manak::utils::cli::CLI::cmdOptionExists(argv, argv + argc, "-v"))
81  {
82  std::cout << manak::GetVersionInfo() << std::endl;
83  exit(0);
84  }
85 
86  std::string pattern = "";
87  if(manak::utils::cli::CLI::cmdOptionExists(argv, argv + argc, "-r"))
88  {
89  char* c_pattern = manak::utils::cli::CLI::getCmdOption(argv,
90  argv + argc,
91  "-r");
92  if(c_pattern)
93  {
94  pattern = std::string(c_pattern);
95  }
96  else
97  {
98  std::cout << "No pattern given!" << std::endl;
99  exit(1);
100  }
101  }
102 
103  if(manak::utils::cli::CLI::cmdOptionExists(argv, argv + argc, "-f"))
104  {
105  std::string format = manak::utils::cli::CLI::getCmdOption(argv, argv + argc, "-f");
106  if(format == "TXT" || format == "txt")
107  output_format_html = false;
108  else if(format == "HTML" || format == "html");
109  else
110  {
111  std::cerr << "Unrecognized format \"" << format << "\"" << std::endl;
112  std::cerr << "For supported formats pass \"-h\"" << std::endl;
113  exit(1);
114  }
115  }
116 
117  std::string filename;
118 
119  if(manak::utils::cli::CLI::cmdOptionExists(argv, argv + argc, "-o"))
120  {
121  filename = std::string(manak::utils::cli::CLI::getCmdOption(argv, argv + argc, "-o"));
122  }
123  else
124  {
126 
127  if(output_format_html)
128  {
129  filename += ".html";
130  }
131  else
132  {
133  filename += ".txt";
134  }
135  }
136 
137  if(output_format_html)
138  {
141  }
142  else
143  {
145  }
146 
147  // call the default init function
149 
150  // Construct the running tree
151  ManakSuite::GetMasterSuite().Run("", pattern, compare);
152 
153  // Run the generated run tree and collect results
155 
156  if(manak::utils::cli::CLI::cmdOptionExists(argv, argv + argc, "-c"))
157  {
158  std::string filename(manak::utils::cli::CLI::getCmdOption(argv, argv + argc, "-c"));
159  std::ifstream com_file(filename);
161  }
162 
163  // Pass the results to registered output handlers
165 
166  if(manak::utils::cli::CLI::cmdOptionExists(argv, argv + argc, "-s"))
167  {
168  std::string filename(manak::utils::cli::CLI::getCmdOption(argv, argv + argc, "-s"));
169 
170  std::ofstream ss(filename);
172  ss.close();
173  }
174 
175  return 0;
176 }
177 
178 #else
179 bool manak_init_module();
180 
181 #endif // defind
182 
183 }; // namespace manak
184 
186 #ifdef MANAK_AUTO_MAIN
187 
188 int main(int argc, char* argv[])
189 {
190  return manak::manak_main(argc, argv);
191 }
192 
193 #endif // MANAK_AUTO_MAIN
194 
195 #endif // MANAK_HPP_INCLUDED
static char * getCmdOption(char **begin, char **end, const std::string &option)
Check if certain option is passed.
Definition: cli.hpp:27
MANAK_INLINE void Print()
static ManakSuite & GetMasterSuite()
Definition: manak_suite.hpp:41
const std::string & GetModuleName() const
Definition: manak_env.hpp:18
static ManakEnv & GlobalEnv()
Definition: manak_env.hpp:12
#define MANAK_MODULE_NAME
Set the module name for further use.
Definition: set_env.hpp:13
#define MANAK_DEFAULT_OUT_FILENAME
If no output file is given benchmarking statistics will be saved to this file.
Definition: set_env.hpp:19
MANAK_INLINE void LoadForComparison(std::istream &stream)
MANAK_INLINE bool Run(const std::string &uname="", const std::string &pattern="", const bool compare=false)
const std::string & Name() const
Definition: manak_suite.hpp:87
static ResultCollector & GlobalResultCollector()
std::string GetVersionInfo()
Returns the version information in string.
Definition: version.hpp:24
#define MANAK_STRINGIZE(X)
Converts the parameter into string.
Definition: macro_utils.hpp:13
MANAK_INLINE void Run()
static OutputManager & GlobalOutputManager()
static bool cmdOptionExists(char **begin, char **end, const std::string &option)
Get passed option.
Definition: cli.hpp:40
MANAK_INLINE void SaveForComparison(std::ostream &stream)
bool manak_init_module()
MANAK_INLINE void AddHandler(OutputHandler *handler)