[{"data":1,"prerenderedAt":1374},["ShallowReactive",2],{"doc-tutorial":3},{"id":4,"title":5,"body":6,"description":144,"extension":1367,"meta":1368,"navigation":246,"path":1369,"seo":1370,"slug":53,"source":1371,"stem":1372,"__hash__":1373},"docs\u002Fdocs\u002Ftutorial.md","Tutorial",{"type":7,"value":8,"toc":1357},"minimark",[9,50,54,98,102,127,130,138,228,425,433,446,570,573,581,593,599,662,667,670,700,707,710,713,725,1112,1129,1136,1269,1272,1275,1278,1311,1324,1327,1330,1342,1345,1353],[10,11,12],"blockquote",{},[13,14,15,19,20,24,25,28,29,32,33,36,37,36,40,43,44,49],"p",{},[16,17,18],"strong",{},"Catch3 compatibility reference:"," This page describes the test-writing API Catch3 shares with Catch2: the macros, such as ",[21,22,23],"code",{},"TEST_CASE"," and ",[21,26,27],{},"REQUIRE",", and the ",[21,30,31],{},"Catch::"," namespace keep Catch2's names. Headers and build names are Catch3's own (",[21,34,35],{},"\u003CProgmasoft\u002FCatch3\u002FTestMacros.hpp>",", ",[21,38,39],{},"find_package(Catch3)",[21,41,42],{},"Catch3::Catch3WithMain","). See ",[45,46,48],"a",{"href":47},"\u002Fdocs\u002Fprogmasoft-catch3\u002F","Catch3 additions"," for Progmasoft APIs.",[51,52,5],"h1",{"id":53},"tutorial",[13,55,56,59,62,66,68,72,74,78,80,84,86,90,92,96],{},[16,57,58],{},"Contents",[60,61],"br",{},[45,63,65],{"href":64},"#getting-catch3","Getting Catch3",[60,67],{},[45,69,71],{"href":70},"#writing-tests","Writing tests",[60,73],{},[45,75,77],{"href":76},"#test-cases-and-sections","Test cases and sections",[60,79],{},[45,81,83],{"href":82},"#bdd-style-testing","BDD style testing",[60,85],{},[45,87,89],{"href":88},"#data-and-type-driven-tests","Data and Type driven tests",[60,91],{},[45,93,95],{"href":94},"#next-steps","Next steps",[60,97],{},[99,100,65],"h2",{"id":101},"getting-catch3",[13,103,104,105,111,112,116,117,119,120,122,123,126],{},"Clone or consume ",[45,106,110],{"href":107,"rel":108},"https:\u002F\u002Fgithub.com\u002FProgmasoft\u002Fcatch3",[109],"nofollow","Progmasoft\u002Fcatch3",",\nthen use its ",[45,113,115],{"href":114},"\u002Fdocs\u002Fcmake-integration\u002F","CMake integration"," or another supported\nbuild system. The examples in this tutorial use the Catch2-compatible API:\nits macros and the ",[21,118,31],{}," namespace, from headers such as\n",[21,121,35],{},".\nFor property tests, snapshots, and the result\u002FXML writer, continue with the\n",[45,124,125],{"href":47},"Progmasoft extensions",".",[99,128,71],{"id":129},"writing-tests",[13,131,132,133,137],{},"Let's start with a really simple example (",[45,134,21],{"href":135,"rel":136},"https:\u002F\u002Fgithub.com\u002FProgmasoft\u002Fcatch3\u002Fblob\u002Fdevel\u002Fexamples\u002F010-TestCase.cpp",[109],"). Say you have written a function to calculate factorials and now you want to test it (let's leave aside TDD for now).",[139,140,145],"pre",{"className":141,"code":142,"language":143,"meta":144,"style":144},"language-c++ shiki shiki-themes github-dark","unsigned int Factorial( unsigned int number ) {\n    return number \u003C= 1 ? number : Factorial(number-1)*number;\n}\n","c++","",[21,146,147,178,222],{"__ignoreMap":144},[148,149,152,156,159,163,167,169,171,175],"span",{"class":150,"line":151},"line",1,[148,153,155],{"class":154},"snl16","unsigned",[148,157,158],{"class":154}," int",[148,160,162],{"class":161},"svObZ"," Factorial",[148,164,166],{"class":165},"s95oV","( ",[148,168,155],{"class":154},[148,170,158],{"class":154},[148,172,174],{"class":173},"s9osk"," number",[148,176,177],{"class":165}," ) {\n",[148,179,181,184,187,190,194,197,199,202,204,207,210,213,216,219],{"class":150,"line":180},2,[148,182,183],{"class":154},"    return",[148,185,186],{"class":165}," number ",[148,188,189],{"class":154},"\u003C=",[148,191,193],{"class":192},"sDLfK"," 1",[148,195,196],{"class":154}," ?",[148,198,186],{"class":165},[148,200,201],{"class":154},":",[148,203,162],{"class":161},[148,205,206],{"class":165},"(number",[148,208,209],{"class":154},"-",[148,211,212],{"class":192},"1",[148,214,215],{"class":165},")",[148,217,218],{"class":154},"*",[148,220,221],{"class":165},"number;\n",[148,223,225],{"class":150,"line":224},3,[148,226,227],{"class":165},"}\n",[139,229,231],{"className":141,"code":230,"language":143,"meta":144,"style":144},"#include \u003CProgmasoft\u002FCatch3\u002FTestMacros.hpp>\n\nunsigned int Factorial( unsigned int number ) {\n    return number \u003C= 1 ? number : Factorial(number-1)*number;\n}\n\nTEST_CASE( \"Factorials are computed\", \"[factorial]\" ) {\n    REQUIRE( Factorial(1) == 1 );\n    REQUIRE( Factorial(2) == 2 );\n    REQUIRE( Factorial(3) == 6 );\n    REQUIRE( Factorial(10) == 3628800 );\n}\n",[21,232,233,242,248,266,297,302,307,324,351,374,397,420],{"__ignoreMap":144},[148,234,235,238],{"class":150,"line":151},[148,236,237],{"class":154},"#include",[148,239,241],{"class":240},"sU2Wk"," \u003CProgmasoft\u002FCatch3\u002FTestMacros.hpp>\n",[148,243,244],{"class":150,"line":180},[148,245,247],{"emptyLinePlaceholder":246},true,"\n",[148,249,250,252,254,256,258,260,262,264],{"class":150,"line":224},[148,251,155],{"class":154},[148,253,158],{"class":154},[148,255,162],{"class":161},[148,257,166],{"class":165},[148,259,155],{"class":154},[148,261,158],{"class":154},[148,263,174],{"class":173},[148,265,177],{"class":165},[148,267,269,271,273,275,277,279,281,283,285,287,289,291,293,295],{"class":150,"line":268},4,[148,270,183],{"class":154},[148,272,186],{"class":165},[148,274,189],{"class":154},[148,276,193],{"class":192},[148,278,196],{"class":154},[148,280,186],{"class":165},[148,282,201],{"class":154},[148,284,162],{"class":161},[148,286,206],{"class":165},[148,288,209],{"class":154},[148,290,212],{"class":192},[148,292,215],{"class":165},[148,294,218],{"class":154},[148,296,221],{"class":165},[148,298,300],{"class":150,"line":299},5,[148,301,227],{"class":165},[148,303,305],{"class":150,"line":304},6,[148,306,247],{"emptyLinePlaceholder":246},[148,308,310,312,314,317,319,322],{"class":150,"line":309},7,[148,311,23],{"class":161},[148,313,166],{"class":165},[148,315,316],{"class":240},"\"Factorials are computed\"",[148,318,36],{"class":165},[148,320,321],{"class":240},"\"[factorial]\"",[148,323,177],{"class":165},[148,325,327,330,332,335,338,340,343,346,348],{"class":150,"line":326},8,[148,328,329],{"class":161},"    REQUIRE",[148,331,166],{"class":165},[148,333,334],{"class":161},"Factorial",[148,336,337],{"class":165},"(",[148,339,212],{"class":192},[148,341,342],{"class":165},") ",[148,344,345],{"class":154},"==",[148,347,193],{"class":192},[148,349,350],{"class":165}," );\n",[148,352,354,356,358,360,362,365,367,369,372],{"class":150,"line":353},9,[148,355,329],{"class":161},[148,357,166],{"class":165},[148,359,334],{"class":161},[148,361,337],{"class":165},[148,363,364],{"class":192},"2",[148,366,342],{"class":165},[148,368,345],{"class":154},[148,370,371],{"class":192}," 2",[148,373,350],{"class":165},[148,375,377,379,381,383,385,388,390,392,395],{"class":150,"line":376},10,[148,378,329],{"class":161},[148,380,166],{"class":165},[148,382,334],{"class":161},[148,384,337],{"class":165},[148,386,387],{"class":192},"3",[148,389,342],{"class":165},[148,391,345],{"class":154},[148,393,394],{"class":192}," 6",[148,396,350],{"class":165},[148,398,400,402,404,406,408,411,413,415,418],{"class":150,"line":399},11,[148,401,329],{"class":161},[148,403,166],{"class":165},[148,405,334],{"class":161},[148,407,337],{"class":165},[148,409,410],{"class":192},"10",[148,412,342],{"class":165},[148,414,345],{"class":154},[148,416,417],{"class":192}," 3628800",[148,419,350],{"class":165},[148,421,423],{"class":150,"line":422},12,[148,424,227],{"class":165},[13,426,427,428,432],{},"This will compile to a complete executable which responds to ",[45,429,431],{"href":430},"\u002Fdocs\u002Fcommand-line\u002F","command line arguments",". If you just run it with no arguments it will execute all test cases (in this case there is just one) in parallel worker processes, report any failures and a summary, and exit with 0 when every test passed (useful for if you just want a yes\u002F no answer to: \"did it work\").",[13,434,435,436,439,440,445],{},"Anyway, as the tests above as written will pass, but there is a bug.\nThe problem is that ",[21,437,438],{},"Factorial(0)"," should return 1 (due to ",[45,441,444],{"href":442,"rel":443},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FFactorial#Factorial_of_zero",[109],"its\ndefinition",").\nLet's add that as an assertion to the test case:",[139,447,449],{"className":141,"code":448,"language":143,"meta":144,"style":144},"TEST_CASE( \"Factorials are computed\", \"[factorial]\" ) {\n    REQUIRE( Factorial(0) == 1 );\n    REQUIRE( Factorial(1) == 1 );\n    REQUIRE( Factorial(2) == 2 );\n    REQUIRE( Factorial(3) == 6 );\n    REQUIRE( Factorial(10) == 3628800 );\n}\n",[21,450,451,465,486,506,526,546,566],{"__ignoreMap":144},[148,452,453,455,457,459,461,463],{"class":150,"line":151},[148,454,23],{"class":161},[148,456,166],{"class":165},[148,458,316],{"class":240},[148,460,36],{"class":165},[148,462,321],{"class":240},[148,464,177],{"class":165},[148,466,467,469,471,473,475,478,480,482,484],{"class":150,"line":180},[148,468,329],{"class":161},[148,470,166],{"class":165},[148,472,334],{"class":161},[148,474,337],{"class":165},[148,476,477],{"class":192},"0",[148,479,342],{"class":165},[148,481,345],{"class":154},[148,483,193],{"class":192},[148,485,350],{"class":165},[148,487,488,490,492,494,496,498,500,502,504],{"class":150,"line":224},[148,489,329],{"class":161},[148,491,166],{"class":165},[148,493,334],{"class":161},[148,495,337],{"class":165},[148,497,212],{"class":192},[148,499,342],{"class":165},[148,501,345],{"class":154},[148,503,193],{"class":192},[148,505,350],{"class":165},[148,507,508,510,512,514,516,518,520,522,524],{"class":150,"line":268},[148,509,329],{"class":161},[148,511,166],{"class":165},[148,513,334],{"class":161},[148,515,337],{"class":165},[148,517,364],{"class":192},[148,519,342],{"class":165},[148,521,345],{"class":154},[148,523,371],{"class":192},[148,525,350],{"class":165},[148,527,528,530,532,534,536,538,540,542,544],{"class":150,"line":299},[148,529,329],{"class":161},[148,531,166],{"class":165},[148,533,334],{"class":161},[148,535,337],{"class":165},[148,537,387],{"class":192},[148,539,342],{"class":165},[148,541,345],{"class":154},[148,543,394],{"class":192},[148,545,350],{"class":165},[148,547,548,550,552,554,556,558,560,562,564],{"class":150,"line":304},[148,549,329],{"class":161},[148,551,166],{"class":165},[148,553,334],{"class":161},[148,555,337],{"class":165},[148,557,410],{"class":192},[148,559,342],{"class":165},[148,561,345],{"class":154},[148,563,417],{"class":192},[148,565,350],{"class":165},[148,567,568],{"class":150,"line":309},[148,569,227],{"class":165},[13,571,572],{},"After another compile & run cycle, we will see a test failure. The output\nwill look something like:",[139,574,579],{"className":575,"code":577,"language":578},[576],"language-text","Example.cpp:9: FAILED:\n  REQUIRE( Factorial(0) == 1 )\nwith expansion:\n  0 == 1\n","text",[21,580,577],{"__ignoreMap":144},[13,582,583,584,587,588,590,591,126],{},"Note that the output contains both the original expression,\n",[21,585,586],{},"REQUIRE( Factorial(0) == 1 )"," and the actual value returned by the call\nto the ",[21,589,334],{}," function: ",[21,592,477],{},[13,594,595,596,598],{},"We can fix this bug by slightly modifying the ",[21,597,334],{}," function to:",[139,600,602],{"className":141,"code":601,"language":143,"meta":144,"style":144},"unsigned int Factorial( unsigned int number ) {\n  return number > 1 ? Factorial(number-1)*number : 1;\n}\n",[21,603,604,622,658],{"__ignoreMap":144},[148,605,606,608,610,612,614,616,618,620],{"class":150,"line":151},[148,607,155],{"class":154},[148,609,158],{"class":154},[148,611,162],{"class":161},[148,613,166],{"class":165},[148,615,155],{"class":154},[148,617,158],{"class":154},[148,619,174],{"class":173},[148,621,177],{"class":165},[148,623,624,627,629,632,634,636,638,640,642,644,646,648,651,653,655],{"class":150,"line":180},[148,625,626],{"class":154},"  return",[148,628,186],{"class":165},[148,630,631],{"class":154},">",[148,633,193],{"class":192},[148,635,196],{"class":154},[148,637,162],{"class":161},[148,639,206],{"class":165},[148,641,209],{"class":154},[148,643,212],{"class":192},[148,645,215],{"class":165},[148,647,218],{"class":154},[148,649,650],{"class":165},"number ",[148,652,201],{"class":154},[148,654,193],{"class":192},[148,656,657],{"class":165},";\n",[148,659,660],{"class":150,"line":224},[148,661,227],{"class":165},[663,664,666],"h3",{"id":665},"what-did-we-do-here","What did we do here?",[13,668,669],{},"Although this was a simple test it's been enough to demonstrate a few\nthings about how Catch2 is used. Let's take a moment to consider those\nbefore we move on.",[671,672,673,684,694],"ul",{},[674,675,676,677,679,680,683],"li",{},"We introduce test cases with the ",[21,678,23],{}," macro. This macro takes\none or two string arguments - a free form test name and, optionally,\none or more tags (for more see ",[45,681,682],{"href":76},"Test cases and Sections",").",[674,685,686,687],{},"The test automatically self-registers with the test runner, and user\ndoes not have do anything more to ensure that it is picked up by the test\nframework. ",[688,689,690,691,126],"em",{},"Note that you can run specific test, or set of tests,\nthrough the ",[45,692,693],{"href":430},"command line",[674,695,696,697,699],{},"The individual test assertions are written using the ",[21,698,27],{}," macro.\nIt accepts a boolean expression, and uses expression templates to\ninternally decompose it, so that it can be individually stringified\non test failure.",[13,701,702,703,706],{},"On the last point, note that there are more testing macros available,\nbecause not all useful checks can be expressed as a simple boolean\nexpression. As an example, checking that an expression throws an exception\nis done with the ",[21,704,705],{},"REQUIRE_THROWS"," macro. More on that later.",[99,708,77],{"id":709},"test-cases-and-sections",[13,711,712],{},"Like most test frameworks, Catch2 supports a class-based fixture mechanism,\nwhere individual tests are methods on class and setup\u002Fteardown can be\ndone in constructor\u002Fdestructor of the type.",[13,714,715,716,719,720,724],{},"However, their use in Catch2 is rare, because idiomatic Catch2 tests\ninstead use ",[688,717,718],{},"sections"," to share setup and teardown code between test code.\nThis is best explained through an example (",[45,721,21],{"href":722,"rel":723},"https:\u002F\u002Fgithub.com\u002FProgmasoft\u002Fcatch3\u002Fblob\u002Fdevel\u002Fexamples\u002F100-Fix-Section.cpp",[109],"):",[139,726,728],{"className":141,"code":727,"language":143,"meta":144,"style":144},"TEST_CASE( \"vectors can be sized and resized\", \"[vector]\" ) {\n    \u002F\u002F This setup will be done 4 times in total, once for each section\n    std::vector\u003Cint> v( 5 );\n\n    REQUIRE( v.size() == 5 );\n    REQUIRE( v.capacity() >= 5 );\n\n    SECTION( \"resizing bigger changes size and capacity\" ) {\n        v.resize( 10 );\n\n        REQUIRE( v.size() == 10 );\n        REQUIRE( v.capacity() >= 10 );\n    }\n    SECTION( \"resizing smaller changes size but not capacity\" ) {\n        v.resize( 0 );\n\n        REQUIRE( v.size() == 0 );\n        REQUIRE( v.capacity() >= 5 );\n    }\n    SECTION( \"reserving bigger changes capacity but not size\" ) {\n        v.reserve( 10 );\n\n        REQUIRE( v.size() == 5 );\n        REQUIRE( v.capacity() >= 10 );\n    }\n    SECTION( \"reserving smaller does not change size or capacity\" ) {\n        v.reserve( 0 );\n\n        REQUIRE( v.size() == 5 );\n        REQUIRE( v.capacity() >= 5 );\n    }\n}\n",[21,729,730,746,752,782,786,806,824,828,840,854,858,876,892,898,910,923,928,946,963,968,980,994,999,1016,1033,1038,1050,1063,1068,1085,1102,1107],{"__ignoreMap":144},[148,731,732,734,736,739,741,744],{"class":150,"line":151},[148,733,23],{"class":161},[148,735,166],{"class":165},[148,737,738],{"class":240},"\"vectors can be sized and resized\"",[148,740,36],{"class":165},[148,742,743],{"class":240},"\"[vector]\"",[148,745,177],{"class":165},[148,747,748],{"class":150,"line":180},[148,749,751],{"class":750},"sAwPA","    \u002F\u002F This setup will be done 4 times in total, once for each section\n",[148,753,754,757,760,763,766,769,772,775,777,780],{"class":150,"line":224},[148,755,756],{"class":161},"    std",[148,758,759],{"class":165},"::",[148,761,762],{"class":161},"vector",[148,764,765],{"class":165},"\u003C",[148,767,768],{"class":154},"int",[148,770,771],{"class":165},"> ",[148,773,774],{"class":161},"v",[148,776,166],{"class":165},[148,778,779],{"class":192},"5",[148,781,350],{"class":165},[148,783,784],{"class":150,"line":268},[148,785,247],{"emptyLinePlaceholder":246},[148,787,788,790,793,796,799,801,804],{"class":150,"line":299},[148,789,329],{"class":161},[148,791,792],{"class":165},"( v.",[148,794,795],{"class":161},"size",[148,797,798],{"class":165},"() ",[148,800,345],{"class":154},[148,802,803],{"class":192}," 5",[148,805,350],{"class":165},[148,807,808,810,812,815,817,820,822],{"class":150,"line":304},[148,809,329],{"class":161},[148,811,792],{"class":165},[148,813,814],{"class":161},"capacity",[148,816,798],{"class":165},[148,818,819],{"class":154},">=",[148,821,803],{"class":192},[148,823,350],{"class":165},[148,825,826],{"class":150,"line":309},[148,827,247],{"emptyLinePlaceholder":246},[148,829,830,833,835,838],{"class":150,"line":326},[148,831,832],{"class":161},"    SECTION",[148,834,166],{"class":165},[148,836,837],{"class":240},"\"resizing bigger changes size and capacity\"",[148,839,177],{"class":165},[148,841,842,845,848,850,852],{"class":150,"line":353},[148,843,844],{"class":165},"        v.",[148,846,847],{"class":161},"resize",[148,849,166],{"class":165},[148,851,410],{"class":192},[148,853,350],{"class":165},[148,855,856],{"class":150,"line":376},[148,857,247],{"emptyLinePlaceholder":246},[148,859,860,863,865,867,869,871,874],{"class":150,"line":399},[148,861,862],{"class":161},"        REQUIRE",[148,864,792],{"class":165},[148,866,795],{"class":161},[148,868,798],{"class":165},[148,870,345],{"class":154},[148,872,873],{"class":192}," 10",[148,875,350],{"class":165},[148,877,878,880,882,884,886,888,890],{"class":150,"line":422},[148,879,862],{"class":161},[148,881,792],{"class":165},[148,883,814],{"class":161},[148,885,798],{"class":165},[148,887,819],{"class":154},[148,889,873],{"class":192},[148,891,350],{"class":165},[148,893,895],{"class":150,"line":894},13,[148,896,897],{"class":165},"    }\n",[148,899,901,903,905,908],{"class":150,"line":900},14,[148,902,832],{"class":161},[148,904,166],{"class":165},[148,906,907],{"class":240},"\"resizing smaller changes size but not capacity\"",[148,909,177],{"class":165},[148,911,913,915,917,919,921],{"class":150,"line":912},15,[148,914,844],{"class":165},[148,916,847],{"class":161},[148,918,166],{"class":165},[148,920,477],{"class":192},[148,922,350],{"class":165},[148,924,926],{"class":150,"line":925},16,[148,927,247],{"emptyLinePlaceholder":246},[148,929,931,933,935,937,939,941,944],{"class":150,"line":930},17,[148,932,862],{"class":161},[148,934,792],{"class":165},[148,936,795],{"class":161},[148,938,798],{"class":165},[148,940,345],{"class":154},[148,942,943],{"class":192}," 0",[148,945,350],{"class":165},[148,947,949,951,953,955,957,959,961],{"class":150,"line":948},18,[148,950,862],{"class":161},[148,952,792],{"class":165},[148,954,814],{"class":161},[148,956,798],{"class":165},[148,958,819],{"class":154},[148,960,803],{"class":192},[148,962,350],{"class":165},[148,964,966],{"class":150,"line":965},19,[148,967,897],{"class":165},[148,969,971,973,975,978],{"class":150,"line":970},20,[148,972,832],{"class":161},[148,974,166],{"class":165},[148,976,977],{"class":240},"\"reserving bigger changes capacity but not size\"",[148,979,177],{"class":165},[148,981,983,985,988,990,992],{"class":150,"line":982},21,[148,984,844],{"class":165},[148,986,987],{"class":161},"reserve",[148,989,166],{"class":165},[148,991,410],{"class":192},[148,993,350],{"class":165},[148,995,997],{"class":150,"line":996},22,[148,998,247],{"emptyLinePlaceholder":246},[148,1000,1002,1004,1006,1008,1010,1012,1014],{"class":150,"line":1001},23,[148,1003,862],{"class":161},[148,1005,792],{"class":165},[148,1007,795],{"class":161},[148,1009,798],{"class":165},[148,1011,345],{"class":154},[148,1013,803],{"class":192},[148,1015,350],{"class":165},[148,1017,1019,1021,1023,1025,1027,1029,1031],{"class":150,"line":1018},24,[148,1020,862],{"class":161},[148,1022,792],{"class":165},[148,1024,814],{"class":161},[148,1026,798],{"class":165},[148,1028,819],{"class":154},[148,1030,873],{"class":192},[148,1032,350],{"class":165},[148,1034,1036],{"class":150,"line":1035},25,[148,1037,897],{"class":165},[148,1039,1041,1043,1045,1048],{"class":150,"line":1040},26,[148,1042,832],{"class":161},[148,1044,166],{"class":165},[148,1046,1047],{"class":240},"\"reserving smaller does not change size or capacity\"",[148,1049,177],{"class":165},[148,1051,1053,1055,1057,1059,1061],{"class":150,"line":1052},27,[148,1054,844],{"class":165},[148,1056,987],{"class":161},[148,1058,166],{"class":165},[148,1060,477],{"class":192},[148,1062,350],{"class":165},[148,1064,1066],{"class":150,"line":1065},28,[148,1067,247],{"emptyLinePlaceholder":246},[148,1069,1071,1073,1075,1077,1079,1081,1083],{"class":150,"line":1070},29,[148,1072,862],{"class":161},[148,1074,792],{"class":165},[148,1076,795],{"class":161},[148,1078,798],{"class":165},[148,1080,345],{"class":154},[148,1082,803],{"class":192},[148,1084,350],{"class":165},[148,1086,1088,1090,1092,1094,1096,1098,1100],{"class":150,"line":1087},30,[148,1089,862],{"class":161},[148,1091,792],{"class":165},[148,1093,814],{"class":161},[148,1095,798],{"class":165},[148,1097,819],{"class":154},[148,1099,803],{"class":192},[148,1101,350],{"class":165},[148,1103,1105],{"class":150,"line":1104},31,[148,1106,897],{"class":165},[148,1108,1110],{"class":150,"line":1109},32,[148,1111,227],{"class":165},[13,1113,1114,1115,1118,1119,1121,1122,1125,1126,1128],{},"For each ",[21,1116,1117],{},"SECTION"," the ",[21,1120,23],{}," is ",[16,1123,1124],{},"executed from the start",". This means\nthat each section is entered with a freshly constructed vector ",[21,1127,774],{},", that\nwe know has size 5 and capacity at least 5, because the two assertions\nare also checked before the section is entered. This behaviour may not be\nideal for tests where setup is expensive. Each run through a test case will\nexecute one, and only one, leaf section.",[13,1130,1131,1132,1135],{},"Section can also be nested, in which case the parent section can be\nentered multiple times, once for each leaf section. Nested sections are\nmost useful when you have multiple tests that share part of the set up.\nTo continue on the vector example above, you could add a check that\n",[21,1133,1134],{},"std::vector::reserve"," does not remove unused excess capacity, like this:",[139,1137,1141],{"className":1138,"code":1139,"language":1140,"meta":144,"style":144},"language-cpp shiki shiki-themes github-dark","    SECTION( \"reserving bigger changes capacity but not size\" ) {\n        v.reserve( 10 );\n\n        REQUIRE( v.size() == 5 );\n        REQUIRE( v.capacity() >= 10 );\n        SECTION( \"reserving down unused capacity does not change capacity\" ) {\n            v.reserve( 7 );\n            REQUIRE( v.size() == 5 );\n            REQUIRE( v.capacity() >= 10 );\n        }\n    }\n","cpp",[21,1142,1143,1153,1165,1169,1185,1201,1213,1227,1244,1260,1265],{"__ignoreMap":144},[148,1144,1145,1147,1149,1151],{"class":150,"line":151},[148,1146,832],{"class":161},[148,1148,166],{"class":165},[148,1150,977],{"class":240},[148,1152,177],{"class":165},[148,1154,1155,1157,1159,1161,1163],{"class":150,"line":180},[148,1156,844],{"class":165},[148,1158,987],{"class":161},[148,1160,166],{"class":165},[148,1162,410],{"class":192},[148,1164,350],{"class":165},[148,1166,1167],{"class":150,"line":224},[148,1168,247],{"emptyLinePlaceholder":246},[148,1170,1171,1173,1175,1177,1179,1181,1183],{"class":150,"line":268},[148,1172,862],{"class":161},[148,1174,792],{"class":165},[148,1176,795],{"class":161},[148,1178,798],{"class":165},[148,1180,345],{"class":154},[148,1182,803],{"class":192},[148,1184,350],{"class":165},[148,1186,1187,1189,1191,1193,1195,1197,1199],{"class":150,"line":299},[148,1188,862],{"class":161},[148,1190,792],{"class":165},[148,1192,814],{"class":161},[148,1194,798],{"class":165},[148,1196,819],{"class":154},[148,1198,873],{"class":192},[148,1200,350],{"class":165},[148,1202,1203,1206,1208,1211],{"class":150,"line":304},[148,1204,1205],{"class":161},"        SECTION",[148,1207,166],{"class":165},[148,1209,1210],{"class":240},"\"reserving down unused capacity does not change capacity\"",[148,1212,177],{"class":165},[148,1214,1215,1218,1220,1222,1225],{"class":150,"line":309},[148,1216,1217],{"class":165},"            v.",[148,1219,987],{"class":161},[148,1221,166],{"class":165},[148,1223,1224],{"class":192},"7",[148,1226,350],{"class":165},[148,1228,1229,1232,1234,1236,1238,1240,1242],{"class":150,"line":326},[148,1230,1231],{"class":161},"            REQUIRE",[148,1233,792],{"class":165},[148,1235,795],{"class":161},[148,1237,798],{"class":165},[148,1239,345],{"class":154},[148,1241,803],{"class":192},[148,1243,350],{"class":165},[148,1245,1246,1248,1250,1252,1254,1256,1258],{"class":150,"line":353},[148,1247,1231],{"class":161},[148,1249,792],{"class":165},[148,1251,814],{"class":161},[148,1253,798],{"class":165},[148,1255,819],{"class":154},[148,1257,873],{"class":192},[148,1259,350],{"class":165},[148,1261,1262],{"class":150,"line":376},[148,1263,1264],{"class":165},"        }\n",[148,1266,1267],{"class":150,"line":399},[148,1268,897],{"class":165},[13,1270,1271],{},"Another way to look at sections is that they are a way to define a tree\nof paths through the test. Each section represents a node, and the final\ntree is walked in depth-first manner, with each path only visiting only\none leaf node.",[13,1273,1274],{},"There is no practical limit on nesting sections, as long as your compiler\ncan handle them, but keep in mind that overly nested sections can become\nunreadable. From experience, having section nest more than 3 levels is\nusually very hard to follow and not worth the removed duplication.",[99,1276,83],{"id":1277},"bdd-style-testing",[13,1279,1280,1281,24,1283,1286,1287,1290,1291,1293,1294,36,1297,36,1300,1303,1304,1307,1308,1310],{},"Catch2 also provides some basic support for BDD-style testing. There are\nmacro aliases for ",[21,1282,23],{},[21,1284,1285],{},"SECTIONS"," that you can use so that\nthe resulting tests read as BDD spec. ",[21,1288,1289],{},"SCENARIO"," acts as a ",[21,1292,23],{},"\nwith \"Scenario: \" name prefix. Then there are ",[21,1295,1296],{},"GIVEN",[21,1298,1299],{},"WHEN",[21,1301,1302],{},"THEN","\n(and their variants with ",[21,1305,1306],{},"AND_"," prefix), which act as a ",[21,1309,1117],{},",\nsimilarly prefixed with the macro name.",[13,1312,1313,1314,1318,1319,126],{},"For more details on the macros look at the ",[45,1315,1317],{"href":1316},"\u002Fdocs\u002Ftest-cases-and-sections\u002F","test cases and\nsections"," part of the reference docs,\nor at the ",[45,1320,1323],{"href":1321,"rel":1322},"https:\u002F\u002Fgithub.com\u002FProgmasoft\u002Fcatch3\u002Fblob\u002Fdevel\u002Fexamples\u002F120-Bdd-ScenarioGivenWhenThen.cpp",[109],"vector example done with BDD macros",[99,1325,89],{"id":1326},"data-and-type-driven-tests",[13,1328,1329],{},"Test cases in Catch2 can also be driven by types, input data, or both\nat the same time.",[13,1331,1332,1333,1337,1338,126],{},"For more details look into the Catch2 reference, either at the\n",[45,1334,1336],{"href":1335},"\u002Fdocs\u002Ftest-cases-and-sections\u002F#type-parametrised-test-cases","type parametrized test cases",",\nor ",[45,1339,1341],{"href":1340},"\u002Fdocs\u002Fgenerators\u002F","data generators",[99,1343,95],{"id":1344},"next-steps",[13,1346,1347,1348,1352],{},"This page is a brief introduction to get you up and running with Catch2,\nand to show the basic features of Catch2. The features mentioned here\ncan get you quite far, but there are many more. However, you can read\nabout these as you go, in the ever-growing ",[45,1349,1351],{"href":1350},"\u002Fdocs\u002F","reference section","\nof the documentation.",[1354,1355,1356],"style",{},"html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}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 .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}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 .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}html pre.shiki code .sAwPA, html code.shiki .sAwPA{--shiki-default:#6A737D}",{"title":144,"searchDepth":180,"depth":180,"links":1358},[1359,1360,1363,1364,1365,1366],{"id":101,"depth":180,"text":65},{"id":129,"depth":180,"text":71,"children":1361},[1362],{"id":665,"depth":224,"text":666},{"id":709,"depth":180,"text":77},{"id":1277,"depth":180,"text":83},{"id":1326,"depth":180,"text":89},{"id":1344,"depth":180,"text":95},"md",{},"\u002Fdocs\u002Ftutorial",{"title":5,"description":144},"docs\u002Ftutorial.md","docs\u002Ftutorial","MUX5DL4IhlFqpfhgYDUZESmY5ySuunFSZb5mPgEzuec",1794961594744]