[{"data":1,"prerenderedAt":816},["ShallowReactive",2],{"doc-logging":3},{"id":4,"title":5,"body":6,"description":68,"extension":808,"meta":809,"navigation":317,"path":810,"seo":811,"slug":812,"source":813,"stem":814,"__hash__":815},"docs\u002Fdocs\u002Flogging.md","Logging macros",{"type":7,"value":8,"toc":803},"minimark",[9,50,54,57,62,219,222,227,242,250,261,271,277,280,506,509,517,524,530,539,545,548,552,562,565,576,583,596,599,608,616,623,632,635,644,647,656,659,668,675,679,693,704,710,716,723,784,787,793,799],[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},"logging-macros",[13,55,56],{},"Catch2 provides various macros for logging extra information when\nrunning a test. These macros default to being scoped, and associate with\nall assertions in the scope, regardless of whether they pass or fail.",[13,58,59],{},[16,60,61],{},"example",[63,64,69],"pre",{"className":65,"code":66,"language":67,"meta":68,"style":68},"language-cpp shiki shiki-themes github-dark","TEST_CASE(\"Simple info\") {\n    INFO(\"Test case start\");\n    SECTION(\"A\") {\n        INFO(\"Section A\");\n        CHECK(false);        \u002F\u002F 1\n    }\n    SECTION(\"B\") {\n        INFO(\"Section B\");\n        CHECK(false);        \u002F\u002F 2\n    }\n    CHECK(false);            \u002F\u002F 3\n}\n","cpp","",[21,70,71,90,104,117,130,149,155,167,179,193,198,213],{"__ignoreMap":68},[72,73,76,79,83,87],"span",{"class":74,"line":75},"line",1,[72,77,23],{"class":78},"svObZ",[72,80,82],{"class":81},"s95oV","(",[72,84,86],{"class":85},"sU2Wk","\"Simple info\"",[72,88,89],{"class":81},") {\n",[72,91,93,96,98,101],{"class":74,"line":92},2,[72,94,95],{"class":78},"    INFO",[72,97,82],{"class":81},[72,99,100],{"class":85},"\"Test case start\"",[72,102,103],{"class":81},");\n",[72,105,107,110,112,115],{"class":74,"line":106},3,[72,108,109],{"class":78},"    SECTION",[72,111,82],{"class":81},[72,113,114],{"class":85},"\"A\"",[72,116,89],{"class":81},[72,118,120,123,125,128],{"class":74,"line":119},4,[72,121,122],{"class":78},"        INFO",[72,124,82],{"class":81},[72,126,127],{"class":85},"\"Section A\"",[72,129,103],{"class":81},[72,131,133,136,138,142,145],{"class":74,"line":132},5,[72,134,135],{"class":78},"        CHECK",[72,137,82],{"class":81},[72,139,141],{"class":140},"sDLfK","false",[72,143,144],{"class":81},");",[72,146,148],{"class":147},"sAwPA","        \u002F\u002F 1\n",[72,150,152],{"class":74,"line":151},6,[72,153,154],{"class":81},"    }\n",[72,156,158,160,162,165],{"class":74,"line":157},7,[72,159,109],{"class":78},[72,161,82],{"class":81},[72,163,164],{"class":85},"\"B\"",[72,166,89],{"class":81},[72,168,170,172,174,177],{"class":74,"line":169},8,[72,171,122],{"class":78},[72,173,82],{"class":81},[72,175,176],{"class":85},"\"Section B\"",[72,178,103],{"class":81},[72,180,182,184,186,188,190],{"class":74,"line":181},9,[72,183,135],{"class":78},[72,185,82],{"class":81},[72,187,141],{"class":140},[72,189,144],{"class":81},[72,191,192],{"class":147},"        \u002F\u002F 2\n",[72,194,196],{"class":74,"line":195},10,[72,197,154],{"class":81},[72,199,201,204,206,208,210],{"class":74,"line":200},11,[72,202,203],{"class":78},"    CHECK",[72,205,82],{"class":81},[72,207,141],{"class":140},[72,209,144],{"class":81},[72,211,212],{"class":147},"            \u002F\u002F 3\n",[72,214,216],{"class":74,"line":215},12,[72,217,218],{"class":81},"}\n",[13,220,221],{},"The first assertion will report messages \"Test case start\", and \"Section A\"\nas extra information. The second one will report messages \"Test case\nstarted\" and \"Section B\", while the third one will only report \"Test case\nstarted\" as the extra info.",[223,224,226],"h2",{"id":225},"logging-outside-of-current-scope","Logging outside of current scope",[10,228,229],{},[13,230,231,234,235,241],{},[21,232,233],{},"UNSCOPED_INFO"," was ",[45,236,240],{"href":237,"rel":238},"https:\u002F\u002Fgithub.com\u002Fcatchorg\u002FCatch2\u002Fissues\u002F1522",[239],"nofollow","introduced"," in Catch2 2.7.0.",[10,243,244],{},[13,245,246,249],{},[21,247,248],{},"UNSCOPED_CAPTURE"," was introduced in Catch2 3.13.0.",[13,251,252,253,256,257,260],{},"The ",[21,254,255],{},"UNSCOPED_X"," macros are similar to their plain ",[21,258,259],{},"X"," macro counterparts,\nwith two key differences:",[262,263,264,268],"ul",{},[265,266,267],"li",{},"The lifetime of an unscoped message is not tied to its own scope.",[265,269,270],{},"An unscoped message can be reported by the first following assertion only, regardless of the result of that assertion.",[13,272,273,274,276],{},"In other words, the ",[21,275,255],{}," macros are useful to add extra information\nto the next assertion, e.g. from helper functions or inner scopes.",[13,278,279],{},"An example:",[63,281,283],{"className":65,"code":282,"language":67,"meta":68,"style":68},"void print_some_info() {\n    UNSCOPED_INFO(\"Info from helper\");\n}\n\nTEST_CASE(\"Baz\") {\n    print_some_info();\n    for (int i = 0; i \u003C 2; ++i) {\n        UNSCOPED_INFO(\"The number is \" \u003C\u003C i);\n    }\n    CHECK(false);\n}\n\nTEST_CASE(\"Qux\") {\n    INFO(\"First info\");\n    UNSCOPED_INFO(\"First unscoped info\");\n    CHECK(false);\n\n    INFO(\"Second info\");\n    UNSCOPED_INFO(\"Second unscoped info\");\n    CHECK(false);\n}\n",[21,284,285,297,309,313,319,330,338,376,392,396,406,410,414,426,438,450,461,466,478,490,501],{"__ignoreMap":68},[72,286,287,291,294],{"class":74,"line":75},[72,288,290],{"class":289},"snl16","void",[72,292,293],{"class":78}," print_some_info",[72,295,296],{"class":81},"() {\n",[72,298,299,302,304,307],{"class":74,"line":92},[72,300,301],{"class":78},"    UNSCOPED_INFO",[72,303,82],{"class":81},[72,305,306],{"class":85},"\"Info from helper\"",[72,308,103],{"class":81},[72,310,311],{"class":74,"line":106},[72,312,218],{"class":81},[72,314,315],{"class":74,"line":119},[72,316,318],{"emptyLinePlaceholder":317},true,"\n",[72,320,321,323,325,328],{"class":74,"line":132},[72,322,23],{"class":78},[72,324,82],{"class":81},[72,326,327],{"class":85},"\"Baz\"",[72,329,89],{"class":81},[72,331,332,335],{"class":74,"line":151},[72,333,334],{"class":78},"    print_some_info",[72,336,337],{"class":81},"();\n",[72,339,340,343,346,349,352,355,358,361,364,367,370,373],{"class":74,"line":157},[72,341,342],{"class":289},"    for",[72,344,345],{"class":81}," (",[72,347,348],{"class":289},"int",[72,350,351],{"class":81}," i ",[72,353,354],{"class":289},"=",[72,356,357],{"class":140}," 0",[72,359,360],{"class":81},"; i ",[72,362,363],{"class":289},"\u003C",[72,365,366],{"class":140}," 2",[72,368,369],{"class":81},"; ",[72,371,372],{"class":289},"++",[72,374,375],{"class":81},"i) {\n",[72,377,378,381,383,386,389],{"class":74,"line":169},[72,379,380],{"class":78},"        UNSCOPED_INFO",[72,382,82],{"class":81},[72,384,385],{"class":85},"\"The number is \"",[72,387,388],{"class":289}," \u003C\u003C",[72,390,391],{"class":81}," i);\n",[72,393,394],{"class":74,"line":181},[72,395,154],{"class":81},[72,397,398,400,402,404],{"class":74,"line":195},[72,399,203],{"class":78},[72,401,82],{"class":81},[72,403,141],{"class":140},[72,405,103],{"class":81},[72,407,408],{"class":74,"line":200},[72,409,218],{"class":81},[72,411,412],{"class":74,"line":215},[72,413,318],{"emptyLinePlaceholder":317},[72,415,417,419,421,424],{"class":74,"line":416},13,[72,418,23],{"class":78},[72,420,82],{"class":81},[72,422,423],{"class":85},"\"Qux\"",[72,425,89],{"class":81},[72,427,429,431,433,436],{"class":74,"line":428},14,[72,430,95],{"class":78},[72,432,82],{"class":81},[72,434,435],{"class":85},"\"First info\"",[72,437,103],{"class":81},[72,439,441,443,445,448],{"class":74,"line":440},15,[72,442,301],{"class":78},[72,444,82],{"class":81},[72,446,447],{"class":85},"\"First unscoped info\"",[72,449,103],{"class":81},[72,451,453,455,457,459],{"class":74,"line":452},16,[72,454,203],{"class":78},[72,456,82],{"class":81},[72,458,141],{"class":140},[72,460,103],{"class":81},[72,462,464],{"class":74,"line":463},17,[72,465,318],{"emptyLinePlaceholder":317},[72,467,469,471,473,476],{"class":74,"line":468},18,[72,470,95],{"class":78},[72,472,82],{"class":81},[72,474,475],{"class":85},"\"Second info\"",[72,477,103],{"class":81},[72,479,481,483,485,488],{"class":74,"line":480},19,[72,482,301],{"class":78},[72,484,82],{"class":81},[72,486,487],{"class":85},"\"Second unscoped info\"",[72,489,103],{"class":81},[72,491,493,495,497,499],{"class":74,"line":492},20,[72,494,203],{"class":78},[72,496,82],{"class":81},[72,498,141],{"class":140},[72,500,103],{"class":81},[72,502,504],{"class":74,"line":503},21,[72,505,218],{"class":81},[13,507,508],{},"\"Baz\" test case prints:",[63,510,515],{"className":511,"code":513,"language":514},[512],"language-text","Info from helper\nThe number is 0\nThe number is 1\n","text",[21,516,513],{"__ignoreMap":68},[13,518,519,520,523],{},"With \"Qux\" test case, two messages will be printed when the first ",[21,521,522],{},"CHECK"," fails:",[63,525,528],{"className":526,"code":527,"language":514},[512],"First info\nFirst unscoped info\n",[21,529,527],{"__ignoreMap":68},[13,531,532,533,535,536,538],{},"\"First unscoped info\" message will be cleared after the first ",[21,534,522],{},", while \"First info\" message will persist until the end of the test case. Therefore, when the second ",[21,537,522],{}," fails, three messages will be printed:",[63,540,543],{"className":541,"code":542,"language":514},[512],"First info\nSecond info\nSecond unscoped info\n",[21,544,542],{"__ignoreMap":68},[13,546,547],{},"Note that unscoped messages are not passed between test cases, even if\nthere were no assertions between them.",[223,549,551],{"id":550},"streaming-macros","Streaming macros",[13,553,554,555,558,559,561],{},"Apart from ",[21,556,557],{},"CAPTURE"," (and its close sibling, ",[21,560,248],{},"), message\nmacros support gradual streaming of messages and values in the same way\nthat the standard streams do.",[13,563,564],{},"E.g.:",[63,566,570],{"className":567,"code":568,"language":569,"meta":68,"style":68},"language-c++ shiki shiki-themes github-dark","INFO( \"The number is \" \u003C\u003C i );\n","c++",[21,571,572],{"__ignoreMap":68},[72,573,574],{"class":74,"line":75},[72,575,568],{},[13,577,578,579,582],{},"(Note that there is no initial ",[21,580,581],{},"\u003C\u003C"," - instead the insertion sequence is placed in parentheses.)\nThese macros come in three forms:",[13,584,585,588,589,588,593],{},[16,586,587],{},"INFO("," ",[590,591,592],"em",{},"message expression",[16,594,595],{},")",[13,597,598],{},"The message is logged to a buffer, but only reported with next assertions that are logged. This allows you to log contextual information in case of failures which is not shown during a successful test run (for the console reporter, without -s). Messages are removed from the buffer at the end of their scope, so may be used, for example, in loops.",[13,600,601,588,604,588,606],{},[16,602,603],{},"UNSCOPED_INFO(",[590,605,592],{},[16,607,595],{},[10,609,610],{},[13,611,612,241],{},[45,613,615],{"href":237,"rel":614},[239],"Introduced",[13,617,618,619,622],{},"Similar to ",[21,620,621],{},"INFO",", but messages are not limited to their own scope: They are removed from the buffer after each assertion, section or test case, whichever comes first.",[13,624,625,588,628,588,630],{},[16,626,627],{},"WARN(",[590,629,592],{},[16,631,595],{},[13,633,634],{},"The message is always reported but does not fail the test.",[13,636,637,588,640,588,642],{},[16,638,639],{},"SUCCEED(",[590,641,592],{},[16,643,595],{},[13,645,646],{},"The message is reported and the test case succeeds.",[13,648,649,588,652,588,654],{},[16,650,651],{},"FAIL(",[590,653,592],{},[16,655,595],{},[13,657,658],{},"The message is reported and the test case fails.",[13,660,661,588,664,588,666],{},[16,662,663],{},"FAIL_CHECK(",[590,665,592],{},[16,667,595],{},[13,669,670,671,674],{},"AS ",[21,672,673],{},"FAIL",", but does not abort the test",[223,676,678],{"id":677},"quickly-capture-value-of-variables-or-expressions","Quickly capture value of variables or expressions",[13,680,681,588,684,36,687,690,691],{},[16,682,683],{},"CAPTURE(",[590,685,686],{},"expression1",[590,688,689],{},"expression2",", ... ",[16,692,595],{},[13,694,695,588,698,36,700,690,702],{},[16,696,697],{},"UNSCOPED_CAPTURE(",[590,699,686],{},[590,701,689],{},[16,703,595],{},[10,705,706],{},[13,707,708,249],{},[21,709,248],{},[13,711,712,713,715],{},"Sometimes you just want to log a value of variable, or expression. For\nconvenience, we provide the ",[21,714,557],{}," macro, that can take a variable,\nor an expression, and prints out that variable\u002Fexpression and its value\nat the time of capture.",[13,717,718,719,722],{},"e.g. ",[21,720,721],{},"CAPTURE( theAnswer );"," will log message \"theAnswer := 42\", while",[63,724,726],{"className":65,"code":725,"language":67,"meta":68,"style":68},"int a = 1, b = 2, c = 3;\nCAPTURE( a, b, c, a + b, c > b, a == 1);\n",[21,727,728,758],{"__ignoreMap":68},[72,729,730,732,735,737,740,743,745,747,750,752,755],{"class":74,"line":75},[72,731,348],{"class":289},[72,733,734],{"class":81}," a ",[72,736,354],{"class":289},[72,738,739],{"class":140}," 1",[72,741,742],{"class":81},", b ",[72,744,354],{"class":289},[72,746,366],{"class":140},[72,748,749],{"class":81},", c ",[72,751,354],{"class":289},[72,753,754],{"class":140}," 3",[72,756,757],{"class":81},";\n",[72,759,760,762,765,768,771,774,777,780,782],{"class":74,"line":92},[72,761,557],{"class":78},[72,763,764],{"class":81},"( a, b, c, a ",[72,766,767],{"class":289},"+",[72,769,770],{"class":81}," b, c ",[72,772,773],{"class":289},">",[72,775,776],{"class":81}," b, a ",[72,778,779],{"class":289},"==",[72,781,739],{"class":140},[72,783,103],{"class":81},[13,785,786],{},"will log a total of 6 messages:",[63,788,791],{"className":789,"code":790,"language":514},[512],"a := 1\nb := 2\nc := 3\na + b := 3\nc > b := true\na == 1 := true\n",[21,792,790],{"__ignoreMap":68},[13,794,795,796],{},"You can also capture expressions that use commas inside parentheses\n(e.g. function calls), brackets, or braces (e.g. initializers). To\nproperly capture expression that contains template parameters list\n(in other words, it contains commas between angle brackets), you need\nto enclose the expression inside parentheses:\n",[21,797,798],{},"CAPTURE( (std::pair\u003Cint, int>{1, 2}) );",[800,801,802],"style",{},"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 .svObZ, html code.shiki .svObZ{--shiki-default:#B392F0}html pre.shiki code .s95oV, html code.shiki .s95oV{--shiki-default:#E1E4E8}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}html pre.shiki code .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}html pre.shiki code .sAwPA, html code.shiki .sAwPA{--shiki-default:#6A737D}html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}",{"title":68,"searchDepth":92,"depth":92,"links":804},[805,806,807],{"id":225,"depth":92,"text":226},{"id":550,"depth":92,"text":551},{"id":677,"depth":92,"text":678},"md",{},"\u002Fdocs\u002Flogging",{"title":5,"description":68},"logging","docs\u002Flogging.md","docs\u002Flogging","h7UFyOM-Fvtn5PD7k31ZIdVa_sPYrKa447Ir7pEldLE",1794961594349]