[{"data":1,"prerenderedAt":613},["ShallowReactive",2],{"doc-own-main":3},{"id":4,"title":5,"body":6,"description":604,"extension":605,"meta":606,"navigation":123,"path":607,"seo":608,"slug":609,"source":610,"stem":611,"__hash__":612},"docs\u002Fdocs\u002Fown-main.md","Supplying main() yourself",{"type":7,"value":8,"toc":599},"minimark",[9,13,42,75,92,96,229,254,265,268,279,542,545,548,551,570,595],[10,11,5],"h1",{"id":12},"supplying-main-yourself",[14,15,16,20,23,28,30,34,36,40],"p",{},[17,18,19],"strong",{},"Contents",[21,22],"br",{},[24,25,27],"a",{"href":26},"#run-the-tests-from-your-own-main","Run the tests from your own main",[21,29],{},[24,31,33],{"href":32},"#options-of-your-own","Options of your own",[21,35],{},[24,37,39],{"href":38},"#version-detection","Version detection",[21,41],{},[14,43,44,45,49,50,53,54,58,59,62,63,65,66,69,70,74],{},"The easiest way to use Catch3 is its own ",[46,47,48],"code",{},"main",": link against\n",[46,51,52],{},"Catch3::Catch3WithMain"," (the ",[24,55,57],{"href":56},"\u002Fdocs\u002Fcmake-integration\u002F#cmake-targets","CMake target",")\nor the ",[46,60,61],{},"catch3-with-main"," pkg-config file. To write your own ",[46,64,48],{},", link\nagainst ",[46,67,68],{},"Catch3::Catch3"," and hand the command line to the\n",[24,71,73],{"href":72},"\u002Fdocs\u002Fprogmasoft-runner\u002F","Catch3 runner",".",[14,76,77,78,80,81,83,84,87,88,91],{},"The runner starts the same binary again for its worker processes, with the\nsame ",[46,79,48],{},". Whatever ",[46,82,48],{}," does before and after ",[46,85,86],{},"run",", it also does in\nevery worker. That is usually what global set-up needs; when only the\nrunner's own process should do something, check whether the environment\nvariable ",[46,89,90],{},"CATCH3_WORKER"," is set, which it is only in workers.",[93,94,27],"h2",{"id":95},"run-the-tests-from-your-own-main",[97,98,103],"pre",{"className":99,"code":100,"language":101,"meta":102,"style":102},"language-cpp shiki shiki-themes github-dark","#include \u003CProgmasoft\u002FCatch3\u002FSession.hpp>\n\nint main( int argc, char* argv[] ) {\n  \u002F\u002F your setup ...\n\n  int result = Catch::Session().run( argc, argv );\n\n  \u002F\u002F your clean-up...\n\n  return result;\n}\n","cpp","",[46,104,105,118,125,157,164,169,198,203,209,214,223],{"__ignoreMap":102},[106,107,110,114],"span",{"class":108,"line":109},"line",1,[106,111,113],{"class":112},"snl16","#include",[106,115,117],{"class":116},"sU2Wk"," \u003CProgmasoft\u002FCatch3\u002FSession.hpp>\n",[106,119,121],{"class":108,"line":120},2,[106,122,124],{"emptyLinePlaceholder":123},true,"\n",[106,126,128,131,135,139,141,145,148,151,154],{"class":108,"line":127},3,[106,129,130],{"class":112},"int",[106,132,134],{"class":133},"svObZ"," main",[106,136,138],{"class":137},"s95oV","( ",[106,140,130],{"class":112},[106,142,144],{"class":143},"s9osk"," argc",[106,146,147],{"class":137},", ",[106,149,150],{"class":112},"char*",[106,152,153],{"class":143}," argv",[106,155,156],{"class":137},"[] ) {\n",[106,158,160],{"class":108,"line":159},4,[106,161,163],{"class":162},"sAwPA","  \u002F\u002F your setup ...\n",[106,165,167],{"class":108,"line":166},5,[106,168,124],{"emptyLinePlaceholder":123},[106,170,172,175,178,181,184,187,190,193,195],{"class":108,"line":171},6,[106,173,174],{"class":112},"  int",[106,176,177],{"class":137}," result ",[106,179,180],{"class":112},"=",[106,182,183],{"class":133}," Catch",[106,185,186],{"class":137},"::",[106,188,189],{"class":133},"Session",[106,191,192],{"class":137},"().",[106,194,86],{"class":133},[106,196,197],{"class":137},"( argc, argv );\n",[106,199,201],{"class":108,"line":200},7,[106,202,124],{"emptyLinePlaceholder":123},[106,204,206],{"class":108,"line":205},8,[106,207,208],{"class":162},"  \u002F\u002F your clean-up...\n",[106,210,212],{"class":108,"line":211},9,[106,213,124],{"emptyLinePlaceholder":123},[106,215,217,220],{"class":108,"line":216},10,[106,218,219],{"class":112},"  return",[106,221,222],{"class":137}," result;\n",[106,224,226],{"class":108,"line":225},11,[106,227,228],{"class":137},"}\n",[14,230,231,233,234,238,239,242,243,246,247,250,251,74],{},[46,232,86],{}," returns the ",[24,235,237],{"href":236},"\u002Fdocs\u002Fprogmasoft-runner\u002F#exit-codes","exit code",". A binary that\nneeds no ",[46,240,241],{},"Catch::Session"," may call ",[46,244,245],{},"Progmasoft::Catch3::RunTests",", from\n",[46,248,249],{},"\u003CProgmasoft\u002FCatch3\u002FRunner.hpp>",", with the arguments as a\n",[46,252,253],{},"std::vector\u003Cstd::string>",[14,255,256],{},[257,258,259,260,264],"em",{},"If you only want to run some set up before tests are run, it might be\nsimpler to use ",[24,261,263],{"href":262},"\u002Fdocs\u002Fevent-listeners\u002F","event listeners"," instead.",[93,266,33],{"id":267},"options-of-your-own",[14,269,270,271,274,275,278],{},"Catch2's ",[46,272,273],{},"Session::cli()"," and ",[46,276,277],{},"Session::configData()"," went with Catch2's\nrunner. Take your own options out of the command line before passing the\nrest on; the runner treats an option it does not know as an error.",[97,280,282],{"className":99,"code":281,"language":101,"meta":102,"style":102},"int main( int argc, char* argv[] ) {\n  int height = 0;\n  std::vector\u003Cchar const*> arguments;\n  for ( int i = 0; i \u003C argc; ++i ) {\n      std::string const argument = argv[i];\n      if ( argument.rfind( \"--height=\", 0 ) == 0 ) {\n          height = std::atoi( argument.c_str() + 9 );\n      } else {\n          arguments.push_back( argv[i] );\n      }\n  }\n\n  return Catch::Session().run( static_cast\u003Cint>( arguments.size() ),\n                               arguments.data() );\n}\n",[46,283,284,304,320,342,373,394,426,459,470,481,486,491,496,525,537],{"__ignoreMap":102},[106,285,286,288,290,292,294,296,298,300,302],{"class":108,"line":109},[106,287,130],{"class":112},[106,289,134],{"class":133},[106,291,138],{"class":137},[106,293,130],{"class":112},[106,295,144],{"class":143},[106,297,147],{"class":137},[106,299,150],{"class":112},[106,301,153],{"class":143},[106,303,156],{"class":137},[106,305,306,308,311,313,317],{"class":108,"line":120},[106,307,174],{"class":112},[106,309,310],{"class":137}," height ",[106,312,180],{"class":112},[106,314,316],{"class":315},"sDLfK"," 0",[106,318,319],{"class":137},";\n",[106,321,322,325,327,330,333,336,339],{"class":108,"line":127},[106,323,324],{"class":133},"  std",[106,326,186],{"class":137},[106,328,329],{"class":133},"vector",[106,331,332],{"class":137},"\u003C",[106,334,335],{"class":112},"char",[106,337,338],{"class":112}," const*",[106,340,341],{"class":137},"> arguments;\n",[106,343,344,347,350,352,355,357,359,362,364,367,370],{"class":108,"line":159},[106,345,346],{"class":112},"  for",[106,348,349],{"class":137}," ( ",[106,351,130],{"class":112},[106,353,354],{"class":137}," i ",[106,356,180],{"class":112},[106,358,316],{"class":315},[106,360,361],{"class":137},"; i ",[106,363,332],{"class":112},[106,365,366],{"class":137}," argc; ",[106,368,369],{"class":112},"++",[106,371,372],{"class":137},"i ) {\n",[106,374,375,378,380,383,386,389,391],{"class":108,"line":166},[106,376,377],{"class":133},"      std",[106,379,186],{"class":137},[106,381,382],{"class":137},"string",[106,384,385],{"class":112}," const",[106,387,388],{"class":137}," argument ",[106,390,180],{"class":112},[106,392,393],{"class":137}," argv[i];\n",[106,395,396,399,402,405,407,410,412,415,418,421,423],{"class":108,"line":171},[106,397,398],{"class":112},"      if",[106,400,401],{"class":137}," ( argument.",[106,403,404],{"class":133},"rfind",[106,406,138],{"class":137},[106,408,409],{"class":116},"\"--height=\"",[106,411,147],{"class":137},[106,413,414],{"class":315},"0",[106,416,417],{"class":137}," ) ",[106,419,420],{"class":112},"==",[106,422,316],{"class":315},[106,424,425],{"class":137}," ) {\n",[106,427,428,431,433,436,438,441,444,447,450,453,456],{"class":108,"line":200},[106,429,430],{"class":137},"          height ",[106,432,180],{"class":112},[106,434,435],{"class":133}," std",[106,437,186],{"class":137},[106,439,440],{"class":133},"atoi",[106,442,443],{"class":137},"( argument.",[106,445,446],{"class":133},"c_str",[106,448,449],{"class":137},"() ",[106,451,452],{"class":112},"+",[106,454,455],{"class":315}," 9",[106,457,458],{"class":137}," );\n",[106,460,461,464,467],{"class":108,"line":205},[106,462,463],{"class":137},"      } ",[106,465,466],{"class":112},"else",[106,468,469],{"class":137}," {\n",[106,471,472,475,478],{"class":108,"line":211},[106,473,474],{"class":137},"          arguments.",[106,476,477],{"class":133},"push_back",[106,479,480],{"class":137},"( argv[i] );\n",[106,482,483],{"class":108,"line":216},[106,484,485],{"class":137},"      }\n",[106,487,488],{"class":108,"line":225},[106,489,490],{"class":137},"  }\n",[106,492,494],{"class":108,"line":493},12,[106,495,124],{"emptyLinePlaceholder":123},[106,497,499,501,503,505,507,509,511,513,516,519,522],{"class":108,"line":498},13,[106,500,219],{"class":112},[106,502,183],{"class":133},[106,504,186],{"class":137},[106,506,189],{"class":133},[106,508,192],{"class":137},[106,510,86],{"class":133},[106,512,138],{"class":137},[106,514,515],{"class":112},"static_cast\u003Cint>",[106,517,518],{"class":137},"( arguments.",[106,520,521],{"class":133},"size",[106,523,524],{"class":137},"() ),\n",[106,526,528,531,534],{"class":108,"line":527},14,[106,529,530],{"class":137},"                               arguments.",[106,532,533],{"class":133},"data",[106,535,536],{"class":137},"() );\n",[106,538,540],{"class":108,"line":539},15,[106,541,228],{"class":137},[14,543,544],{},"Workers are started with the runner's own options. A value the tests need\nin every worker belongs in the environment, which workers inherit.",[93,546,39],{"id":547},"version-detection",[14,549,550],{},"Catch2 provides a triplet of macros providing the header's version,",[552,553,554,560,565],"ul",{},[555,556,557],"li",{},[46,558,559],{},"CATCH_VERSION_MAJOR",[555,561,562],{},[46,563,564],{},"CATCH_VERSION_MINOR",[555,566,567],{},[46,568,569],{},"CATCH_VERSION_PATCH",[14,571,572,573,147,576,579,580,583,584,587,588,579,591,594],{},"these macros expand into a single number, that corresponds to the appropriate\npart of the version. As an example, given single header version v2.3.4,\nthe macros would expand into ",[46,574,575],{},"2",[46,577,578],{},"3",", and ",[46,581,582],{},"4"," respectively. The version of\nthe Catch3 runner is ",[46,585,586],{},"Progmasoft::Catch3::kVersion"," in\n",[46,589,590],{},"\u003CProgmasoft\u002FCatch3\u002FVersion.hpp>",[46,592,593],{},"--version"," prints it.",[596,597,598],"style",{},"html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}html pre.shiki code .svObZ, html code.shiki .svObZ{--shiki-default:#B392F0}html pre.shiki code .s95oV, html code.shiki .s95oV{--shiki-default:#E1E4E8}html pre.shiki code .s9osk, html code.shiki .s9osk{--shiki-default:#FFAB70}html pre.shiki code .sAwPA, html code.shiki .sAwPA{--shiki-default:#6A737D}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}",{"title":102,"searchDepth":120,"depth":120,"links":600},[601,602,603],{"id":95,"depth":120,"text":27},{"id":267,"depth":120,"text":33},{"id":547,"depth":120,"text":39},"ContentsRun the tests from your own mainOptions of your ownVersion detection","md",{},"\u002Fdocs\u002Fown-main",{"title":5,"description":604},"own-main","docs\u002Fown-main.md","docs\u002Fown-main","7byYF4hXJIG8jAXt0xTvB6kIiHAK8WQvwjvLDx98BJ0",1794961592297]