Direct-BT  2.3.1
Direct-BT - Direct Bluetooth Programming.
catch2_my_main.cpp
Go to the documentation of this file.
1 /*
2  * Author: Sven Gothel <sgothel@jausoft.com>
3  * Copyright (c) 2020 Gothel Software e.K.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  *************************************************************************
25  *
26  * Distributed under the Boost Software License, Version 1.0.
27  * (See accompanying file LICENSE_1_0.txt or copy at
28  * https://www.boost.org/LICENSE_1_0.txt)
29  *
30  * SPDX-License-Identifier: BSL-1.0
31  */
32 
33 #ifndef CATCH2_MY_MAIN_H
34 #define CATCH2_MY_MAIN_H
35 
36 #include <catch2/catch_amalgamated.hpp>
37 
38 /** Run w/o command-line args, i.e. default CI unit test. */
40 
41 /** Run w/ command-line arg '--perf_analysis'. */
43 
44 static char * extra_args[] = { (char*)"--use-colour", (char*)"no" };
45 static int extra_args_c = sizeof(extra_args) / sizeof(const char *);
46 
47 int main( int argc, char* argv[] )
48 {
49  Catch::Session session; // There must be exactly one instance
50 
51  catch_auto_run = ( 1 >= argc );
52 
53  int argc_2=0;
54  char* argv_2[argc+extra_args_c];
55 
56  for(int i=0; i<argc; i++) {
57  if( 0 == strcmp("--perf_analysis", argv[i]) ) {
58  catch_perf_analysis = true;
59  } else {
60  argv_2[argc_2++] = argv[i];
61  }
62  }
63  for(int i=0; i<extra_args_c; i++) {
64  argv_2[argc_2++] = extra_args[i];
65  }
66  fprintf(stderr, "argc %d -> %d, auto_run %d, perf_analysis %d\n",
67  argc, argc_2, catch_auto_run, catch_perf_analysis);
68  for(int i=0; i<argc_2; i++) {
69  printf("[%d] %s\n", i, argv_2[i]);
70  }
71 
72  // writing to session.configData() here sets defaults
73  // this is the preferred way to set them
74 
75  int returnCode = session.applyCommandLine( argc_2, argv_2 );
76 
77  if( returnCode != 0 ) { // Indicates a command line error
78  return returnCode;
79  }
80 
81  if( catch_auto_run ) {
82  const char* my_args[] = { argv[0],
83  "--benchmark-warmup-time", "1",
84  "--benchmark-confidence-interval", "0",
85  "--benchmark-samples", "1",
86  "--benchmark-resamples", "0",
87  "--benchmark-no-analysis"
88  };
89  int res = session.applyCommandLine( sizeof(my_args)/sizeof(char*), my_args );
90  if( 0 != res ) {
91  return res;
92  }
93  // Catch::Config& config = session.config();
94  }
95 
96  // writing to session.configData() or session.Config() here
97  // overrides command line args
98  // only do this if you know you need to
99 
100  int numFailed = session.run();
101 
102  // numFailed is clamped to 255 as some unices only use the lower 8 bits.
103  // This clamping has already been applied, so just return it here
104  // You can also do any post run clean-up here
105  return numFailed;
106 }
107 
108 #endif // CATCH2_MY_MAIN_H
109 
catch_auto_run
bool catch_auto_run
Run w/o command-line args, i.e.
Definition: catch2_my_main.cpp:39
main
int main(int argc, char *argv[])
Definition: catch2_my_main.cpp:47
extra_args_c
static int extra_args_c
Definition: catch2_my_main.cpp:45
extra_args
static char * extra_args[]
Definition: catch2_my_main.cpp:44
catch_perf_analysis
bool catch_perf_analysis
Run w/ command-line arg '–perf_analysis'.
Definition: catch2_my_main.cpp:42